Skip to content

Lutron component overhaul and improvements#36902

Closed
cdheiser wants to merge 8 commits intohome-assistant:devfrom
cdheiser:pylutron-upgrade
Closed

Lutron component overhaul and improvements#36902
cdheiser wants to merge 8 commits intohome-assistant:devfrom
cdheiser:pylutron-upgrade

Conversation

@cdheiser
Copy link
Contributor

@cdheiser cdheiser commented Jun 18, 2020

Proposed change

  • Upgrade pylutron to 0.2.7
  • Add support for configuring via the integrations UI
  • Bring in new unique IDs from pylutron
  • Properly define devices vs. entities
    • Keypads, Switches, Main Repeater, and Remotes are all devices
  • Add support for importing Area names and assignments from Lutron
    • Users can enable this to import areas and then turn it off to
      override specific devices.
  • Add services for press-and-hold, release, and tapping of buttons
    • This allows for the use of the alarm button where holding the
      holding the button is required to keep the alarm state active.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

@probot-home-assistant
Copy link

Hey there @JonGilmore, mind taking a look at this pull request as its been labeled with a integration (lutron) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

@JonGilmore
Copy link
Contributor

Excellent @cdheiser! I'll do some testing of this later today and get back to you

@cdheiser
Copy link
Contributor Author

I've rebased and fixed some of the lint errors. I have some outstanding PRs for pylutron to get in to clean up the rest.

1) Buttons
The LutronButton has been updated to support press (and hold), release,
and tap events.  This allows automations and other integrations to
activate buttons like an alarm.

2) Unique IDs.
pylutron 0.2.6 added support for unique IDs.  These have been added
to the entities here.
cdheiser added 2 commits June 19, 2020 17:59
- Make it possible to ask the AreaRegistry to return an area or create it if one does not exist.
- Make it possible for a device to assert which area it should be in.
  This is useful for integration with platforms that also have a concept of areas.
- Upgrade pylutron to 0.2.6
- Add support for configuring via the integrations UI
- Bring in new unique IDs from pylutron
- Properly define devices vs. entities
  - Keypads, Switches, Main Repeater, and Remotes are all devices
- Add support for importing Area names and assignments from Lutron
  - Users can enable this to import areas and then turn it off to
    override specific devices.
- Add services for press-and-hold, release, and tapping of buttons
  - This allows for the use of the alarm button where holding the
    holding the button is required to keep the alarm state active.
I accidentally dropped the update-after-add for adding entities with the
overhaul to use config entries and async code.
@JonGilmore
Copy link
Contributor

Just getting around to testing this out. Things are looking good, but I'm seeing some issues with text displaying correctly. For example, when you click options on the Lutron integration, you'll see empty text here:
image

Or, when you add the integration via the UI, it's missing text description labels as well:
image

cdheiser added 2 commits June 22, 2020 11:35
The new version of pylutron properly binds an OccupancyGroup to all areas as defined in the XML.
@cdheiser
Copy link
Contributor Author

cdheiser commented Jun 23, 2020 via email

@shenxn
Copy link
Contributor

shenxn commented Jun 24, 2020

@cdheiser You can use

python3 -m script.translations develop

to generate translation files to test locally. But do not commit the generated files.

@cdheiser
Copy link
Contributor Author

That's what I thought. Thanks for confirming. So @JonGilmore you can generate the right translation files locally to fill in the words.

And you really need to try turning on the option to use areas from Lutron. I can't believe it took me this long to suggest this PR.

cdheiser added a commit to cdheiser/home-assistant.io that referenced this pull request Jul 10, 2020
- Lutron now supports config_flow
- And also now has an optional setting via the UI to use Areas defined by the Lutron RadioRA2 system.
@cdheiser cdheiser marked this pull request as ready for review July 10, 2020 06:05
@cdheiser
Copy link
Contributor Author

This should now be ready to go. pylutron was updated today as was this PR

@JonGilmore
Copy link
Contributor

thanks @cdheiser - i'll be testing this out today and I'll get back to you with any feedback

@cdheiser
Copy link
Contributor Author

What's next?

@cdheiser
Copy link
Contributor Author

@homeassistant What's next?

@cdheiser
Copy link
Contributor Author

@JonGilmore you have any idea how to get someone assigned to accept and merge this PR?

@JonGilmore
Copy link
Contributor

JonGilmore commented Aug 1, 2020

@MartinHjelmare can you help us in getting this merged?

@cdheiser
Copy link
Contributor Author

cdheiser commented Aug 7, 2020 via email

@JonGilmore
Copy link
Contributor

@frenck could you help us out?

@cdheiser
Copy link
Contributor Author

cdheiser commented Aug 14, 2020 via email

@MartinHjelmare
Copy link
Member

Please be patient. We'll get to it.

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests for the config flow are missing. Please use the scaffold script to get started with that.

