-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
ZHA - add events for remote like devices #18493
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
Closed
Closed
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8c69c15
remote events
dmulcahey c4af1e2
refactor remote support
dmulcahey 9076fe5
add osram lightify dimmer
dmulcahey 3b1e44a
remove unused field and change event name
dmulcahey d050473
prefix events
dmulcahey e13745b
move event pieces to separate file
dmulcahey 857c2a2
cleanup
dmulcahey e3a4ff7
move events to ApplicationListener and cleanup
dmulcahey 867ad95
hound
dmulcahey d0194d4
hound
dmulcahey 3189973
load remote mappings from a file and fix populate_data
dmulcahey 0a0938b
lint
dmulcahey b3a0020
make config file more user friendly
dmulcahey f0a2d97
update debug info to make configuring automations easier
dmulcahey 93f38e1
hound
dmulcahey 9d6f00c
lint
dmulcahey 96445b2
remove debug logs - from review request
dmulcahey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import logging | ||
| from homeassistant.util import slugify | ||
| from homeassistant.core import EventOrigin, callback | ||
|
|
||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| async def _async_setup_event(hass, discovery_info): | ||
|
dmulcahey marked this conversation as resolved.
Outdated
|
||
| from homeassistant.components.zha import const as zha_const | ||
|
dmulcahey marked this conversation as resolved.
Outdated
|
||
| from homeassistant.components.zha import configure_reporting | ||
| out_clusters = discovery_info['out_clusters'] | ||
| in_clusters = discovery_info['in_clusters'] | ||
| for in_cluster in in_clusters: | ||
| event = ZHAEvent(hass, in_cluster, discovery_info) | ||
| if discovery_info['new_join']: | ||
| await configure_reporting(event.event_id, in_cluster, 0, | ||
| False, 0, 600, 1) | ||
| hass.data[zha_const.DATA_ZHA_EVENT].append( | ||
|
dmulcahey marked this conversation as resolved.
Outdated
|
||
| event | ||
| ) | ||
| for out_cluster in out_clusters: | ||
| event = ZHAEvent(hass, out_cluster, discovery_info) | ||
| if discovery_info['new_join']: | ||
| await configure_reporting(event.event_id, out_cluster, 0, | ||
| False, 0, 600, 1) | ||
| hass.data[zha_const.DATA_ZHA_EVENT].append( | ||
| event | ||
| ) | ||
|
|
||
|
|
||
| class ZHAEvent(object): | ||
| """When you want signals instead of entities. | ||
| Stateless sensors such as remotes are expected to generate an event | ||
| instead of a sensor entity in hass. | ||
| """ | ||
|
|
||
| def __init__(self, hass, cluster, discovery_info): | ||
| """Register callback that will be used for signals.""" | ||
| self._hass = hass | ||
| self._cluster = cluster | ||
| self._cluster.add_listener(self) | ||
| ieee = discovery_info['endpoint'].device.ieee | ||
| ieeetail = ''.join(['%02x' % (o, ) for o in ieee[-4:]]) | ||
| if discovery_info['manufacturer'] and discovery_info['model'] is not \ | ||
| None: | ||
| self.event_id = "{}.{}_{}_{}{}".format( | ||
| slugify(discovery_info['manufacturer']), | ||
| slugify(discovery_info['model']), | ||
| ieeetail, | ||
| discovery_info['endpoint'].endpoint_id, | ||
| discovery_info.get('entity_suffix', '') | ||
| ) | ||
| else: | ||
| self.event_id = "{}.event_{}{}".format( | ||
| ieeetail, | ||
| discovery_info['endpoint'].endpoint_id, | ||
| discovery_info.get('entity_suffix', '') | ||
| ) | ||
|
|
||
| @callback | ||
| def cluster_command(self, tsn, command_id, args): | ||
| """Handle commands received to this cluster.""" | ||
| self._hass.bus.async_fire( | ||
| 'zha_' + self._cluster.server_commands.get(command_id)[0], | ||
| {'device': self.event_id, 'args': args}, | ||
| EventOrigin.remote | ||
| ) | ||
| _LOGGER.debug( | ||
|
dmulcahey marked this conversation as resolved.
Outdated
|
||
| "%s: fired %s event with arguments: %s", self.event_id, | ||
| self._cluster.server_commands.get(command_id)[0], | ||
| args | ||
| ) | ||
|
|
||
| @callback | ||
| def attribute_updated(self, attrid, value): | ||
| self._hass.bus.async_fire( | ||
| 'zha_attribute_updated', | ||
| {'device': self.event_id, | ||
| 'attribute': self._cluster.attributes.get(attrid, ['Unknown'])[0], | ||
| 'attribute_id': attrid, | ||
| 'value': value}, | ||
| EventOrigin.remote | ||
| ) | ||
| _LOGGER.debug( | ||
|
dmulcahey marked this conversation as resolved.
Outdated
|
||
| "%s: updated attribute %s with value: %s and id: %s", | ||
| self.event_id, | ||
| self._cluster.attributes.get(attrid, ['Unknown'])[0], | ||
| value, | ||
| attrid | ||
| ) | ||
|
|
||
| @callback | ||
| def zdo_command(self, *args, **kwargs): | ||
|
MartinHjelmare marked this conversation as resolved.
|
||
| _LOGGER.debug( | ||
| "%s: issued zdo command %s with args: %s", self.event_id, | ||
| args, | ||
| kwargs | ||
| ) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this too.
There was a problem hiding this comment.
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.