-
Notifications
You must be signed in to change notification settings - Fork 171
/
stickup_cam.py
183 lines (169 loc) · 5.96 KB
/
stickup_cam.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# coding: utf-8
# vim:sw=4:ts=4:et:
"""Python Ring Doorbell wrapper."""
import logging
from ring_doorbell.const import (
FLOODLIGHT_CAM_KINDS,
FLOODLIGHT_CAM_PLUS_KINDS,
FLOODLIGHT_CAM_PRO_KINDS,
HEALTH_DOORBELL_ENDPOINT,
INDOOR_CAM_GEN2_KINDS,
INDOOR_CAM_KINDS,
LIGHTS_ENDPOINT,
MSG_ALLOWED_VALUES,
MSG_VOL_OUTBOUND,
SIREN_DURATION_MAX,
SIREN_DURATION_MIN,
SIREN_ENDPOINT,
SPOTLIGHT_CAM_BATTERY_KINDS,
SPOTLIGHT_CAM_PLUS_KINDS,
SPOTLIGHT_CAM_PRO_KINDS,
SPOTLIGHT_CAM_WIRED_KINDS,
STICKUP_CAM_BATTERY_KINDS,
STICKUP_CAM_ELITE_KINDS,
STICKUP_CAM_GEN3_KINDS,
STICKUP_CAM_KINDS,
)
from ring_doorbell.doorbot import RingDoorBell
_LOGGER = logging.getLogger(__name__)
class RingStickUpCam(RingDoorBell):
"""Implementation for RingStickUpCam."""
@property
def family(self):
"""Return Ring device family type."""
return "stickup_cams"
def update_health_data(self):
"""Update health attrs."""
self._health_attrs = (
self._ring.query(HEALTH_DOORBELL_ENDPOINT.format(self.device_api_id))
.json()
.get("device_health", {})
)
@property
def model(self):
"""Return Ring device model name."""
if self.kind in FLOODLIGHT_CAM_KINDS:
return "Floodlight Cam"
if self.kind in FLOODLIGHT_CAM_PRO_KINDS:
return "Floodlight Cam Pro"
if self.kind in FLOODLIGHT_CAM_PLUS_KINDS:
return "Floodlight Cam Plus"
if self.kind in INDOOR_CAM_KINDS:
return "Indoor Cam"
if self.kind in INDOOR_CAM_GEN2_KINDS:
return "Indoor Cam (2nd Gen)"
if self.kind in SPOTLIGHT_CAM_BATTERY_KINDS:
return "Spotlight Cam {}".format(
self._attrs.get("ring_cam_setup_flow", "battery").title()
)
if self.kind in SPOTLIGHT_CAM_WIRED_KINDS:
return "Spotlight Cam {}".format(
self._attrs.get("ring_cam_setup_flow", "wired").title()
)
if self.kind in SPOTLIGHT_CAM_PLUS_KINDS:
return "Spotlight Cam Plus"
if self.kind in SPOTLIGHT_CAM_PRO_KINDS:
return "Spotlight Cam Pro"
if self.kind in STICKUP_CAM_KINDS:
return "Stick Up Cam"
if self.kind in STICKUP_CAM_BATTERY_KINDS:
return "Stick Up Cam Battery"
if self.kind in STICKUP_CAM_ELITE_KINDS:
return "Stick Up Cam Wired"
if self.kind in STICKUP_CAM_GEN3_KINDS:
return "Stick Up Cam (3rd Gen)"
_LOGGER.error("Unknown kind: %s", self.kind)
return None
def has_capability(self, capability):
"""Return if device has specific capability."""
if capability == "battery":
return self.kind in (
SPOTLIGHT_CAM_BATTERY_KINDS
+ STICKUP_CAM_KINDS
+ STICKUP_CAM_BATTERY_KINDS
+ STICKUP_CAM_GEN3_KINDS
)
if capability == "light":
return self.kind in (
FLOODLIGHT_CAM_KINDS
+ FLOODLIGHT_CAM_PRO_KINDS
+ FLOODLIGHT_CAM_PLUS_KINDS
+ SPOTLIGHT_CAM_BATTERY_KINDS
+ SPOTLIGHT_CAM_WIRED_KINDS
+ SPOTLIGHT_CAM_PLUS_KINDS
+ SPOTLIGHT_CAM_PRO_KINDS
)
if capability == "siren":
return self.kind in (
FLOODLIGHT_CAM_KINDS
+ FLOODLIGHT_CAM_PRO_KINDS
+ FLOODLIGHT_CAM_PLUS_KINDS
+ INDOOR_CAM_KINDS
+ INDOOR_CAM_GEN2_KINDS
+ SPOTLIGHT_CAM_BATTERY_KINDS
+ SPOTLIGHT_CAM_WIRED_KINDS
+ SPOTLIGHT_CAM_PLUS_KINDS
+ SPOTLIGHT_CAM_PRO_KINDS
+ STICKUP_CAM_BATTERY_KINDS
+ STICKUP_CAM_ELITE_KINDS
+ STICKUP_CAM_GEN3_KINDS
)
if capability in ("motion_detection", "video"):
return self.kind in (
FLOODLIGHT_CAM_KINDS
+ FLOODLIGHT_CAM_PRO_KINDS
+ FLOODLIGHT_CAM_PLUS_KINDS
+ INDOOR_CAM_KINDS
+ INDOOR_CAM_GEN2_KINDS
+ SPOTLIGHT_CAM_BATTERY_KINDS
+ SPOTLIGHT_CAM_WIRED_KINDS
+ SPOTLIGHT_CAM_PLUS_KINDS
+ SPOTLIGHT_CAM_PRO_KINDS
+ STICKUP_CAM_KINDS
+ STICKUP_CAM_BATTERY_KINDS
+ STICKUP_CAM_ELITE_KINDS
+ STICKUP_CAM_GEN3_KINDS
)
return False
@property
def lights(self):
"""Return lights status."""
return self._attrs.get("led_status")
@lights.setter
def lights(self, state):
"""Control the lights."""
values = ["on", "off"]
if state not in values:
_LOGGER.error("%s", MSG_ALLOWED_VALUES.format(", ".join(values)))
return False
url = LIGHTS_ENDPOINT.format(self.device_api_id, state)
self._ring.query(url, method="PUT")
self._ring.update_devices()
return True
@property
def siren(self):
"""Return siren status."""
if self._attrs.get("siren_status"):
return self._attrs.get("siren_status").get("seconds_remaining")
return None
@siren.setter
def siren(self, duration):
"""Control the siren."""
if not (
(isinstance(duration, int))
and (SIREN_DURATION_MIN <= duration <= SIREN_DURATION_MAX)
):
_LOGGER.error(
"%s", MSG_VOL_OUTBOUND.format(SIREN_DURATION_MIN, SIREN_DURATION_MAX)
)
return False
if duration > 0:
state = "on"
params = {"duration": duration}
else:
state = "off"
params = {}
url = SIREN_ENDPOINT.format(self.device_api_id, state)
self._ring.query(url, extra_params=params, method="PUT")
self._ring.update_devices()
return True