hOn/custom_components/hon/binary_sensor.py

324 lines
10 KiB
Python
Raw Normal View History

2023-03-05 18:19:52 +00:00
import logging
from dataclasses import dataclass
2023-04-10 17:51:16 +00:00
from homeassistant.components.binary_sensor import (
BinarySensorEntityDescription,
BinarySensorDeviceClass,
BinarySensorEntity,
)
2023-03-05 18:19:52 +00:00
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import HomeAssistantType
2023-05-24 22:52:54 +00:00
2023-03-05 18:19:52 +00:00
from .const import DOMAIN
2023-05-24 23:30:33 +00:00
from .hon import HonEntity, unique_entities
2023-03-05 18:19:52 +00:00
_LOGGER = logging.getLogger(__name__)
@dataclass
2023-07-09 22:21:45 +00:00
class HonBinarySensorEntityDescription(BinarySensorEntityDescription):
2023-06-12 22:14:51 +00:00
on_value: str | float = ""
2023-03-05 18:19:52 +00:00
BINARY_SENSORS: dict[str, tuple[HonBinarySensorEntityDescription, ...]] = {
"WM": (
HonBinarySensorEntityDescription(
2023-03-08 22:00:55 +00:00
key="attributes.lastConnEvent.category",
2023-03-22 21:57:14 +00:00
name="Remote Control",
2023-03-05 18:19:52 +00:00
device_class=BinarySensorDeviceClass.CONNECTIVITY,
on_value="CONNECTED",
2023-04-10 17:51:16 +00:00
icon="mdi:remote",
2023-04-23 00:01:14 +00:00
translation_key="remote_control",
2023-03-05 18:19:52 +00:00
),
HonBinarySensorEntityDescription(
key="doorLockStatus",
2023-03-22 21:57:14 +00:00
name="Door Lock",
device_class=BinarySensorDeviceClass.LOCK,
2023-06-12 22:14:51 +00:00
on_value=0,
2023-04-23 00:01:14 +00:00
translation_key="door_lock",
2023-03-22 21:57:14 +00:00
),
HonBinarySensorEntityDescription(
key="doorStatus",
2023-03-08 22:00:55 +00:00
name="Door",
2023-03-05 18:19:52 +00:00
device_class=BinarySensorDeviceClass.DOOR,
2023-06-12 22:14:51 +00:00
on_value=1,
translation_key="door_open",
2023-03-05 18:19:52 +00:00
),
2023-04-08 02:44:47 +00:00
HonBinarySensorEntityDescription(
2023-07-09 22:19:43 +00:00
key="prewash",
icon="mdi:tshirt-crew",
name="Pre Wash",
translation_key="prewash",
2023-04-08 02:44:47 +00:00
),
HonBinarySensorEntityDescription(
2023-07-09 22:19:43 +00:00
key="extraRinse1",
icon="mdi:numeric-1-box-multiple-outline",
name="Extra Rinse 1",
translation_key="extra_rinse_1",
2023-04-08 02:44:47 +00:00
),
HonBinarySensorEntityDescription(
2023-07-09 22:19:43 +00:00
key="extraRinse2",
icon="mdi:numeric-2-box-multiple-outline",
name="Extra Rinse 2",
translation_key="extra_rinse_2",
2023-04-08 02:44:47 +00:00
),
HonBinarySensorEntityDescription(
2023-07-09 22:19:43 +00:00
key="extraRinse3",
icon="mdi:numeric-3-box-multiple-outline",
name="Extra Rinse 3",
translation_key="extra_rinse_3",
2023-04-08 02:44:47 +00:00
),
HonBinarySensorEntityDescription(
2023-07-09 22:19:43 +00:00
key="goodNight",
icon="mdi:weather-night",
name="Good Night Mode",
translation_key="good_night",
2023-04-08 02:44:47 +00:00
),
HonBinarySensorEntityDescription(
2023-07-09 22:19:43 +00:00
key="acquaplus",
icon="mdi:water-plus",
name="Acqua Plus",
translation_key="acqua_plus",
2023-04-08 02:44:47 +00:00
),
2023-05-07 14:39:45 +00:00
),
"TD": (
HonBinarySensorEntityDescription(
key="attributes.lastConnEvent.category",
name="Connection",
device_class=BinarySensorDeviceClass.CONNECTIVITY,
on_value="CONNECTED",
translation_key="connection",
),
HonBinarySensorEntityDescription(
key="doorStatus",
name="Door",
device_class=BinarySensorDeviceClass.DOOR,
2023-06-12 22:14:51 +00:00
on_value=1,
2023-05-07 14:39:45 +00:00
translation_key="door_open",
),
2023-04-08 02:44:47 +00:00
HonBinarySensorEntityDescription(
2023-07-09 22:19:43 +00:00
key="anticrease",
name="Anti-Crease",
icon="mdi:iron",
translation_key="anti_crease",
2023-04-08 02:44:47 +00:00
),
),
2023-04-07 11:52:55 +00:00
"OV": (
HonBinarySensorEntityDescription(
key="attributes.lastConnEvent.category",
2023-04-15 02:27:40 +00:00
name="Connection",
2023-04-07 11:52:55 +00:00
device_class=BinarySensorDeviceClass.CONNECTIVITY,
on_value="CONNECTED",
2023-04-10 17:51:16 +00:00
icon="mdi:wifi",
2023-04-23 00:01:14 +00:00
translation_key="connection",
2023-04-07 11:52:55 +00:00
),
2023-04-15 02:27:40 +00:00
HonBinarySensorEntityDescription(
key="attributes.parameters.onOffStatus",
2023-04-07 11:52:55 +00:00
name="On",
2023-04-15 02:27:40 +00:00
device_class=BinarySensorDeviceClass.RUNNING,
2023-06-12 22:14:51 +00:00
on_value=1,
2023-04-15 02:27:40 +00:00
icon="mdi:power-cycle",
2023-04-24 19:38:05 +00:00
translation_key="on",
2023-04-15 02:27:40 +00:00
),
),
2023-04-16 11:55:08 +00:00
"IH": (
2023-04-15 02:27:40 +00:00
HonBinarySensorEntityDescription(
key="attributes.lastConnEvent.category",
name="Connection",
device_class=BinarySensorDeviceClass.CONNECTIVITY,
on_value="CONNECTED",
icon="mdi:wifi",
2023-04-23 00:01:14 +00:00
translation_key="connection",
2023-04-15 02:27:40 +00:00
),
2023-04-07 11:52:55 +00:00
HonBinarySensorEntityDescription(
key="attributes.parameters.onOffStatus",
name="On",
device_class=BinarySensorDeviceClass.RUNNING,
2023-06-12 22:14:51 +00:00
on_value=1,
2023-04-10 17:51:16 +00:00
icon="mdi:power-cycle",
2023-04-24 19:38:05 +00:00
translation_key="on",
2023-04-07 11:52:55 +00:00
),
2023-04-15 02:27:40 +00:00
HonBinarySensorEntityDescription(
key="hotStatus",
name="Hot Status",
device_class=BinarySensorDeviceClass.HEAT,
2023-06-12 22:14:51 +00:00
on_value=1,
2023-04-23 00:01:14 +00:00
translation_key="still_hot",
2023-04-15 02:27:40 +00:00
),
2023-04-18 21:44:23 +00:00
HonBinarySensorEntityDescription(
2023-04-23 00:01:14 +00:00
key="panStatus",
name="Pan Status",
2023-06-12 22:14:51 +00:00
on_value=1,
2023-04-23 00:01:14 +00:00
icon="mdi:pot-mix",
translation_key="pan_status",
2023-04-18 21:44:23 +00:00
),
2023-04-15 02:27:40 +00:00
HonBinarySensorEntityDescription(
key="hobLockStatus",
name="Hob Lock",
device_class=BinarySensorDeviceClass.LOCK,
2023-06-12 22:14:51 +00:00
on_value=0,
2023-04-24 19:38:05 +00:00
translation_key="child_lock",
2023-04-15 02:27:40 +00:00
),
2023-04-08 02:44:47 +00:00
),
2023-04-16 19:46:17 +00:00
"DW": (
HonBinarySensorEntityDescription(
key="saltStatus",
name="Salt",
device_class=BinarySensorDeviceClass.PROBLEM,
2023-06-12 22:14:51 +00:00
on_value=1,
2023-04-16 19:46:17 +00:00
icon="mdi:shaker-outline",
2023-04-23 00:01:14 +00:00
translation_key="salt_level",
2023-04-16 19:46:17 +00:00
),
HonBinarySensorEntityDescription(
key="rinseAidStatus",
name="Rinse Aid",
device_class=BinarySensorDeviceClass.PROBLEM,
2023-06-12 22:14:51 +00:00
on_value=1,
2023-04-16 19:46:17 +00:00
icon="mdi:spray-bottle",
2023-04-23 00:01:14 +00:00
translation_key="rinse_aid",
2023-04-16 19:46:17 +00:00
),
HonBinarySensorEntityDescription(
key="attributes.lastConnEvent.category",
name="Connection",
device_class=BinarySensorDeviceClass.CONNECTIVITY,
on_value="CONNECTED",
2023-04-23 00:01:14 +00:00
translation_key="connection",
2023-04-16 19:46:17 +00:00
),
HonBinarySensorEntityDescription(
key="doorStatus",
name="Door",
device_class=BinarySensorDeviceClass.DOOR,
2023-06-12 22:14:51 +00:00
on_value=1,
2023-04-23 00:01:14 +00:00
translation_key="door_open",
2023-04-16 19:46:17 +00:00
),
),
2023-05-16 22:01:33 +00:00
"AC": (
HonBinarySensorEntityDescription(
key="filterChangeStatusLocal",
name="Filter Replacement",
device_class=BinarySensorDeviceClass.PROBLEM,
2023-06-12 22:14:51 +00:00
on_value=1,
2023-05-16 22:01:33 +00:00
translation_key="filter_replacement",
),
HonBinarySensorEntityDescription(
key="ch2oCleaningStatus",
name="Ch2O Cleaning",
2023-06-12 22:14:51 +00:00
on_value=1,
2023-05-16 22:01:33 +00:00
),
),
2023-05-14 22:38:41 +00:00
"REF": (
HonBinarySensorEntityDescription(
key="quickModeZ1",
2023-05-14 22:38:41 +00:00
name="Super Cool",
icon="mdi:snowflake",
device_class=BinarySensorDeviceClass.RUNNING,
2023-06-12 22:14:51 +00:00
on_value=1,
2023-05-14 22:38:41 +00:00
translation_key="super_cool",
),
HonBinarySensorEntityDescription(
key="quickModeZ2",
2023-05-14 22:38:41 +00:00
name="Super Freeze",
icon="mdi:snowflake-variant",
device_class=BinarySensorDeviceClass.RUNNING,
2023-06-12 22:14:51 +00:00
on_value=1,
2023-05-14 22:38:41 +00:00
translation_key="super_freeze",
),
HonBinarySensorEntityDescription(
key="doorStatusZ1",
name="Door1 Status Fridge",
2023-05-14 22:38:41 +00:00
device_class=BinarySensorDeviceClass.DOOR,
icon="mdi:fridge-top",
2023-06-12 22:14:51 +00:00
on_value=1,
translation_key="fridge_door",
2023-05-14 22:38:41 +00:00
),
HonBinarySensorEntityDescription(
key="door2StatusZ1",
name="Door2 Status Fridge",
icon="mdi:fridge-top",
2023-05-14 22:38:41 +00:00
device_class=BinarySensorDeviceClass.DOOR,
2023-06-12 22:14:51 +00:00
on_value=1,
2023-05-14 22:38:41 +00:00
translation_key="fridge_door",
),
HonBinarySensorEntityDescription(
key="doorStatusZ2",
name="Door1 Status Freezer",
icon="mdi:fridge-bottom",
device_class=BinarySensorDeviceClass.DOOR,
on_value=1,
translation_key="freezer_door",
),
HonBinarySensorEntityDescription(
key="door2StatusZ2",
name="Door2 Status Freezer",
icon="mdi:fridge-bottom",
device_class=BinarySensorDeviceClass.DOOR,
on_value=1,
translation_key="freezer_door",
),
HonBinarySensorEntityDescription(
2023-05-14 22:38:41 +00:00
key="intelligenceMode",
name="Auto-Set Mode",
icon="mdi:thermometer-auto",
2023-05-14 22:38:41 +00:00
device_class=BinarySensorDeviceClass.RUNNING,
2023-06-12 22:14:51 +00:00
on_value=1,
2023-05-14 22:38:41 +00:00
translation_key="auto_set",
),
HonBinarySensorEntityDescription(
key="holidayMode",
name="Holiday Mode",
icon="mdi:palm-tree",
device_class=BinarySensorDeviceClass.RUNNING,
2023-06-12 22:14:51 +00:00
on_value=1,
2023-05-14 22:38:41 +00:00
translation_key="holiday_mode",
),
),
2023-06-20 22:59:00 +00:00
"AP": (
HonBinarySensorEntityDescription(
key="attributes.parameters.onOffStatus",
name="On",
device_class=BinarySensorDeviceClass.RUNNING,
on_value="1",
icon="mdi:power-cycle",
translation_key="on",
),
),
2023-03-05 18:19:52 +00:00
}
2023-05-07 14:39:45 +00:00
BINARY_SENSORS["WD"] = unique_entities(BINARY_SENSORS["WM"], BINARY_SENSORS["TD"])
async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
2023-05-24 23:30:33 +00:00
entities = []
for device in hass.data[DOMAIN][entry.unique_id].appliances:
for description in BINARY_SENSORS.get(device.appliance_type, []):
2023-06-12 22:14:51 +00:00
if device.get(description.key) is None:
2023-05-24 23:30:33 +00:00
continue
entity = HonBinarySensorEntity(hass, entry, device, description)
await entity.coordinator.async_config_entry_first_refresh()
entities.append(entity)
async_add_entities(entities)
2023-03-05 18:19:52 +00:00
class HonBinarySensorEntity(HonEntity, BinarySensorEntity):
entity_description: HonBinarySensorEntityDescription
@property
def is_on(self) -> bool:
return bool(
2023-04-10 17:51:16 +00:00
self._device.get(self.entity_description.key, "")
== self.entity_description.on_value
)
2023-03-05 18:19:52 +00:00
@callback
def _handle_coordinator_update(self, update: bool = True) -> None:
2023-04-10 17:51:16 +00:00
self._attr_native_value = (
self._device.get(self.entity_description.key, "")
== self.entity_description.on_value
)
2023-06-08 18:01:55 +00:00
if update:
self.async_write_ha_state()