mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Handle UnsupportedError in HomeWizard (#91608)
* Handle UnsupportedEror * Make error message more clear * Remove debug line, whoops
This commit is contained in:
parent
c544da7426
commit
6b02892c28
@ -5,7 +5,7 @@ import logging
|
|||||||
|
|
||||||
from homewizard_energy import HomeWizardEnergy
|
from homewizard_energy import HomeWizardEnergy
|
||||||
from homewizard_energy.const import SUPPORTS_IDENTIFY, SUPPORTS_STATE, SUPPORTS_SYSTEM
|
from homewizard_energy.const import SUPPORTS_IDENTIFY, SUPPORTS_STATE, SUPPORTS_SYSTEM
|
||||||
from homewizard_energy.errors import DisabledError, RequestError
|
from homewizard_energy.errors import DisabledError, RequestError, UnsupportedError
|
||||||
from homewizard_energy.models import Device
|
from homewizard_energy.models import Device
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -24,6 +24,8 @@ class HWEnergyDeviceUpdateCoordinator(DataUpdateCoordinator[DeviceResponseEntry]
|
|||||||
api: HomeWizardEnergy
|
api: HomeWizardEnergy
|
||||||
api_disabled: bool = False
|
api_disabled: bool = False
|
||||||
|
|
||||||
|
_unsupported_error: bool = False
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -43,11 +45,22 @@ class HWEnergyDeviceUpdateCoordinator(DataUpdateCoordinator[DeviceResponseEntry]
|
|||||||
data=await self.api.data(),
|
data=await self.api.data(),
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.supports_state(data.device):
|
try:
|
||||||
data.state = await self.api.state()
|
if self.supports_state(data.device):
|
||||||
|
data.state = await self.api.state()
|
||||||
|
|
||||||
if self.supports_system(data.device):
|
if self.supports_system(data.device):
|
||||||
data.system = await self.api.system()
|
data.system = await self.api.system()
|
||||||
|
|
||||||
|
except UnsupportedError as ex:
|
||||||
|
# Old firmware, ignore
|
||||||
|
if not self._unsupported_error:
|
||||||
|
self._unsupported_error = True
|
||||||
|
_LOGGER.warning(
|
||||||
|
"%s is running an outdated firmware version (%s). Contact HomeWizard support to update your device",
|
||||||
|
self.entry.title,
|
||||||
|
ex,
|
||||||
|
)
|
||||||
|
|
||||||
except RequestError as ex:
|
except RequestError as ex:
|
||||||
raise UpdateFailed(ex) from ex
|
raise UpdateFailed(ex) from ex
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""Test the update coordinator for HomeWizard."""
|
"""Test the update coordinator for HomeWizard."""
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
from homewizard_energy.errors import DisabledError, RequestError
|
from homewizard_energy.errors import DisabledError, RequestError, UnsupportedError
|
||||||
from homewizard_energy.models import State, System
|
from homewizard_energy.models import State, System
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -507,3 +507,39 @@ async def test_switch_handles_disablederror(
|
|||||||
{"entity_id": "switch.product_name_aabbccddeeff_cloud_connection"},
|
{"entity_id": "switch.product_name_aabbccddeeff_cloud_connection"},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_switch_handles_unsupportedrrror(
|
||||||
|
hass: HomeAssistant, mock_config_entry_data, mock_config_entry
|
||||||
|
) -> None:
|
||||||
|
"""Test entity raises HomeAssistantError when Disabled was raised."""
|
||||||
|
|
||||||
|
api = get_mock_device(product_type="HWE-SKT", firmware_version="3.02")
|
||||||
|
api.state = AsyncMock(side_effect=UnsupportedError())
|
||||||
|
api.system = AsyncMock(side_effect=UnsupportedError())
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.homewizard.coordinator.HomeWizardEnergy",
|
||||||
|
return_value=api,
|
||||||
|
):
|
||||||
|
entry = mock_config_entry
|
||||||
|
entry.data = mock_config_entry_data
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert (
|
||||||
|
hass.states.get("switch.product_name_aabbccddeeff_cloud_connection").state
|
||||||
|
== STATE_UNAVAILABLE
|
||||||
|
)
|
||||||
|
|
||||||
|
assert (
|
||||||
|
hass.states.get("switch.product_name_aabbccddeeff_switch_lock").state
|
||||||
|
== STATE_UNAVAILABLE
|
||||||
|
)
|
||||||
|
|
||||||
|
assert (
|
||||||
|
hass.states.get("switch.product_name_aabbccddeeff").state
|
||||||
|
== STATE_UNAVAILABLE
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user