From 7e72cefc2ae6543d1d7ca720e516ba928f17993e Mon Sep 17 00:00:00 2001 From: matrix Date: Sun, 23 Apr 2023 10:05:26 +0000 Subject: [PATCH 1/5] add ys-7106 --- homeassistant/components/yolink/manifest.json | 2 +- homeassistant/components/yolink/sensor.py | 12 ++++++++++++ requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/yolink/manifest.json b/homeassistant/components/yolink/manifest.json index 2353afe5f69621..088ddd114f8fa7 100644 --- a/homeassistant/components/yolink/manifest.json +++ b/homeassistant/components/yolink/manifest.json @@ -6,5 +6,5 @@ "dependencies": ["auth", "application_credentials"], "documentation": "https://www.home-assistant.io/integrations/yolink", "iot_class": "cloud_push", - "requirements": ["yolink-api==0.2.8"] + "requirements": ["yolink-api==0.2.9"] } diff --git a/homeassistant/components/yolink/sensor.py b/homeassistant/components/yolink/sensor.py index 5f89f54ccbe706..60daa1ed186590 100644 --- a/homeassistant/components/yolink/sensor.py +++ b/homeassistant/components/yolink/sensor.py @@ -14,6 +14,7 @@ ATTR_DEVICE_MOTION_SENSOR, ATTR_DEVICE_MULTI_OUTLET, ATTR_DEVICE_OUTLET, + ATTR_DEVICE_POWER_FAILURE_ALARM, ATTR_DEVICE_SIREN, ATTR_DEVICE_SMART_REMOTER, ATTR_DEVICE_SWITCH, @@ -71,6 +72,7 @@ class YoLinkSensorEntityDescription( ATTR_DEVICE_MULTI_OUTLET, ATTR_DEVICE_SMART_REMOTER, ATTR_DEVICE_OUTLET, + ATTR_DEVICE_POWER_FAILURE_ALARM, ATTR_DEVICE_SIREN, ATTR_DEVICE_SWITCH, ATTR_DEVICE_TH_SENSOR, @@ -86,6 +88,7 @@ class YoLinkSensorEntityDescription( ATTR_DEVICE_DOOR_SENSOR, ATTR_DEVICE_LEAK_SENSOR, ATTR_DEVICE_MOTION_SENSOR, + ATTR_DEVICE_POWER_FAILURE_ALARM, ATTR_DEVICE_SMART_REMOTER, ATTR_DEVICE_TH_SENSOR, ATTR_DEVICE_VIBRATION_SENSOR, @@ -157,6 +160,15 @@ def cvt_battery(val: int | None) -> int | None: entity_registry_enabled_default=False, should_update_entity=lambda value: value is not None, ), + YoLinkSensorEntityDescription( + key="state", + device_class=SensorDeviceClass.ENUM, + name="State", + icon="mdi:flash", + options=["normal", "alert", "off"], + translation_key="power_failed_state", + exists_fn=lambda device: device.device_type in ATTR_DEVICE_POWER_FAILURE_ALARM, + ), ) diff --git a/requirements_all.txt b/requirements_all.txt index 84d5259dd1ca83..b2653ae743c04f 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2694,7 +2694,7 @@ yeelight==0.7.10 yeelightsunflower==0.0.10 # homeassistant.components.yolink -yolink-api==0.2.8 +yolink-api==0.2.9 # homeassistant.components.youless youless-api==1.0.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index ec6d9385544911..c5329f56d21249 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1946,7 +1946,7 @@ yalexs==1.3.0 yeelight==0.7.10 # homeassistant.components.yolink -yolink-api==0.2.8 +yolink-api==0.2.9 # homeassistant.components.youless youless-api==1.0.1 From f9a5dc436b8fda3bed45ff5e645348c938d81a6d Mon Sep 17 00:00:00 2001 From: matrix Date: Sun, 23 Apr 2023 11:37:46 +0000 Subject: [PATCH 2/5] expose mute property --- homeassistant/components/yolink/sensor.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/homeassistant/components/yolink/sensor.py b/homeassistant/components/yolink/sensor.py index 60daa1ed186590..4c0eb73aa06a61 100644 --- a/homeassistant/components/yolink/sensor.py +++ b/homeassistant/components/yolink/sensor.py @@ -169,6 +169,16 @@ def cvt_battery(val: int | None) -> int | None: translation_key="power_failed_state", exists_fn=lambda device: device.device_type in ATTR_DEVICE_POWER_FAILURE_ALARM, ), + YoLinkSensorEntityDescription( + key="mute", + device_class=SensorDeviceClass.ENUM, + name="Mute", + icon="mdi:volume-mute", + options=["Yes", "No"], + translation_key="power_failed_mute", + exists_fn=lambda device: device.device_type in ATTR_DEVICE_POWER_FAILURE_ALARM, + value=lambda value: "Yes" if value is True else "No", + ), ) From d7d8843f30d4c7a8bf06aa11dfbaaf376a5d836d Mon Sep 17 00:00:00 2001 From: matrix Date: Mon, 24 Apr 2023 01:27:43 +0000 Subject: [PATCH 3/5] add volume entity description --- homeassistant/components/yolink/sensor.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/yolink/sensor.py b/homeassistant/components/yolink/sensor.py index 4c0eb73aa06a61..5641e323c0d07e 100644 --- a/homeassistant/components/yolink/sensor.py +++ b/homeassistant/components/yolink/sensor.py @@ -113,6 +113,14 @@ def cvt_battery(val: int | None) -> int | None: return 0 +def cvt_volume(val: int | None) -> str | None: + """Convert volume to string.""" + if val is None: + return None + volume_level = {1: "low", 2: "medium", 3: "high"} + return volume_level.get(val, None) + + SENSOR_TYPES: tuple[YoLinkSensorEntityDescription, ...] = ( YoLinkSensorEntityDescription( key="battery", @@ -166,7 +174,6 @@ def cvt_battery(val: int | None) -> int | None: name="State", icon="mdi:flash", options=["normal", "alert", "off"], - translation_key="power_failed_state", exists_fn=lambda device: device.device_type in ATTR_DEVICE_POWER_FAILURE_ALARM, ), YoLinkSensorEntityDescription( @@ -174,10 +181,17 @@ def cvt_battery(val: int | None) -> int | None: device_class=SensorDeviceClass.ENUM, name="Mute", icon="mdi:volume-mute", - options=["Yes", "No"], - translation_key="power_failed_mute", + options=["yes", "no"], + exists_fn=lambda device: device.device_type in ATTR_DEVICE_POWER_FAILURE_ALARM, + value=lambda value: "yes" if value is True else "no", + ), + YoLinkSensorEntityDescription( + key="sound", + device_class=SensorDeviceClass.ENUM, + name="Volume", + icon="mdi:volume-high", exists_fn=lambda device: device.device_type in ATTR_DEVICE_POWER_FAILURE_ALARM, - value=lambda value: "Yes" if value is True else "No", + value=cvt_volume, ), ) From 1407ec3c1238bb9d27dde12e4d478e222612caf3 Mon Sep 17 00:00:00 2001 From: matrix Date: Mon, 24 Apr 2023 02:49:57 +0000 Subject: [PATCH 4/5] add beep entity description --- homeassistant/components/yolink/sensor.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/homeassistant/components/yolink/sensor.py b/homeassistant/components/yolink/sensor.py index 5641e323c0d07e..299ee4a415ff2d 100644 --- a/homeassistant/components/yolink/sensor.py +++ b/homeassistant/components/yolink/sensor.py @@ -190,9 +190,19 @@ def cvt_volume(val: int | None) -> str | None: device_class=SensorDeviceClass.ENUM, name="Volume", icon="mdi:volume-high", + options=["low", "medium", "high"], exists_fn=lambda device: device.device_type in ATTR_DEVICE_POWER_FAILURE_ALARM, value=cvt_volume, ), + YoLinkSensorEntityDescription( + key="beep", + device_class=SensorDeviceClass.ENUM, + name="Beep", + icon="mdi:bullhorn", + options=["enable", "disable"], + exists_fn=lambda device: device.device_type in ATTR_DEVICE_POWER_FAILURE_ALARM, + value=lambda value: "enable" if value is True else "disable", + ), ) From 8dec9440277298e32dc2fdd75058d4bcce7a475d Mon Sep 17 00:00:00 2001 From: matrixd2 Date: Wed, 24 May 2023 14:20:18 +0000 Subject: [PATCH 5/5] fix as suggest --- homeassistant/components/yolink/sensor.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/yolink/sensor.py b/homeassistant/components/yolink/sensor.py index 299ee4a415ff2d..75c4949859cb45 100644 --- a/homeassistant/components/yolink/sensor.py +++ b/homeassistant/components/yolink/sensor.py @@ -171,7 +171,7 @@ def cvt_volume(val: int | None) -> str | None: YoLinkSensorEntityDescription( key="state", device_class=SensorDeviceClass.ENUM, - name="State", + name="Power failure alarm", icon="mdi:flash", options=["normal", "alert", "off"], exists_fn=lambda device: device.device_type in ATTR_DEVICE_POWER_FAILURE_ALARM, @@ -179,16 +179,16 @@ def cvt_volume(val: int | None) -> str | None: YoLinkSensorEntityDescription( key="mute", device_class=SensorDeviceClass.ENUM, - name="Mute", + name="Power failure alarm mute", icon="mdi:volume-mute", - options=["yes", "no"], + options=["muted", "unmuted"], exists_fn=lambda device: device.device_type in ATTR_DEVICE_POWER_FAILURE_ALARM, - value=lambda value: "yes" if value is True else "no", + value=lambda value: "muted" if value is True else "unmuted", ), YoLinkSensorEntityDescription( key="sound", device_class=SensorDeviceClass.ENUM, - name="Volume", + name="Power failure alarm volume", icon="mdi:volume-high", options=["low", "medium", "high"], exists_fn=lambda device: device.device_type in ATTR_DEVICE_POWER_FAILURE_ALARM, @@ -197,11 +197,11 @@ def cvt_volume(val: int | None) -> str | None: YoLinkSensorEntityDescription( key="beep", device_class=SensorDeviceClass.ENUM, - name="Beep", + name="Power failure alarm beep", icon="mdi:bullhorn", - options=["enable", "disable"], + options=["enabled", "disabled"], exists_fn=lambda device: device.device_type in ATTR_DEVICE_POWER_FAILURE_ALARM, - value=lambda value: "enable" if value is True else "disable", + value=lambda value: "enabled" if value is True else "disabled", ), )