Skip to content

Commit

Permalink
feat(integration): add attribute parameter to state integration
Browse files Browse the repository at this point in the history
closes #106
  • Loading branch information
xaviml committed Jul 30, 2020
1 parent f9c1bb1 commit fa6634f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion apps/controllerx/cx_core/integration/state.py
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion docs/others/integrations.md
Expand Up @@ -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

Expand Down

0 comments on commit fa6634f

Please sign in to comment.