1 """Module for SIA Binary Sensors."""
3 from __future__
import annotations
5 from collections.abc
import Iterable
6 from dataclasses
import dataclass
9 from pysiaalarm
import SIAEvent
12 BinarySensorDeviceClass,
14 BinarySensorEntityDescription,
31 from .entity
import SIABaseEntity, SIAEntityDescription
33 _LOGGER = logging.getLogger(__name__)
36 @dataclass(frozen=True)
38 BinarySensorEntityDescription,
41 """Describes SIA sensor entity."""
46 device_class=BinarySensorDeviceClass.POWER,
47 entity_category=EntityCategory.DIAGNOSTIC,
56 device_class=BinarySensorDeviceClass.SMOKE,
65 entity_registry_enabled_default=
False,
70 device_class=BinarySensorDeviceClass.MOISTURE,
75 entity_registry_enabled_default=
False,
80 device_class=BinarySensorDeviceClass.CONNECTIVITY,
81 entity_category=EntityCategory.DIAGNOSTIC,
82 code_consequences={
"RP":
True},
87 """Generate binary sensors.
89 For each Account there is one power sensor with zone == 0.
90 For each Zone in each Account there is one smoke and one moisture sensor.
92 for account_data
in entry.data[CONF_ACCOUNTS]:
93 account = account_data[CONF_ACCOUNT]
94 zones = entry.options[CONF_ACCOUNTS][account][CONF_ZONES]
97 entry, account, SIA_HUB_ZONE, ENTITY_DESCRIPTION_CONNECTIVITY
99 yield SIABinarySensor(entry, account, SIA_HUB_ZONE, ENTITY_DESCRIPTION_POWER)
100 for zone
in range(1, zones + 1):
102 yield SIABinarySensor(entry, account, zone, ENTITY_DESCRIPTION_MOISTURE)
108 async_add_entities: AddEntitiesCallback,
110 """Set up SIA binary sensors from a config entry."""
115 """Class for SIA Binary Sensors."""
117 entity_description: SIABinarySensorEntityDescription
120 """Handle the last state."""
121 if last_state
is not None and last_state.state
is not None:
122 if last_state.state == STATE_ON:
124 elif last_state.state == STATE_OFF:
126 elif last_state.state == STATE_UNAVAILABLE:
130 """Update the state of the binary sensor.
132 Return True if the event was relevant for this entity.
136 new_state = self.
entity_descriptionentity_description.code_consequences.get(sia_event.code)
137 if new_state
is None:
139 _LOGGER.debug(
"New state will be %s", new_state)
145 """Class for Connectivity Sensor."""
149 """Update state after a ping interval. Overwritten from sia entity base."""
None async_post_interval_update(self, _)
bool update_state(self, SIAEvent sia_event)
None handle_last_state(self, State|None last_state)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Iterable[SIABinarySensor] generate_binary_sensors(ConfigEntry entry)