2022-01-20 09:01:04 +00:00
|
|
|
"""Support for IntelliFire Binary Sensors."""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from collections.abc import Callable
|
|
|
|
from dataclasses import dataclass
|
|
|
|
|
|
|
|
from intellifire4py import IntellifirePollData
|
|
|
|
|
|
|
|
from homeassistant.components.binary_sensor import (
|
2022-03-30 07:41:25 +00:00
|
|
|
BinarySensorDeviceClass,
|
2022-01-20 09:01:04 +00:00
|
|
|
BinarySensorEntity,
|
|
|
|
BinarySensorEntityDescription,
|
|
|
|
)
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2023-02-09 19:15:37 +00:00
|
|
|
from homeassistant.const import EntityCategory
|
2022-01-20 09:01:04 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
|
|
|
|
from . import IntellifireDataUpdateCoordinator
|
|
|
|
from .const import DOMAIN
|
2022-02-12 00:01:38 +00:00
|
|
|
from .entity import IntellifireEntity
|
2022-01-20 09:01:04 +00:00
|
|
|
|
|
|
|
|
2023-12-19 02:28:13 +00:00
|
|
|
@dataclass(frozen=True)
|
2022-01-26 15:16:25 +00:00
|
|
|
class IntellifireBinarySensorRequiredKeysMixin:
|
2022-01-20 09:01:04 +00:00
|
|
|
"""Mixin for required keys."""
|
|
|
|
|
|
|
|
value_fn: Callable[[IntellifirePollData], bool]
|
|
|
|
|
|
|
|
|
2023-12-19 02:28:13 +00:00
|
|
|
@dataclass(frozen=True)
|
2022-01-20 09:01:04 +00:00
|
|
|
class IntellifireBinarySensorEntityDescription(
|
2022-01-26 15:16:25 +00:00
|
|
|
BinarySensorEntityDescription, IntellifireBinarySensorRequiredKeysMixin
|
2022-01-20 09:01:04 +00:00
|
|
|
):
|
|
|
|
"""Describes a binary sensor entity."""
|
|
|
|
|
|
|
|
|
|
|
|
INTELLIFIRE_BINARY_SENSORS: tuple[IntellifireBinarySensorEntityDescription, ...] = (
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="on_off", # This is the sensor name
|
2023-07-22 14:31:36 +00:00
|
|
|
translation_key="flame", # This is the translation key
|
2022-01-20 09:01:04 +00:00
|
|
|
value_fn=lambda data: data.is_on,
|
|
|
|
),
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="timer_on",
|
2023-07-22 14:31:36 +00:00
|
|
|
translation_key="timer_on",
|
2022-01-20 09:01:04 +00:00
|
|
|
value_fn=lambda data: data.timer_on,
|
|
|
|
),
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="pilot_light_on",
|
2023-07-22 14:31:36 +00:00
|
|
|
translation_key="pilot_light_on",
|
2022-01-20 09:01:04 +00:00
|
|
|
value_fn=lambda data: data.pilot_on,
|
|
|
|
),
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="thermostat_on",
|
2023-07-22 14:31:36 +00:00
|
|
|
translation_key="thermostat_on",
|
2022-01-20 09:01:04 +00:00
|
|
|
value_fn=lambda data: data.thermostat_on,
|
|
|
|
),
|
2022-03-30 07:41:25 +00:00
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="error_pilot_flame",
|
2023-07-22 14:31:36 +00:00
|
|
|
translation_key="pilot_flame_error",
|
2022-03-30 07:41:25 +00:00
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
value_fn=lambda data: data.error_pilot_flame,
|
|
|
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
|
|
|
),
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="error_flame",
|
2023-07-22 14:31:36 +00:00
|
|
|
translation_key="flame_error",
|
2022-03-30 07:41:25 +00:00
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
value_fn=lambda data: data.error_flame,
|
|
|
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
|
|
|
),
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="error_fan_delay",
|
2023-07-22 14:31:36 +00:00
|
|
|
translation_key="fan_delay_error",
|
2022-03-30 07:41:25 +00:00
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
value_fn=lambda data: data.error_fan_delay,
|
|
|
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
|
|
|
),
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="error_maintenance",
|
2023-07-22 14:31:36 +00:00
|
|
|
translation_key="maintenance_error",
|
2022-03-30 07:41:25 +00:00
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
value_fn=lambda data: data.error_maintenance,
|
|
|
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
|
|
|
),
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="error_disabled",
|
2023-07-22 14:31:36 +00:00
|
|
|
translation_key="disabled_error",
|
2022-03-30 07:41:25 +00:00
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
value_fn=lambda data: data.error_disabled,
|
|
|
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
|
|
|
),
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="error_fan",
|
2023-07-22 14:31:36 +00:00
|
|
|
translation_key="fan_error",
|
2022-03-30 07:41:25 +00:00
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
value_fn=lambda data: data.error_fan,
|
|
|
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
|
|
|
),
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="error_lights",
|
2023-07-22 14:31:36 +00:00
|
|
|
translation_key="lights_error",
|
2022-03-30 07:41:25 +00:00
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
value_fn=lambda data: data.error_lights,
|
|
|
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
|
|
|
),
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="error_accessory",
|
2023-07-22 14:31:36 +00:00
|
|
|
translation_key="accessory_error",
|
2022-03-30 07:41:25 +00:00
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
value_fn=lambda data: data.error_accessory,
|
|
|
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
|
|
|
),
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="error_soft_lock_out",
|
2023-07-22 14:31:36 +00:00
|
|
|
translation_key="soft_lock_out_error",
|
2022-03-30 07:41:25 +00:00
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
value_fn=lambda data: data.error_soft_lock_out,
|
|
|
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
|
|
|
),
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="error_ecm_offline",
|
2023-07-22 14:31:36 +00:00
|
|
|
translation_key="ecm_offline_error",
|
2022-03-30 07:41:25 +00:00
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
value_fn=lambda data: data.error_ecm_offline,
|
|
|
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
|
|
|
),
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="error_offline",
|
2023-07-22 14:31:36 +00:00
|
|
|
translation_key="offline_error",
|
2022-03-30 07:41:25 +00:00
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
value_fn=lambda data: data.error_offline,
|
|
|
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
|
|
|
),
|
2022-01-20 09:01:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
|
|
|
"""Set up a IntelliFire On/Off Sensor."""
|
|
|
|
coordinator: IntellifireDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
|
|
|
|
|
|
|
async_add_entities(
|
2022-01-20 12:48:24 +00:00
|
|
|
IntellifireBinarySensor(coordinator=coordinator, description=description)
|
2022-01-20 09:01:04 +00:00
|
|
|
for description in INTELLIFIRE_BINARY_SENSORS
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-02-12 00:01:38 +00:00
|
|
|
class IntellifireBinarySensor(IntellifireEntity, BinarySensorEntity):
|
|
|
|
"""Extends IntellifireEntity with Binary Sensor specific logic."""
|
2022-01-20 09:01:04 +00:00
|
|
|
|
|
|
|
entity_description: IntellifireBinarySensorEntityDescription
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self) -> bool:
|
|
|
|
"""Use this to get the correct value."""
|
2022-04-21 16:14:13 +00:00
|
|
|
return self.entity_description.value_fn(self.coordinator.read_api.data)
|