1 """Support for Vera devices."""
3 from __future__
import annotations
8 import pyvera
as veraApi
20 from .common
import ControllerData
21 from .const
import CONF_LEGACY_UNIQUE_ID, VERA_ID_FORMAT
23 _LOGGER = logging.getLogger(__name__)
26 class VeraEntity[_DeviceTypeT: veraApi.VeraDevice](Entity):
27 """Representation of a Vera device entity."""
30 self, vera_device: _DeviceTypeT, controller_data: ControllerData
32 """Initialize the device."""
33 self.vera_device = vera_device
34 self.controller = controller_data.controller
36 self._name = self.vera_device.name
38 self.vera_id = VERA_ID_FORMAT.format(
39 slugify(vera_device.name), vera_device.vera_device_id
42 if controller_data.config_entry.data.get(CONF_LEGACY_UNIQUE_ID):
43 self._unique_id =
str(self.vera_device.vera_device_id)
45 self._unique_id = f
"vera_{controller_data.config_entry.unique_id}_{self.vera_device.vera_device_id}"
48 """Subscribe to updates."""
49 self.controller.
register(self.vera_device, self._update_callback)
52 """Update the state."""
53 self.schedule_update_ha_state(
True)
56 """Force a refresh from the device if the device is unavailable."""
57 refresh_needed = self.vera_device.should_poll
or not self.available
58 _LOGGER.debug(
"%s: update called (refresh=%s)", self._name, refresh_needed)
60 self.vera_device.refresh()
64 """Return the name of the device."""
69 """Return the state attributes of the device."""
72 if self.vera_device.has_battery:
73 attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level
75 if self.vera_device.is_armable:
76 armed = self.vera_device.is_armed
77 attr[ATTR_ARMED] =
"True" if armed
else "False"
79 if self.vera_device.is_trippable:
80 if (last_tripped := self.vera_device.last_trip)
is not None:
82 attr[ATTR_LAST_TRIP_TIME] = utc_time.isoformat()
84 attr[ATTR_LAST_TRIP_TIME] =
None
85 tripped = self.vera_device.is_tripped
86 attr[ATTR_TRIPPED] =
"True" if tripped
else "False"
88 attr[
"Vera Device Id"] = self.vera_device.vera_device_id
94 """If device communications have failed return false."""
95 return not self.vera_device.comm_failure
99 """Return a unique ID.
101 The Vera assigns a unique and immutable ID number to each device.
103 return self._unique_id
def register(HomeAssistant hass, Heos controller)
None __init__(self, _DeviceTypeT vera_device, ControllerData controller_data)
dict[str, Any]|None extra_state_attributes(self)
None _update_callback(self, _DeviceTypeT _device)
None async_added_to_hass(self)