Home Assistant Unofficial Reference 2024.12.1
sensor.py
Go to the documentation of this file.
1 """Sensor checking adc and status values from your ROMY."""
2 
4  SensorDeviceClass,
5  SensorEntity,
6  SensorEntityDescription,
7  SensorStateClass,
8 )
9 from homeassistant.config_entries import ConfigEntry
10 from homeassistant.const import (
11  PERCENTAGE,
12  SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
13  EntityCategory,
14  UnitOfArea,
15  UnitOfLength,
16  UnitOfTime,
17 )
18 from homeassistant.core import HomeAssistant
19 from homeassistant.helpers.entity_platform import AddEntitiesCallback
20 
21 from .const import DOMAIN
22 from .coordinator import RomyVacuumCoordinator
23 from .entity import RomyEntity
24 
25 SENSORS: list[SensorEntityDescription] = [
27  key="battery_level",
28  native_unit_of_measurement=PERCENTAGE,
29  device_class=SensorDeviceClass.BATTERY,
30  entity_category=EntityCategory.DIAGNOSTIC,
31  ),
33  key="rssi",
34  entity_registry_enabled_default=False,
35  native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
36  device_class=SensorDeviceClass.SIGNAL_STRENGTH,
37  entity_category=EntityCategory.DIAGNOSTIC,
38  ),
40  key="dustbin_sensor",
41  translation_key="dustbin_sensor",
42  entity_registry_enabled_default=False,
43  state_class=SensorStateClass.MEASUREMENT,
44  entity_category=EntityCategory.DIAGNOSTIC,
45  ),
47  key="total_cleaning_time",
48  translation_key="total_cleaning_time",
49  state_class=SensorStateClass.TOTAL,
50  native_unit_of_measurement=UnitOfTime.HOURS,
51  entity_category=EntityCategory.DIAGNOSTIC,
52  ),
54  key="total_number_of_cleaning_runs",
55  translation_key="total_number_of_cleaning_runs",
56  state_class=SensorStateClass.TOTAL,
57  native_unit_of_measurement="runs",
58  entity_category=EntityCategory.DIAGNOSTIC,
59  ),
61  key="total_area_cleaned",
62  translation_key="total_area_cleaned",
63  state_class=SensorStateClass.TOTAL,
64  native_unit_of_measurement=UnitOfArea.SQUARE_METERS,
65  entity_category=EntityCategory.DIAGNOSTIC,
66  ),
68  key="total_distance_driven",
69  translation_key="total_distance_driven",
70  state_class=SensorStateClass.TOTAL,
71  native_unit_of_measurement=UnitOfLength.METERS,
72  entity_category=EntityCategory.DIAGNOSTIC,
73  ),
74 ]
75 
76 
78  hass: HomeAssistant,
79  config_entry: ConfigEntry,
80  async_add_entities: AddEntitiesCallback,
81 ) -> None:
82  """Set up ROMY vacuum cleaner."""
83 
84  coordinator: RomyVacuumCoordinator = hass.data[DOMAIN][config_entry.entry_id]
85 
87  RomySensor(coordinator, entity_description)
88  for entity_description in SENSORS
89  if entity_description.key in coordinator.romy.sensors
90  )
91 
92 
94  """RomySensor Class."""
95 
96  entity_description: SensorEntityDescription
97 
98  def __init__(
99  self,
100  coordinator: RomyVacuumCoordinator,
101  entity_description: SensorEntityDescription,
102  ) -> None:
103  """Initialize ROMYs StatusSensor."""
104  super().__init__(coordinator)
105  self._attr_unique_id_attr_unique_id = f"{entity_description.key}_{self.romy.unique_id}"
106  self.entity_descriptionentity_description = entity_description
107 
108  @property
109  def native_value(self) -> int:
110  """Return the value of the sensor."""
111  value: int = self.romyromyromy.sensors[self.entity_descriptionentity_description.key]
112  return value
None __init__(self, RomyVacuumCoordinator coordinator, SensorEntityDescription entity_description)
Definition: sensor.py:102
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: sensor.py:81