Add number to V2C (#103681)
This commit is contained in:
parent
dda40c10d4
commit
93f63c5472
4 changed files with 100 additions and 1 deletions
|
@ -1432,6 +1432,7 @@ omit =
|
|||
homeassistant/components/v2c/__init__.py
|
||||
homeassistant/components/v2c/coordinator.py
|
||||
homeassistant/components/v2c/entity.py
|
||||
homeassistant/components/v2c/number.py
|
||||
homeassistant/components/v2c/sensor.py
|
||||
homeassistant/components/v2c/switch.py
|
||||
homeassistant/components/velbus/__init__.py
|
||||
|
|
|
@ -11,7 +11,7 @@ from homeassistant.helpers.httpx_client import get_async_client
|
|||
from .const import DOMAIN
|
||||
from .coordinator import V2CUpdateCoordinator
|
||||
|
||||
PLATFORMS: list[Platform] = [Platform.SENSOR, Platform.SWITCH]
|
||||
PLATFORMS: list[Platform] = [Platform.NUMBER, Platform.SENSOR, Platform.SWITCH]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
|
93
homeassistant/components/v2c/number.py
Normal file
93
homeassistant/components/v2c/number.py
Normal file
|
@ -0,0 +1,93 @@
|
|||
"""Number platform for V2C settings."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable, Coroutine
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from pytrydan import Trydan, TrydanData
|
||||
|
||||
from homeassistant.components.number import (
|
||||
NumberDeviceClass,
|
||||
NumberEntity,
|
||||
NumberEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import V2CUpdateCoordinator
|
||||
from .entity import V2CBaseEntity
|
||||
|
||||
MIN_INTENSITY = 6
|
||||
MAX_INTENSITY = 32
|
||||
|
||||
|
||||
@dataclass
|
||||
class V2CSettingsRequiredKeysMixin:
|
||||
"""Mixin for required keys."""
|
||||
|
||||
value_fn: Callable[[TrydanData], int]
|
||||
update_fn: Callable[[Trydan, int], Coroutine[Any, Any, None]]
|
||||
|
||||
|
||||
@dataclass
|
||||
class V2CSettingsNumberEntityDescription(
|
||||
NumberEntityDescription, V2CSettingsRequiredKeysMixin
|
||||
):
|
||||
"""Describes V2C EVSE number entity."""
|
||||
|
||||
|
||||
TRYDAN_NUMBER_SETTINGS = (
|
||||
V2CSettingsNumberEntityDescription(
|
||||
key="intensity",
|
||||
translation_key="intensity",
|
||||
device_class=NumberDeviceClass.CURRENT,
|
||||
native_min_value=MIN_INTENSITY,
|
||||
native_max_value=MAX_INTENSITY,
|
||||
value_fn=lambda evse_data: evse_data.intensity,
|
||||
update_fn=lambda evse, value: evse.intensity(value),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up V2C Trydan number platform."""
|
||||
coordinator: V2CUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
entities: list[NumberEntity] = [
|
||||
V2CSettingsNumberEntity(coordinator, description, config_entry.entry_id)
|
||||
for description in TRYDAN_NUMBER_SETTINGS
|
||||
]
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class V2CSettingsNumberEntity(V2CBaseEntity, NumberEntity):
|
||||
"""Representation of V2C EVSE settings number entity."""
|
||||
|
||||
entity_description: V2CSettingsNumberEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: V2CUpdateCoordinator,
|
||||
description: V2CSettingsNumberEntityDescription,
|
||||
entry_id: str,
|
||||
) -> None:
|
||||
"""Initialize the V2C number entity."""
|
||||
super().__init__(coordinator, description)
|
||||
self._attr_unique_id = f"{entry_id}_{description.key}"
|
||||
|
||||
@property
|
||||
def native_value(self) -> float:
|
||||
"""Return the state of the setting entity."""
|
||||
return self.entity_description.value_fn(self.data)
|
||||
|
||||
async def async_set_native_value(self, value: float) -> None:
|
||||
"""Update the setting."""
|
||||
await self.entity_description.update_fn(self.coordinator.evse, int(value))
|
||||
await self.coordinator.async_request_refresh()
|
|
@ -16,6 +16,11 @@
|
|||
}
|
||||
},
|
||||
"entity": {
|
||||
"number": {
|
||||
"intensity": {
|
||||
"name": "Intensity"
|
||||
}
|
||||
},
|
||||
"sensor": {
|
||||
"charge_power": {
|
||||
"name": "Charge power"
|
||||
|
|
Loading…
Add table
Reference in a new issue