1 """Base class for Netatmo entities."""
3 from __future__
import annotations
5 from abc
import abstractmethod
6 from typing
import Any, cast
8 from pyatmo
import DeviceType, Home, Module, Room
9 from pyatmo.modules.base_class
import NetatmoBase, Place
10 from pyatmo.modules.device_types
import DEVICE_DESCRIPTION_MAP
26 from .data_handler
import PUBLIC, NetatmoDataHandler, NetatmoDevice, NetatmoRoom
30 """Netatmo entity base class."""
32 _attr_attribution = DEFAULT_ATTRIBUTION
33 _attr_has_entity_name =
True
35 def __init__(self, data_handler: NetatmoDataHandler) ->
None:
36 """Set up Netatmo entity base."""
38 self._publishers: list[dict[str, Any]] = []
43 for publisher
in self._publishers:
44 signal_name = publisher[SIGNAL_NAME]
46 if "home_id" in publisher:
51 home_id=publisher[
"home_id"],
54 elif publisher[
"name"] == PUBLIC:
59 lat_ne=publisher[
"lat_ne"],
60 lon_ne=publisher[
"lon_ne"],
61 lat_sw=publisher[
"lat_sw"],
62 lon_sw=publisher[
"lon_sw"],
72 for sub
in self.
data_handlerdata_handler.publisher[signal_name].subscriptions
74 await self.
data_handlerdata_handler.unsubscribe(signal_name,
None)
79 """Run when entity will be removed from hass."""
82 for publisher
in self._publishers:
89 """Update the entity's state."""
90 raise NotImplementedError
94 """Netatmo entity base class."""
96 def __init__(self, data_handler: NetatmoDataHandler, device: NetatmoBase) ->
None:
97 """Set up Netatmo entity base."""
104 """Return the device type."""
108 """Return the model of this device."""
109 return DEVICE_DESCRIPTION_MAP[self.
device_typedevice_type]
113 """Return the home this room belongs to."""
114 return self.
devicedevice.home
118 """Netatmo room entity base class."""
123 """Set up a Netatmo room entity."""
124 super().
__init__(room.data_handler, room.room)
126 identifiers={(DOMAIN, room.room.entity_id)},
130 configuration_url=CONF_URL_ENERGY,
131 suggested_area=room.room.name,
135 """Entity created."""
137 registry = dr.async_get(self.
hasshass)
138 if device := registry.async_get_device(
139 identifiers={(DOMAIN, self.
devicedevice.entity_id)}
141 self.
hasshass.data[DOMAIN][DATA_DEVICE_IDS][self.
devicedevice.entity_id] = device.id
145 """Return the device type."""
146 assert self.
devicedevice.climate_type
147 return self.
devicedevice.climate_type
151 """Netatmo module entity base class."""
154 _attr_configuration_url: str
157 """Set up a Netatmo module entity."""
158 super().
__init__(device.data_handler, device.device)
160 identifiers={(DOMAIN, device.device.entity_id)},
161 name=device.device.name,
164 configuration_url=self._attr_configuration_url,
169 """Return the device type."""
170 return self.
devicedevice.device_type
174 """Netatmo weather module entity base class."""
176 _attr_configuration_url = CONF_URL_WEATHER
179 """Set up a Netatmo weather module entity."""
181 category = getattr(self.
devicedevice.device_category,
"name")
182 self._publishers.extend(
186 SIGNAL_NAME: category,
191 if hasattr(self.
devicedevice,
"place"):
192 place = cast(Place, getattr(self.
devicedevice,
"place"))
193 if hasattr(place,
"location")
and place.location
is not None:
196 ATTR_LATITUDE: place.location.latitude,
197 ATTR_LONGITUDE: place.location.longitude,
203 """Return the Netatmo device type."""
204 if "." not in self.
devicedevice.device_type:
205 return super().device_type
206 return DeviceType(self.
devicedevice.device_type.partition(
".")[2])
_attr_extra_state_attributes
None async_added_to_hass(self)
None async_will_remove_from_hass(self)
None async_update_callback(self)
None __init__(self, NetatmoDataHandler data_handler)
None __init__(self, NetatmoDataHandler data_handler, NetatmoBase device)
tuple[str, str] device_description(self)
DeviceType device_type(self)
DeviceType device_type(self)
None __init__(self, NetatmoDevice device)
None __init__(self, NetatmoRoom room)
DeviceType device_type(self)
None async_added_to_hass(self)
None __init__(self, NetatmoDevice device)
DeviceType device_type(self)
Callable[[], None] subscribe(HomeAssistant hass, str topic, MessageCallbackType msg_callback, int qos=DEFAULT_QOS, str encoding="utf-8")