mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Set up Renault entities per vehicle (#187254)
This commit is contained in:
@@ -17,11 +17,12 @@ from homeassistant.components.binary_sensor import (
|
||||
BinarySensorEntity,
|
||||
BinarySensorEntityDescription,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import RenaultConfigEntry
|
||||
from .entity import RenaultDataEntity, RenaultDataEntityDescription
|
||||
from .renault_vehicle import RenaultVehicleProxy
|
||||
|
||||
# Coordinator is used to centralize the data updates
|
||||
PARALLEL_UPDATES = 0
|
||||
@@ -53,13 +54,17 @@ async def async_setup_entry(
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Renault entities from config entry."""
|
||||
entities: list[RenaultBinarySensor] = [
|
||||
RenaultBinarySensor(vehicle, description)
|
||||
for vehicle in config_entry.runtime_data.vehicles.values()
|
||||
for description in BINARY_SENSOR_TYPES
|
||||
if description.coordinator in vehicle.coordinators
|
||||
]
|
||||
async_add_entities(entities)
|
||||
|
||||
@callback
|
||||
def _async_add_vehicle(vehicle: RenaultVehicleProxy) -> None:
|
||||
async_add_entities(
|
||||
RenaultBinarySensor(vehicle, description)
|
||||
for description in BINARY_SENSOR_TYPES
|
||||
if description.coordinator in vehicle.coordinators
|
||||
)
|
||||
|
||||
for vehicle in config_entry.runtime_data.vehicles.values():
|
||||
_async_add_vehicle(vehicle)
|
||||
|
||||
|
||||
class RenaultBinarySensor[T: KamereonVehicleDataAttributes](
|
||||
|
||||
@@ -5,7 +5,7 @@ from dataclasses import dataclass
|
||||
from typing import Any, override
|
||||
|
||||
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import RenaultConfigEntry
|
||||
@@ -31,13 +31,17 @@ async def async_setup_entry(
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Renault entities from config entry."""
|
||||
entities: list[RenaultButtonEntity] = [
|
||||
RenaultButtonEntity(vehicle, description)
|
||||
for vehicle in config_entry.runtime_data.vehicles.values()
|
||||
for description in BUTTON_TYPES
|
||||
if description.is_supported(vehicle)
|
||||
]
|
||||
async_add_entities(entities)
|
||||
|
||||
@callback
|
||||
def _async_add_vehicle(vehicle: RenaultVehicleProxy) -> None:
|
||||
async_add_entities(
|
||||
RenaultButtonEntity(vehicle, description)
|
||||
for description in BUTTON_TYPES
|
||||
if description.is_supported(vehicle)
|
||||
)
|
||||
|
||||
for vehicle in config_entry.runtime_data.vehicles.values():
|
||||
_async_add_vehicle(vehicle)
|
||||
|
||||
|
||||
class RenaultButtonEntity(RenaultEntity, ButtonEntity):
|
||||
|
||||
@@ -9,11 +9,12 @@ from homeassistant.components.device_tracker import (
|
||||
TrackerEntity,
|
||||
TrackerEntityDescription,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import RenaultConfigEntry
|
||||
from .entity import RenaultDataEntity, RenaultDataEntityDescription
|
||||
from .renault_vehicle import RenaultVehicleProxy
|
||||
|
||||
# Coordinator is used to centralize the data updates
|
||||
PARALLEL_UPDATES = 0
|
||||
@@ -32,13 +33,17 @@ async def async_setup_entry(
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Renault entities from config entry."""
|
||||
entities: list[RenaultDeviceTracker] = [
|
||||
RenaultDeviceTracker(vehicle, description)
|
||||
for vehicle in config_entry.runtime_data.vehicles.values()
|
||||
for description in DEVICE_TRACKER_TYPES
|
||||
if description.coordinator in vehicle.coordinators
|
||||
]
|
||||
async_add_entities(entities)
|
||||
|
||||
@callback
|
||||
def _async_add_vehicle(vehicle: RenaultVehicleProxy) -> None:
|
||||
async_add_entities(
|
||||
RenaultDeviceTracker(vehicle, description)
|
||||
for description in DEVICE_TRACKER_TYPES
|
||||
if description.coordinator in vehicle.coordinators
|
||||
)
|
||||
|
||||
for vehicle in config_entry.runtime_data.vehicles.values():
|
||||
_async_add_vehicle(vehicle)
|
||||
|
||||
|
||||
class RenaultDeviceTracker(
|
||||
|
||||
@@ -16,13 +16,14 @@ from homeassistant.components.number import (
|
||||
NumberMode,
|
||||
)
|
||||
from homeassistant.const import PERCENTAGE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import RenaultConfigEntry
|
||||
from .const import DOMAIN
|
||||
from .entity import RenaultDataEntity, RenaultDataEntityDescription
|
||||
from .renault_vehicle import RenaultVehicleProxy
|
||||
|
||||
# Coordinator is used to centralize the data updates
|
||||
# but renault servers are unreliable and it's safer to queue action calls
|
||||
@@ -94,13 +95,17 @@ async def async_setup_entry(
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Renault entities from config entry."""
|
||||
entities: list[RenaultNumberEntity] = [
|
||||
RenaultNumberEntity(vehicle, description)
|
||||
for vehicle in config_entry.runtime_data.vehicles.values()
|
||||
for description in NUMBER_TYPES
|
||||
if description.coordinator in vehicle.coordinators
|
||||
]
|
||||
async_add_entities(entities)
|
||||
|
||||
@callback
|
||||
def _async_add_vehicle(vehicle: RenaultVehicleProxy) -> None:
|
||||
async_add_entities(
|
||||
RenaultNumberEntity(vehicle, description)
|
||||
for description in NUMBER_TYPES
|
||||
if description.coordinator in vehicle.coordinators
|
||||
)
|
||||
|
||||
for vehicle in config_entry.runtime_data.vehicles.values():
|
||||
_async_add_vehicle(vehicle)
|
||||
|
||||
|
||||
class RenaultNumberEntity[T: KamereonVehicleDataAttributes](
|
||||
|
||||
@@ -10,11 +10,12 @@ from renault_api.kamereon.models import (
|
||||
)
|
||||
|
||||
from homeassistant.components.select import SelectEntity, SelectEntityDescription
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import RenaultConfigEntry
|
||||
from .entity import RenaultDataEntity, RenaultDataEntityDescription
|
||||
from .renault_vehicle import RenaultVehicleProxy
|
||||
|
||||
# Coordinator is used to centralize the data updates
|
||||
# but renault servers are unreliable and it's safer to queue action calls
|
||||
@@ -37,13 +38,17 @@ async def async_setup_entry(
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Renault entities from config entry."""
|
||||
entities: list[RenaultSelectEntity] = [
|
||||
RenaultSelectEntity(vehicle, description)
|
||||
for vehicle in config_entry.runtime_data.vehicles.values()
|
||||
for description in SENSOR_TYPES
|
||||
if description.coordinator in vehicle.coordinators
|
||||
]
|
||||
async_add_entities(entities)
|
||||
|
||||
@callback
|
||||
def _async_add_vehicle(vehicle: RenaultVehicleProxy) -> None:
|
||||
async_add_entities(
|
||||
RenaultSelectEntity(vehicle, description)
|
||||
for description in SENSOR_TYPES
|
||||
if description.coordinator in vehicle.coordinators
|
||||
)
|
||||
|
||||
for vehicle in config_entry.runtime_data.vehicles.values():
|
||||
_async_add_vehicle(vehicle)
|
||||
|
||||
|
||||
class RenaultSelectEntity[T: KamereonVehicleDataAttributes](
|
||||
|
||||
@@ -32,7 +32,7 @@ from homeassistant.const import (
|
||||
UnitOfTime,
|
||||
UnitOfVolume,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.util.dt import as_utc, parse_datetime
|
||||
@@ -62,15 +62,22 @@ async def async_setup_entry(
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Renault entities from config entry."""
|
||||
entities: list[RenaultSensor[Any]] = [
|
||||
RenaultSensor(vehicle, description)
|
||||
for vehicle in config_entry.runtime_data.vehicles.values()
|
||||
for description in SENSOR_TYPES
|
||||
if description.coordinator in vehicle.coordinators
|
||||
and (not description.requires_fuel or vehicle.details.uses_fuel())
|
||||
and (not description.condition_lambda or description.condition_lambda(vehicle))
|
||||
]
|
||||
async_add_entities(entities)
|
||||
|
||||
@callback
|
||||
def _async_add_vehicle(vehicle: RenaultVehicleProxy) -> None:
|
||||
async_add_entities(
|
||||
RenaultSensor(vehicle, description)
|
||||
for description in SENSOR_TYPES
|
||||
if description.coordinator in vehicle.coordinators
|
||||
and (not description.requires_fuel or vehicle.details.uses_fuel())
|
||||
and (
|
||||
not description.condition_lambda
|
||||
or description.condition_lambda(vehicle)
|
||||
)
|
||||
)
|
||||
|
||||
for vehicle in config_entry.runtime_data.vehicles.values():
|
||||
_async_add_vehicle(vehicle)
|
||||
|
||||
|
||||
class RenaultSensor[T: KamereonVehicleDataAttributes](
|
||||
|
||||
Reference in New Issue
Block a user