From 7ae17527eba7f84d59c11c95109d5fbfe2686f9f Mon Sep 17 00:00:00 2001 From: "jangwon.lee" Date: Mon, 2 Sep 2024 13:16:42 +0900 Subject: [PATCH 1/3] Add binary_sensor entity --- homeassistant/components/lg_thinq/__init__.py | 2 +- .../components/lg_thinq/binary_sensor.py | 115 ++++++++++++++++++ homeassistant/components/lg_thinq/icons.json | 17 +++ .../components/lg_thinq/strings.json | 17 +++ 4 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 homeassistant/components/lg_thinq/binary_sensor.py diff --git a/homeassistant/components/lg_thinq/__init__.py b/homeassistant/components/lg_thinq/__init__.py index 259d494902e4a3..a86afc681710db 100644 --- a/homeassistant/components/lg_thinq/__init__.py +++ b/homeassistant/components/lg_thinq/__init__.py @@ -19,7 +19,7 @@ type ThinqConfigEntry = ConfigEntry[dict[str, DeviceDataUpdateCoordinator]] -PLATFORMS = [Platform.SWITCH] +PLATFORMS = [Platform.BINARY_SENSOR, Platform.SWITCH] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/lg_thinq/binary_sensor.py b/homeassistant/components/lg_thinq/binary_sensor.py new file mode 100644 index 00000000000000..fc6564c7652bb5 --- /dev/null +++ b/homeassistant/components/lg_thinq/binary_sensor.py @@ -0,0 +1,115 @@ +"""Support for binary sensor entities.""" + +from __future__ import annotations + +from thinqconnect import PROPERTY_READABLE, DeviceType +from thinqconnect.devices.const import Property as ThinQProperty +from thinqconnect.integration.homeassistant.property import create_properties + +from homeassistant.components.binary_sensor import ( + BinarySensorEntity, + BinarySensorEntityDescription, +) +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddEntitiesCallback + +from . import ThinqConfigEntry +from .entity import ThinQEntity + +BINARY_SENSOR_DESC: dict[ThinQProperty, BinarySensorEntityDescription] = { + ThinQProperty.RINSE_REFILL: BinarySensorEntityDescription( + key=ThinQProperty.RINSE_REFILL, + translation_key=ThinQProperty.RINSE_REFILL, + ), + ThinQProperty.ECO_FRIENDLY_MODE: BinarySensorEntityDescription( + key=ThinQProperty.ECO_FRIENDLY_MODE, + translation_key=ThinQProperty.ECO_FRIENDLY_MODE, + ), + ThinQProperty.POWER_SAVE_ENABLED: BinarySensorEntityDescription( + key=ThinQProperty.POWER_SAVE_ENABLED, + translation_key=ThinQProperty.POWER_SAVE_ENABLED, + ), + ThinQProperty.REMOTE_CONTROL_ENABLED: BinarySensorEntityDescription( + key=ThinQProperty.REMOTE_CONTROL_ENABLED, + translation_key=ThinQProperty.REMOTE_CONTROL_ENABLED, + ), + ThinQProperty.SABBATH_MODE: BinarySensorEntityDescription( + key=ThinQProperty.SABBATH_MODE, + translation_key=ThinQProperty.SABBATH_MODE, + ), +} + +DEVICE_TYPE_BINARY_SENSOR_MAP: dict[ + DeviceType, tuple[BinarySensorEntityDescription, ...] +] = { + DeviceType.COOKTOP: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],), + DeviceType.DISH_WASHER: ( + BINARY_SENSOR_DESC[ThinQProperty.RINSE_REFILL], + BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED], + ), + DeviceType.DRYER: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],), + DeviceType.OVEN: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],), + DeviceType.REFRIGERATOR: ( + BINARY_SENSOR_DESC[ThinQProperty.ECO_FRIENDLY_MODE], + BINARY_SENSOR_DESC[ThinQProperty.POWER_SAVE_ENABLED], + BINARY_SENSOR_DESC[ThinQProperty.SABBATH_MODE], + ), + DeviceType.STYLER: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],), + DeviceType.WASHCOMBO_MAIN: ( + BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED], + ), + DeviceType.WASHCOMBO_MINI: ( + BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED], + ), + DeviceType.WASHER: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],), + DeviceType.WASHTOWER_DRYER: ( + BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED], + ), + DeviceType.WASHTOWER: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],), + DeviceType.WASHTOWER_WASHER: ( + BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED], + ), + DeviceType.WINE_CELLAR: (BINARY_SENSOR_DESC[ThinQProperty.SABBATH_MODE],), +} + + +async def async_setup_entry( + hass: HomeAssistant, + entry: ThinqConfigEntry, + async_add_entities: AddEntitiesCallback, +) -> None: + """Set up an entry for binary sensor platform.""" + entities: list[ThinQBinarySensorEntity] = [] + for coordinator in entry.runtime_data.values(): + if ( + descriptions := DEVICE_TYPE_BINARY_SENSOR_MAP.get( + coordinator.device_api.device_type + ) + ) is not None: + for description in descriptions: + properties = create_properties( + device_api=coordinator.device_api, + key=description.key, + children_keys=None, + rw_type=PROPERTY_READABLE, + ) + if not properties: + continue + + entities.extend( + ThinQBinarySensorEntity(coordinator, description, prop) + for prop in properties + ) + + if entities: + async_add_entities(entities) + + +class ThinQBinarySensorEntity(ThinQEntity, BinarySensorEntity): + """Represent a thinq binary sensor platform.""" + + def _update_status(self) -> None: + """Update status itself.""" + super()._update_status() + + self._attr_is_on = self.property.get_value_as_bool() diff --git a/homeassistant/components/lg_thinq/icons.json b/homeassistant/components/lg_thinq/icons.json index 6a4ff48494a998..550d023d278d35 100644 --- a/homeassistant/components/lg_thinq/icons.json +++ b/homeassistant/components/lg_thinq/icons.json @@ -4,6 +4,23 @@ "operation_power": { "default": "mdi:power" } + }, + "binary_sensor": { + "eco_friendly_mode": { + "default": "mdi:sprout" + }, + "power_save_enabled": { + "default": "mdi:meter-electric" + }, + "remote_control_enabled": { + "default": "mdi:remote" + }, + "rinse_refill": { + "default": "mdi:tune-vertical-variant" + }, + "sabbath_mode": { + "default": "mdi:food-off-outline" + } } } } diff --git a/homeassistant/components/lg_thinq/strings.json b/homeassistant/components/lg_thinq/strings.json index 6334fd9a893b9a..26c521e58f62bb 100644 --- a/homeassistant/components/lg_thinq/strings.json +++ b/homeassistant/components/lg_thinq/strings.json @@ -23,6 +23,23 @@ "operation_power": { "name": "Power" } + }, + "binary_sensor": { + "eco_friendly_mode": { + "name": "Eco Friendly" + }, + "power_save_enabled": { + "name": "Power Saving Mode" + }, + "remote_control_enabled": { + "name": "{location}Remote Start" + }, + "rinse_refill": { + "name": "Rinse refill needed" + }, + "sabbath_mode": { + "name": "Sabbath" + } } } } From 53747b5b5353256b471da896de0d80f122ea494f Mon Sep 17 00:00:00 2001 From: "jangwon.lee" Date: Mon, 2 Sep 2024 17:44:02 +0900 Subject: [PATCH 2/3] Update the document link due to the domain name change --- homeassistant/components/lg_thinq/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/lg_thinq/manifest.json b/homeassistant/components/lg_thinq/manifest.json index 0fa447a511b8a7..a49b91892f5e97 100644 --- a/homeassistant/components/lg_thinq/manifest.json +++ b/homeassistant/components/lg_thinq/manifest.json @@ -4,7 +4,7 @@ "codeowners": ["@LG-ThinQ-Integration"], "config_flow": true, "dependencies": [], - "documentation": "https://www.home-assistant.io/integrations/lgthinq/", + "documentation": "https://www.home-assistant.io/integrations/lg_thinq/", "iot_class": "cloud_push", "loggers": ["thinqconnect"], "requirements": ["thinqconnect==0.9.5"] From 01588b76496538238b4e2a1c2eccea9820f46d74 Mon Sep 17 00:00:00 2001 From: "jangwon.lee" Date: Mon, 2 Sep 2024 19:10:59 +0900 Subject: [PATCH 3/3] Update casing --- homeassistant/components/lg_thinq/strings.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/lg_thinq/strings.json b/homeassistant/components/lg_thinq/strings.json index 26c521e58f62bb..472e8b848b7be7 100644 --- a/homeassistant/components/lg_thinq/strings.json +++ b/homeassistant/components/lg_thinq/strings.json @@ -26,13 +26,13 @@ }, "binary_sensor": { "eco_friendly_mode": { - "name": "Eco Friendly" + "name": "Eco friendly" }, "power_save_enabled": { - "name": "Power Saving Mode" + "name": "Power saving mode" }, "remote_control_enabled": { - "name": "{location}Remote Start" + "name": "Remote start" }, "rinse_refill": { "name": "Rinse refill needed"