airzone: select: change options to lists (from enums)
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>pull/92894/head
parent
8b6d9141b7
commit
e503a1dd3a
|
@ -1,7 +1,7 @@
|
|||
"""Support for the Airzone sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, replace
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Final
|
||||
|
||||
from aioairzone.common import GrilleAngle, SleepTimeout
|
||||
|
@ -32,7 +32,6 @@ class AirzoneSelectDescriptionMixin:
|
|||
"""Define an entity description mixin for select entities."""
|
||||
|
||||
api_param: str
|
||||
options_dict: dict[str, int]
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -40,19 +39,9 @@ class AirzoneSelectDescription(SelectEntityDescription, AirzoneSelectDescription
|
|||
"""Class to describe an Airzone select entity."""
|
||||
|
||||
|
||||
GRILLE_ANGLE_DICT: Final[dict[str, int]] = {
|
||||
"90deg": GrilleAngle.DEG_90,
|
||||
"50deg": GrilleAngle.DEG_50,
|
||||
"45deg": GrilleAngle.DEG_45,
|
||||
"40deg": GrilleAngle.DEG_40,
|
||||
}
|
||||
GRILLE_ANGLE_OPTIONS: Final[list[str]] = [str(opt.value) for opt in GrilleAngle]
|
||||
|
||||
SLEEP_DICT: Final[dict[str, int]] = {
|
||||
"off": SleepTimeout.SLEEP_OFF,
|
||||
"30m": SleepTimeout.SLEEP_30,
|
||||
"60m": SleepTimeout.SLEEP_60,
|
||||
"90m": SleepTimeout.SLEEP_90,
|
||||
}
|
||||
SLEEP_OPTIONS: Final[list[str]] = [str(opt.value) for opt in SleepTimeout]
|
||||
|
||||
|
||||
ZONE_SELECT_TYPES: Final[tuple[AirzoneSelectDescription, ...]] = (
|
||||
|
@ -61,7 +50,7 @@ ZONE_SELECT_TYPES: Final[tuple[AirzoneSelectDescription, ...]] = (
|
|||
entity_category=EntityCategory.CONFIG,
|
||||
key=AZD_COLD_ANGLE,
|
||||
name="Cold Angle",
|
||||
options_dict=GRILLE_ANGLE_DICT,
|
||||
options=GRILLE_ANGLE_OPTIONS,
|
||||
translation_key="grille_angles",
|
||||
),
|
||||
AirzoneSelectDescription(
|
||||
|
@ -69,7 +58,7 @@ ZONE_SELECT_TYPES: Final[tuple[AirzoneSelectDescription, ...]] = (
|
|||
entity_category=EntityCategory.CONFIG,
|
||||
key=AZD_HEAT_ANGLE,
|
||||
name="Heat Angle",
|
||||
options_dict=GRILLE_ANGLE_DICT,
|
||||
options=GRILLE_ANGLE_OPTIONS,
|
||||
translation_key="grille_angles",
|
||||
),
|
||||
AirzoneSelectDescription(
|
||||
|
@ -77,7 +66,7 @@ ZONE_SELECT_TYPES: Final[tuple[AirzoneSelectDescription, ...]] = (
|
|||
entity_category=EntityCategory.CONFIG,
|
||||
key=AZD_SLEEP,
|
||||
name="Sleep",
|
||||
options_dict=SLEEP_DICT,
|
||||
options=SLEEP_OPTIONS,
|
||||
translation_key="sleep_times",
|
||||
),
|
||||
)
|
||||
|
@ -94,14 +83,10 @@ async def async_setup_entry(
|
|||
for system_zone_id, zone_data in coordinator.data[AZD_ZONES].items():
|
||||
for description in ZONE_SELECT_TYPES:
|
||||
if description.key in zone_data:
|
||||
_desc = replace(
|
||||
description,
|
||||
options=list(description.options_dict),
|
||||
)
|
||||
entities.append(
|
||||
AirzoneZoneSelect(
|
||||
coordinator,
|
||||
_desc,
|
||||
description,
|
||||
entry,
|
||||
system_zone_id,
|
||||
zone_data,
|
||||
|
@ -115,7 +100,6 @@ class AirzoneBaseSelect(AirzoneEntity, SelectEntity):
|
|||
"""Define an Airzone select."""
|
||||
|
||||
entity_description: AirzoneSelectDescription
|
||||
values_dict: dict[int, str]
|
||||
|
||||
@callback
|
||||
def _handle_coordinator_update(self) -> None:
|
||||
|
@ -123,14 +107,12 @@ class AirzoneBaseSelect(AirzoneEntity, SelectEntity):
|
|||
self._async_update_attrs()
|
||||
super()._handle_coordinator_update()
|
||||
|
||||
def _get_current_option(self) -> str | None:
|
||||
value = self.get_airzone_value(self.entity_description.key)
|
||||
return self.values_dict.get(value)
|
||||
|
||||
@callback
|
||||
def _async_update_attrs(self) -> None:
|
||||
"""Update select attributes."""
|
||||
self._attr_current_option = self._get_current_option()
|
||||
self._attr_current_option = str(
|
||||
self.get_airzone_value(self.entity_description.key)
|
||||
)
|
||||
|
||||
|
||||
class AirzoneZoneSelect(AirzoneZoneEntity, AirzoneBaseSelect):
|
||||
|
@ -152,12 +134,12 @@ class AirzoneZoneSelect(AirzoneZoneEntity, AirzoneBaseSelect):
|
|||
f"{self._attr_unique_id}_{system_zone_id}_{description.key}"
|
||||
)
|
||||
self.entity_description = description
|
||||
self.values_dict = {v: k for k, v in description.options_dict.items()}
|
||||
|
||||
self._async_update_attrs()
|
||||
|
||||
async def async_select_option(self, option: str) -> None:
|
||||
"""Change the selected option."""
|
||||
param = self.entity_description.api_param
|
||||
value = self.entity_description.options_dict[option]
|
||||
await self._async_update_hvac_params({param: value})
|
||||
params = {
|
||||
self.entity_description.api_param: int(option),
|
||||
}
|
||||
await self._async_update_hvac_params(params)
|
||||
|
|
|
@ -28,18 +28,18 @@
|
|||
"select": {
|
||||
"grille_angles": {
|
||||
"state": {
|
||||
"90deg": "90º",
|
||||
"50deg": "50º",
|
||||
"45deg": "45º",
|
||||
"40deg": "40º"
|
||||
"0": "90º",
|
||||
"1": "50º",
|
||||
"2": "45º",
|
||||
"3": "40º"
|
||||
}
|
||||
},
|
||||
"sleep_times": {
|
||||
"state": {
|
||||
"off": "[%key:common::state::off%]",
|
||||
"30m": "30 minutes",
|
||||
"60m": "60 minutes",
|
||||
"90m": "90 minutes"
|
||||
"0": "[%key:common::state::off%]",
|
||||
"30": "30 minutes",
|
||||
"60": "60 minutes",
|
||||
"90": "90 minutes"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
from unittest.mock import patch
|
||||
|
||||
from aioairzone.common import GrilleAngle, SleepTimeout
|
||||
from aioairzone.const import (
|
||||
API_COLD_ANGLE,
|
||||
API_DATA,
|
||||
|
@ -25,49 +26,49 @@ async def test_airzone_create_selects(hass: HomeAssistant) -> None:
|
|||
await async_init_integration(hass)
|
||||
|
||||
state = hass.states.get("select.despacho_cold_angle")
|
||||
assert state.state == "90deg"
|
||||
assert state.state == str(GrilleAngle.DEG_90)
|
||||
|
||||
state = hass.states.get("select.despacho_heat_angle")
|
||||
assert state.state == "90deg"
|
||||
assert state.state == str(GrilleAngle.DEG_90)
|
||||
|
||||
state = hass.states.get("select.despacho_sleep")
|
||||
assert state.state == "off"
|
||||
assert state.state == str(SleepTimeout.SLEEP_OFF)
|
||||
|
||||
state = hass.states.get("select.dorm_1_cold_angle")
|
||||
assert state.state == "90deg"
|
||||
assert state.state == str(GrilleAngle.DEG_90)
|
||||
|
||||
state = hass.states.get("select.dorm_1_heat_angle")
|
||||
assert state.state == "90deg"
|
||||
assert state.state == str(GrilleAngle.DEG_90)
|
||||
|
||||
state = hass.states.get("select.dorm_1_sleep")
|
||||
assert state.state == "off"
|
||||
assert state.state == str(SleepTimeout.SLEEP_OFF)
|
||||
|
||||
state = hass.states.get("select.dorm_2_cold_angle")
|
||||
assert state.state == "90deg"
|
||||
assert state.state == str(GrilleAngle.DEG_90)
|
||||
|
||||
state = hass.states.get("select.dorm_2_heat_angle")
|
||||
assert state.state == "90deg"
|
||||
assert state.state == str(GrilleAngle.DEG_90)
|
||||
|
||||
state = hass.states.get("select.dorm_2_sleep")
|
||||
assert state.state == "off"
|
||||
assert state.state == str(SleepTimeout.SLEEP_OFF)
|
||||
|
||||
state = hass.states.get("select.dorm_ppal_cold_angle")
|
||||
assert state.state == "45deg"
|
||||
assert state.state == str(GrilleAngle.DEG_45)
|
||||
|
||||
state = hass.states.get("select.dorm_ppal_heat_angle")
|
||||
assert state.state == "50deg"
|
||||
assert state.state == str(GrilleAngle.DEG_50)
|
||||
|
||||
state = hass.states.get("select.dorm_ppal_sleep")
|
||||
assert state.state == "30m"
|
||||
assert state.state == str(SleepTimeout.SLEEP_30)
|
||||
|
||||
state = hass.states.get("select.salon_cold_angle")
|
||||
assert state.state == "90deg"
|
||||
assert state.state == str(GrilleAngle.DEG_90)
|
||||
|
||||
state = hass.states.get("select.salon_heat_angle")
|
||||
assert state.state == "90deg"
|
||||
assert state.state == str(GrilleAngle.DEG_90)
|
||||
|
||||
state = hass.states.get("select.salon_sleep")
|
||||
assert state.state == "off"
|
||||
assert state.state == str(SleepTimeout.SLEEP_OFF)
|
||||
|
||||
|
||||
async def test_airzone_select_sleep(hass: HomeAssistant) -> None:
|
||||
|
@ -80,7 +81,7 @@ async def test_airzone_select_sleep(hass: HomeAssistant) -> None:
|
|||
{
|
||||
API_SYSTEM_ID: 1,
|
||||
API_ZONE_ID: 3,
|
||||
API_SLEEP: 30,
|
||||
API_SLEEP: SleepTimeout.SLEEP_30.value,
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -105,13 +106,13 @@ async def test_airzone_select_sleep(hass: HomeAssistant) -> None:
|
|||
SERVICE_SELECT_OPTION,
|
||||
{
|
||||
ATTR_ENTITY_ID: "select.dorm_1_sleep",
|
||||
ATTR_OPTION: "30m",
|
||||
ATTR_OPTION: str(SleepTimeout.SLEEP_30),
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
state = hass.states.get("select.dorm_1_sleep")
|
||||
assert state.state == "30m"
|
||||
assert state.state == str(SleepTimeout.SLEEP_30)
|
||||
|
||||
|
||||
async def test_airzone_select_grille_angle(hass: HomeAssistant) -> None:
|
||||
|
@ -126,7 +127,7 @@ async def test_airzone_select_grille_angle(hass: HomeAssistant) -> None:
|
|||
{
|
||||
API_SYSTEM_ID: 1,
|
||||
API_ZONE_ID: 3,
|
||||
API_COLD_ANGLE: 1,
|
||||
API_COLD_ANGLE: GrilleAngle.DEG_50.value,
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -140,13 +141,13 @@ async def test_airzone_select_grille_angle(hass: HomeAssistant) -> None:
|
|||
SERVICE_SELECT_OPTION,
|
||||
{
|
||||
ATTR_ENTITY_ID: "select.dorm_1_cold_angle",
|
||||
ATTR_OPTION: "50deg",
|
||||
ATTR_OPTION: str(GrilleAngle.DEG_50),
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
state = hass.states.get("select.dorm_1_cold_angle")
|
||||
assert state.state == "50deg"
|
||||
assert state.state == str(GrilleAngle.DEG_50)
|
||||
|
||||
# Heat Angle
|
||||
|
||||
|
@ -155,7 +156,7 @@ async def test_airzone_select_grille_angle(hass: HomeAssistant) -> None:
|
|||
{
|
||||
API_SYSTEM_ID: 1,
|
||||
API_ZONE_ID: 3,
|
||||
API_HEAT_ANGLE: 2,
|
||||
API_HEAT_ANGLE: GrilleAngle.DEG_45.value,
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -168,10 +169,10 @@ async def test_airzone_select_grille_angle(hass: HomeAssistant) -> None:
|
|||
SERVICE_SELECT_OPTION,
|
||||
{
|
||||
ATTR_ENTITY_ID: "select.dorm_1_heat_angle",
|
||||
ATTR_OPTION: "45deg",
|
||||
ATTR_OPTION: str(GrilleAngle.DEG_45),
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
state = hass.states.get("select.dorm_1_heat_angle")
|
||||
assert state.state == "45deg"
|
||||
assert state.state == str(GrilleAngle.DEG_45)
|
||||
|
|
Loading…
Reference in New Issue