Have the area registry changes been discussed with the core team? I'm not sure we'll approve those.

from homeassistant import config_entries
from homeassistant.const import ATTR_ID, CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.helpers import discovery
from homeassistant.helpers import area_registry as ar, device_registry as dr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use longer variable names than two characters.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MartinHjelmare I'm asking to learn, but this example shows something very similar, so is the example incorrect?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This particular case is fine. Normally we want at minimum three characters.


async def async_setup_entry(hass, entry):
"""Set up a single Lutron deployment."""
if not entry.data:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would entry.data be falsy? That can't happen.

config = entry.data
device_registry = await dr.async_get_registry(hass)
area_registry = await ar.async_get_registry(hass)
hass_data = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please name this something that's not so easily confused with hass.data.

Suggested change
hass_data = {
lutron_data = {

},
}
hass.data[DOMAIN][entry.entry_id] = hass_data
hass_data[LUTRON_CONTROLLER] = Lutron(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hass_data[LUTRON_CONTROLLER] = Lutron(
controller = hass_data[LUTRON_CONTROLLER] = Lutron(


hass.data[LUTRON_CONTROLLER].load_xml_db()
hass.data[LUTRON_CONTROLLER].connect()
await hass.async_add_executor_job(hass_data[LUTRON_CONTROLLER].load_xml_db)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await hass.async_add_executor_job(hass_data[LUTRON_CONTROLLER].load_xml_db)
await hass.async_add_executor_job(controller.load_xml_db)

if user_input is None:
return self._show_setup_form()

await self.async_set_unique_id(user_input[CONF_HOST])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ip address is not allowed as unique id. Is this an ip address?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's no other good unique id, we can just check the existing config entries and make sure we don't set up another entry with the same host. Ie do this without using the unique id api.

await self.async_set_unique_id(user_input[CONF_HOST])
self._abort_if_unique_id_configured()

return self.async_create_entry(title=user_input[CONF_HOST], data=user_input)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before creating the entry we need to validate the connection to the controller.

"name": f"{self._area.name} {self._keypad.name}",
"manufacturer": "Lutron",
"model": self._keypad.type,
# "sw_version": self.light.swversion,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# "sw_version": self.light.swversion,

"name": f"{self._area.name} {self._keypad.name}",
"manufacturer": "Lutron",
"model": self._keypad.type,
# "sw_version": self.light.swversion,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# "sw_version": self.light.swversion,

return self.areas.values()

@callback
def async_get_or_create(self, name: str) -> AreaEntry:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be approved first by the core team. Has this been discussed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have the area registry changes been discussed with the core team? I'm not sure we'll approve those.

They have not. How would you suggest we proceed on that specifically? (I could separate them out into a different PR). This is incredibly useful for those of us with systems that have their own notion of areas. Generally speaking, this was the entire motivation for this entire overhaul.

I'll go over the other requested changes and config_flow tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please open an architecture issue.
https://github.com/home-assistant/architecture/issues

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to remove it from this PR if possible so we aren't blocked by that review.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created home-assistant/architecture#425 and a PR specifically for that functionality.

I'll rebase this PR and then split out the area integration support and work on the comments.

@stale
Copy link

stale bot commented Sep 20, 2020

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
Thank you for your contributions.

@stale stale bot added the stale label Sep 20, 2020
@cdheiser
Copy link
Contributor Author

I plan to get back to revising this in the next week or so.

@chrisaljoudi
Copy link
Contributor

@cdheiser @MartinHjelmare I know & appreciate you guys are busy—would you mind quickly sharing what all still needs to be done here? Happy to try and help.

@MartinHjelmare
Copy link
Member

The comments above need to be addressed.

@balloob
Copy link
Member

balloob commented Jan 13, 2021

This PR seems to have gone stale. Closing it.

@balloob balloob closed this Jan 13, 2021
@joshtbernstein
Copy link

joshtbernstein commented Feb 10, 2021

@cdheiser There's some good changes here. Would you have any interest in merging them in a new PR before the area stuff goes through? I'm happy to help in anyway that I'm able to.

@cdheiser
Copy link
Contributor Author

cdheiser commented Feb 12, 2021 via email

@joshtbernstein
Copy link

What would be the proper way to pick this up? Do I fork HA and manually add in your changes or do I start with your branch?

@cdheiser
Copy link
Contributor Author

cdheiser commented Mar 21, 2021 via email

@cdheiser
Copy link
Contributor Author

cdheiser commented Mar 22, 2021 via email

@joshtbernstein
Copy link

@cdheiser

You have a typo here, but after correcting that it loads and adds devices. I'll do some more testing over the next few days. Should we be tracking this somewhere else?

@home-assistant home-assistant locked and limited conversation to collaborators Mar 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants