Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Support for Melnor RainCloud sprinkler water timer."""
2 
3 from homeassistant.helpers.dispatcher import async_dispatcher_connect
4 from homeassistant.helpers.entity import Entity
5 
6 from .const import SIGNAL_UPDATE_RAINCLOUD
7 
8 KEY_MAP = {
9  "auto_watering": "Automatic Watering",
10  "battery": "Battery",
11  "is_watering": "Watering",
12  "manual_watering": "Manual Watering",
13  "next_cycle": "Next Cycle",
14  "rain_delay": "Rain Delay",
15  "status": "Status",
16  "watering_time": "Remaining Watering Time",
17 }
18 
19 ICON_MAP = {
20  "auto_watering": "mdi:autorenew",
21  "battery": "",
22  "is_watering": "",
23  "manual_watering": "mdi:water-pump",
24  "next_cycle": "mdi:calendar-clock",
25  "rain_delay": "mdi:weather-rainy",
26  "status": "",
27  "watering_time": "mdi:water-pump",
28 }
29 
30 
32  """Entity class for RainCloud devices."""
33 
34  _attr_attribution = "Data provided by Melnor Aquatimer.com"
35 
36  def __init__(self, data, sensor_type):
37  """Initialize the RainCloud entity."""
38  self.datadata = data
39  self._sensor_type_sensor_type = sensor_type
40  self._name_name = f"{self.data.name} {KEY_MAP.get(self._sensor_type)}"
41  self._state_state = None
42 
43  @property
44  def name(self):
45  """Return the name of the sensor."""
46  return self._name_name
47 
48  async def async_added_to_hass(self):
49  """Register callbacks."""
50  self.async_on_removeasync_on_remove(
52  self.hasshass, SIGNAL_UPDATE_RAINCLOUD, self._update_callback_update_callback
53  )
54  )
55 
56  def _update_callback(self):
57  """Call update method."""
58  self.schedule_update_ha_stateschedule_update_ha_state(True)
59 
60  @property
62  """Return the state attributes."""
63  return {"identifier": self.datadata.serial}
64 
65  @property
66  def icon(self):
67  """Return the icon to use in the frontend, if any."""
68  return ICON_MAP.get(self._sensor_type_sensor_type)
None async_on_remove(self, CALLBACK_TYPE func)
Definition: entity.py:1331
None schedule_update_ha_state(self, bool force_refresh=False)
Definition: entity.py:1244
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
Definition: dispatcher.py:103