v0.6.4
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"domain": "gree_controller",
|
||||
"name": "GREE Controller",
|
||||
"version": "0.6.3",
|
||||
"version": "0.6.4",
|
||||
"config_flow": true,
|
||||
"integration_type": "hub",
|
||||
"iot_class": "local_polling",
|
||||
|
||||
Reference in New Issue
Block a user