diff --git a/.coveragerc b/.coveragerc index ca2cce2719f..1ccb9e461df 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1161,6 +1161,7 @@ omit = homeassistant/components/romy/binary_sensor.py homeassistant/components/romy/coordinator.py homeassistant/components/romy/entity.py + homeassistant/components/romy/sensor.py homeassistant/components/romy/vacuum.py homeassistant/components/roomba/__init__.py homeassistant/components/roomba/binary_sensor.py diff --git a/homeassistant/components/romy/binary_sensor.py b/homeassistant/components/romy/binary_sensor.py index 263c5840e5f..d8f6216007f 100644 --- a/homeassistant/components/romy/binary_sensor.py +++ b/homeassistant/components/romy/binary_sensor.py @@ -62,7 +62,7 @@ class RomyBinarySensor(RomyEntity, BinarySensorEntity): coordinator: RomyVacuumCoordinator, entity_description: BinarySensorEntityDescription, ) -> None: - """Initialize ROMYs StatusSensor.""" + """Initialize the RomyBinarySensor.""" super().__init__(coordinator) self._attr_unique_id = f"{entity_description.key}_{self.romy.unique_id}" self.entity_description = entity_description diff --git a/homeassistant/components/romy/const.py b/homeassistant/components/romy/const.py index 0fa039e8d1b..a41482ffe59 100644 --- a/homeassistant/components/romy/const.py +++ b/homeassistant/components/romy/const.py @@ -6,6 +6,6 @@ import logging from homeassistant.const import Platform DOMAIN = "romy" -PLATFORMS = [Platform.BINARY_SENSOR, Platform.VACUUM] +PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR, Platform.VACUUM] UPDATE_INTERVAL = timedelta(seconds=5) LOGGER = logging.getLogger(__package__) diff --git a/homeassistant/components/romy/icons.json b/homeassistant/components/romy/icons.json index c27b36af64c..3425d5cfade 100644 --- a/homeassistant/components/romy/icons.json +++ b/homeassistant/components/romy/icons.json @@ -15,6 +15,23 @@ "on": "mdi:basket-check" } } + }, + "sensor": { + "dustbin_sensor": { + "default": "mdi:basket-fill" + }, + "total_cleaning_time": { + "default": "mdi:clock" + }, + "total_number_of_cleaning_runs": { + "default": "mdi:counter" + }, + "total_area_cleaned": { + "default": "mdi:texture-box" + }, + "total_distance_driven": { + "default": "mdi:run" + } } } } diff --git a/homeassistant/components/romy/sensor.py b/homeassistant/components/romy/sensor.py new file mode 100644 index 00000000000..bdd486c4f8f --- /dev/null +++ b/homeassistant/components/romy/sensor.py @@ -0,0 +1,112 @@ +"""Sensor checking adc and status values from your ROMY.""" + +from homeassistant.components.sensor import ( + SensorDeviceClass, + SensorEntity, + SensorEntityDescription, + SensorStateClass, +) +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import ( + AREA_SQUARE_METERS, + PERCENTAGE, + SIGNAL_STRENGTH_DECIBELS_MILLIWATT, + EntityCategory, + UnitOfLength, + UnitOfTime, +) +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddEntitiesCallback + +from .const import DOMAIN +from .coordinator import RomyVacuumCoordinator +from .entity import RomyEntity + +SENSORS: list[SensorEntityDescription] = [ + SensorEntityDescription( + key="battery_level", + native_unit_of_measurement=PERCENTAGE, + device_class=SensorDeviceClass.BATTERY, + entity_category=EntityCategory.DIAGNOSTIC, + ), + SensorEntityDescription( + key="rssi", + entity_registry_enabled_default=False, + native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT, + device_class=SensorDeviceClass.SIGNAL_STRENGTH, + entity_category=EntityCategory.DIAGNOSTIC, + ), + SensorEntityDescription( + key="dustbin_sensor", + translation_key="dustbin_sensor", + entity_registry_enabled_default=False, + state_class=SensorStateClass.MEASUREMENT, + entity_category=EntityCategory.DIAGNOSTIC, + ), + SensorEntityDescription( + key="total_cleaning_time", + translation_key="total_cleaning_time", + state_class=SensorStateClass.TOTAL, + native_unit_of_measurement=UnitOfTime.HOURS, + entity_category=EntityCategory.DIAGNOSTIC, + ), + SensorEntityDescription( + key="total_number_of_cleaning_runs", + translation_key="total_number_of_cleaning_runs", + state_class=SensorStateClass.TOTAL, + native_unit_of_measurement="runs", + entity_category=EntityCategory.DIAGNOSTIC, + ), + SensorEntityDescription( + key="total_area_cleaned", + translation_key="total_area_cleaned", + state_class=SensorStateClass.TOTAL, + native_unit_of_measurement=AREA_SQUARE_METERS, + entity_category=EntityCategory.DIAGNOSTIC, + ), + SensorEntityDescription( + key="total_distance_driven", + translation_key="total_distance_driven", + state_class=SensorStateClass.TOTAL, + native_unit_of_measurement=UnitOfLength.METERS, + entity_category=EntityCategory.DIAGNOSTIC, + ), +] + + +async def async_setup_entry( + hass: HomeAssistant, + config_entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, +) -> None: + """Set up ROMY vacuum cleaner.""" + + coordinator: RomyVacuumCoordinator = hass.data[DOMAIN][config_entry.entry_id] + + async_add_entities( + RomySensor(coordinator, entity_description) + for entity_description in SENSORS + if entity_description.key in coordinator.romy.sensors + ) + + +class RomySensor(RomyEntity, SensorEntity): + """RomySensor Class.""" + + entity_description: SensorEntityDescription + + def __init__( + self, + coordinator: RomyVacuumCoordinator, + entity_description: SensorEntityDescription, + ) -> None: + """Initialize ROMYs StatusSensor.""" + super().__init__(coordinator) + self._attr_unique_id = f"{entity_description.key}_{self.romy.unique_id}" + self.entity_description = entity_description + + @property + def native_value(self) -> int: + """Return the value of the sensor.""" + value: int = self.romy.sensors[self.entity_description.key] + return value diff --git a/homeassistant/components/romy/strings.json b/homeassistant/components/romy/strings.json index f4bc4d191ff..78721da17ba 100644 --- a/homeassistant/components/romy/strings.json +++ b/homeassistant/components/romy/strings.json @@ -60,6 +60,23 @@ "water_tank_empty": { "name": "Watertank empty" } + }, + "sensor": { + "dustbin_sensor": { + "name": "Dustbin dirt level" + }, + "total_cleaning_time": { + "name": "Total cleaning time" + }, + "total_number_of_cleaning_runs": { + "name": "Total cleaning runs" + }, + "total_area_cleaned": { + "name": "Total cleaned area" + }, + "total_distance_driven": { + "name": "Total distance driven" + } } } }