diff --git a/homeassistant/components/lg_thinq/binary_sensor.py b/homeassistant/components/lg_thinq/binary_sensor.py index c3179ea6948..c4f21861e54 100644 --- a/homeassistant/components/lg_thinq/binary_sensor.py +++ b/homeassistant/components/lg_thinq/binary_sensor.py @@ -2,6 +2,7 @@ from __future__ import annotations +from dataclasses import dataclass import logging from thinqconnect import DeviceType @@ -9,6 +10,7 @@ from thinqconnect.devices.const import Property as ThinQProperty from thinqconnect.integration import ActiveMode from homeassistant.components.binary_sensor import ( + BinarySensorDeviceClass, BinarySensorEntity, BinarySensorEntityDescription, ) @@ -18,44 +20,95 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import ThinqConfigEntry from .entity import ThinQEntity -BINARY_SENSOR_DESC: dict[ThinQProperty, BinarySensorEntityDescription] = { - ThinQProperty.RINSE_REFILL: BinarySensorEntityDescription( + +@dataclass(frozen=True, kw_only=True) +class ThinQBinarySensorEntityDescription(BinarySensorEntityDescription): + """Describes ThinQ sensor entity.""" + + on_key: str | None = None + + +BINARY_SENSOR_DESC: dict[ThinQProperty, ThinQBinarySensorEntityDescription] = { + ThinQProperty.RINSE_REFILL: ThinQBinarySensorEntityDescription( key=ThinQProperty.RINSE_REFILL, translation_key=ThinQProperty.RINSE_REFILL, ), - ThinQProperty.ECO_FRIENDLY_MODE: BinarySensorEntityDescription( + ThinQProperty.ECO_FRIENDLY_MODE: ThinQBinarySensorEntityDescription( key=ThinQProperty.ECO_FRIENDLY_MODE, translation_key=ThinQProperty.ECO_FRIENDLY_MODE, ), - ThinQProperty.POWER_SAVE_ENABLED: BinarySensorEntityDescription( + ThinQProperty.POWER_SAVE_ENABLED: ThinQBinarySensorEntityDescription( key=ThinQProperty.POWER_SAVE_ENABLED, translation_key=ThinQProperty.POWER_SAVE_ENABLED, ), - ThinQProperty.REMOTE_CONTROL_ENABLED: BinarySensorEntityDescription( + ThinQProperty.REMOTE_CONTROL_ENABLED: ThinQBinarySensorEntityDescription( key=ThinQProperty.REMOTE_CONTROL_ENABLED, translation_key=ThinQProperty.REMOTE_CONTROL_ENABLED, ), - ThinQProperty.SABBATH_MODE: BinarySensorEntityDescription( + ThinQProperty.SABBATH_MODE: ThinQBinarySensorEntityDescription( key=ThinQProperty.SABBATH_MODE, translation_key=ThinQProperty.SABBATH_MODE, ), + ThinQProperty.DOOR_STATE: ThinQBinarySensorEntityDescription( + key=ThinQProperty.DOOR_STATE, + device_class=BinarySensorDeviceClass.DOOR, + on_key="open", + ), + ThinQProperty.MACHINE_CLEAN_REMINDER: ThinQBinarySensorEntityDescription( + key=ThinQProperty.MACHINE_CLEAN_REMINDER, + translation_key=ThinQProperty.MACHINE_CLEAN_REMINDER, + on_key="mcreminder_on", + ), + ThinQProperty.SIGNAL_LEVEL: ThinQBinarySensorEntityDescription( + key=ThinQProperty.SIGNAL_LEVEL, + translation_key=ThinQProperty.SIGNAL_LEVEL, + on_key="signallevel_on", + ), + ThinQProperty.CLEAN_LIGHT_REMINDER: ThinQBinarySensorEntityDescription( + key=ThinQProperty.CLEAN_LIGHT_REMINDER, + translation_key=ThinQProperty.CLEAN_LIGHT_REMINDER, + on_key="cleanlreminder_on", + ), + ThinQProperty.HOOD_OPERATION_MODE: ThinQBinarySensorEntityDescription( + key=ThinQProperty.HOOD_OPERATION_MODE, + translation_key="operation_mode", + on_key="power_on", + ), + ThinQProperty.WATER_HEATER_OPERATION_MODE: ThinQBinarySensorEntityDescription( + key=ThinQProperty.WATER_HEATER_OPERATION_MODE, + translation_key="operation_mode", + on_key="power_on", + ), + ThinQProperty.ONE_TOUCH_FILTER: ThinQBinarySensorEntityDescription( + key=ThinQProperty.ONE_TOUCH_FILTER, + translation_key=ThinQProperty.ONE_TOUCH_FILTER, + ), } DEVICE_TYPE_BINARY_SENSOR_MAP: dict[ - DeviceType, tuple[BinarySensorEntityDescription, ...] + DeviceType, tuple[ThinQBinarySensorEntityDescription, ...] ] = { DeviceType.COOKTOP: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],), DeviceType.DISH_WASHER: ( + BINARY_SENSOR_DESC[ThinQProperty.DOOR_STATE], BINARY_SENSOR_DESC[ThinQProperty.RINSE_REFILL], BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED], + BINARY_SENSOR_DESC[ThinQProperty.MACHINE_CLEAN_REMINDER], + BINARY_SENSOR_DESC[ThinQProperty.SIGNAL_LEVEL], + BINARY_SENSOR_DESC[ThinQProperty.CLEAN_LIGHT_REMINDER], ), DeviceType.DRYER: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],), + DeviceType.HOOD: (BINARY_SENSOR_DESC[ThinQProperty.HOOD_OPERATION_MODE],), DeviceType.OVEN: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],), DeviceType.REFRIGERATOR: ( + BINARY_SENSOR_DESC[ThinQProperty.DOOR_STATE], BINARY_SENSOR_DESC[ThinQProperty.ECO_FRIENDLY_MODE], BINARY_SENSOR_DESC[ThinQProperty.POWER_SAVE_ENABLED], BINARY_SENSOR_DESC[ThinQProperty.SABBATH_MODE], ), + DeviceType.KIMCHI_REFRIGERATOR: ( + BINARY_SENSOR_DESC[ThinQProperty.ONE_TOUCH_FILTER], + ), DeviceType.STYLER: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],), DeviceType.WASHCOMBO_MAIN: ( BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED], @@ -71,6 +124,9 @@ DEVICE_TYPE_BINARY_SENSOR_MAP: dict[ DeviceType.WASHTOWER_WASHER: ( BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED], ), + DeviceType.WATER_HEATER: ( + BINARY_SENSOR_DESC[ThinQProperty.WATER_HEATER_OPERATION_MODE], + ), DeviceType.WINE_CELLAR: (BINARY_SENSOR_DESC[ThinQProperty.SABBATH_MODE],), } _LOGGER = logging.getLogger(__name__) @@ -104,14 +160,21 @@ async def async_setup_entry( class ThinQBinarySensorEntity(ThinQEntity, BinarySensorEntity): """Represent a thinq binary sensor platform.""" + entity_description: ThinQBinarySensorEntityDescription + def _update_status(self) -> None: """Update status itself.""" super()._update_status() + if (key := self.entity_description.on_key) is not None: + self._attr_is_on = self.data.value == key + else: + self._attr_is_on = self.data.is_on + _LOGGER.debug( - "[%s:%s] update status: %s", + "[%s:%s] update status: %s -> %s", self.coordinator.device_name, self.property_id, - self.data.is_on, + self.data.value, + self.is_on, ) - self._attr_is_on = self.data.is_on diff --git a/homeassistant/components/lg_thinq/icons.json b/homeassistant/components/lg_thinq/icons.json index 3cc4ab784c2..d96214725c8 100644 --- a/homeassistant/components/lg_thinq/icons.json +++ b/homeassistant/components/lg_thinq/icons.json @@ -23,6 +23,21 @@ }, "sabbath_mode": { "default": "mdi:food-off-outline" + }, + "machine_clean_reminder": { + "default": "mdi:tune-vertical-variant" + }, + "signal_level": { + "default": "mdi:tune-vertical-variant" + }, + "clean_light_reminder": { + "default": "mdi:tune-vertical-variant" + }, + "operation_mode": { + "default": "mdi:power" + }, + "one_touch_filter": { + "default": "mdi:air-filter" } } } diff --git a/homeassistant/components/lg_thinq/strings.json b/homeassistant/components/lg_thinq/strings.json index 6649c6b0c13..9ec11952a9a 100644 --- a/homeassistant/components/lg_thinq/strings.json +++ b/homeassistant/components/lg_thinq/strings.json @@ -42,6 +42,21 @@ }, "sabbath_mode": { "name": "Sabbath" + }, + "machine_clean_reminder": { + "name": "Machine clean reminder" + }, + "signal_level": { + "name": "Chime sound" + }, + "clean_light_reminder": { + "name": "Clean indicator light" + }, + "operation_mode": { + "name": "[%key:component::binary_sensor::entity_component::power::name%]" + }, + "one_touch_filter": { + "name": "Fresh air filter" } } }