Skip to content

Commit

Permalink
№2
Browse files Browse the repository at this point in the history
  • Loading branch information
SashaXser authored Dec 28, 2023
1 parent d4658e0 commit 65b9c22
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 51 deletions.
24 changes: 11 additions & 13 deletions custom_components/yandex_station/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
21 changes: 8 additions & 13 deletions custom_components/yandex_station/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 4 additions & 8 deletions custom_components/yandex_station/core/yandex_quasar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""Основная функция. Возвращает список колонок."""
Expand Down
35 changes: 18 additions & 17 deletions custom_components/yandex_station/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 65b9c22

Please sign in to comment.