Add string-constants to Plugwise - part 1 (#156042)

This commit is contained in:
Bouwe Westerdijk
2025-11-08 15:09:38 +01:00
committed by GitHub
parent 074c1ff775
commit 1f04e0e655
4 changed files with 23 additions and 13 deletions

View File

@@ -8,7 +8,7 @@ from homeassistant.const import Platform
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import device_registry as dr, entity_registry as er
from .const import DOMAIN, LOGGER, PLATFORMS
from .const import DEV_CLASS, DOMAIN, LOGGER, PLATFORMS
from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
@@ -47,7 +47,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) ->
def async_migrate_entity_entry(entry: er.RegistryEntry) -> dict[str, Any] | None:
"""Migrate Plugwise entity entries.
- Migrates old unique ID's from old binary_sensors and switches to the new unique ID's
Migrates old unique ID's from old binary_sensors and switches to the new unique ID's.
"""
if entry.domain == Platform.BINARY_SENSOR and entry.unique_id.endswith(
"-slave_boiler_state"
@@ -80,7 +80,7 @@ def migrate_sensor_entities(
# Migrating opentherm_outdoor_temperature
# to opentherm_outdoor_air_temperature sensor
for device_id, device in coordinator.data.items():
if device["dev_class"] != "heater_central":
if device[DEV_CLASS] != "heater_central":
continue
old_unique_id = f"{device_id}-outdoor_temperature"

View File

@@ -31,14 +31,18 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.service_info.zeroconf import ZeroconfServiceInfo
from .const import (
ANNA_WITH_ADAM,
DEFAULT_PORT,
DEFAULT_USERNAME,
DOMAIN,
FLOW_SMILE,
FLOW_STRETCH,
SMILE,
SMILE_OPEN_THERM,
SMILE_THERMO,
STRETCH,
STRETCH_USERNAME,
UNKNOWN_SMILE,
ZEROCONF_MAP,
)
@@ -117,7 +121,7 @@ class PlugwiseConfigFlow(ConfigFlow, domain=DOMAIN):
VERSION = 1
discovery_info: ZeroconfServiceInfo | None = None
product: str = "Unknown Smile"
product: str = UNKNOWN_SMILE
_username: str = DEFAULT_USERNAME
async def async_step_zeroconf(
@@ -151,20 +155,20 @@ class PlugwiseConfigFlow(ConfigFlow, domain=DOMAIN):
if DEFAULT_USERNAME not in unique_id:
self._username = STRETCH_USERNAME
self.product = _product = _properties.get("product", "Unknown Smile")
self.product = _product = _properties.get("product", UNKNOWN_SMILE)
_version = _properties.get("version", "n/a")
_name = f"{ZEROCONF_MAP.get(_product, _product)} v{_version}"
# This is an Anna, but we already have config entries.
# Assuming that the user has already configured Adam, aborting discovery.
if self._async_current_entries() and _product == "smile_thermo":
return self.async_abort(reason="anna_with_adam")
if self._async_current_entries() and _product == SMILE_THERMO:
return self.async_abort(reason=ANNA_WITH_ADAM)
# If we have discovered an Adam or Anna, both might be on the network.
# In that case, we need to cancel the Anna flow, as the Adam should
# be added.
if self.hass.config_entries.flow.async_has_matching_flow(self):
return self.async_abort(reason="anna_with_adam")
return self.async_abort(reason=ANNA_WITH_ADAM)
self.context.update(
{
@@ -179,11 +183,11 @@ class PlugwiseConfigFlow(ConfigFlow, domain=DOMAIN):
def is_matching(self, other_flow: Self) -> bool:
"""Return True if other_flow is matching this flow."""
# This is an Anna, and there is already an Adam flow in progress
if self.product == "smile_thermo" and other_flow.product == "smile_open_therm":
if self.product == SMILE_THERMO and other_flow.product == SMILE_OPEN_THERM:
return True
# This is an Adam, and there is already an Anna flow in progress
if self.product == "smile_open_therm" and other_flow.product == "smile_thermo":
if self.product == SMILE_OPEN_THERM and other_flow.product == SMILE_THERMO:
self.hass.config_entries.flow.async_abort(other_flow.flow_id)
return False

View File

@@ -12,7 +12,10 @@ DOMAIN: Final = "plugwise"
LOGGER = logging.getLogger(__package__)
ANNA_WITH_ADAM: Final = "anna_with_adam"
API: Final = "api"
AVAILABLE: Final = "available"
DEV_CLASS: Final = "dev_class"
FLOW_SMILE: Final = "smile (Adam/Anna/P1)"
FLOW_STRETCH: Final = "stretch (Stretch)"
FLOW_TYPE: Final = "flow_type"
@@ -21,8 +24,11 @@ LOCATION: Final = "location"
PW_TYPE: Final = "plugwise_type"
REBOOT: Final = "reboot"
SMILE: Final = "smile"
SMILE_OPEN_THERM: Final = "smile_open_therm"
SMILE_THERMO: Final = "smile_thermo"
STRETCH: Final = "stretch"
STRETCH_USERNAME: Final = "stretch"
UNKNOWN_SMILE: Final = "Unknown Smile"
PLATFORMS: Final[list[str]] = [
Platform.BINARY_SENSOR,

View File

@@ -12,7 +12,7 @@ from homeassistant.helpers.device_registry import (
)
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN
from .const import AVAILABLE, DOMAIN
from .coordinator import PlugwiseDataUpdateCoordinator
@@ -56,7 +56,7 @@ class PlugwiseEntity(CoordinatorEntity[PlugwiseDataUpdateCoordinator]):
if device_id != coordinator.api.gateway_id:
self._attr_device_info.update(
{
ATTR_NAME: data.get("name"),
ATTR_NAME: data.get(ATTR_NAME),
ATTR_VIA_DEVICE: (
DOMAIN,
str(self.coordinator.api.gateway_id),
@@ -69,7 +69,7 @@ class PlugwiseEntity(CoordinatorEntity[PlugwiseDataUpdateCoordinator]):
"""Return if entity is available."""
return (
self._dev_id in self.coordinator.data
and ("available" not in self.device or self.device["available"] is True)
and (AVAILABLE not in self.device or self.device[AVAILABLE] is True)
and super().available
)