Add permobil entity (#111761)

* add permobil entity

* small fixes

* remove sensor init
pull/111765/head
Isak Nyberg 2024-02-28 22:55:47 +01:00 committed by GitHub
parent e886bc8939
commit fb10ef9ac0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 16 deletions

View File

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

View File

@ -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",
)

View File

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