mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +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 dataclasses import dataclass
|
||||
from json.decoder import JSONDecodeError
|
||||
from typing import Any, Final
|
||||
|
||||
from aiovodafone.exceptions import (
|
||||
AlreadyLogged,
|
||||
CannotAuthenticate,
|
||||
CannotConnect,
|
||||
GenericLoginError,
|
||||
)
|
||||
|
||||
from homeassistant.components.button import (
|
||||
ButtonDeviceClass,
|
||||
ButtonEntity,
|
||||
@ -13,10 +21,11 @@ from homeassistant.components.button import (
|
||||
)
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import _LOGGER
|
||||
from .const import _LOGGER, DOMAIN
|
||||
from .coordinator import VodafoneConfigEntry, VodafoneStationRouter
|
||||
|
||||
# Coordinator is used to centralize the data updates
|
||||
@ -108,4 +117,25 @@ class VodafoneStationSensorEntity(
|
||||
|
||||
async def async_press(self) -> None:
|
||||
"""Triggers the Shelly button press service."""
|
||||
await self.entity_description.press_action(self.coordinator)
|
||||
|
||||
try:
|
||||
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
|
||||
|
||||
# Silver
|
||||
action-exceptions:
|
||||
status: todo
|
||||
comment: button presses not exception handled with HomeAssistantError
|
||||
action-exceptions: done
|
||||
config-entry-unloading: done
|
||||
docs-configuration-parameters: done
|
||||
docs-installation-parameters: done
|
||||
|
@ -116,6 +116,9 @@
|
||||
"update_failed": {
|
||||
"message": "Error fetching data: {error}"
|
||||
},
|
||||
"cannot_execute_action": {
|
||||
"message": "Cannot execute requested action: {error}"
|
||||
},
|
||||
"cannot_authenticate": {
|
||||
"message": "Error authenticating: {error}"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user