-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathcover.py
132 lines (105 loc) · 3.46 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
"""Support for NeoSmartBlinds covers."""
import logging
from homeassistant.components.cover import CoverDevice, PLATFORM_SCHEMA
from custom_components.neosmartblinds.neosmartblinds.neo_smart_blinds_remote import NeoSmartBlinds
import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.script import Script
from homeassistant.components.cover import (
SUPPORT_CLOSE,
SUPPORT_OPEN,
SUPPORT_STOP,
SUPPORT_SET_POSITION,
SUPPORT_OPEN_TILT,
SUPPORT_CLOSE_TILT,
CoverDevice,
)
from homeassistant.const import (
CONF_HOST,
CONF_NAME,
)
_LOGGER = logging.getLogger(__name__)
from homeassistant.const import (
CONF_HOST,
CONF_NAME,
)
CONF_DEVICE = "blind_code"
CONF_CLOSE_TIME = "close_time"
LOGGER = logging.getLogger(__name__)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_NAME): cv.string,
vol.Required(CONF_DEVICE): cv.string,
vol.Required(CONF_CLOSE_TIME): cv.string,
}
)
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up NeoSmartBlinds cover."""
cover = NeoSmartBlindsCover(
hass,
config.get(CONF_NAME),
config.get(CONF_HOST),
config.get(CONF_DEVICE),
config.get(CONF_CLOSE_TIME),
)
add_entities([cover])
class NeoSmartBlindsCover(CoverDevice):
"""Representation of a NeoSmartBlinds cover."""
def __init__(self, hass, name, host, device, close_time):
"""Initialize the cover."""
self.hass = hass
self._name = name
self._host = host
self._device = device
self._client = NeoSmartBlinds(host,device, close_time)
@property
def name(self):
"""Return the name of the NeoSmartBlinds device."""
return self._name
@property
def should_poll(self):
"""No polling needed within NeoSmartBlinds."""
return False
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION | SUPPORT_OPEN_TILT | SUPPORT_CLOSE_TILT | SUPPORT_STOP
@property
def current_cover_position(self):
"""Return the current position of the cover."""
return 100
@property
def device_class(self):
"""Define this cover as either window/blind/awning/shutter."""
return "blind"
@property
def is_closed(self):
"""Return if the cover is closed."""
return None
@property
def current_cover_position(self):
"""Return current position of cover."""
return 50
@property
def current_cover_tilt_position(self):
"""Return current position of cover tilt."""
return 50
def close_cover(self, **kwargs):
self._client.sendCommand('dn')
"""Close the cover."""
def open_cover(self, **kwargs):
self._client.sendCommand('up')
"""Open the cover."""
def stop_cover(self, **kwargs):
self._client.sendCommand('sp')
"""Stop the cover."""
def open_cover_tilt(self, **kwargs):
self._client.sendCommand('mu')
"""Open the cover tilt."""
def close_cover_tilt(self, **kwargs):
self._client.sendCommand('md')
"""Close the cover tilt."""
def set_cover_position(self, **kwargs):
self._client.adjust(kwargs['position'])
"""Move the cover to a specific position."""