1 """Base Entity for all TelldusLive entities."""
3 from datetime
import datetime
6 from tellduslive
import BATTERY_LOW, BATTERY_OK, BATTERY_UNKNOWN
18 from .const
import SIGNAL_UPDATE_ENTITY
20 _LOGGER = logging.getLogger(__name__)
22 ATTR_LAST_UPDATED =
"time_last_updated"
26 """Base class for all Telldus Live entities."""
28 _attr_should_poll =
False
29 _attr_has_entity_name =
True
32 """Initialize the entity."""
33 self.
_id_id = device_id
37 """Call when entity is added to hass."""
38 _LOGGER.debug(
"Created device %s", self)
47 """Return the id of the device."""
52 """Return the representation of the device."""
57 """Return the state of the device."""
58 return self.
devicedevice.state
62 """Return true if unable to access real state of entity."""
67 """Return true if device is not offline."""
72 """Return the state attributes."""
82 """Return the battery level of a device."""
83 if self.
devicedevice.battery == BATTERY_LOW:
85 if self.
devicedevice.battery == BATTERY_UNKNOWN:
87 if self.
devicedevice.battery == BATTERY_OK:
89 return self.
devicedevice.battery
93 """Return the last update of a device."""
95 str(datetime.fromtimestamp(self.
devicedevice.lastUpdated))
96 if self.
devicedevice.lastUpdated
102 """Return a unique ID."""
107 """Return device info."""
110 identifiers={(
"tellduslive", self.
devicedevice.device_id)},
111 name=self.
devicedevice.name,
113 if (model := device.get(
"model"))
is not None:
114 device_info[ATTR_MODEL] = model.title()
115 if (protocol := device.get(
"protocol"))
is not None:
116 device_info[ATTR_MANUFACTURER] = protocol.title()
117 if (client := device.get(
"client"))
is not None:
118 device_info[ATTR_VIA_DEVICE] = (
"tellduslive", client)
def __init__(self, client, device_id)
def async_added_to_hass(self)
def extra_state_attributes(self)
DeviceInfo device_info(self)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)