1 """Generic entity for the HomematicIP Cloud component."""
3 from __future__
import annotations
8 from homematicip.aio.device
import AsyncDevice
9 from homematicip.aio.group
import AsyncGroup
10 from homematicip.base.functionalChannels
import FunctionalChannel
18 from .const
import DOMAIN
19 from .hap
import AsyncHome, HomematicipHAP
21 _LOGGER = logging.getLogger(__name__)
23 ATTR_MODEL_TYPE =
"model_type"
24 ATTR_LOW_BATTERY =
"low_battery"
25 ATTR_CONFIG_PENDING =
"config_pending"
26 ATTR_CONNECTION_TYPE =
"connection_type"
27 ATTR_DUTY_CYCLE_REACHED =
"duty_cycle_reached"
28 ATTR_IS_GROUP =
"is_group"
30 ATTR_RSSI_DEVICE =
"rssi_device"
32 ATTR_RSSI_PEER =
"rssi_peer"
33 ATTR_SABOTAGE =
"sabotage"
34 ATTR_GROUP_MEMBER_UNREACHABLE =
"group_member_unreachable"
35 ATTR_DEVICE_OVERHEATED =
"device_overheated"
36 ATTR_DEVICE_OVERLOADED =
"device_overloaded"
37 ATTR_DEVICE_UNTERVOLTAGE =
"device_undervoltage"
38 ATTR_EVENT_DELAY =
"event_delay"
40 DEVICE_ATTRIBUTE_ICONS = {
41 "lowBat":
"mdi:battery-outline",
42 "sabotage":
"mdi:shield-alert",
43 "dutyCycle":
"mdi:alert",
44 "deviceOverheated":
"mdi:alert",
45 "deviceOverloaded":
"mdi:alert",
46 "deviceUndervoltage":
"mdi:alert",
47 "configPending":
"mdi:alert-circle",
51 "modelType": ATTR_MODEL_TYPE,
52 "connectionType": ATTR_CONNECTION_TYPE,
53 "sabotage": ATTR_SABOTAGE,
54 "dutyCycle": ATTR_DUTY_CYCLE_REACHED,
55 "rssiDeviceValue": ATTR_RSSI_DEVICE,
56 "rssiPeerValue": ATTR_RSSI_PEER,
57 "deviceOverheated": ATTR_DEVICE_OVERHEATED,
58 "deviceOverloaded": ATTR_DEVICE_OVERLOADED,
59 "deviceUndervoltage": ATTR_DEVICE_UNTERVOLTAGE,
60 "configPending": ATTR_CONFIG_PENDING,
61 "eventDelay": ATTR_EVENT_DELAY,
66 "modelType": ATTR_MODEL_TYPE,
67 "lowBat": ATTR_LOW_BATTERY,
68 "sabotage": ATTR_SABOTAGE,
69 "dutyCycle": ATTR_DUTY_CYCLE_REACHED,
70 "configPending": ATTR_CONFIG_PENDING,
71 "unreach": ATTR_GROUP_MEMBER_UNREACHABLE,
76 """Representation of the HomematicIP generic entity."""
78 _attr_should_poll =
False
84 post: str |
None =
None,
85 channel: int |
None =
None,
86 is_multi_channel: bool |
None =
False,
88 """Initialize the generic entity."""
90 self._home: AsyncHome = hap.home
101 """Return device specific attributes."""
103 if isinstance(self.
_device_device, AsyncDevice):
107 (DOMAIN, self.
_device_device.id)
109 manufacturer=self.
_device_device.oem,
110 model=self.
_device_device.modelType,
111 name=self.
_device_device.label,
112 sw_version=self.
_device_device.firmwareVersion,
114 via_device=(DOMAIN, self.
_device_device.homeId),
119 """Register callbacks."""
126 """Handle device state changes."""
129 _LOGGER.debug(
"Event %s (%s)", self.
namenamename, self.
_device_device.modelType)
133 "Device Changed Event for %s (%s) not fired. Entity is disabled",
139 """Run when hmip device will be removed from hass."""
146 del self.
_hap_hap.hmip_device_by_entity_id[self.
entity_identity_id]
148 except KeyError
as err:
149 _LOGGER.debug(
"Error removing HMIP device from registry: %s", err)
153 """Remove entity/device from registry."""
163 device_registry = dr.async_get(self.
hasshass)
164 if device_id
in device_registry.devices:
166 device_registry.async_remove_device(device_id)
171 entity_registry = er.async_get(self.
hasshass)
172 if entity_id
in entity_registry.entities:
173 entity_registry.async_remove(entity_id)
177 """Handle hmip device removal."""
180 self.
hasshass.async_create_task(
181 self.
async_removeasync_remove(force_remove=
True), eager_start=
False
186 """Return the name of the generic entity."""
190 if hasattr(self.
_device_device,
"functionalChannels"):
192 name = self.
_device_device.functionalChannels[self.
_channel_channel].label
193 elif len(self.
_device_device.functionalChannels) > 1:
194 name = self.
_device_device.functionalChannels[1].label
198 name = self.
_device_device.label
200 name = f
"{name} {self._post}"
202 name = f
"{name} Channel{self._channel}"
205 if name
and self._home.name:
206 name = f
"{self._home.name} {name}"
212 """Return if entity is available."""
213 return not self.
_device_device.unreach
217 """Return a unique ID."""
218 unique_id = f
"{self.__class__.__name__}_{self._device.id}"
221 f
"{self.__class__.__name__}_Channel{self._channel}_{self._device.id}"
228 """Return the icon."""
229 for attr, icon
in DEVICE_ATTRIBUTE_ICONS.items():
230 if getattr(self.
_device_device, attr,
None):
237 """Return the state attributes of the generic entity."""
240 if isinstance(self.
_device_device, AsyncDevice):
241 for attr, attr_key
in DEVICE_ATTRIBUTES.items():
242 if attr_value := getattr(self.
_device_device, attr,
None):
243 state_attr[attr_key] = attr_value
245 state_attr[ATTR_IS_GROUP] =
False
247 if isinstance(self.
_device_device, AsyncGroup):
248 for attr, attr_key
in GROUP_ATTRIBUTES.items():
249 if attr_value := getattr(self.
_device_device, attr,
None):
250 state_attr[attr_key] = attr_value
252 state_attr[ATTR_IS_GROUP] =
True
257 """Return the FunctionalChannel for device."""
258 if hasattr(self.
_device_device,
"functionalChannels"):
262 if len(self.
_device_device.functionalChannels) > 1:
263 return self.
_device_device.functionalChannels[1]
dict[str, Any] extra_state_attributes(self)
DeviceInfo|None device_info(self)
FunctionalChannel get_current_channel(self)
None async_remove_from_registries(self)
None async_added_to_hass(self)
None _async_device_removed(self, *args, **kwargs)
None async_will_remove_from_hass(self)
None __init__(self, HomematicipHAP hap, device, str|None post=None, int|None channel=None, bool|None is_multi_channel=False)
None _async_device_changed(self, *args, **kwargs)
None async_write_ha_state(self)
None async_remove(self, *bool force_remove=False)
str|UndefinedType|None name(self)