This commit is contained in:
Mateusz Gruszczyński
2026-08-24 23:58:44 +02:00
parent 9191fba212
commit 25e1a854e3
9 changed files with 71 additions and 17 deletions
@@ -20,6 +20,7 @@ from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util import slugify
from . import GreeControllerRuntimeData
from .const import DOMAIN
@@ -73,11 +74,54 @@ async def async_setup_entry(
for zone in runtime.coordinator.plan.get("zones", []):
zone_id = str(zone.get("zone_id") or "").strip()
if zone_id:
_ensure_zone_thermostat_entity_id(registry, zone)
entities.append(GreeControllerZoneClimate(runtime.coordinator, zone_id))
async_add_entities(entities)
def _ensure_zone_thermostat_entity_id(
registry: er.EntityRegistry, zone: dict[str, Any]
) -> None:
"""Keep zone climate entity IDs stable and descriptive.
Zone climate entities use ``climate.<zone_name>_thermostat``. Existing
registry entries are migrated to the same scheme, which also fixes stale
IDs left behind after a zone was renamed (for example ``climate.jan_2``
for a zone currently named Igor).
"""
zone_id = str(zone.get("zone_id") or "").strip()
if not zone_id:
return
unique_id = f"{zone_id}-zone-climate"
current_entity_id = registry.async_get_entity_id("climate", DOMAIN, unique_id)
if current_entity_id is None:
return
zone_name = str(zone.get("zone_name") or zone_id).strip() or zone_id
object_id = slugify(zone_name) or slugify(zone_id) or "zone"
desired_entity_id = f"climate.{object_id}_thermostat"
if current_entity_id == desired_entity_id:
return
occupied = registry.async_get(desired_entity_id)
if occupied is not None and occupied.entity_id != current_entity_id:
_LOGGER.warning(
"Cannot rename zone thermostat %s to %s because that entity ID is already in use",
current_entity_id,
desired_entity_id,
)
return
registry.async_update_entity(current_entity_id, new_entity_id=desired_entity_id)
_LOGGER.info(
"Renamed zone thermostat entity %s to %s",
current_entity_id,
desired_entity_id,
)
class GreeControllerClimate(CoordinatorEntity[GreeControllerCoordinator], ClimateEntity):
"""Home Assistant climate entity controlled through the Rust service."""
@@ -216,7 +260,7 @@ class GreeControllerZoneClimate(CoordinatorEntity[GreeControllerCoordinator], Cl
"""Full climate entity for a controller thermostat zone."""
_attr_has_entity_name = True
_attr_name = None
_attr_name = "Thermostat"
_attr_temperature_unit = UnitOfTemperature.CELSIUS
_attr_min_temp = 8.0
_attr_max_temp = 30.0