1 """Support for Freebox base features."""
3 from __future__
import annotations
5 from collections.abc
import Callable
14 from .const
import CATEGORY_TO_MODEL, DOMAIN, FreeboxHomeCategory
15 from .router
import FreeboxRouter
17 _LOGGER = logging.getLogger(__name__)
21 """Representation of a Freebox base entity."""
26 router: FreeboxRouter,
28 sub_node: dict[str, Any] |
None =
None,
30 """Initialize a Freebox Home entity."""
35 self.
_id_id = node[
"id"]
40 if sub_node
is not None:
41 self.
_attr_name_attr_name +=
" " + sub_node[
"label"].strip()
49 self.
_model_model = CATEGORY_TO_MODEL.get(node[
"category"])
50 if self.
_model_model
is None:
51 if node[
"type"].
get(
"inherit") ==
"node::rts":
53 self.
_model_model = CATEGORY_TO_MODEL[FreeboxHomeCategory.RTS]
54 elif node[
"type"].
get(
"inherit") ==
"node::ios":
56 self.
_model_model = CATEGORY_TO_MODEL[FreeboxHomeCategory.IOHOME]
59 identifiers={(DOMAIN, self.
_id_id)},
78 self.
_node_node[
"label"].strip() +
" " + self.
_sub_node_sub_node[
"label"].strip()
83 self, command_id: int |
None, value: bool |
None =
None
85 """Set Home endpoint value."""
86 if command_id
is None:
87 _LOGGER.error(
"Unable to SET a value through the API. Command is None")
90 await self.
_router_router.home.set_home_endpoint_value(
91 self.
_id_id, command_id, {
"value": value}
96 """Get Home endpoint value."""
97 if command_id
is None:
98 _LOGGER.error(
"Unable to GET a value through the API. Command is None")
101 node = await self.
_router_router.home.get_home_endpoint_value(self.
_id_id, command_id)
102 return node.get(
"value")
105 """Get the command id."""
107 filter(
lambda x: (x[
"name"] == name
and x[
"ep_type"] == ep_type), nodes),
112 "The Freebox Home device has no command value for: %s/%s", name, ep_type
118 """Register state update callback."""
122 self.
_router_router.signal_home_device_update,
128 """When entity will be removed from hass."""
133 """Register state update callback."""
141 for endpoint
in self.
_node_node[
"show_endpoints"]
142 if endpoint[
"name"] == name
and endpoint[
"ep_type"] == ep_type
148 "The Freebox Home device has no node value for: %s/%s", ep_type, name
151 return node.get(
"value")
None __init__(self, HomeAssistant hass, FreeboxRouter router, dict[str, Any] node, dict[str, Any]|None sub_node=None)
None remove_signal_update(self, Callable[[], None] dispatcher)
def get_value(self, str ep_type, str name)
None async_added_to_hass(self)
Any|None get_home_endpoint_value(self, Any command_id)
int|None get_command_id(self, nodes, str ep_type, str name)
None async_update_signal(self)
bool set_home_endpoint_value(self, int|None command_id, bool|None value=None)
None async_will_remove_from_hass(self)
None async_write_ha_state(self)
web.Response get(self, web.Request request, str config_key)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)