mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Handle Home Connect error at diagnostics (#131644)
This commit is contained in:
parent
8b8c409916
commit
a6520d2627
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeconnect.api import HomeConnectAppliance
|
||||
from homeconnect.api import HomeConnectAppliance, HomeConnectError
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceEntry
|
||||
@ -14,9 +14,14 @@ from .api import HomeConnectDevice
|
||||
|
||||
|
||||
def _generate_appliance_diagnostics(appliance: HomeConnectAppliance) -> dict[str, Any]:
|
||||
try:
|
||||
programs = appliance.get_programs_available()
|
||||
except HomeConnectError:
|
||||
programs = None
|
||||
return {
|
||||
"connected": appliance.connected,
|
||||
"status": appliance.status,
|
||||
"programs": appliance.get_programs_available(),
|
||||
"programs": programs,
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
# name: test_async_get_config_entry_diagnostics
|
||||
dict({
|
||||
'BOSCH-000000000-000000000000': dict({
|
||||
'connected': True,
|
||||
'programs': list([
|
||||
]),
|
||||
'status': dict({
|
||||
@ -23,6 +24,7 @@
|
||||
}),
|
||||
}),
|
||||
'BOSCH-HCS000000-D00000000001': dict({
|
||||
'connected': True,
|
||||
'programs': list([
|
||||
'LaundryCare.WasherDryer.Program.Mix',
|
||||
'LaundryCare.Washer.Option.Temperature',
|
||||
@ -46,6 +48,7 @@
|
||||
}),
|
||||
}),
|
||||
'BOSCH-HCS000000-D00000000002': dict({
|
||||
'connected': True,
|
||||
'programs': list([
|
||||
]),
|
||||
'status': dict({
|
||||
@ -67,6 +70,7 @@
|
||||
}),
|
||||
}),
|
||||
'BOSCH-HCS000000-D00000000003': dict({
|
||||
'connected': True,
|
||||
'programs': list([
|
||||
]),
|
||||
'status': dict({
|
||||
@ -88,6 +92,7 @@
|
||||
}),
|
||||
}),
|
||||
'BOSCH-HCS000000-D00000000004': dict({
|
||||
'connected': True,
|
||||
'programs': list([
|
||||
]),
|
||||
'status': dict({
|
||||
@ -144,6 +149,7 @@
|
||||
}),
|
||||
}),
|
||||
'BOSCH-HCS000000-D00000000005': dict({
|
||||
'connected': True,
|
||||
'programs': list([
|
||||
]),
|
||||
'status': dict({
|
||||
@ -165,6 +171,7 @@
|
||||
}),
|
||||
}),
|
||||
'BOSCH-HCS000000-D00000000006': dict({
|
||||
'connected': True,
|
||||
'programs': list([
|
||||
]),
|
||||
'status': dict({
|
||||
@ -186,6 +193,7 @@
|
||||
}),
|
||||
}),
|
||||
'BOSCH-HCS01OVN1-43E0065FE245': dict({
|
||||
'connected': True,
|
||||
'programs': list([
|
||||
'Cooking.Oven.Program.HeatingMode.HotAir',
|
||||
'Cooking.Oven.Program.HeatingMode.TopBottomHeating',
|
||||
@ -217,6 +225,7 @@
|
||||
}),
|
||||
}),
|
||||
'BOSCH-HCS04DYR1-831694AE3C5A': dict({
|
||||
'connected': True,
|
||||
'programs': list([
|
||||
'LaundryCare.Dryer.Program.Cotton',
|
||||
'LaundryCare.Dryer.Program.Synthetic',
|
||||
@ -241,6 +250,7 @@
|
||||
}),
|
||||
}),
|
||||
'BOSCH-HCS06COM1-D70390681C2C': dict({
|
||||
'connected': True,
|
||||
'programs': list([
|
||||
'ConsumerProducts.CoffeeMaker.Program.Beverage.Espresso',
|
||||
'ConsumerProducts.CoffeeMaker.Program.Beverage.EspressoMacchiato',
|
||||
@ -268,6 +278,7 @@
|
||||
}),
|
||||
}),
|
||||
'SIEMENS-HCS02DWH1-6BE58C26DCC1': dict({
|
||||
'connected': True,
|
||||
'programs': list([
|
||||
'Dishcare.Dishwasher.Program.Auto1',
|
||||
'Dishcare.Dishwasher.Program.Auto2',
|
||||
@ -319,6 +330,7 @@
|
||||
}),
|
||||
}),
|
||||
'SIEMENS-HCS03WCH1-7BC6383CF794': dict({
|
||||
'connected': True,
|
||||
'programs': list([
|
||||
'LaundryCare.Washer.Program.Cotton',
|
||||
'LaundryCare.Washer.Program.EasyCare',
|
||||
@ -356,6 +368,7 @@
|
||||
}),
|
||||
}),
|
||||
'SIEMENS-HCS05FRF1-304F4F9E541D': dict({
|
||||
'connected': True,
|
||||
'programs': list([
|
||||
]),
|
||||
'status': dict({
|
||||
@ -415,6 +428,7 @@
|
||||
# ---
|
||||
# name: test_async_get_device_diagnostics
|
||||
dict({
|
||||
'connected': True,
|
||||
'programs': list([
|
||||
'Dishcare.Dishwasher.Program.Auto1',
|
||||
'Dishcare.Dishwasher.Program.Auto2',
|
||||
|
@ -1,8 +1,9 @@
|
||||
"""Test diagnostics for Home Connect."""
|
||||
|
||||
from collections.abc import Awaitable, Callable
|
||||
from unittest.mock import MagicMock
|
||||
from unittest.mock import MagicMock, Mock
|
||||
|
||||
from homeconnect.api import HomeConnectError
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
@ -63,14 +64,13 @@ async def test_async_get_device_diagnostics(
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("bypass_throttle")
|
||||
async def test_async_device_diagnostics_exceptions(
|
||||
async def test_async_device_diagnostics_not_found(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
integration_setup: Callable[[], Awaitable[bool]],
|
||||
setup_credentials: None,
|
||||
get_appliances: MagicMock,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test device config entry diagnostics."""
|
||||
get_appliances.side_effect = get_all_appliances
|
||||
@ -85,3 +85,45 @@ async def test_async_device_diagnostics_exceptions(
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
await async_get_device_diagnostics(hass, config_entry, device)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("api_error", "expected_connection_status"),
|
||||
[
|
||||
(HomeConnectError(), "unknown"),
|
||||
(
|
||||
HomeConnectError(
|
||||
{
|
||||
"key": "SDK.Error.HomeAppliance.Connection.Initialization.Failed",
|
||||
}
|
||||
),
|
||||
"offline",
|
||||
),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("bypass_throttle")
|
||||
async def test_async_device_diagnostics_api_error(
|
||||
api_error: HomeConnectError,
|
||||
expected_connection_status: str,
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
integration_setup: Callable[[], Awaitable[bool]],
|
||||
setup_credentials: None,
|
||||
get_appliances: MagicMock,
|
||||
appliance: Mock,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
) -> None:
|
||||
"""Test device config entry diagnostics."""
|
||||
appliance.get_programs_available.side_effect = api_error
|
||||
get_appliances.return_value = [appliance]
|
||||
assert config_entry.state == ConfigEntryState.NOT_LOADED
|
||||
assert await integration_setup()
|
||||
assert config_entry.state == ConfigEntryState.LOADED
|
||||
|
||||
device = device_registry.async_get_or_create(
|
||||
config_entry_id=config_entry.entry_id,
|
||||
identifiers={(DOMAIN, appliance.haId)},
|
||||
)
|
||||
|
||||
diagnostics = await async_get_device_diagnostics(hass, config_entry, device)
|
||||
assert diagnostics["programs"] is None
|
||||
|
Loading…
x
Reference in New Issue
Block a user