mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Raise on reauth in devolo Home Network switch platform (#92850)
This commit is contained in:
parent
0fca90127b
commit
3abcffe3a0
@ -13,6 +13,7 @@ from homeassistant.components.switch import SwitchEntity, SwitchEntityDescriptio
|
|||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import EntityCategory
|
from homeassistant.const import EntityCategory
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
|
|
||||||
@ -113,8 +114,11 @@ class DevoloSwitchEntity(DevoloCoordinatorEntity[_DataT], SwitchEntity):
|
|||||||
"""Turn the entity on."""
|
"""Turn the entity on."""
|
||||||
try:
|
try:
|
||||||
await self.entity_description.turn_on_func(self.device)
|
await self.entity_description.turn_on_func(self.device)
|
||||||
except DevicePasswordProtected:
|
except DevicePasswordProtected as ex:
|
||||||
self.entry.async_start_reauth(self.hass)
|
self.entry.async_start_reauth(self.hass)
|
||||||
|
raise HomeAssistantError(
|
||||||
|
f"Device {self.entry.title} require re-authenticatication to set or change the password"
|
||||||
|
) from ex
|
||||||
except DeviceUnavailable:
|
except DeviceUnavailable:
|
||||||
pass # The coordinator will handle this
|
pass # The coordinator will handle this
|
||||||
await self.coordinator.async_request_refresh()
|
await self.coordinator.async_request_refresh()
|
||||||
@ -123,8 +127,11 @@ class DevoloSwitchEntity(DevoloCoordinatorEntity[_DataT], SwitchEntity):
|
|||||||
"""Turn the entity off."""
|
"""Turn the entity off."""
|
||||||
try:
|
try:
|
||||||
await self.entity_description.turn_off_func(self.device)
|
await self.entity_description.turn_off_func(self.device)
|
||||||
except DevicePasswordProtected:
|
except DevicePasswordProtected as ex:
|
||||||
self.entry.async_start_reauth(self.hass)
|
self.entry.async_start_reauth(self.hass)
|
||||||
|
raise HomeAssistantError(
|
||||||
|
f"Device {self.entry.title} require re-authenticatication to set or change the password"
|
||||||
|
) from ex
|
||||||
except DeviceUnavailable:
|
except DeviceUnavailable:
|
||||||
pass # The coordinator will handle this
|
pass # The coordinator will handle this
|
||||||
await self.coordinator.async_request_refresh()
|
await self.coordinator.async_request_refresh()
|
||||||
|
@ -21,6 +21,7 @@ from homeassistant.const import (
|
|||||||
EntityCategory,
|
EntityCategory,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.update_coordinator import REQUEST_REFRESH_DEFAULT_COOLDOWN
|
from homeassistant.helpers.update_coordinator import REQUEST_REFRESH_DEFAULT_COOLDOWN
|
||||||
from homeassistant.util import dt
|
from homeassistant.util import dt
|
||||||
@ -300,9 +301,10 @@ async def test_auth_failed(
|
|||||||
api = getattr(mock_device.device, set_method)
|
api = getattr(mock_device.device, set_method)
|
||||||
api.side_effect = DevicePasswordProtected
|
api.side_effect = DevicePasswordProtected
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError):
|
||||||
PLATFORM, SERVICE_TURN_ON, {"entity_id": state_key}, blocking=True
|
await hass.services.async_call(
|
||||||
)
|
PLATFORM, SERVICE_TURN_ON, {"entity_id": state_key}, blocking=True
|
||||||
|
)
|
||||||
flows = hass.config_entries.flow.async_progress()
|
flows = hass.config_entries.flow.async_progress()
|
||||||
assert len(flows) == 1
|
assert len(flows) == 1
|
||||||
|
|
||||||
@ -313,9 +315,10 @@ async def test_auth_failed(
|
|||||||
assert flow["context"]["source"] == SOURCE_REAUTH
|
assert flow["context"]["source"] == SOURCE_REAUTH
|
||||||
assert flow["context"]["entry_id"] == entry.entry_id
|
assert flow["context"]["entry_id"] == entry.entry_id
|
||||||
|
|
||||||
await hass.services.async_call(
|
with pytest.raises(HomeAssistantError):
|
||||||
PLATFORM, SERVICE_TURN_OFF, {"entity_id": state_key}, blocking=True
|
await hass.services.async_call(
|
||||||
)
|
PLATFORM, SERVICE_TURN_OFF, {"entity_id": state_key}, blocking=True
|
||||||
|
)
|
||||||
flows = hass.config_entries.flow.async_progress()
|
flows = hass.config_entries.flow.async_progress()
|
||||||
assert len(flows) == 1
|
assert len(flows) == 1
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user