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
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
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]
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
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
|
|
|
|
name="Flame", # This is the human readable name
|
|
|
|
icon="mdi:fire",
|
|
|
|
value_fn=lambda data: data.is_on,
|
|
|
|
),
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="timer_on",
|
2023-03-03 14:04:27 +00:00
|
|
|
name="Timer on",
|
2022-01-20 09:01:04 +00:00
|
|
|
icon="mdi:camera-timer",
|
|
|
|
value_fn=lambda data: data.timer_on,
|
|
|
|
),
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="pilot_light_on",
|
2023-03-03 14:04:27 +00:00
|
|
|
name="Pilot light on",
|
2022-01-20 09:01:04 +00:00
|
|
|
icon="mdi:fire-alert",
|
|
|
|
value_fn=lambda data: data.pilot_on,
|
|
|
|
),
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="thermostat_on",
|
2023-03-03 14:04:27 +00:00
|
|
|
name="Thermostat on",
|
2022-01-20 09:01:04 +00:00
|
|
|
icon="mdi:home-thermometer-outline",
|
|
|
|
value_fn=lambda data: data.thermostat_on,
|
|
|
|
),
|
2022-03-30 07:41:25 +00:00
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="error_pilot_flame",
|
2023-03-03 14:04:27 +00:00
|
|
|
name="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",
|
|
|
|
name="Flame Error",
|
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
value_fn=lambda data: data.error_flame,
|
|
|
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
|
|
|
),
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="error_fan_delay",
|
2023-03-03 14:04:27 +00:00
|
|
|
name="Fan delay error",
|
2022-03-30 07:41:25 +00:00
|
|
|
icon="mdi:fan-alert",
|
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
value_fn=lambda data: data.error_fan_delay,
|
|
|
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
|
|
|
),
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="error_maintenance",
|
2023-03-03 14:04:27 +00:00
|
|
|
name="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-03-03 14:04:27 +00:00
|
|
|
name="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-03-03 14:04:27 +00:00
|
|
|
name="Fan error",
|
2022-03-30 07:41:25 +00:00
|
|
|
icon="mdi:fan-alert",
|
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
value_fn=lambda data: data.error_fan,
|
|
|
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
|
|
|
),
|
|
|
|
IntellifireBinarySensorEntityDescription(
|
|
|
|
key="error_lights",
|
2023-03-03 14:04:27 +00:00
|
|
|
name="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-03-03 14:04:27 +00:00
|
|
|
name="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-03-03 14:04:27 +00:00
|
|
|
name="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-03-03 14:04:27 +00:00
|
|
|
name="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-03-03 14:04:27 +00:00
|
|
|
name="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)
|