diff --git a/custom_components/yandex_station/core/yandex_station.py b/custom_components/yandex_station/core/yandex_station.py index 47bb095..330189c 100644 --- a/custom_components/yandex_station/core/yandex_station.py +++ b/custom_components/yandex_station/core/yandex_station.py @@ -230,18 +230,22 @@ def on_update(self, device: dict): if not self.hass: return - for item in device["capabilities"]: - if not (event_data := item["state"]): - continue - - event_data["entity_id"] = self.entity_id - event_data["name"] = self.name - - if "scenario_name" in device: + if "scenario_name" in device: + for item in device["capabilities"]: + event_data = item["state"] + event_data["entity_id"] = self.entity_id + event_data["name"] = self.name event_data["scenario_name"] = device["scenario_name"] self.debug(f"yandex_scenario: {event_data}") self.hass.bus.async_fire("yandex_scenario", event_data) - else: + else: + for item in device["capabilities"]: + if item["type"] != "devices.capabilities.quasar.server_action" or not item["state"]: + continue + + event_data = item["state"] + event_data["entity_id"] = self.entity_id + event_data["name"] = self.name self.debug(f"yandex_speaker: {event_data}") self.hass.bus.async_fire("yandex_speaker", event_data) diff --git a/tests/test_scenario.py b/tests/test_scenario.py new file mode 100644 index 0000000..9060c0b --- /dev/null +++ b/tests/test_scenario.py @@ -0,0 +1,14 @@ +def test_update_states(): + device = { + "id": "xxx", + "state": "online", + "capabilities": [ + { + "reportable": False, + "retrievable": False, + "type": "devices.capabilities.quasar.server_action", + "state": {"instance": "text_action", "value": "Сделай громче на 0"}, + "parameters": {"instance": "text_action"}, + } + ], + }