Skip to content

Commit adb19a8

Browse files
committed
Add text entity for future features
1 parent b09548f commit adb19a8

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

custom_components/yandex_station/core/yandex_quasar.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@
3939
"camera_pan": "devices.capabilities.range",
4040
"camera_tilt": "devices.capabilities.range",
4141
"get_stream": "devices.capabilities.video_stream",
42-
# "devices.types.remote_car.seat"
42+
# devices.types.remote_car.seat
4343
"heating_mode": "devices.capabilities.range",
44+
# devices.types.smart_speaker.yandex.station.orion
45+
"led_array": "devices.capabilities.led_mask",
4446
# don't work
4547
"hsv": "devices.capabilities.color_setting",
4648
"rgb": "devices.capabilities.color_setting",
@@ -398,6 +400,8 @@ async def device_action(self, device: dict, instance: str, value, relative=False
398400
self.dispatch_update(device["id"], device)
399401

400402
async def get_device_action(self, device: dict, instance: str, value) -> list[dict]:
403+
_LOGGER.debug(f"Device action: {instance}={value}")
404+
401405
action = {
402406
"state": {"instance": instance, "value": value},
403407
"type": IOT_TYPES[instance],
@@ -437,6 +441,8 @@ async def device_actions(self, device: dict, **kwargs):
437441
self.dispatch_update(device["id"], device)
438442

439443
async def device_color(self, device: dict, **kwargs):
444+
_LOGGER.debug(f"Device color: {kwargs}")
445+
440446
r = await self.session.post(
441447
f"https://iot.quasar.yandex.ru/m/v3/user/custom/group/color/apply",
442448
json={"device_ids": [device['id']], **kwargs},
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import re
2+
3+
from homeassistant.components.text import TextEntity
4+
5+
from .core.entity import YandexEntity
6+
from .hass import hass_utils
7+
8+
INCLUDE_TYPES = (
9+
"devices.types.smart_speaker.yandex.station.orion",
10+
)
11+
12+
13+
async def async_setup_entry(hass, entry, async_add_entities):
14+
async_add_entities(
15+
YandexText(quasar, device, config)
16+
for quasar, device, config in hass_utils.incluce_devices(hass, entry)
17+
if device["type"] in INCLUDE_TYPES
18+
)
19+
20+
21+
class YandexText(TextEntity, YandexEntity):
22+
def internal_init(self, capabilities: dict, properties: dict):
23+
pass
24+
25+
def internal_update(self, capabilities: dict, properties: dict):
26+
if "led_array" in capabilities:
27+
array: list[int] = capabilities["led_array"]
28+
self._attr_native_value = ",".join(str(i) for i in array)
29+
30+
async def async_set_value(self, value: str) -> None:
31+
array: list[int] = [int(i) for i in re.findall(r"\d+", value)]
32+
await self.device_action("led_array", array)

0 commit comments

Comments
 (0)