From 47c92c6dd6d49233593f9f8b9e9dfb21facf5bca Mon Sep 17 00:00:00 2001 From: Thibaut Date: Wed, 29 Sep 2021 14:59:16 +0200 Subject: [PATCH] Trigger event on failure (#573) --- README.md | 25 +++++++++++++++++++++++++ custom_components/tahoma/coordinator.py | 10 ++++++++++ 2 files changed, 35 insertions(+) diff --git a/README.md b/README.md index 4bd7bf607..0ff8b675e 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,31 @@ After installation this integration adds new services to Home Assistant which ca + Overkiz (by Somfy): Execute command (tahoma.execute_command) + Overkiz (by Somfy): Get execution history (tahoma.get_execution_history) +## Events +This component listen for events returned by Overkiz. In case of command failure, the event will forwarded to Home Assistant. + +You can subscribe to the `overkiz.event` event type in Developer Tools/Events in order to examine the event data JSON for the correct parameters to use in your automations. For example, `overkiz.event` returns event data JSON similar to the following when your cover is blocked. + +```JSON +{ + "event_type": "overkiz.event", + "data": { + "event_name": "ExecutionStateChangedEvent", + "failure_type_code": 106, + "failure_type": "CMDCANCELLED" + }, + "origin": "LOCAL", + "time_fired": "2021-09-28T20:03:57.102478+00:00", + "context": { + "id": "92a84240d914b43ceaf1aee3249568f6", + "parent_id": null, + "user_id": null + } +} +``` + +You can find the list of available failure_type [here](https://github.com/iMicknl/python-tahoma-api/blob/master/pyhoma/enums.py#L118). + ### Enable debug logging The [logger](https://www.home-assistant.io/integrations/logger/) integration lets you define the level of logging activities in Home Assistant. Turning on debug mode will show more information about unsupported devices in your logbook. diff --git a/custom_components/tahoma/coordinator.py b/custom_components/tahoma/coordinator.py index 5e824dfe6..354fcdee7 100644 --- a/custom_components/tahoma/coordinator.py +++ b/custom_components/tahoma/coordinator.py @@ -98,6 +98,16 @@ async def _async_update_data(self) -> Dict[str, Device]: for event in events: _LOGGER.debug(event) + if event.failure_type_code: + self.hass.bus.fire( + "overkiz.event", + { + "event_name": event.name.value, + "failure_type_code": event.failure_type_code.value, + "failure_type": event.failure_type, + }, + ) + if event.name == EventName.DEVICE_AVAILABLE: self.devices[event.deviceurl].available = True