Renault code quality improvements (#55313)
* Use constants * Drop entity_class for binary_sensor * Move data property from RenaultDataEntity to RenaultSensor * Update function description
This commit is contained in:
parent
259eeb3169
commit
adab367f0e
4 changed files with 40 additions and 33 deletions
|
@ -18,7 +18,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from .const import DOMAIN
|
||||
from .renault_entities import RenaultDataEntity, RenaultEntityDescription, T
|
||||
from .renault_entities import RenaultDataEntity, RenaultEntityDescription
|
||||
from .renault_hub import RenaultHub
|
||||
|
||||
|
||||
|
@ -26,7 +26,7 @@ from .renault_hub import RenaultHub
|
|||
class RenaultBinarySensorRequiredKeysMixin:
|
||||
"""Mixin for required keys."""
|
||||
|
||||
entity_class: type[RenaultBinarySensor]
|
||||
on_key: str
|
||||
on_value: StateType
|
||||
|
||||
|
||||
|
@ -47,7 +47,7 @@ async def async_setup_entry(
|
|||
"""Set up the Renault entities from config entry."""
|
||||
proxy: RenaultHub = hass.data[DOMAIN][config_entry.entry_id]
|
||||
entities: list[RenaultBinarySensor] = [
|
||||
description.entity_class(vehicle, description)
|
||||
RenaultBinarySensor(vehicle, description)
|
||||
for vehicle in proxy.vehicles.values()
|
||||
for description in BINARY_SENSOR_TYPES
|
||||
if description.coordinator in vehicle.coordinators
|
||||
|
@ -55,7 +55,9 @@ async def async_setup_entry(
|
|||
async_add_entities(entities)
|
||||
|
||||
|
||||
class RenaultBinarySensor(RenaultDataEntity[T], BinarySensorEntity):
|
||||
class RenaultBinarySensor(
|
||||
RenaultDataEntity[KamereonVehicleBatteryStatusData], BinarySensorEntity
|
||||
):
|
||||
"""Mixin for binary sensor specific attributes."""
|
||||
|
||||
entity_description: RenaultBinarySensorEntityDescription
|
||||
|
@ -63,26 +65,27 @@ class RenaultBinarySensor(RenaultDataEntity[T], BinarySensorEntity):
|
|||
@property
|
||||
def is_on(self) -> bool | None:
|
||||
"""Return true if the binary sensor is on."""
|
||||
return self.data == self.entity_description.on_value
|
||||
return (
|
||||
self._get_data_attr(self.entity_description.on_key)
|
||||
== self.entity_description.on_value
|
||||
)
|
||||
|
||||
|
||||
BINARY_SENSOR_TYPES: tuple[RenaultBinarySensorEntityDescription, ...] = (
|
||||
RenaultBinarySensorEntityDescription(
|
||||
key="plugged_in",
|
||||
coordinator="battery",
|
||||
data_key="plugStatus",
|
||||
device_class=DEVICE_CLASS_PLUG,
|
||||
entity_class=RenaultBinarySensor[KamereonVehicleBatteryStatusData],
|
||||
name="Plugged In",
|
||||
on_key="plugStatus",
|
||||
on_value=PlugState.PLUGGED.value,
|
||||
),
|
||||
RenaultBinarySensorEntityDescription(
|
||||
key="charging",
|
||||
coordinator="battery",
|
||||
data_key="chargingStatus",
|
||||
device_class=DEVICE_CLASS_BATTERY_CHARGING,
|
||||
entity_class=RenaultBinarySensor[KamereonVehicleBatteryStatusData],
|
||||
name="Charging",
|
||||
on_key="chargingStatus",
|
||||
on_value=ChargeState.CHARGE_IN_PROGRESS.value,
|
||||
),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue