-
Notifications
You must be signed in to change notification settings - Fork 6
/
cover.py
149 lines (119 loc) · 5.18 KB
/
cover.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"""Support for Freebox covers."""
import logging
import json
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.components.cover import CoverEntity, CoverDeviceClass
from .const import DOMAIN
from .base_class import FreeboxBaseClass
from homeassistant.const import (
STATE_CLOSED,
STATE_CLOSING,
STATE_OPEN,
STATE_OPENING,
)
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass, entry, async_add_entities):
router = hass.data[DOMAIN][entry.unique_id]
entities = []
for nodeId, node in router.nodes.items():
if node["category"]=="basic_shutter":
entities.append(FreeboxBasicShutter(hass, router, node))
elif node["category"]=="shutter":
entities.append(FreeboxShutter(hass, router, node))
async_add_entities(entities, True)
class FreeboxBasicShutter(FreeboxBaseClass,CoverEntity):
def __init__(self, hass, router, node) -> None:
"""Initialize a Cover"""
super().__init__(hass, router, node)
self._command_up = self.get_command_id(node['show_endpoints'], "slot", "up")
self._command_stop = self.get_command_id(node['show_endpoints'], "slot", "stop")
self._command_down = self.get_command_id(node['show_endpoints'], "slot", "down")
self._command_state = self.get_command_id(node['show_endpoints'], "signal", "state")
self._state = self.get_node_value(node['show_endpoints'], "signal", "state")
@property
def device_class(self) -> str:
return CoverDeviceClass.SHUTTER
@property
def current_cover_position(self):
return None
@property
def current_cover_tilt_position(self):
return None
@property
def is_closed(self):
"""Return if the cover is closed or not."""
if(self._state == STATE_OPEN):
return False
if(self._state == STATE_CLOSED):
return True
return None
async def async_open_cover(self, **kwargs):
"""Open cover."""
await self.set_home_endpoint_value(self._command_up, {"value": None})
self._state = STATE_OPEN
async def async_close_cover(self, **kwargs):
"""Close cover."""
await self.set_home_endpoint_value(self._command_down, {"value": None})
self._state = STATE_CLOSED
async def async_stop_cover(self, **kwargs):
"""Stop cover."""
await self.set_home_endpoint_value(self._command_stop, {"value": None})
self._state = None
async def async_update(self):
"""Get the state & name and update it."""
node = self._router.nodes[self._id];
self._name = node["label"].strip()
self._state = self.convert_state(await self.get_home_endpoint_value(self._command_state))
def convert_state(self, state):
if( state ):
return STATE_CLOSED
elif( state is not None):
return STATE_OPEN
else:
return None
class FreeboxShutter(FreeboxBaseClass,CoverEntity):
def __init__(self, hass, router, node) -> None:
"""Initialize a Cover"""
super().__init__(hass, router, node)
self._command_position = self.get_command_id(node['type']['endpoints'], "slot", "position_set")
self._command_up = self.get_command_id(node['type']['endpoints'], "slot", "position_set")
self._command_down = self.get_command_id(node['type']['endpoints'], "slot", "position_set")
self._command_stop = self.get_command_id(node['show_endpoints'], "slot", "stop")
self._command_toggle = self.get_command_id(node['show_endpoints'], "slot", "toggle")
self._command_state = self.get_command_id(node['type']['endpoints'], "signal", "position_set")
self._state = self.get_node_value(node['show_endpoints'], "signal", "state")
@property
def device_class(self) -> str:
return CoverDeviceClass.SHUTTER
@property
def current_cover_position(self):
return self._state
@property
def current_cover_tilt_position(self):
return None
@property
def is_closed(self):
"""Return if the cover is closed or not."""
if(self._state == 100):
return True
return False
async def async_set_cover_position(self, position, **kwargs):
"""Set cover position."""
await self.set_home_endpoint_value(self._command_position, {"value": position})
self._state = STATE_OPEN
async def async_open_cover(self, **kwargs):
"""Open cover."""
await self.set_home_endpoint_value(self._command_up, {"value": 0})
async def async_close_cover(self, **kwargs):
"""Close cover."""
await self.set_home_endpoint_value(self._command_down, {"value": 100})
async def async_stop_cover(self, **kwargs):
"""Stop cover."""
await self.set_home_endpoint_value(self._command_stop, {"value": None})
self._state = None
async def async_update(self):
"""Get the state & name and update it."""
node = self._router.nodes[self._id];
self._name = node["label"].strip()
self._state = await self.get_home_endpoint_value(self._command_state)