1 """Support for Soma Smartshades."""
3 from __future__
import annotations
5 from collections.abc
import Callable, Coroutine
9 from requests
import RequestException
14 from .const
import DOMAIN
15 from .utils
import is_api_response_success
17 _LOGGER = logging.getLogger(__name__)
20 def soma_api_call[_SomaEntityT: SomaEntity](
21 api_call: Callable[[_SomaEntityT], Coroutine[Any, Any, dict]],
22 ) -> Callable[[_SomaEntityT], Coroutine[Any, Any, dict]]:
23 """Soma api call decorator."""
25 async
def inner(self: _SomaEntityT) -> dict:
28 response_from_api = await api_call(self)
29 except RequestException:
30 if self.api_is_available:
31 _LOGGER.warning(
"Connection to SOMA Connect failed")
32 self.api_is_available =
False
34 if not self.api_is_available:
35 self.api_is_available =
True
36 _LOGGER.info(
"Connection to SOMA Connect succeeded")
40 self.is_available =
False
43 "Device is unreachable (%s). Error while fetching the"
47 response_from_api[
"msg"],
50 if not self.is_available:
51 self.is_available =
True
52 _LOGGER.info(
"Device %s is now reachable", self.name)
53 response = response_from_api
60 """Representation of a generic Soma device."""
62 _attr_has_entity_name =
True
65 """Initialize the Soma device."""
75 """Return true if the last API commands returned successfully."""
80 """Return the unique id base on the id returned by pysoma API."""
81 return self.
devicedevice[
"mac"]
85 """Return device specific attributes.
87 Implemented by platform classes.
91 manufacturer=
"Wazombi Labs",
92 name=self.
devicedevice[
"name"],
96 """Set the current device position."""
102 """Return the shade state from the api."""
103 return await self.
hasshass.async_add_executor_job(
104 self.
apiapi.get_shade_state, self.
devicedevice[
"mac"]
109 """Return the battery level from the api."""
110 return await self.
hasshass.async_add_executor_job(
111 self.
apiapi.get_battery_level, self.
devicedevice[
"mac"]
None set_position(self, int position)
dict get_shade_state_from_api(self)
def __init__(self, device, api)
DeviceInfo device_info(self)
dict get_battery_level_from_api(self)
None schedule_update_ha_state(self, bool force_refresh=False)
bool is_api_response_success(dict api_response)