1 """Support for Obihai Sensors."""
3 from __future__
import annotations
7 from requests.exceptions
import RequestException
14 from .connectivity
import ObihaiConnection
15 from .const
import DOMAIN, LOGGER, OBIHAI
17 SCAN_INTERVAL = datetime.timedelta(seconds=5)
21 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
23 """Set up the Obihai sensor entries."""
25 requester: ObihaiConnection = hass.data[DOMAIN][entry.entry_id]
33 if requester.line_services
is not None:
42 """Get the status of each Obihai Lines."""
44 def __init__(self, requester: ObihaiConnection, service_name: str) ->
None:
45 """Initialize monitor sensor."""
49 self.
_attr_name_attr_name = f
"{OBIHAI} {self._service_name}"
61 return "mdi:phone-off"
63 return "mdi:phone-incoming"
64 return "mdi:phone-outgoing"
66 return "mdi:phone-log"
69 return "mdi:phone-ring"
71 return "mdi:phone-in-talk"
72 return "mdi:phone-hangup"
74 if "OBiTALK Service Status" in self.
_service_name_service_name:
75 return "mdi:phone-check"
77 return "mdi:phone-hangup"
78 return "mdi:phone-in-talk"
81 return "mdi:restart-off"
82 return "mdi:restart-alert"
86 """Update the sensor."""
88 LOGGER.debug(
"Running update on %s", self.
_service_name_service_name)
92 services = self.
_pyobihai_pyobihai.get_line_state()
94 if services
is not None and self.
_service_name_service_name
in services:
97 call_direction = self.
_pyobihai_pyobihai.get_call_direction()
107 if not self.
requesterrequester.available:
109 LOGGER.warning(
"Connection restored")
112 except RequestException
as exc:
114 LOGGER.warning(
"Connection failed, Obihai offline? %s", exc)
117 self.
requesterrequester.available =
False
118 except IndexError
as exc:
120 LOGGER.warning(
"Connection failed, bad response: %s", exc)
123 self.
requesterrequester.available =
False
None __init__(self, ObihaiConnection requester, str service_name)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
str get_state(int upload, int download)