Skip to content

Commit a206604

Browse files
Fix tado via_device warnings (home-assistant#156884)
1 parent 2e82ac8 commit a206604

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

homeassistant/components/tado/__init__.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
ConfigEntryError,
2222
ConfigEntryNotReady,
2323
)
24-
from homeassistant.helpers import config_validation as cv
24+
from homeassistant.helpers import config_validation as cv, device_registry as dr
2525
from homeassistant.helpers.typing import ConfigType
2626

2727
from .const import (
@@ -32,6 +32,7 @@
3232
CONST_OVERLAY_TADO_MODE,
3333
CONST_OVERLAY_TADO_OPTIONS,
3434
DOMAIN,
35+
TADO_BRIDGE_MODELS,
3536
)
3637
from .coordinator import TadoDataUpdateCoordinator, TadoMobileDeviceUpdateCoordinator
3738
from .models import TadoData
@@ -105,6 +106,21 @@ def create_tado_instance() -> tuple[Tado, str]:
105106
mobile_coordinator = TadoMobileDeviceUpdateCoordinator(hass, entry, tado)
106107
await mobile_coordinator.async_config_entry_first_refresh()
107108

109+
# Pre-register the bridge device to ensure it exists before other devices reference it
110+
device_registry = dr.async_get(hass)
111+
for device in coordinator.data["device"].values():
112+
if device["deviceType"] in TADO_BRIDGE_MODELS:
113+
_LOGGER.debug("Pre-registering Tado bridge: %s", device["shortSerialNo"])
114+
device_registry.async_get_or_create(
115+
config_entry_id=entry.entry_id,
116+
identifiers={(DOMAIN, device["shortSerialNo"])},
117+
manufacturer="Tado",
118+
model=device["deviceType"],
119+
name=device["serialNo"],
120+
sw_version=device["currentFwVersion"],
121+
configuration_url=f"https://app.tado.com/en/main/settings/rooms-and-devices/device/{device['serialNo']}",
122+
)
123+
108124
entry.runtime_data = TadoData(coordinator, mobile_coordinator)
109125
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
110126

homeassistant/components/tado/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205

206206
TADO_HOME = "Home"
207207
TADO_ZONE = "Zone"
208+
TADO_BRIDGE_MODELS = ["IB01", "IB02"]
208209

209210
# Constants for Temperature Offset
210211
INSIDE_TEMPERATURE_MEASUREMENT = "INSIDE_TEMPERATURE_MEASUREMENT"

homeassistant/components/tado/entity.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from homeassistant.helpers.device_registry import DeviceInfo
66
from homeassistant.helpers.update_coordinator import CoordinatorEntity
77

8-
from .const import DEFAULT_NAME, DOMAIN, TADO_HOME, TADO_ZONE
8+
from .const import DEFAULT_NAME, DOMAIN, TADO_BRIDGE_MODELS, TADO_HOME, TADO_ZONE
99
from .coordinator import TadoDataUpdateCoordinator
1010

1111
_LOGGER = logging.getLogger(__name__)
@@ -28,15 +28,23 @@ def __init__(
2828
self._device_info = device_info
2929
self.device_name = device_info["serialNo"]
3030
self.device_id = device_info["shortSerialNo"]
31+
via_device: tuple[str, str] | None = None
32+
if device_info["deviceType"] not in TADO_BRIDGE_MODELS:
33+
for device in coordinator.data["device"].values():
34+
if device["deviceType"] in TADO_BRIDGE_MODELS:
35+
via_device = (DOMAIN, device["shortSerialNo"])
36+
break
37+
3138
self._attr_device_info = DeviceInfo(
3239
configuration_url=f"https://app.tado.com/en/main/settings/rooms-and-devices/device/{self.device_name}",
3340
identifiers={(DOMAIN, self.device_id)},
3441
name=self.device_name,
3542
manufacturer=DEFAULT_NAME,
3643
sw_version=device_info["currentFwVersion"],
3744
model=device_info["deviceType"],
38-
via_device=(DOMAIN, device_info["serialNo"]),
3945
)
46+
if via_device:
47+
self._attr_device_info["via_device"] = via_device
4048

4149

4250
class TadoHomeEntity(TadoCoordinatorEntity):

0 commit comments

Comments
 (0)