Skip to content

Commit

Permalink
Add support custom sensor types
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Jan 15, 2024
1 parent dcb3403 commit 43f53fd
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 2 deletions.
21 changes: 20 additions & 1 deletion custom_components/yandex_station/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,26 @@

_LOGGER = logging.getLogger(__name__)

INCLUDE_TYPES = ["devices.types.sensor", "devices.types.socket"]
# https://yandex.ru/dev/dialogs/smart-home/doc/concepts/device-type-sensor.html
INCLUDE_TYPES = [
"devices.types.sensor",
"devices.types.sensor.button",
"devices.types.sensor.climate",
"devices.types.sensor.gas",
"devices.types.sensor.illumination",
"devices.types.sensor.motion",
"devices.types.sensor.open",
"devices.types.sensor.smoke",
"devices.types.sensor.vibration",
"devices.types.sensor.water_leak",
"devices.types.smart_meter",
"devices.types.smart_meter.cold_water",
"devices.types.smart_meter.electricity",
"devices.types.smart_meter.gas",
"devices.types.smart_meter.heat",
"devices.types.smart_meter.heat.hot_water",
"devices.types.socket",
]
INCLUDE_PROPERTIES = ["devices.properties.float", "devices.properties.event"]

SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
Expand Down
79 changes: 78 additions & 1 deletion tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from homeassistant.const import UnitOfTemperature

from custom_components.yandex_station.sensor import YandexCustomSensor
from . import true, null, update_ha_state
from . import true, false, null, update_ha_state


def test_sensor():
Expand Down Expand Up @@ -66,3 +66,80 @@ def test_sensor():
"state_class": SensorStateClass.MEASUREMENT,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
}


def test_sensor_yandex():
device = {
"id": "xxx",
"name": "Датчик климата 1",
"type": "devices.types.sensor.climate",
"icon_url": "https://avatars.mds.yandex.net/get-iot/icons-devices-devices.types.other.svg/orig",
"capabilities": [],
"properties": [
{
"type": "devices.properties.float",
"retrievable": false,
"reportable": true,
"parameters": {
"instance": "battery_level",
"name": "уровень заряда",
"unit": "unit.percent",
},
"state": {"percent": 100, "status": "normal", "value": 100},
"state_changed_at": "2024-01-13T18:52:17Z",
"last_updated": "2024-01-14T20:26:31Z",
},
{
"type": "devices.properties.float",
"retrievable": false,
"reportable": true,
"parameters": {
"instance": "temperature",
"name": "температура",
"unit": "unit.temperature.celsius",
},
"state": {"percent": null, "status": null, "value": 23.1},
"state_changed_at": "2024-01-14T20:52:07Z",
"last_updated": "2024-01-14T20:52:07Z",
},
{
"type": "devices.properties.float",
"retrievable": false,
"reportable": true,
"parameters": {
"instance": "humidity",
"name": "влажность",
"unit": "unit.percent",
},
"state": {"percent": 59, "status": "normal", "value": 59},
"state_changed_at": "2024-01-14T20:26:31Z",
"last_updated": "2024-01-14T20:26:31Z",
},
{
"type": "devices.properties.float",
"retrievable": false,
"reportable": true,
"parameters": {
"instance": "pressure",
"name": "давление",
"unit": "unit.pressure.mmhg",
},
"state": {"percent": null, "status": null, "value": 751},
"state_changed_at": "2024-01-14T20:37:52Z",
"last_updated": "2024-01-14T20:48:17Z",
},
],
"item_type": "device",
"skill_id": "YANDEX_IO",
"room_name": "Гостиная",
"state": "online",
"created": "2024-01-13T18:52:07Z",
"parameters": {
"device_info": {
"manufacturer": "LUMI",
"model": "lumi.sensor_ht.agl02",
"hw_version": "1",
"sw_version": "28",
}
},
}

0 comments on commit 43f53fd

Please sign in to comment.