Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZHA - add events for remote like devices #18493

Closed
wants to merge 17 commits into from

Conversation

dmulcahey
Copy link
Contributor

@dmulcahey dmulcahey commented Nov 15, 2018

The original motivation for this came from comments in #14795. I then opened PR #14902 which I closed due to it getting stale and hard to rebase easily. There was good feedback in that PR and I believe I managed to address most of the comments. That being said, I have changed direction a bit. This PR adds support for events for remote like devices. It also avoids breaking changes by leaving the original entities intact and functional.

This is opt in only. There is a new config file zha-remotes.json that has this shape:

{
    "Zigbee_home_automation": {
        "CentraLite": [
            "3130"
        ],
        "LUMI": [
            "lumi.sensor_switch.aq2"
        ],
        "OSRAM": [
            "LIGHTIFY Dimming Switch"
        ]
    },
    "Zigbee_light_link": {}
}

This allows users to opt into this functionality without needing HA releases to "remap" devices.

homeassistant/components/zha/event.py Outdated Show resolved Hide resolved
homeassistant/components/zha/__init__.py Outdated Show resolved Hide resolved
@dmulcahey dmulcahey changed the title ZHA - add events for remote like devices WIP - ZHA - add events for remote like devices Nov 16, 2018
homeassistant/components/zha/event.py Outdated Show resolved Hide resolved
homeassistant/components/zha/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/zha/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/zha/__init__.py Outdated Show resolved Hide resolved
@dmulcahey dmulcahey changed the title WIP - ZHA - add events for remote like devices ZHA - add events for remote like devices Nov 17, 2018
@dmulcahey dmulcahey closed this Nov 19, 2018
@dmulcahey dmulcahey reopened this Nov 19, 2018
@ghost ghost added in progress and removed in progress labels Nov 19, 2018
hass.data[DISCOVERY_KEY] = hass.data.get(DISCOVERY_KEY, {})
import homeassistant.components.zha.const as zha_const
Copy link
Member

Choose a reason for hiding this comment

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

This can be imported at the top of the module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a design issue w/ the modules that causes circular imports. I have it corrected in another branch and can fix this in a subsequent PR if that is ok.

@@ -177,8 +180,8 @@ def device_removed(self, device):
async def async_device_initialized(self, device, join):
"""Handle device joined and basic information discovered (async)."""
import zigpy.profiles
import homeassistant.components.zha.event as zha_event
Copy link
Member

Choose a reason for hiding this comment

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

See above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a design issue w/ the modules that causes circular imports. I have it corrected in another branch and can fix this in a subsequent PR if that is ok.

@@ -177,8 +180,8 @@ def device_removed(self, device):
async def async_device_initialized(self, device, join):
"""Handle device joined and basic information discovered (async)."""
import zigpy.profiles
import homeassistant.components.zha.event as zha_event
import homeassistant.components.zha.const as zha_const
Copy link
Member

Choose a reason for hiding this comment

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

Please move this too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a design issue w/ the modules that causes circular imports. I have it corrected in another branch and can fix this in a subsequent PR if that is ok.

homeassistant/components/zha/event.py Outdated Show resolved Hide resolved
homeassistant/components/zha/event.py Outdated Show resolved Hide resolved
homeassistant/components/zha/event.py Show resolved Hide resolved
_LOGGER.debug(
"remotes config path: %s Is path: %s",
remotes_config_path,
os.path.isfile(remotes_config_path)
Copy link
Member

Choose a reason for hiding this comment

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

This is doing I/O in an async context. That's not allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

any suggestions on how to handle? Should I just load this at the top of the module and not in the function?

{ZHA: {}, ZLL: {}}
)

remote_devices = load_json(remotes_config_path)
Copy link
Member

Choose a reason for hiding this comment

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

What are we doing here and what does it have to do with events? Looks like another feature, so should not be part of this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

without this nothing sends events. This is a registry so users can opt certain devices in to sending events. It is described in the PR description.

Copy link
Member

Choose a reason for hiding this comment

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

Why does it need to be configurable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are 100’s of zigbee devices and they don’t all follow defined specs. Also, there is no hard rule for what devices should use / need events. The alternative is a HA PR for every particular device that people want events from.

@dmulcahey
Copy link
Contributor Author

@MartinHjelmare Thanks a bunch for the help here and the comments. I think I have a much more elegant solution as a result that ditches the registration file. Closing this and I will open a new PR that references this one so that I can get your feedback. Thanks again!

@dmulcahey dmulcahey closed this Nov 20, 2018
@ghost ghost removed the in progress label Nov 20, 2018
@dmulcahey dmulcahey deleted the dm/new-remotes branch December 26, 2018 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants