mirror of
https://github.com/home-assistant/core.git
synced 2026-08-06 13:26:29 +01:00
Adapt tado to set via_device_id in DeviceInfo (#178079)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
@@ -28,11 +29,15 @@ class TadoDeviceEntity(TadoCoordinatorEntity):
|
||||
self._device_info = device_info
|
||||
self.device_name = device_info["serialNo"]
|
||||
self.device_id = device_info["shortSerialNo"]
|
||||
via_device: tuple[str, str] | None = None
|
||||
via_device_id: str | None = None
|
||||
if device_info["deviceType"] not in TADO_BRIDGE_MODELS:
|
||||
for device in coordinator.data["device"].values():
|
||||
if device["deviceType"] in TADO_BRIDGE_MODELS:
|
||||
via_device = (DOMAIN, device["shortSerialNo"])
|
||||
via_device_id = dr.async_get_device_id_by_identifier(
|
||||
coordinator.hass,
|
||||
(DOMAIN, device["shortSerialNo"]),
|
||||
config_entry_id=coordinator.config_entry.entry_id,
|
||||
)
|
||||
break
|
||||
|
||||
self._attr_device_info = DeviceInfo(
|
||||
@@ -43,8 +48,8 @@ class TadoDeviceEntity(TadoCoordinatorEntity):
|
||||
sw_version=device_info["currentFwVersion"],
|
||||
model=device_info["deviceType"],
|
||||
)
|
||||
if via_device:
|
||||
self._attr_device_info["via_device"] = via_device
|
||||
if via_device_id:
|
||||
self._attr_device_info["via_device_id"] = via_device_id
|
||||
|
||||
|
||||
class TadoHomeEntity(TadoCoordinatorEntity):
|
||||
|
||||
@@ -34,5 +34,18 @@
|
||||
"capabilities": ["INSIDE_TEMPERATURE_MEASUREMENT", "IDENTIFY"]
|
||||
},
|
||||
"childLockEnabled": false
|
||||
},
|
||||
{
|
||||
"deviceType": "IB01",
|
||||
"currentFwVersion": "62.7",
|
||||
"characteristics": {
|
||||
"capabilities": []
|
||||
},
|
||||
"serialNo": "IB1234",
|
||||
"shortSerialNo": "IB1234",
|
||||
"connectionState": {
|
||||
"value": true,
|
||||
"timestamp": "2020-03-23T18:30:07.377Z"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -869,6 +869,57 @@
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_entities[binary_sensor.ib1234_connection_state-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
None,
|
||||
]),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.ib1234_connection_state',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'Connection state',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.CONNECTIVITY: 'connectivity'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Connection state',
|
||||
'platform': 'tado',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'connection_state',
|
||||
'unique_id': 'connection state IB1234 1',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_entities[binary_sensor.ib1234_connection_state-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'connectivity',
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'IB1234 Connection state',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.ib1234_connection_state',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_entities[binary_sensor.second_water_heater_second_water_heater_connectivity-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
|
||||
@@ -3,6 +3,20 @@
|
||||
dict({
|
||||
'data': dict({
|
||||
'device': dict({
|
||||
'IB1234': dict({
|
||||
'characteristics': dict({
|
||||
'capabilities': list([
|
||||
]),
|
||||
}),
|
||||
'connectionState': dict({
|
||||
'timestamp': '2020-03-23T18:30:07.377Z',
|
||||
'value': True,
|
||||
}),
|
||||
'currentFwVersion': '62.7',
|
||||
'deviceType': 'IB01',
|
||||
'serialNo': 'IB1234',
|
||||
'shortSerialNo': 'IB1234',
|
||||
}),
|
||||
'WR1': dict({
|
||||
'accessPointWiFi': dict({
|
||||
'ssid': 'tado8480',
|
||||
|
||||
@@ -6,10 +6,12 @@ import time
|
||||
from unittest.mock import patch
|
||||
|
||||
from PyTado.http import Http
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.tado import DOMAIN
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@@ -32,6 +34,25 @@ async def test_v1_migration(hass: HomeAssistant) -> None:
|
||||
assert CONF_USERNAME not in entry.data
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_integration")
|
||||
async def test_device_via_device_links(
|
||||
hass: HomeAssistant, device_registry: dr.DeviceRegistry
|
||||
) -> None:
|
||||
"""Test that child devices link to the bridge via via_device_id."""
|
||||
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
|
||||
|
||||
bridge_device = device_registry.async_get_device_by_identifier(
|
||||
(DOMAIN, "IB1234"), config_entry.entry_id
|
||||
)
|
||||
assert bridge_device is not None
|
||||
|
||||
child_device = device_registry.async_get_device_by_identifier(
|
||||
(DOMAIN, "WR1"), config_entry.entry_id
|
||||
)
|
||||
assert child_device is not None
|
||||
assert child_device.via_device_id == bridge_device.id
|
||||
|
||||
|
||||
async def test_refresh_token_threading_lock(hass: HomeAssistant) -> None:
|
||||
"""Test that threading.Lock in Http._refresh_token serializes concurrent calls."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user