1 """Support the ElkM1 Gold and ElkM1 EZ8 alarm/integration panels."""
3 from __future__
import annotations
5 from collections.abc
import Iterable
10 from elkm1_lib.elements
import Element
11 from elkm1_lib.elk
import Elk
18 from .const
import DOMAIN
19 from .models
import ELKM1Data
21 _LOGGER = logging.getLogger(__name__)
26 elk_elements: Iterable[Element],
29 entities: list[ElkEntity],
30 ) -> list[ElkEntity] |
None:
31 """Create the ElkM1 devices of a particular class."""
32 auto_configure = elk_data.auto_configure
34 if not auto_configure
and not elk_data.config[element_type][
"enabled"]:
38 _LOGGER.debug(
"Creating elk entities for %s", elk)
40 for element
in elk_elements:
42 if not element.configured:
45 elif not elk_data.config[element_type][
"included"][element.index]:
48 entities.append(class_(element, elk, elk_data))
53 """Base class for all Elk entities."""
55 _attr_has_entity_name =
True
56 _attr_should_poll =
False
58 def __init__(self, element: Element, elk: Elk, elk_data: ELKM1Data) ->
None:
59 """Initialize the base of all Elk devices."""
62 self.
_mac_mac = elk_data.mac
64 self._temperature_unit: str = elk_data.config[
"temperature_unit"]
74 uid_start = f
"elkm1m_{self._prefix}"
77 self.
_unique_id_unique_id = f
"{uid_start}_{self._element.default_name('_')}".lower()
82 """Return unique id of the element."""
87 """Return the default attributes of the element."""
89 for key, val
in self.
_element_element.as_dict().items():
90 dict_as_str[key] = val.value
if isinstance(val, Enum)
else val
95 """Is the entity available to be updated."""
99 """Return the underlying element's attributes as a dict."""
100 return {
"index": self.
_element_element.index + 1}
107 """Handle callback from an Elk element that has changed."""
112 """Register callback for ElkM1 changes and update entity state."""
118 """Device info connecting via the ElkM1 system."""
121 identifiers={(DOMAIN, self.
_unique_id_unique_id)},
122 via_device=(DOMAIN, f
"{self._prefix}_system"),
127 """An elk entity that is attached to the elk system."""
131 """Device info for the underlying ElkM1 system."""
132 device_name =
"ElkM1"
134 device_name += f
" {self._prefix}"
136 identifiers={(DOMAIN, f
"{self._prefix}_system")},
137 manufacturer=
"ELK Products, Inc.",
140 sw_version=self.
_elk_elk.panel.elkm1_version,
143 device_info[ATTR_CONNECTIONS] = {(CONNECTION_NETWORK_MAC, self.
_mac_mac)}
DeviceInfo device_info(self)
None async_added_to_hass(self)
dict[str, Any] initial_attrs(self)
None _element_changed(self, Element element, dict[str, Any] changeset)
None _element_callback(self, Element element, dict[str, Any] changeset)
dict[str, Any] extra_state_attributes(self)
DeviceInfo device_info(self)
None __init__(self, Element element, Elk elk, ELKM1Data elk_data)
None async_write_ha_state(self)
list[ElkEntity]|None create_elk_entities(ELKM1Data elk_data, Iterable[Element] elk_elements, str element_type, Any class_, list[ElkEntity] entities)