Skip to content

Commit

Permalink
Add support covers
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Apr 6, 2024
1 parent 7164e6d commit e0d662b
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 2 deletions.
3 changes: 2 additions & 1 deletion custom_components/yandex_station/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@
PLATFORMS = [
"button",
"climate",
"light",
"cover",
"humidifier",
"light",
"media_player",
"number",
"select",
Expand Down
2 changes: 2 additions & 0 deletions custom_components/yandex_station/core/yandex_quasar.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
# kettle:
"keep_warm": "devices.capabilities.toggle",
"tea_mode": "devices.capabilities.mode",
# cover
"open": "devices.capabilities.range",
# don't work
"hsv": "devices.capabilities.color_setting",
"rgb": "devices.capabilities.color_setting",
Expand Down
61 changes: 61 additions & 0 deletions custom_components/yandex_station/cover.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import logging

from homeassistant.components.cover import CoverEntity, CoverEntityFeature
from homeassistant.components.humidifier import (
HumidifierEntity,
HumidifierEntityFeature,
)

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

_LOGGER = logging.getLogger(__name__)

INCLUDE_TYPES = ("devices.types.openable.curtain",)


async def async_setup_entry(hass, entry, async_add_entities):
async_add_entities(
YandexCover(quasar, device, config)
for quasar, device, config in hass_utils.incluce_devices(hass, entry)
if device["type"] in INCLUDE_TYPES
)


# noinspection PyAbstractClass
class YandexCover(CoverEntity, YandexEntity):
_attr_is_closed = None
_attr_supported_features = 0

def internal_init(self, capabilities: dict, properties: dict):
if "on" in capabilities:
self._attr_supported_features |= (
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
)

if "open" in capabilities:
self._attr_supported_features |= CoverEntityFeature.SET_POSITION

if "pause" in capabilities:
self._attr_supported_features |= CoverEntityFeature.STOP

def internal_update(self, capabilities: dict, properties: dict):
if (value := capabilities.get("on")) is not None:
self._attr_is_closed = value is False

if (value := capabilities.get("open")) is not None:
self._attr_current_cover_position = value
self._attr_is_closed = value == 0

async def async_open_cover(self, **kwargs):
await self.quasar.device_action(self.device["id"], "on", True)

async def async_close_cover(self, **kwargs):
await self.quasar.device_action(self.device["id"], "on", False)

async def async_stop_cover(self, **kwargs):
await self.quasar.device_action(self.device["id"], "pause", True)

async def async_set_cover_position(self, position: int, **kwargs):
await self.quasar.device_action(self.device["id"], "open", position)
3 changes: 2 additions & 1 deletion custom_components/yandex_station/hass/hass_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ..climate import INCLUDE_TYPES as CLIMATE
from ..core.const import DOMAIN, DATA_CONFIG
from ..core.yandex_quasar import YandexQuasar
from ..cover import INCLUDE_TYPES as COVER
from ..humidifier import INCLUDE_TYPES as HUMIDIFIER
from ..light import INCLUDE_TYPES as LIGHT
from ..media_player import INCLUDE_TYPES as MEDIA_PLAYER
Expand All @@ -24,7 +25,6 @@
"devices.types.dishwasher",
"devices.types.iron",
"devices.types.openable",
"devices.types.openable.curtain",
"devices.types.other",
"devices.types.pet_drinking_fountain",
"devices.types.pet_feeder",
Expand All @@ -41,6 +41,7 @@
"humidity",
"fan_speed",
],
COVER: ["on", "open", "pause"],
HUMIDIFIER: ["on", "fan_speed", "work_speed", "humidity"],
LIGHT: ["on", "brightness", "color"],
MEDIA_PLAYER: ["on", "pause", "volume", "mute", "channel", "input_source"],
Expand Down
50 changes: 50 additions & 0 deletions tests/test_curtain.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,53 @@ def test_curtain():
}
},
}


def test_curtain2():
device = {
"id": "xxx",
"name": "Левая штора",
"type": "devices.types.openable.curtain",
"icon_url": "https://avatars.mds.yandex.net/get-iot/icons-devices-devices.types.openable.curtain.svg/orig",
"capabilities": [
{
"reportable": false,
"retrievable": true,
"type": "devices.capabilities.on_off",
"state": {"instance": "on", "value": true},
"parameters": {"split": false},
},
{
"reportable": false,
"retrievable": true,
"type": "devices.capabilities.range",
"state": {"instance": "open", "value": 100},
"parameters": {
"instance": "open",
"name": "открытие",
"unit": "unit.percent",
"random_access": true,
"looped": false,
"range": {"min": 0, "max": 100, "precision": 1},
},
},
{
"reportable": false,
"retrievable": false,
"type": "devices.capabilities.toggle",
"state": null,
"parameters": {"instance": "pause", "name": "пауза"},
},
],
"properties": [],
"item_type": "device",
"skill_id": "xxx",
"state": "online",
"parameters": {
"device_info": {
"manufacturer": "IKEA",
"model": "Zigbee: E1757, FYRTUR block-out roller blind",
"sw_version": "34",
}
},
}

0 comments on commit e0d662b

Please sign in to comment.