Bump screenlogicpy to v0.9.0 (#92475)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
8de3945bd4
commit
092580a3ed
28 changed files with 3821 additions and 652 deletions
|
@ -1,28 +1,97 @@
|
|||
"""Support for a ScreenLogic Binary Sensor."""
|
||||
from screenlogicpy.const import CODE, DATA as SL_DATA, DEVICE_TYPE, EQUIPMENT, ON_OFF
|
||||
from dataclasses import dataclass
|
||||
import logging
|
||||
|
||||
from screenlogicpy.const.common import DEVICE_TYPE, ON_OFF
|
||||
from screenlogicpy.const.data import ATTR, DEVICE, GROUP, VALUE
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DOMAIN,
|
||||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
BinarySensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ScreenlogicDataUpdateCoordinator
|
||||
from .const import DOMAIN
|
||||
from .entity import ScreenlogicEntity, ScreenLogicPushEntity
|
||||
from .const import DOMAIN as SL_DOMAIN, ScreenLogicDataPath
|
||||
from .coordinator import ScreenlogicDataUpdateCoordinator
|
||||
from .data import (
|
||||
DEVICE_INCLUSION_RULES,
|
||||
DEVICE_SUBSCRIPTION,
|
||||
SupportedValueParameters,
|
||||
build_base_entity_description,
|
||||
iterate_expand_group_wildcard,
|
||||
preprocess_supported_values,
|
||||
)
|
||||
from .entity import (
|
||||
ScreenlogicEntity,
|
||||
ScreenLogicEntityDescription,
|
||||
ScreenLogicPushEntity,
|
||||
ScreenLogicPushEntityDescription,
|
||||
)
|
||||
from .util import cleanup_excluded_entity, generate_unique_id
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass
|
||||
class SupportedBinarySensorValueParameters(SupportedValueParameters):
|
||||
"""Supported predefined data for a ScreenLogic binary sensor entity."""
|
||||
|
||||
device_class: BinarySensorDeviceClass | None = None
|
||||
|
||||
|
||||
SUPPORTED_DATA: list[
|
||||
tuple[ScreenLogicDataPath, SupportedValueParameters]
|
||||
] = preprocess_supported_values(
|
||||
{
|
||||
DEVICE.CONTROLLER: {
|
||||
GROUP.SENSOR: {
|
||||
VALUE.ACTIVE_ALERT: SupportedBinarySensorValueParameters(),
|
||||
VALUE.CLEANER_DELAY: SupportedBinarySensorValueParameters(),
|
||||
VALUE.FREEZE_MODE: SupportedBinarySensorValueParameters(),
|
||||
VALUE.POOL_DELAY: SupportedBinarySensorValueParameters(),
|
||||
VALUE.SPA_DELAY: SupportedBinarySensorValueParameters(),
|
||||
},
|
||||
},
|
||||
DEVICE.PUMP: {
|
||||
"*": {
|
||||
VALUE.STATE: SupportedBinarySensorValueParameters(),
|
||||
},
|
||||
},
|
||||
DEVICE.INTELLICHEM: {
|
||||
GROUP.ALARM: {
|
||||
VALUE.FLOW_ALARM: SupportedBinarySensorValueParameters(),
|
||||
VALUE.ORP_HIGH_ALARM: SupportedBinarySensorValueParameters(),
|
||||
VALUE.ORP_LOW_ALARM: SupportedBinarySensorValueParameters(),
|
||||
VALUE.ORP_SUPPLY_ALARM: SupportedBinarySensorValueParameters(),
|
||||
VALUE.PH_HIGH_ALARM: SupportedBinarySensorValueParameters(),
|
||||
VALUE.PH_LOW_ALARM: SupportedBinarySensorValueParameters(),
|
||||
VALUE.PH_SUPPLY_ALARM: SupportedBinarySensorValueParameters(),
|
||||
VALUE.PROBE_FAULT_ALARM: SupportedBinarySensorValueParameters(),
|
||||
},
|
||||
GROUP.ALERT: {
|
||||
VALUE.ORP_LIMIT: SupportedBinarySensorValueParameters(),
|
||||
VALUE.PH_LIMIT: SupportedBinarySensorValueParameters(),
|
||||
VALUE.PH_LOCKOUT: SupportedBinarySensorValueParameters(),
|
||||
},
|
||||
GROUP.WATER_BALANCE: {
|
||||
VALUE.CORROSIVE: SupportedBinarySensorValueParameters(),
|
||||
VALUE.SCALING: SupportedBinarySensorValueParameters(),
|
||||
},
|
||||
},
|
||||
DEVICE.SCG: {
|
||||
GROUP.SENSOR: {
|
||||
VALUE.STATE: SupportedBinarySensorValueParameters(),
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
SL_DEVICE_TYPE_TO_HA_DEVICE_CLASS = {DEVICE_TYPE.ALARM: BinarySensorDeviceClass.PROBLEM}
|
||||
|
||||
SUPPORTED_CONFIG_BINARY_SENSORS = (
|
||||
"freeze_mode",
|
||||
"pool_delay",
|
||||
"spa_delay",
|
||||
"cleaner_delay",
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
|
@ -30,132 +99,92 @@ async def async_setup_entry(
|
|||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up entry."""
|
||||
entities: list[ScreenLogicBinarySensorEntity] = []
|
||||
coordinator: ScreenlogicDataUpdateCoordinator = hass.data[DOMAIN][
|
||||
entities: list[ScreenLogicBinarySensor] = []
|
||||
coordinator: ScreenlogicDataUpdateCoordinator = hass.data[SL_DOMAIN][
|
||||
config_entry.entry_id
|
||||
]
|
||||
gateway_data = coordinator.gateway_data
|
||||
config = gateway_data[SL_DATA.KEY_CONFIG]
|
||||
gateway = coordinator.gateway
|
||||
data_path: ScreenLogicDataPath
|
||||
value_params: SupportedBinarySensorValueParameters
|
||||
for data_path, value_params in iterate_expand_group_wildcard(
|
||||
gateway, SUPPORTED_DATA
|
||||
):
|
||||
entity_key = generate_unique_id(*data_path)
|
||||
|
||||
# Generic binary sensor
|
||||
entities.append(
|
||||
ScreenLogicStatusBinarySensor(coordinator, "chem_alarm", CODE.STATUS_CHANGED)
|
||||
)
|
||||
device = data_path[0]
|
||||
|
||||
entities.extend(
|
||||
[
|
||||
ScreenlogicConfigBinarySensor(coordinator, cfg_sensor, CODE.STATUS_CHANGED)
|
||||
for cfg_sensor in config
|
||||
if cfg_sensor in SUPPORTED_CONFIG_BINARY_SENSORS
|
||||
]
|
||||
)
|
||||
if not (DEVICE_INCLUSION_RULES.get(device) or value_params.included).test(
|
||||
gateway, data_path
|
||||
):
|
||||
cleanup_excluded_entity(coordinator, DOMAIN, entity_key)
|
||||
continue
|
||||
|
||||
if config["equipment_flags"] & EQUIPMENT.FLAG_INTELLICHEM:
|
||||
chemistry = gateway_data[SL_DATA.KEY_CHEMISTRY]
|
||||
# IntelliChem alarm sensors
|
||||
entities.extend(
|
||||
[
|
||||
ScreenlogicChemistryAlarmBinarySensor(
|
||||
coordinator, chem_alarm, CODE.CHEMISTRY_CHANGED
|
||||
try:
|
||||
value_data = gateway.get_data(*data_path, strict=True)
|
||||
except KeyError:
|
||||
_LOGGER.debug("Failed to find %s", data_path)
|
||||
continue
|
||||
|
||||
entity_description_kwargs = {
|
||||
**build_base_entity_description(
|
||||
gateway, entity_key, data_path, value_data, value_params
|
||||
),
|
||||
"device_class": SL_DEVICE_TYPE_TO_HA_DEVICE_CLASS.get(
|
||||
value_data.get(ATTR.DEVICE_TYPE)
|
||||
),
|
||||
}
|
||||
|
||||
if (
|
||||
sub_code := (
|
||||
value_params.subscription_code or DEVICE_SUBSCRIPTION.get(device)
|
||||
)
|
||||
) is not None:
|
||||
entities.append(
|
||||
ScreenLogicPushBinarySensor(
|
||||
coordinator,
|
||||
ScreenLogicPushBinarySensorDescription(
|
||||
subscription_code=sub_code, **entity_description_kwargs
|
||||
),
|
||||
)
|
||||
for chem_alarm in chemistry[SL_DATA.KEY_ALERTS]
|
||||
if not chem_alarm.startswith("_")
|
||||
]
|
||||
)
|
||||
|
||||
# Intellichem notification sensors
|
||||
entities.extend(
|
||||
[
|
||||
ScreenlogicChemistryNotificationBinarySensor(
|
||||
coordinator, chem_notif, CODE.CHEMISTRY_CHANGED
|
||||
)
|
||||
else:
|
||||
entities.append(
|
||||
ScreenLogicBinarySensor(
|
||||
coordinator,
|
||||
ScreenLogicBinarySensorDescription(**entity_description_kwargs),
|
||||
)
|
||||
for chem_notif in chemistry[SL_DATA.KEY_NOTIFICATIONS]
|
||||
if not chem_notif.startswith("_")
|
||||
]
|
||||
)
|
||||
|
||||
if config["equipment_flags"] & EQUIPMENT.FLAG_CHLORINATOR:
|
||||
# SCG binary sensor
|
||||
entities.append(ScreenlogicSCGBinarySensor(coordinator, "scg_status"))
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class ScreenLogicBinarySensorEntity(ScreenlogicEntity, BinarySensorEntity):
|
||||
@dataclass
|
||||
class ScreenLogicBinarySensorDescription(
|
||||
BinarySensorEntityDescription, ScreenLogicEntityDescription
|
||||
):
|
||||
"""A class that describes ScreenLogic binary sensor eneites."""
|
||||
|
||||
|
||||
class ScreenLogicBinarySensor(ScreenlogicEntity, BinarySensorEntity):
|
||||
"""Base class for all ScreenLogic binary sensor entities."""
|
||||
|
||||
entity_description: ScreenLogicBinarySensorDescription
|
||||
_attr_has_entity_name = True
|
||||
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||
|
||||
@property
|
||||
def name(self) -> str | None:
|
||||
"""Return the sensor name."""
|
||||
return self.sensor["name"]
|
||||
|
||||
@property
|
||||
def device_class(self) -> BinarySensorDeviceClass | None:
|
||||
"""Return the device class."""
|
||||
device_type = self.sensor.get("device_type")
|
||||
return SL_DEVICE_TYPE_TO_HA_DEVICE_CLASS.get(device_type)
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Determine if the sensor is on."""
|
||||
return self.sensor["value"] == ON_OFF.ON
|
||||
|
||||
@property
|
||||
def sensor(self) -> dict:
|
||||
"""Shortcut to access the sensor data."""
|
||||
return self.gateway_data[SL_DATA.KEY_SENSORS][self._data_key]
|
||||
return self.entity_data[ATTR.VALUE] == ON_OFF.ON
|
||||
|
||||
|
||||
class ScreenLogicStatusBinarySensor(
|
||||
ScreenLogicBinarySensorEntity, ScreenLogicPushEntity
|
||||
@dataclass
|
||||
class ScreenLogicPushBinarySensorDescription(
|
||||
ScreenLogicBinarySensorDescription, ScreenLogicPushEntityDescription
|
||||
):
|
||||
"""Describes a ScreenLogicPushBinarySensor."""
|
||||
|
||||
|
||||
class ScreenLogicPushBinarySensor(ScreenLogicPushEntity, ScreenLogicBinarySensor):
|
||||
"""Representation of a basic ScreenLogic sensor entity."""
|
||||
|
||||
|
||||
class ScreenlogicChemistryAlarmBinarySensor(
|
||||
ScreenLogicBinarySensorEntity, ScreenLogicPushEntity
|
||||
):
|
||||
"""Representation of a ScreenLogic IntelliChem alarm binary sensor entity."""
|
||||
|
||||
@property
|
||||
def sensor(self) -> dict:
|
||||
"""Shortcut to access the sensor data."""
|
||||
return self.gateway_data[SL_DATA.KEY_CHEMISTRY][SL_DATA.KEY_ALERTS][
|
||||
self._data_key
|
||||
]
|
||||
|
||||
|
||||
class ScreenlogicChemistryNotificationBinarySensor(
|
||||
ScreenLogicBinarySensorEntity, ScreenLogicPushEntity
|
||||
):
|
||||
"""Representation of a ScreenLogic IntelliChem notification binary sensor entity."""
|
||||
|
||||
@property
|
||||
def sensor(self) -> dict:
|
||||
"""Shortcut to access the sensor data."""
|
||||
return self.gateway_data[SL_DATA.KEY_CHEMISTRY][SL_DATA.KEY_NOTIFICATIONS][
|
||||
self._data_key
|
||||
]
|
||||
|
||||
|
||||
class ScreenlogicSCGBinarySensor(ScreenLogicBinarySensorEntity):
|
||||
"""Representation of a ScreenLogic SCG binary sensor entity."""
|
||||
|
||||
@property
|
||||
def sensor(self) -> dict:
|
||||
"""Shortcut to access the sensor data."""
|
||||
return self.gateway_data[SL_DATA.KEY_SCG][self._data_key]
|
||||
|
||||
|
||||
class ScreenlogicConfigBinarySensor(
|
||||
ScreenLogicBinarySensorEntity, ScreenLogicPushEntity
|
||||
):
|
||||
"""Representation of a ScreenLogic config data binary sensor entity."""
|
||||
|
||||
@property
|
||||
def sensor(self) -> dict:
|
||||
"""Shortcut to access the sensor data."""
|
||||
return self.gateway_data[SL_DATA.KEY_CONFIG][self._data_key]
|
||||
entity_description: ScreenLogicPushBinarySensorDescription
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue