Add sensor platform to romy integration (#112388)

* poc romy status sensor working

* poc romy adc sensor working

* code review changes

* code review changes base enitity.py see branch romy_binary_sensor

* code review change: move CoordinatorEntity to the base class

* code review changes: sensors disabled per default

* code review: icons.json added

* checkout main entity.py

* code review changes: sensors enabled per default again

* disable rssi sensor per default

* Update homeassistant/components/romy/strings.json

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* code review changes

* code review changes

* code review changes

* pylint fix

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
Manuel Dipolt 2024-04-24 17:06:46 +02:00 committed by GitHub
parent 380f192c93
commit 2beab34de8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 149 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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__)

View File

@ -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"
}
}
}
}

View File

@ -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

View File

@ -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"
}
}
}
}