* Add binary sensors to TechnoVE integration * Add unit tests for TechnoVE binary sensors * Implement PR feedback for TechnoVE * Limit to appropriate sensors in TechnoVE tests * Removed leftover code * Implement feedback in TechnoVE PR #108938 * Add auto-charge switch to TechnoVE * Improve TechnoVE test_switches to be consistent with other platforms * Regenerate test_switch.ambr snapshot * Add binary sensors to TechnoVE integration * Add unit tests for TechnoVE binary sensors * Implement PR feedback for TechnoVE * Limit to appropriate sensors in TechnoVE tests * Implement feedback in TechnoVE PR #108938 * Add auto-charge switch to TechnoVE * Apply suggestions from code review Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Fix conflict merge issue * Implement feedback from TechnoVE PR #109093 * Use TechnoVESwitchDescription * Remove None from is_on in TechnoVE switches * Update homeassistant/components/technove/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Remove unneeded code. * Update test_switch.ambr * Update TechnoVE switch test similar to Flexit_bacnet --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
"""Helpers for TechnoVE."""
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Callable, Coroutine
|
|
from typing import Any, Concatenate, ParamSpec, TypeVar
|
|
|
|
from technove import TechnoVEConnectionError, TechnoVEError
|
|
|
|
from homeassistant.exceptions import HomeAssistantError
|
|
|
|
from .entity import TechnoVEEntity
|
|
|
|
_TechnoVEEntityT = TypeVar("_TechnoVEEntityT", bound=TechnoVEEntity)
|
|
_P = ParamSpec("_P")
|
|
|
|
|
|
def technove_exception_handler(
|
|
func: Callable[Concatenate[_TechnoVEEntityT, _P], Coroutine[Any, Any, Any]],
|
|
) -> Callable[Concatenate[_TechnoVEEntityT, _P], Coroutine[Any, Any, None]]:
|
|
"""Decorate TechnoVE calls to handle TechnoVE exceptions.
|
|
|
|
A decorator that wraps the passed in function, catches TechnoVE errors,
|
|
and handles the availability of the device in the data coordinator.
|
|
"""
|
|
|
|
async def handler(
|
|
self: _TechnoVEEntityT, *args: _P.args, **kwargs: _P.kwargs
|
|
) -> None:
|
|
try:
|
|
await func(self, *args, **kwargs)
|
|
|
|
except TechnoVEConnectionError as error:
|
|
self.coordinator.last_update_success = False
|
|
self.coordinator.async_update_listeners()
|
|
raise HomeAssistantError("Error communicating with TechnoVE API") from error
|
|
|
|
except TechnoVEError as error:
|
|
raise HomeAssistantError("Invalid response from TechnoVE API") from error
|
|
|
|
return handler
|