mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use SelectEntityDescription in kostal plenticore (#78840)
This commit is contained in:
parent
67f7c17d34
commit
daba474182
@ -2,11 +2,11 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from abc import ABC
|
from abc import ABC
|
||||||
|
from dataclasses import dataclass
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import NamedTuple
|
|
||||||
|
|
||||||
from homeassistant.components.select import SelectEntity
|
from homeassistant.components.select import SelectEntity, SelectEntityDescription
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import DEVICE_DEFAULT_NAME
|
from homeassistant.const import DEVICE_DEFAULT_NAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -20,31 +20,33 @@ from .helper import Plenticore, SelectDataUpdateCoordinator
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class SelectData(NamedTuple):
|
@dataclass
|
||||||
"""Representation of a SelectData tuple."""
|
class PlenticoreRequiredKeysMixin:
|
||||||
|
"""A class that describes required properties for plenticore select entities."""
|
||||||
|
|
||||||
module_id: str
|
module_id: str
|
||||||
data_id: str
|
|
||||||
name: str
|
|
||||||
options: list
|
options: list
|
||||||
is_on: str
|
is_on: str
|
||||||
|
|
||||||
|
|
||||||
# Defines all entities for select widgets.
|
@dataclass
|
||||||
#
|
class PlenticoreSelectEntityDescription(
|
||||||
# Each entry is defined with a tuple of these values:
|
SelectEntityDescription, PlenticoreRequiredKeysMixin
|
||||||
# - module id (str)
|
):
|
||||||
# - process data id (str)
|
"""A class that describes plenticore select entities."""
|
||||||
# - entity name suffix (str)
|
|
||||||
# - options
|
|
||||||
# - entity is enabled by default (bool)
|
|
||||||
SELECT_SETTINGS_DATA = [
|
SELECT_SETTINGS_DATA = [
|
||||||
SelectData(
|
PlenticoreSelectEntityDescription(
|
||||||
"devices:local",
|
module_id="devices:local",
|
||||||
"battery_charge",
|
key="battery_charge",
|
||||||
"Battery Charging / Usage mode",
|
name="Battery Charging / Usage mode",
|
||||||
["None", "Battery:SmartBatteryControl:Enable", "Battery:TimeControl:Enable"],
|
options=[
|
||||||
"1",
|
"None",
|
||||||
|
"Battery:SmartBatteryControl:Enable",
|
||||||
|
"Battery:TimeControl:Enable",
|
||||||
|
],
|
||||||
|
is_on="1",
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -81,7 +83,7 @@ async def async_setup_entry(
|
|||||||
platform_name=entry.title,
|
platform_name=entry.title,
|
||||||
device_class="kostal_plenticore__battery",
|
device_class="kostal_plenticore__battery",
|
||||||
module_id=select.module_id,
|
module_id=select.module_id,
|
||||||
data_id=select.data_id,
|
data_id=select.key,
|
||||||
name=select.name,
|
name=select.name,
|
||||||
current_option="None",
|
current_option="None",
|
||||||
options=select.options,
|
options=select.options,
|
||||||
@ -107,7 +109,7 @@ class PlenticoreDataSelect(CoordinatorEntity, SelectEntity, ABC):
|
|||||||
device_class: str | None,
|
device_class: str | None,
|
||||||
module_id: str,
|
module_id: str,
|
||||||
data_id: str,
|
data_id: str,
|
||||||
name: str,
|
name: str | None,
|
||||||
current_option: str | None,
|
current_option: str | None,
|
||||||
options: list[str],
|
options: list[str],
|
||||||
is_on: str,
|
is_on: str,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user