This commit is contained in:
Mateusz Gruszczyński
2026-08-25 19:44:12 +02:00
parent 62d071c972
commit 0d65a6a946
15 changed files with 464 additions and 38 deletions
@@ -1,4 +1,4 @@
"""Whole-house thermostat controls for GREE Controller."""
"""Whole-house and climate-group thermostat selectors for GREE Controller."""
from __future__ import annotations
@@ -30,6 +30,15 @@ HOUSE_PRESET_LABELS = {
}
HOUSE_PRESET_VALUES = {label: value for value, label in HOUSE_PRESET_LABELS.items()}
GROUP_MODE_LABELS = {
"house": "Global",
"cool": "Cooling",
"heat": "Heating",
}
GROUP_MODE_VALUES = {label: value for value, label in GROUP_MODE_LABELS.items()}
GROUP_PRESET_LABELS = HOUSE_PRESET_LABELS
GROUP_PRESET_VALUES = HOUSE_PRESET_VALUES
async def async_setup_entry(
hass: HomeAssistant,
@@ -38,12 +47,14 @@ async def async_setup_entry(
) -> None:
"""Create whole-house thermostat mode and work-profile selectors."""
runtime: GreeControllerRuntimeData = entry.runtime_data
async_add_entities(
[
GreeControllerHouseModeSelect(runtime.coordinator),
GreeControllerHousePresetSelect(runtime.coordinator),
]
)
entities: list[SelectEntity] = [
GreeControllerHouseModeSelect(runtime.coordinator),
GreeControllerHousePresetSelect(runtime.coordinator),
]
for group_id in runtime.coordinator.groups:
entities.append(GreeControllerGroupModeSelect(runtime.coordinator, group_id))
entities.append(GreeControllerGroupPresetSelect(runtime.coordinator, group_id))
async_add_entities(entities)
class _GreeControllerHouseSelect(CoordinatorEntity[GreeControllerCoordinator], SelectEntity):
@@ -103,3 +114,87 @@ class GreeControllerHousePresetSelect(_GreeControllerHouseSelect):
return
await self.coordinator.client.house_preset(value)
await self.coordinator.async_request_refresh()
class _GreeControllerGroupSelect(CoordinatorEntity[GreeControllerCoordinator], SelectEntity):
"""Base class for climate-group selectors."""
_attr_has_entity_name = True
def __init__(self, coordinator: GreeControllerCoordinator, group_id: str) -> None:
super().__init__(coordinator)
self._group_id = group_id
@property
def _group(self) -> dict[str, Any]:
return self.coordinator.groups.get(self._group_id, {})
@property
def available(self) -> bool:
return super().available and bool(self._group)
@property
def device_info(self) -> DeviceInfo:
group = self._group
return DeviceInfo(
identifiers={(DOMAIN, f"group:{self._group_id}")},
name=str(group.get("name") or self._group_id),
manufacturer="GREE Controller",
model="Climate group",
via_device=(DOMAIN, "controller"),
)
class GreeControllerGroupModeSelect(_GreeControllerGroupSelect):
"""Select the thermostat mode policy for one climate group."""
_attr_name = "Thermostat mode"
_attr_options = list(GROUP_MODE_VALUES)
def __init__(self, coordinator: GreeControllerCoordinator, group_id: str) -> None:
super().__init__(coordinator, group_id)
self._attr_unique_id = f"{group_id}-group-thermostat-mode"
@property
def current_option(self) -> str | None:
return GROUP_MODE_LABELS.get(str(self._group.get("mode") or ""))
@property
def extra_state_attributes(self) -> dict[str, Any]:
return {
"mixed_group_mode": self._group.get("mode") == "mixed",
"global_house_mode": self._group.get("house_mode"),
}
async def async_select_option(self, option: str) -> None:
value = GROUP_MODE_VALUES.get(option)
if value is None:
return
await self.coordinator.client.group_control(self._group_id, {"mode": value})
await self.coordinator.async_request_refresh()
class GreeControllerGroupPresetSelect(_GreeControllerGroupSelect):
"""Select the work profile for one climate group."""
_attr_name = "Work profile"
_attr_options = list(GROUP_PRESET_VALUES)
def __init__(self, coordinator: GreeControllerCoordinator, group_id: str) -> None:
super().__init__(coordinator, group_id)
self._attr_unique_id = f"{group_id}-group-work-profile"
@property
def current_option(self) -> str | None:
return GROUP_PRESET_LABELS.get(str(self._group.get("preset") or ""))
@property
def extra_state_attributes(self) -> dict[str, Any]:
return {"mixed_group_profiles": self._group.get("preset") == "mixed"}
async def async_select_option(self, option: str) -> None:
value = GROUP_PRESET_VALUES.get(option)
if value is None:
return
await self.coordinator.client.group_control(self._group_id, {"preset": value})
await self.coordinator.async_request_refresh()