mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Handle button presses exceptions for Vodafone Station (#140953)
* Handle button presses execeptions for Vodafone Station * apply review comment
This commit is contained in:
parent
f84a46680d
commit
c1753631b1
@ -4,8 +4,16 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from json.decoder import JSONDecodeError
|
||||||
from typing import Any, Final
|
from typing import Any, Final
|
||||||
|
|
||||||
|
from aiovodafone.exceptions import (
|
||||||
|
AlreadyLogged,
|
||||||
|
CannotAuthenticate,
|
||||||
|
CannotConnect,
|
||||||
|
GenericLoginError,
|
||||||
|
)
|
||||||
|
|
||||||
from homeassistant.components.button import (
|
from homeassistant.components.button import (
|
||||||
ButtonDeviceClass,
|
ButtonDeviceClass,
|
||||||
ButtonEntity,
|
ButtonEntity,
|
||||||
@ -13,10 +21,11 @@ from homeassistant.components.button import (
|
|||||||
)
|
)
|
||||||
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 AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import _LOGGER
|
from .const import _LOGGER, DOMAIN
|
||||||
from .coordinator import VodafoneConfigEntry, VodafoneStationRouter
|
from .coordinator import VodafoneConfigEntry, VodafoneStationRouter
|
||||||
|
|
||||||
# Coordinator is used to centralize the data updates
|
# Coordinator is used to centralize the data updates
|
||||||
@ -108,4 +117,25 @@ class VodafoneStationSensorEntity(
|
|||||||
|
|
||||||
async def async_press(self) -> None:
|
async def async_press(self) -> None:
|
||||||
"""Triggers the Shelly button press service."""
|
"""Triggers the Shelly button press service."""
|
||||||
|
|
||||||
|
try:
|
||||||
await self.entity_description.press_action(self.coordinator)
|
await self.entity_description.press_action(self.coordinator)
|
||||||
|
except CannotAuthenticate as err:
|
||||||
|
self.coordinator.config_entry.async_start_reauth(self.hass)
|
||||||
|
raise HomeAssistantError(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="cannot_authenticate",
|
||||||
|
translation_placeholders={"error": repr(err)},
|
||||||
|
) from err
|
||||||
|
except (
|
||||||
|
CannotConnect,
|
||||||
|
AlreadyLogged,
|
||||||
|
GenericLoginError,
|
||||||
|
JSONDecodeError,
|
||||||
|
) as err:
|
||||||
|
self.coordinator.last_update_success = False
|
||||||
|
raise HomeAssistantError(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="cannot_execute_action",
|
||||||
|
translation_placeholders={"error": repr(err)},
|
||||||
|
) from err
|
||||||
|
@ -26,9 +26,7 @@ rules:
|
|||||||
unique-config-entry: done
|
unique-config-entry: done
|
||||||
|
|
||||||
# Silver
|
# Silver
|
||||||
action-exceptions:
|
action-exceptions: done
|
||||||
status: todo
|
|
||||||
comment: button presses not exception handled with HomeAssistantError
|
|
||||||
config-entry-unloading: done
|
config-entry-unloading: done
|
||||||
docs-configuration-parameters: done
|
docs-configuration-parameters: done
|
||||||
docs-installation-parameters: done
|
docs-installation-parameters: done
|
||||||
|
@ -116,6 +116,9 @@
|
|||||||
"update_failed": {
|
"update_failed": {
|
||||||
"message": "Error fetching data: {error}"
|
"message": "Error fetching data: {error}"
|
||||||
},
|
},
|
||||||
|
"cannot_execute_action": {
|
||||||
|
"message": "Cannot execute requested action: {error}"
|
||||||
|
},
|
||||||
"cannot_authenticate": {
|
"cannot_authenticate": {
|
||||||
"message": "Error authenticating: {error}"
|
"message": "Error authenticating: {error}"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user