mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Add binary_sensor platform to LG ThinQ integration (#125664)
* Add binary_sensor platform to LG ThinQ integration * Update homeassistant/components/lg_thinq/binary_sensor.py * Remove unused translation key * Add one_touch_filter property to binary_sensor * Add one_touch_filter to icons, strings * Update homeassistant/components/lg_thinq/strings.json --------- Co-authored-by: jangwon.lee <jangwon.lee@lge.com> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
11fe48f2d2
commit
2475e8c0c4
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from thinqconnect import DeviceType
|
from thinqconnect import DeviceType
|
||||||
@ -9,6 +10,7 @@ from thinqconnect.devices.const import Property as ThinQProperty
|
|||||||
from thinqconnect.integration import ActiveMode
|
from thinqconnect.integration import ActiveMode
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
|
BinarySensorDeviceClass,
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
BinarySensorEntityDescription,
|
BinarySensorEntityDescription,
|
||||||
)
|
)
|
||||||
@ -18,44 +20,95 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
from . import ThinqConfigEntry
|
from . import ThinqConfigEntry
|
||||||
from .entity import ThinQEntity
|
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,
|
key=ThinQProperty.RINSE_REFILL,
|
||||||
translation_key=ThinQProperty.RINSE_REFILL,
|
translation_key=ThinQProperty.RINSE_REFILL,
|
||||||
),
|
),
|
||||||
ThinQProperty.ECO_FRIENDLY_MODE: BinarySensorEntityDescription(
|
ThinQProperty.ECO_FRIENDLY_MODE: ThinQBinarySensorEntityDescription(
|
||||||
key=ThinQProperty.ECO_FRIENDLY_MODE,
|
key=ThinQProperty.ECO_FRIENDLY_MODE,
|
||||||
translation_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,
|
key=ThinQProperty.POWER_SAVE_ENABLED,
|
||||||
translation_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,
|
key=ThinQProperty.REMOTE_CONTROL_ENABLED,
|
||||||
translation_key=ThinQProperty.REMOTE_CONTROL_ENABLED,
|
translation_key=ThinQProperty.REMOTE_CONTROL_ENABLED,
|
||||||
),
|
),
|
||||||
ThinQProperty.SABBATH_MODE: BinarySensorEntityDescription(
|
ThinQProperty.SABBATH_MODE: ThinQBinarySensorEntityDescription(
|
||||||
key=ThinQProperty.SABBATH_MODE,
|
key=ThinQProperty.SABBATH_MODE,
|
||||||
translation_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[
|
DEVICE_TYPE_BINARY_SENSOR_MAP: dict[
|
||||||
DeviceType, tuple[BinarySensorEntityDescription, ...]
|
DeviceType, tuple[ThinQBinarySensorEntityDescription, ...]
|
||||||
] = {
|
] = {
|
||||||
DeviceType.COOKTOP: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],),
|
DeviceType.COOKTOP: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],),
|
||||||
DeviceType.DISH_WASHER: (
|
DeviceType.DISH_WASHER: (
|
||||||
|
BINARY_SENSOR_DESC[ThinQProperty.DOOR_STATE],
|
||||||
BINARY_SENSOR_DESC[ThinQProperty.RINSE_REFILL],
|
BINARY_SENSOR_DESC[ThinQProperty.RINSE_REFILL],
|
||||||
BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],
|
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.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.OVEN: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],),
|
||||||
DeviceType.REFRIGERATOR: (
|
DeviceType.REFRIGERATOR: (
|
||||||
|
BINARY_SENSOR_DESC[ThinQProperty.DOOR_STATE],
|
||||||
BINARY_SENSOR_DESC[ThinQProperty.ECO_FRIENDLY_MODE],
|
BINARY_SENSOR_DESC[ThinQProperty.ECO_FRIENDLY_MODE],
|
||||||
BINARY_SENSOR_DESC[ThinQProperty.POWER_SAVE_ENABLED],
|
BINARY_SENSOR_DESC[ThinQProperty.POWER_SAVE_ENABLED],
|
||||||
BINARY_SENSOR_DESC[ThinQProperty.SABBATH_MODE],
|
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.STYLER: (BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],),
|
||||||
DeviceType.WASHCOMBO_MAIN: (
|
DeviceType.WASHCOMBO_MAIN: (
|
||||||
BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],
|
BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],
|
||||||
@ -71,6 +124,9 @@ DEVICE_TYPE_BINARY_SENSOR_MAP: dict[
|
|||||||
DeviceType.WASHTOWER_WASHER: (
|
DeviceType.WASHTOWER_WASHER: (
|
||||||
BINARY_SENSOR_DESC[ThinQProperty.REMOTE_CONTROL_ENABLED],
|
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],),
|
DeviceType.WINE_CELLAR: (BINARY_SENSOR_DESC[ThinQProperty.SABBATH_MODE],),
|
||||||
}
|
}
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -104,14 +160,21 @@ async def async_setup_entry(
|
|||||||
class ThinQBinarySensorEntity(ThinQEntity, BinarySensorEntity):
|
class ThinQBinarySensorEntity(ThinQEntity, BinarySensorEntity):
|
||||||
"""Represent a thinq binary sensor platform."""
|
"""Represent a thinq binary sensor platform."""
|
||||||
|
|
||||||
|
entity_description: ThinQBinarySensorEntityDescription
|
||||||
|
|
||||||
def _update_status(self) -> None:
|
def _update_status(self) -> None:
|
||||||
"""Update status itself."""
|
"""Update status itself."""
|
||||||
super()._update_status()
|
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(
|
_LOGGER.debug(
|
||||||
"[%s:%s] update status: %s",
|
"[%s:%s] update status: %s -> %s",
|
||||||
self.coordinator.device_name,
|
self.coordinator.device_name,
|
||||||
self.property_id,
|
self.property_id,
|
||||||
self.data.is_on,
|
self.data.value,
|
||||||
|
self.is_on,
|
||||||
)
|
)
|
||||||
self._attr_is_on = self.data.is_on
|
|
||||||
|
@ -23,6 +23,21 @@
|
|||||||
},
|
},
|
||||||
"sabbath_mode": {
|
"sabbath_mode": {
|
||||||
"default": "mdi:food-off-outline"
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,21 @@
|
|||||||
},
|
},
|
||||||
"sabbath_mode": {
|
"sabbath_mode": {
|
||||||
"name": "Sabbath"
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user