Skip to content

Commit

Permalink
Support all device types as simple controls
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Apr 4, 2024
1 parent 9ca54ba commit dbd57dc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
29 changes: 28 additions & 1 deletion custom_components/yandex_station/hass/hass_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@
from ..core.yandex_quasar import YandexQuasar

INCLUDE_KEYS = ("id", "name", "type", "room_name", "skill_id")
INCLUDE_ALL_TYPES = (
"devices.types.camera",
"devices.types.cooking",
"devices.types.cooking.coffee_maker",
"devices.types.cooking.multicooker",
"devices.types.dishwasher",
"devices.types.iron",
"devices.types.openable",
"devices.types.openable.curtain",
"devices.types.pet_drinking_fountain",
"devices.types.pet_feeder",
"devices.types.washing_machine",
)


def incluce_devices(
Expand All @@ -24,7 +37,12 @@ def incluce_devices(
for device in quasar.devices:
if isinstance(conf, str):
if conf == device["name"] or conf == device["id"]:
devices.append((quasar, device, {}))
conf = (
include_all_config(device)
if device["type"] in INCLUDE_ALL_TYPES
else {}
)
devices.append((quasar, device, conf))
break
elif isinstance(conf, dict):
if any(conf[k] == device.get(k) for k in INCLUDE_KEYS if k in conf):
Expand All @@ -34,6 +52,15 @@ def incluce_devices(
return devices


def include_all_config(device: dict) -> dict:
return {
"capabilities": [
i["parameters"].get("instance", "on") for i in device["capabilities"]
],
"properties": [i["parameters"]["instance"] for i in device["properties"]],
}


def load_fake_devies(hass: HomeAssistant, quasar: YandexQuasar):
path = hass.config.path(DOMAIN + ".json")
if os.path.isfile(path):
Expand Down
1 change: 1 addition & 0 deletions custom_components/yandex_station/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
SCAN_INTERVAL = timedelta(minutes=5)

INCLUDE_TYPES = [
"devices.types.media_device",
"devices.types.media_device.receiver",
"devices.types.media_device.tv",
"devices.types.media_device.tv_box",
Expand Down
1 change: 0 additions & 1 deletion custom_components/yandex_station/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from homeassistant.components.select import SelectEntity
from homeassistant.helpers.entity import DeviceInfo

from .core import utils
from .core.const import DOMAIN
from .core.entity import YandexCustomEntity
from .core.yandex_quasar import YandexQuasar
Expand Down
4 changes: 2 additions & 2 deletions custom_components/yandex_station/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ async def async_setup_entry(hass, entry, async_add_entities):
for instance in device["properties"]:
if instance["type"] not in INCLUDE_PROPERTIES:
continue
if instance["parameters"].get("instance", "on") in instances:
if instance["parameters"]["instance"] in instances:
entities.append(YandexCustomSensor(quasar, device, instance))

async_add_entities(entities, True)
async_add_entities(entities)


# noinspection PyAbstractClass
Expand Down
2 changes: 1 addition & 1 deletion custom_components/yandex_station/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
if instance["parameters"].get("instance", "on") in instances:
entities.append(YandexCustomSwitch(quasar, device, instance))

async_add_entities(entities, True)
async_add_entities(entities)


# noinspection PyAbstractClass
Expand Down

0 comments on commit dbd57dc

Please sign in to comment.