From fa6634f27967ea253439463472a4fead0f4e2acc Mon Sep 17 00:00:00 2001 From: Xavi Date: Thu, 30 Jul 2020 23:32:11 +0200 Subject: [PATCH] feat(integration): add `attribute` parameter to state integration closes #106 --- apps/controllerx/cx_core/integration/state.py | 5 ++++- docs/others/integrations.md | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/apps/controllerx/cx_core/integration/state.py b/apps/controllerx/cx_core/integration/state.py index b5101bb2..be7d3048 100644 --- a/apps/controllerx/cx_core/integration/state.py +++ b/apps/controllerx/cx_core/integration/state.py @@ -14,7 +14,10 @@ def get_actions_mapping(self) -> Optional[TypeActionsMapping]: return self.controller.get_z2m_actions_mapping() def listen_changes(self, controller_id: str) -> None: - Hass.listen_state(self.controller, self.callback, controller_id) + attribute = self.kwargs.get("attribute", None) + Hass.listen_state( + self.controller, self.callback, controller_id, attribute=attribute + ) async def callback( self, entity: Optional[str], attribute: Optional[str], old, new, kwargs diff --git a/docs/others/integrations.md b/docs/others/integrations.md index b55e30be..ddb3d9dd 100644 --- a/docs/others/integrations.md +++ b/docs/others/integrations.md @@ -7,7 +7,21 @@ Integrations is a way to abstract the logic from the event extraction in Control #### State -This integration (**`state`**) listens for the state of a sensor and the action is fired with the changed event. It does not have any additional arguments. +This integration (**`state`**) listens for the state of a sensor and the action is fired with the changed event. You can add `attribute` parameter if you want to listen to state change on the state attribute level. Read more about the options in [here](https://appdaemon.readthedocs.io/en/latest/AD_API_REFERENCE.html#appdaemon.adapi.ADAPI.listen_state). An example could be: + +```yaml +example_app: + module: controllerx + class: LightController + controller: sensor.my_custom_button + integration: + name: state + attribute: click + light: light.example_light + mapping: + 1_click: "on" + 2_click: "off" +``` #### Zigbee2MQTT