Add binary_sensor platform to LG Thinq (#125054)

* Add binary_sensor entity

* Update the document link due to the domain name change

* Update casing

---------

Co-authored-by: jangwon.lee <jangwon.lee@lge.com>
This commit is contained in:
LG-ThinQ-Integration 2024-09-03 16:30:46 +09:00 committed by GitHub
parent 7c223db1d5
commit aa8fe99113
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 151 additions and 2 deletions

View File

@ -19,7 +19,7 @@ from .coordinator import DeviceDataUpdateCoordinator, async_setup_device_coordin
type ThinqConfigEntry = ConfigEntry[dict[str, DeviceDataUpdateCoordinator]]
PLATFORMS = [Platform.SWITCH]
PLATFORMS = [Platform.BINARY_SENSOR, Platform.SWITCH]
_LOGGER = logging.getLogger(__name__)

View File

@ -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()

View File

@ -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"
}
}
}
}

View File

@ -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"]

View File

@ -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": "Remote start"
},
"rinse_refill": {
"name": "Rinse refill needed"
},
"sabbath_mode": {
"name": "Sabbath"
}
}
}
}