mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +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
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeconnect.api import HomeConnectAppliance
|
|
||||||
from requests import HTTPError
|
from requests import HTTPError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -92,12 +91,27 @@ PLATFORMS = [
|
|||||||
|
|
||||||
def _get_appliance_by_device_id(
|
def _get_appliance_by_device_id(
|
||||||
hass: HomeAssistant, device_id: str
|
hass: HomeAssistant, device_id: str
|
||||||
) -> HomeConnectAppliance:
|
) -> api.HomeConnectAppliance:
|
||||||
"""Return a Home Connect appliance instance given an device_id."""
|
"""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 hc_api in hass.data[DOMAIN].values():
|
||||||
for device in hc_api.devices:
|
for device in hc_api.devices:
|
||||||
if device.device_id == device_id:
|
appliance = device.appliance
|
||||||
return device.appliance
|
if appliance.haId == ha_id:
|
||||||
|
return appliance
|
||||||
raise ValueError(f"Appliance for device id {device_id} not found")
|
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]
|
data = hass.data[DOMAIN]
|
||||||
hc_api = data[entry.entry_id]
|
hc_api = data[entry.entry_id]
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
try:
|
try:
|
||||||
await hass.async_add_executor_job(hc_api.get_devices)
|
await hass.async_add_executor_job(hc_api.get_devices)
|
||||||
for device in hc_api.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)
|
await hass.async_add_executor_job(device.initialize)
|
||||||
except HTTPError as err:
|
except HTTPError as err:
|
||||||
_LOGGER.warning("Cannot update devices: %s", err.response.status_code)
|
_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 await integration_setup()
|
||||||
assert config_entry.state == ConfigEntryState.LOADED
|
assert config_entry.state == ConfigEntryState.LOADED
|
||||||
|
|
||||||
device = device_registry.async_get_device(
|
device = device_registry.async_get_or_create(
|
||||||
identifiers={(DOMAIN, "SIEMENS-HCS02DWH1-6BE58C26DCC1")}
|
config_entry_id=config_entry.entry_id,
|
||||||
|
identifiers={(DOMAIN, "SIEMENS-HCS02DWH1-6BE58C26DCC1")},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert await async_get_device_diagnostics(hass, config_entry, device) == snapshot
|
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"
|
service_call["service_data"]["device_id"] = "DOES_NOT_EXISTS"
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(AssertionError):
|
||||||
await hass.services.async_call(**service_call)
|
await hass.services.async_call(**service_call)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user