From fb10ef9ac0800e5bd76524fdc11da0e289bf83e7 Mon Sep 17 00:00:00 2001 From: Isak Nyberg <36712644+IsakNyberg@users.noreply.github.com> Date: Wed, 28 Feb 2024 22:55:47 +0100 Subject: [PATCH] Add permobil entity (#111761) * add permobil entity * small fixes * remove sensor init --- .coveragerc | 1 + homeassistant/components/permobil/entity.py | 29 +++++++++++++++++++++ homeassistant/components/permobil/sensor.py | 18 ++----------- 3 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 homeassistant/components/permobil/entity.py diff --git a/.coveragerc b/.coveragerc index 378532dfd88..626c2122d6f 100644 --- a/.coveragerc +++ b/.coveragerc @@ -983,6 +983,7 @@ omit = homeassistant/components/pencom/switch.py homeassistant/components/permobil/__init__.py homeassistant/components/permobil/coordinator.py + homeassistant/components/permobil/entity.py homeassistant/components/permobil/sensor.py homeassistant/components/philips_js/__init__.py homeassistant/components/philips_js/light.py diff --git a/homeassistant/components/permobil/entity.py b/homeassistant/components/permobil/entity.py new file mode 100644 index 00000000000..702781aa361 --- /dev/null +++ b/homeassistant/components/permobil/entity.py @@ -0,0 +1,29 @@ +"""PermobilEntity class.""" + +from homeassistant.helpers.device_registry import DeviceInfo +from homeassistant.helpers.entity import EntityDescription +from homeassistant.helpers.update_coordinator import CoordinatorEntity + +from .const import DOMAIN +from .coordinator import MyPermobilCoordinator + + +class PermobilEntity(CoordinatorEntity[MyPermobilCoordinator]): + """Representation of a permobil Entity.""" + + _attr_has_entity_name = True + + def __init__( + self, + coordinator: MyPermobilCoordinator, + description: EntityDescription, + ) -> None: + """Initialize the entity.""" + super().__init__(coordinator) + self.entity_description = description + self._attr_unique_id = f"{coordinator.p_api.email}_{description.key}" + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, coordinator.p_api.email)}, + manufacturer="Permobil", + name="Permobil Wheelchair", + ) diff --git a/homeassistant/components/permobil/sensor.py b/homeassistant/components/permobil/sensor.py index 8a504248f5a..d01be68d775 100644 --- a/homeassistant/components/permobil/sensor.py +++ b/homeassistant/components/permobil/sensor.py @@ -32,10 +32,10 @@ from homeassistant.components.sensor import ( from homeassistant.const import PERCENTAGE, UnitOfEnergy, UnitOfLength, UnitOfTime from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import BATTERY_ASSUMED_VOLTAGE, DOMAIN, KM, MILES from .coordinator import MyPermobilCoordinator +from .entity import PermobilEntity _LOGGER = logging.getLogger(__name__) @@ -202,28 +202,14 @@ async def async_setup_entry( ) -class PermobilSensor(CoordinatorEntity[MyPermobilCoordinator], SensorEntity): +class PermobilSensor(PermobilEntity, SensorEntity): """Representation of a Sensor. This implements the common functions of all sensors. """ - _attr_has_entity_name = True _attr_suggested_display_precision = 0 entity_description: PermobilSensorEntityDescription - _available = True - - def __init__( - self, - coordinator: MyPermobilCoordinator, - description: PermobilSensorEntityDescription, - ) -> None: - """Initialize the sensor.""" - super().__init__(coordinator=coordinator) - self.entity_description = description - self._attr_unique_id = ( - f"{coordinator.p_api.email}_{self.entity_description.key}" - ) @property def native_unit_of_measurement(self) -> str | None: