mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Don't save Home Assistant device ID at Home Connect device (#131013)
This commit is contained in:
parent
3c96c559dc
commit
1ab2bbe3b0
@ -6,7 +6,6 @@ from datetime import timedelta
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from homeconnect.api import HomeConnectAppliance
|
||||
from requests import HTTPError
|
||||
import voluptuous as vol
|
||||
|
||||
@ -92,12 +91,27 @@ PLATFORMS = [
|
||||
|
||||
def _get_appliance_by_device_id(
|
||||
hass: HomeAssistant, device_id: str
|
||||
) -> HomeConnectAppliance:
|
||||
) -> api.HomeConnectAppliance:
|
||||
"""Return a Home Connect appliance instance given an device_id."""
|
||||
device_registry = dr.async_get(hass)
|
||||
device_entry = device_registry.async_get(device_id)
|
||||
assert device_entry
|
||||
|
||||
ha_id = next(
|
||||
(
|
||||
identifier[1]
|
||||
for identifier in device_entry.identifiers
|
||||
if identifier[0] == DOMAIN
|
||||
),
|
||||
None,
|
||||
)
|
||||
assert ha_id
|
||||
|
||||
for hc_api in hass.data[DOMAIN].values():
|
||||
for device in hc_api.devices:
|
||||
if device.device_id == device_id:
|
||||
return device.appliance
|
||||
appliance = device.appliance
|
||||
if appliance.haId == ha_id:
|
||||
return appliance
|
||||
raise ValueError(f"Appliance for device id {device_id} not found")
|
||||
|
||||
|
||||
@ -259,20 +273,9 @@ async def update_all_devices(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
data = hass.data[DOMAIN]
|
||||
hc_api = data[entry.entry_id]
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
try:
|
||||
await hass.async_add_executor_job(hc_api.get_devices)
|
||||
for device in hc_api.devices:
|
||||
device_entry = device_registry.async_get_or_create(
|
||||
config_entry_id=entry.entry_id,
|
||||
identifiers={(DOMAIN, device.appliance.haId)},
|
||||
name=device.appliance.name,
|
||||
manufacturer=device.appliance.brand,
|
||||
model=device.appliance.vib,
|
||||
)
|
||||
|
||||
device.device_id = device_entry.id
|
||||
|
||||
await hass.async_add_executor_job(device.initialize)
|
||||
except HTTPError as err:
|
||||
_LOGGER.warning("Cannot update devices: %s", err.response.status_code)
|
||||
|
@ -54,8 +54,9 @@ async def test_async_get_device_diagnostics(
|
||||
assert await integration_setup()
|
||||
assert config_entry.state == ConfigEntryState.LOADED
|
||||
|
||||
device = device_registry.async_get_device(
|
||||
identifiers={(DOMAIN, "SIEMENS-HCS02DWH1-6BE58C26DCC1")}
|
||||
device = device_registry.async_get_or_create(
|
||||
config_entry_id=config_entry.entry_id,
|
||||
identifiers={(DOMAIN, "SIEMENS-HCS02DWH1-6BE58C26DCC1")},
|
||||
)
|
||||
|
||||
assert await async_get_device_diagnostics(hass, config_entry, device) == snapshot
|
||||
|
@ -305,7 +305,7 @@ async def test_services_exception(
|
||||
|
||||
service_call["service_data"]["device_id"] = "DOES_NOT_EXISTS"
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
with pytest.raises(AssertionError):
|
||||
await hass.services.async_call(**service_call)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user