diff --git a/custom_components/yandex_station/climate.py b/custom_components/yandex_station/climate.py index c32187a..65447b4 100644 --- a/custom_components/yandex_station/climate.py +++ b/custom_components/yandex_station/climate.py @@ -112,23 +112,21 @@ def min_temp(self): def max_temp(self): return self._max_temp + async def async_set_hvac_mode(self, hvac_mode): - if ( - hvac_mode != HVAC_MODE_OFF - and hvac_mode == HVAC_MODE_HEAT - and self._preset_modes is not None - ): - await self.quasar.device_action(self.device["id"], on=True) - elif ( - hvac_mode != HVAC_MODE_OFF - and hvac_mode == HVAC_MODE_HEAT - or hvac_mode != HVAC_MODE_OFF - ): + if hvac_mode == HVAC_MODE_OFF: + await self.quasar.device_action(self.device["id"], on=False) + elif hvac_mode == HVAC_MODE_HEAT: + if self._preset_modes is not None: + await self.quasar.device_action(self.device["id"], on=True) + else: + await self.quasar.device_action( + self.device["id"], on=True, thermostat=hvac_mode + ) + else: await self.quasar.device_action( self.device["id"], on=True, thermostat=hvac_mode ) - else: - await self.quasar.device_action(self.device["id"], on=False) async def async_set_temperature(self, **kwargs): await self.quasar.device_action( diff --git a/custom_components/yandex_station/core/utils.py b/custom_components/yandex_station/core/utils.py index 16dee83..88d7ef9 100644 --- a/custom_components/yandex_station/core/utils.py +++ b/custom_components/yandex_station/core/utils.py @@ -103,19 +103,14 @@ def update_form(name: str, **kwargs): def find_station(devices, name: str = None): """Найти станцию по ID, имени или просто первую попавшуюся.""" - return next( - ( - device["entity"].entity_id - for device in devices - if device.get("entity") - and ( - device["quasar_info"]["device_id"] == name - or device["name"] == name - or name is None - ) - ), - None, - ) + for device in devices: + if device.get("entity") and ( + device["quasar_info"]["device_id"] == name + or device["name"] == name + or name is None + ): + return device["entity"].entity_id + return None async def error(hass: HomeAssistantType, text: str): diff --git a/custom_components/yandex_station/core/yandex_quasar.py b/custom_components/yandex_station/core/yandex_quasar.py index 526f870..81c3892 100644 --- a/custom_components/yandex_station/core/yandex_quasar.py +++ b/custom_components/yandex_station/core/yandex_quasar.py @@ -70,14 +70,10 @@ def __init__(self, session: YandexSession): @property def hass_id(self): - return next( - ( - device["id"] - for device in self.devices - if device["name"] == "Yandex Intents" - ), - None, - ) + for device in self.devices: + if device["name"] == "Yandex Intents": + return device["id"] + return None async def init(self): """Основная функция. Возвращает список колонок.""" diff --git a/custom_components/yandex_station/media_player.py b/custom_components/yandex_station/media_player.py index f0e15c6..e9d7ff3 100644 --- a/custom_components/yandex_station/media_player.py +++ b/custom_components/yandex_station/media_player.py @@ -705,7 +705,7 @@ async def async_set_volume_level(self, volume: float): # https://github.com/AlexxIT/YandexStation/issues/324 if isinstance(volume, str): try: - volume = volume + volume = float(volume) except Exception: return @@ -802,7 +802,7 @@ async def async_play_media( if query.get("volume_level"): extra.setdefault("volume_level", float(query["volume_level"])) # provider, music - from 3rd party TTS (ex google) - if media_type in {"provider", "music"}: + if media_type in ("provider", "music"): media_type = "text" if not media_id: @@ -885,25 +885,26 @@ async def async_play_media( await self.glagol.send(payload) - elif media_type.startswith(("text:", "dialog:")): - media_id = self.yandex_dialog(media_type, media_id) - await self.quasar.send(self.device, media_id) + else: + if media_type.startswith(("text:", "dialog:")): + media_id = self.yandex_dialog(media_type, media_id) + await self.quasar.send(self.device, media_id) - elif media_type == "text": - media_id = utils.fix_cloud_text(media_id) - await self.quasar.send(self.device, media_id, is_tts=True) + elif media_type == "text": + media_id = utils.fix_cloud_text(media_id) + await self.quasar.send(self.device, media_id, is_tts=True) - elif media_type == "command": - media_id = utils.fix_cloud_text(media_id) - await self.quasar.send(self.device, media_id) + elif media_type == "command": + media_id = utils.fix_cloud_text(media_id) + await self.quasar.send(self.device, media_id) - elif media_type == "brightness": - await self._set_brightness(media_id) - return + elif media_type == "brightness": + await self._set_brightness(media_id) + return - else: - _LOGGER.warning(f"Unsupported cloud media: {media_type}") - return + else: + _LOGGER.warning(f"Unsupported cloud media: {media_type}") + return class YandexStation(YandexStationBase):