Skip to content

Commit

Permalink
Add smart device auto config
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Apr 5, 2024
1 parent c733199 commit 795146e
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 28 deletions.
4 changes: 2 additions & 2 deletions custom_components/yandex_station/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

_LOGGER = logging.getLogger(__name__)

INCLUDE_TYPES = [
INCLUDE_TYPES = (
"devices.types.purifier",
"devices.types.thermostat",
"devices.types.thermostat.ac",
]
)


async def async_setup_entry(hass, entry, async_add_entities):
Expand Down
50 changes: 39 additions & 11 deletions custom_components/yandex_station/hass/hass_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
from homeassistant.const import CONF_INCLUDE
from homeassistant.core import HomeAssistant

from ..climate import INCLUDE_TYPES as CLIMATE
from ..core.const import DOMAIN, DATA_CONFIG
from ..core.yandex_quasar import YandexQuasar
from ..humidifier import INCLUDE_TYPES as HUMIDIFIER
from ..light import INCLUDE_TYPES as LIGHT
from ..media_player import INCLUDE_TYPES as MEDIA_PLAYER
from ..vacuum import INCLUDE_TYPES as VACUUM
from ..water_heater import INCLUDE_TYPES as WATER_HEATER

INCLUDE_KEYS = ("id", "name", "type", "room_name", "skill_id")
INCLUDE_ALL_TYPES = (

INCLUDE_TYPES_UNKNOWN = (
"devices.types.camera",
"devices.types.cooking",
"devices.types.cooking.coffee_maker",
Expand All @@ -22,6 +29,24 @@
"devices.types.pet_feeder",
"devices.types.washing_machine",
)
INCLUDE_SKIP_INSTANCES = {
CLIMATE: [
"on",
"thermostat",
"program",
"heat",
"work_speed",
"temperature",
"humidity",
"fan_speed",
],
HUMIDIFIER: ["on", "fan_speed", "work_speed", "humidity"],
LIGHT: ["on", "brightness", "color"],
MEDIA_PLAYER: ["on", "pause", "volume", "mute", "channel", "input_source"],
VACUUM: ["on", "pause", "work_speed", "battery_level"],
WATER_HEATER: ["on", "tea_mode", "temperature"],
INCLUDE_TYPES_UNKNOWN: [],
}


def incluce_devices(
Expand All @@ -37,11 +62,7 @@ def incluce_devices(
for device in quasar.devices:
if isinstance(conf, str):
if conf == device["name"] or conf == device["id"]:
conf = (
include_all_config(device)
if device["type"] in INCLUDE_ALL_TYPES
else {}
)
conf = build_include_config(device)
devices.append((quasar, device, conf))
break
elif isinstance(conf, dict):
Expand All @@ -52,12 +73,19 @@ def incluce_devices(
return devices


def include_all_config(device: dict) -> dict:
def build_include_config(device: dict) -> dict:
for include_types, include_skip in INCLUDE_SKIP_INSTANCES.items():
if device["type"] in include_types:
break
else:
return {}

caps = [i["parameters"].get("instance", "on") for i in device["capabilities"]]
props = [i["parameters"]["instance"] for i in device["properties"]]

return {
"capabilities": [
i["parameters"].get("instance", "on") for i in device["capabilities"]
],
"properties": [i["parameters"]["instance"] for i in device["properties"]],
"capabilities": [i for i in caps if i not in include_skip],
"properties": [i for i in props if i not in include_skip],
}


Expand Down
2 changes: 1 addition & 1 deletion custom_components/yandex_station/humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

_LOGGER = logging.getLogger(__name__)

INCLUDE_TYPES = ["devices.types.humidifier"]
INCLUDE_TYPES = ("devices.types.humidifier",)


async def async_setup_entry(hass, entry, async_add_entities):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/yandex_station/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .core.entity import YandexEntity
from .hass import hass_utils

INCLUDE_TYPES = ["devices.types.light"]
INCLUDE_TYPES = ("devices.types.light",)


async def async_setup_entry(hass, entry, async_add_entities):
Expand Down
4 changes: 2 additions & 2 deletions custom_components/yandex_station/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
# update speaker online state once per 5 minutes
SCAN_INTERVAL = timedelta(minutes=5)

INCLUDE_TYPES = [
INCLUDE_TYPES = (
"devices.types.media_device",
"devices.types.media_device.receiver",
"devices.types.media_device.tv",
"devices.types.media_device.tv_box",
]
)


async def async_setup_entry(hass, entry, async_add_entities):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/yandex_station/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

_LOGGER = logging.getLogger(__name__)

INCLUDE_CAPABILITIES = ["devices.capabilities.range"]
INCLUDE_CAPABILITIES = ("devices.capabilities.range",)

UNITS = {"unit.temperature.celsius": UnitOfTemperature.CELSIUS}

Expand Down
2 changes: 1 addition & 1 deletion custom_components/yandex_station/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

_LOGGER = logging.getLogger(__name__)

INCLUDE_TYPES = ["devices.types.other"]
INCLUDE_TYPES = ("devices.types.other",)


async def async_setup_entry(hass, entry, async_add_entities):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/yandex_station/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"lesshigh": [0, 0, 0, 0, -5],
}

INCLUDE_CAPABILITIES = ["devices.capabilities.mode"]
INCLUDE_CAPABILITIES = ("devices.capabilities.mode",)

EQUALIZER_PLATFORMS = (
"cucumber",
Expand Down
7 changes: 3 additions & 4 deletions custom_components/yandex_station/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
)

from .core import utils
from .core.entity import YandexCustomEntity
from .hass import hass_utils

_LOGGER = logging.getLogger(__name__)

# https://yandex.ru/dev/dialogs/smart-home/doc/concepts/device-type-sensor.html
INCLUDE_TYPES = [
INCLUDE_TYPES = (
"devices.types.sensor",
"devices.types.sensor.button",
"devices.types.sensor.climate",
Expand All @@ -42,8 +41,8 @@
"devices.types.smart_meter.heat",
"devices.types.smart_meter.heat.hot_water",
"devices.types.socket",
]
INCLUDE_PROPERTIES = ["devices.properties.float", "devices.properties.event"]
)
INCLUDE_PROPERTIES = ("devices.properties.float", "devices.properties.event")

SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
Expand Down
4 changes: 2 additions & 2 deletions custom_components/yandex_station/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

_LOGGER = logging.getLogger(__name__)

INCLUDE_TYPES = ["devices.types.switch", "devices.types.socket"]
INCLUDE_CAPABILITIES = ["devices.capabilities.on_off", "devices.capabilities.toggle"]
INCLUDE_TYPES = ("devices.types.switch", "devices.types.socket")
INCLUDE_CAPABILITIES = ("devices.capabilities.on_off", "devices.capabilities.toggle")


async def async_setup_entry(hass, entry, async_add_entities):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/yandex_station/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

_LOGGER = logging.getLogger(__name__)

INCLUDE_TYPES = ["devices.types.vacuum_cleaner"]
INCLUDE_TYPES = ("devices.types.vacuum_cleaner",)


async def async_setup_entry(hass, entry, async_add_entities):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/yandex_station/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

_LOGGER = logging.getLogger(__name__)

INCLUDE_TYPES = ["devices.types.cooking.kettle"]
INCLUDE_TYPES = ("devices.types.cooking.kettle",)


async def async_setup_entry(hass, entry, async_add_entities):
Expand Down

0 comments on commit 795146e

Please sign in to comment.