devialet 1.4.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- devialet/__init__.py +2 -0
- devialet/const.py +60 -0
- devialet/devialet_api.py +501 -0
- devialet-1.4.4.dist-info/LICENSE +21 -0
- devialet-1.4.4.dist-info/METADATA +24 -0
- devialet-1.4.4.dist-info/RECORD +8 -0
- devialet-1.4.4.dist-info/WHEEL +5 -0
- devialet-1.4.4.dist-info/top_level.txt +1 -0
devialet/__init__.py
ADDED
devialet/const.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Constants for the Devialet integration."""
|
|
2
|
+
import logging
|
|
3
|
+
from enum import Enum
|
|
4
|
+
|
|
5
|
+
LOGGER = logging.getLogger(__package__)
|
|
6
|
+
|
|
7
|
+
NORMAL_INPUTS = {
|
|
8
|
+
"Airplay": "airplay2",
|
|
9
|
+
"Bluetooth": "bluetooth",
|
|
10
|
+
"Digital left": "digital_left", #Arch only
|
|
11
|
+
"Digital right": "digital_right", #Arch only
|
|
12
|
+
"Line": "line", #Arch only
|
|
13
|
+
"Online": "upnp",
|
|
14
|
+
"Optical": "optical", #Phantom I, Dialog (Mono)
|
|
15
|
+
"Optical left": "optical_left", #Phantom I (Stereo)
|
|
16
|
+
"Optical right": "optical_right", #Phantom I (Stereo)
|
|
17
|
+
"Optical jack": "opticaljack", #Phantom II (Mono)
|
|
18
|
+
"Optical jack left": "opticaljack_left", #Phantom II (Stereo)
|
|
19
|
+
"Optical jack right": "opticaljack_right", #Phantom II (Stereo)
|
|
20
|
+
"Phono": "phono", #Arch only
|
|
21
|
+
"Raat": "raat",
|
|
22
|
+
"Spotify Connect": "spotifyconnect",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
SPEAKER_POSITIONS = {
|
|
26
|
+
"FrontLeft": "left",
|
|
27
|
+
"FrontRight": "right",
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class UrlSuffix(Enum):
|
|
32
|
+
GET_GENERAL_INFO = "/ipcontrol/v1/devices/current"
|
|
33
|
+
GET_SOURCES = "/ipcontrol/v1/groups/current/sources"
|
|
34
|
+
GET_CURRENT_SOURCE = "/ipcontrol/v1/groups/current/sources/current"
|
|
35
|
+
GET_VOLUME = "/ipcontrol/v1/systems/current/sources/current/soundControl/volume"
|
|
36
|
+
GET_NIGHT_MODE = "/ipcontrol/v1/systems/current/settings/audio/nightMode"
|
|
37
|
+
GET_EQUALIZER = "/ipcontrol/v1/systems/current/settings/audio/equalizer"
|
|
38
|
+
GET_CURRENT_POSITION = (
|
|
39
|
+
"/ipcontrol/v1/groups/current/sources/current/playback/position"
|
|
40
|
+
)
|
|
41
|
+
SEEK = "/ipcontrol/v1/systems/current/sources/current/playback/position"
|
|
42
|
+
PLAY = "/ipcontrol/v1/systems/current/sources/current/playback/play"
|
|
43
|
+
PAUSE = "/ipcontrol/v1/systems/current/sources/current/playback/pause"
|
|
44
|
+
STOP = "/ipcontrol/v1/systems/current/sources/current/playback/pause"
|
|
45
|
+
PREVIOUS_TRACK = "/ipcontrol/v1/systems/current/sources/current/playback/previous"
|
|
46
|
+
NEXT_TRACK = "/ipcontrol/v1/systems/current/sources/current/playback/next"
|
|
47
|
+
TURN_OFF = "/ipcontrol/v1/systems/current/powerOff"
|
|
48
|
+
VOLUME_UP = "/ipcontrol/v1/systems/current/sources/current/soundControl/volumeUp"
|
|
49
|
+
VOLUME_DOWN = (
|
|
50
|
+
"/ipcontrol/v1/systems/current/sources/current/soundControl/volumeDown"
|
|
51
|
+
)
|
|
52
|
+
VOLUME_SET = "/ipcontrol/v1/systems/current/sources/current/soundControl/volume"
|
|
53
|
+
MUTE = "/ipcontrol/v1/groups/current/sources/current/playback/mute"
|
|
54
|
+
UNMUTE = "/ipcontrol/v1/groups/current/sources/current/playback/unmute"
|
|
55
|
+
EQUALIZER = "/ipcontrol/v1/systems/current/settings/audio/equalizer"
|
|
56
|
+
NIGHT_MODE = "/ipcontrol/v1/systems/current/settings/audio/nightMode"
|
|
57
|
+
SELECT_SOURCE = "/ipcontrol/v1/groups/current/sources/%SOURCE_ID%/playback/play"
|
|
58
|
+
|
|
59
|
+
def __str__(self):
|
|
60
|
+
return str(self.value)
|
devialet/devialet_api.py
ADDED
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
"""Support for Devialet Phantom speakers."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import asyncio
|
|
5
|
+
import datetime
|
|
6
|
+
import json
|
|
7
|
+
|
|
8
|
+
import aiohttp
|
|
9
|
+
|
|
10
|
+
from .const import LOGGER, NORMAL_INPUTS, SPEAKER_POSITIONS, UrlSuffix
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class DevialetApi:
|
|
14
|
+
"""Devialet API class."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, host, session):
|
|
17
|
+
"""Initialize the Devialet API."""
|
|
18
|
+
|
|
19
|
+
self._host = host
|
|
20
|
+
self._session = session
|
|
21
|
+
|
|
22
|
+
self._general_info = None
|
|
23
|
+
self._volume = None
|
|
24
|
+
self._muted = False
|
|
25
|
+
self._source_state = None
|
|
26
|
+
self._current_position = 0
|
|
27
|
+
self._sources = None
|
|
28
|
+
self._night_mode = None
|
|
29
|
+
self._equalizer = None
|
|
30
|
+
self._source_list = {}
|
|
31
|
+
self._position_updated_at = 0
|
|
32
|
+
self._media_duration = 0
|
|
33
|
+
self._device_role = ""
|
|
34
|
+
self._is_available = False
|
|
35
|
+
|
|
36
|
+
async def async_update(self) -> bool | None:
|
|
37
|
+
"""Get the latest details from the device."""
|
|
38
|
+
if self._general_info is None:
|
|
39
|
+
self._general_info = await self.get_request(UrlSuffix.GET_GENERAL_INFO)
|
|
40
|
+
|
|
41
|
+
# Without general info the device has not been online yet
|
|
42
|
+
if self._general_info is None:
|
|
43
|
+
return False
|
|
44
|
+
|
|
45
|
+
self._source_state = await self.get_request(UrlSuffix.GET_CURRENT_SOURCE)
|
|
46
|
+
# the source state call if enough to find out if the device is available (On or Off)
|
|
47
|
+
if not self._is_available:
|
|
48
|
+
return True
|
|
49
|
+
|
|
50
|
+
if self._sources is None:
|
|
51
|
+
self._sources = await self.get_request(UrlSuffix.GET_SOURCES)
|
|
52
|
+
|
|
53
|
+
self._volume = await self.get_request(UrlSuffix.GET_VOLUME)
|
|
54
|
+
self._night_mode = await self.get_request(UrlSuffix.GET_NIGHT_MODE)
|
|
55
|
+
self._equalizer = await self.get_request(UrlSuffix.GET_EQUALIZER)
|
|
56
|
+
|
|
57
|
+
try:
|
|
58
|
+
self._media_duration = self._source_state["metadata"]["duration"]
|
|
59
|
+
except (KeyError, TypeError):
|
|
60
|
+
self._media_duration = None
|
|
61
|
+
self._current_position = None
|
|
62
|
+
self._position_updated_at = None
|
|
63
|
+
|
|
64
|
+
if self._media_duration == 0:
|
|
65
|
+
self._media_duration = None
|
|
66
|
+
|
|
67
|
+
if self._media_duration is not None:
|
|
68
|
+
position = await self.get_request(UrlSuffix.GET_CURRENT_POSITION)
|
|
69
|
+
try:
|
|
70
|
+
self._current_position = position["position"]
|
|
71
|
+
self._position_updated_at = datetime.datetime.utcnow()
|
|
72
|
+
except (KeyError, TypeError):
|
|
73
|
+
self._current_position = None
|
|
74
|
+
self._position_updated_at = None
|
|
75
|
+
|
|
76
|
+
return True
|
|
77
|
+
|
|
78
|
+
@property
|
|
79
|
+
def is_available(self) -> bool | None:
|
|
80
|
+
"""Return available."""
|
|
81
|
+
return self._is_available
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
def device_id(self) -> str | None:
|
|
85
|
+
"""Return the device id."""
|
|
86
|
+
try:
|
|
87
|
+
return self._general_info["deviceId"]
|
|
88
|
+
except (KeyError, TypeError):
|
|
89
|
+
return None
|
|
90
|
+
|
|
91
|
+
@property
|
|
92
|
+
def serial(self) -> str | None:
|
|
93
|
+
"""Return the serial."""
|
|
94
|
+
try:
|
|
95
|
+
return self._general_info["serial"]
|
|
96
|
+
except (KeyError, TypeError):
|
|
97
|
+
return None
|
|
98
|
+
|
|
99
|
+
@property
|
|
100
|
+
def device_name(self) -> str | None:
|
|
101
|
+
"""Return the device name."""
|
|
102
|
+
try:
|
|
103
|
+
return self._general_info["deviceName"]
|
|
104
|
+
except (KeyError, TypeError):
|
|
105
|
+
return None
|
|
106
|
+
|
|
107
|
+
@property
|
|
108
|
+
def device_role(self) -> str | None:
|
|
109
|
+
"""Return the device role."""
|
|
110
|
+
try:
|
|
111
|
+
return self._general_info["role"]
|
|
112
|
+
except (KeyError, TypeError):
|
|
113
|
+
return None
|
|
114
|
+
|
|
115
|
+
@property
|
|
116
|
+
def model(self) -> str | None:
|
|
117
|
+
"""Return the device model."""
|
|
118
|
+
try:
|
|
119
|
+
return self._general_info["model"]
|
|
120
|
+
except (KeyError, TypeError):
|
|
121
|
+
return None
|
|
122
|
+
|
|
123
|
+
@property
|
|
124
|
+
def version(self) -> str | None:
|
|
125
|
+
"""Return the device version."""
|
|
126
|
+
try:
|
|
127
|
+
return self._general_info["release"]["version"]
|
|
128
|
+
except (KeyError, TypeError):
|
|
129
|
+
return None
|
|
130
|
+
|
|
131
|
+
@property
|
|
132
|
+
def source_state(self) -> any | None:
|
|
133
|
+
"""Return the source state object."""
|
|
134
|
+
return self._source_state
|
|
135
|
+
|
|
136
|
+
@property
|
|
137
|
+
def playing_state(self) -> str | None:
|
|
138
|
+
"""Return the state of the device."""
|
|
139
|
+
try:
|
|
140
|
+
return self._source_state["playingState"]
|
|
141
|
+
except (KeyError, TypeError):
|
|
142
|
+
return None
|
|
143
|
+
|
|
144
|
+
@property
|
|
145
|
+
def volume_level(self) -> float | None:
|
|
146
|
+
"""Volume level of the media player (0..1)."""
|
|
147
|
+
try:
|
|
148
|
+
return self._volume["volume"] * 0.01
|
|
149
|
+
except (KeyError, TypeError):
|
|
150
|
+
return None
|
|
151
|
+
|
|
152
|
+
@property
|
|
153
|
+
def is_volume_muted(self) -> bool | None:
|
|
154
|
+
"""Return boolean if volume is currently muted."""
|
|
155
|
+
try:
|
|
156
|
+
return self._source_state["muteState"] == "muted"
|
|
157
|
+
except (KeyError, TypeError):
|
|
158
|
+
return None
|
|
159
|
+
|
|
160
|
+
@property
|
|
161
|
+
def source_list(self) -> list | None:
|
|
162
|
+
"""Return the list of available input sources."""
|
|
163
|
+
|
|
164
|
+
if self._sources is None or len(self._source_list) > 0:
|
|
165
|
+
return sorted(self._source_list)
|
|
166
|
+
|
|
167
|
+
for source in self._sources["sources"]:
|
|
168
|
+
source_type = source["type"]
|
|
169
|
+
device_id = source["deviceId"]
|
|
170
|
+
|
|
171
|
+
if self.device_role in SPEAKER_POSITIONS and (
|
|
172
|
+
source_type == "optical" or source_type == "opticaljack"
|
|
173
|
+
):
|
|
174
|
+
# Stereo devices have the role FrontLeft or FrontRight.
|
|
175
|
+
# Add a suffix to the source to recognize the device.
|
|
176
|
+
for role, position in SPEAKER_POSITIONS.items():
|
|
177
|
+
if (device_id == self.device_id and role == self.device_role) or (
|
|
178
|
+
device_id != self.device_id and role != self.device_role
|
|
179
|
+
):
|
|
180
|
+
source_type = source_type + "_" + position
|
|
181
|
+
|
|
182
|
+
for pretty_name, name in NORMAL_INPUTS.items():
|
|
183
|
+
if name == source_type:
|
|
184
|
+
self._source_list[pretty_name] = name
|
|
185
|
+
|
|
186
|
+
return sorted(self._source_list)
|
|
187
|
+
|
|
188
|
+
@property
|
|
189
|
+
def available_options(self) -> any | None:
|
|
190
|
+
"""Return the list of available options for this source."""
|
|
191
|
+
try:
|
|
192
|
+
return self._source_state["availableOptions"]
|
|
193
|
+
except (KeyError, TypeError):
|
|
194
|
+
return None
|
|
195
|
+
|
|
196
|
+
@property
|
|
197
|
+
def media_artist(self) -> str | None:
|
|
198
|
+
"""Artist of current playing media, music track only."""
|
|
199
|
+
try:
|
|
200
|
+
return self._source_state["metadata"]["artist"]
|
|
201
|
+
except (KeyError, TypeError):
|
|
202
|
+
return None
|
|
203
|
+
|
|
204
|
+
@property
|
|
205
|
+
def media_album_name(self) -> str | None:
|
|
206
|
+
"""Album name of current playing media, music track only."""
|
|
207
|
+
try:
|
|
208
|
+
return self._source_state["metadata"]["album"]
|
|
209
|
+
except (KeyError, TypeError):
|
|
210
|
+
return None
|
|
211
|
+
|
|
212
|
+
@property
|
|
213
|
+
def media_title(self) -> str | None:
|
|
214
|
+
"""Return the current media info."""
|
|
215
|
+
try:
|
|
216
|
+
return self._source_state["metadata"]["title"]
|
|
217
|
+
except (KeyError, TypeError):
|
|
218
|
+
return None
|
|
219
|
+
|
|
220
|
+
@property
|
|
221
|
+
def media_image_url(self) -> str | None:
|
|
222
|
+
"""Image url of current playing media, not available for Airplay."""
|
|
223
|
+
try:
|
|
224
|
+
return self._source_state["metadata"]["coverArtUrl"]
|
|
225
|
+
except (KeyError, TypeError):
|
|
226
|
+
return None
|
|
227
|
+
|
|
228
|
+
@property
|
|
229
|
+
def media_duration(self) -> int | None:
|
|
230
|
+
"""Duration of current playing media in seconds."""
|
|
231
|
+
return self._media_duration
|
|
232
|
+
|
|
233
|
+
@property
|
|
234
|
+
def current_position(self) -> int | None:
|
|
235
|
+
"""Position of current playing media in seconds."""
|
|
236
|
+
return self._current_position
|
|
237
|
+
|
|
238
|
+
@property
|
|
239
|
+
def position_updated_at(self) -> datetime.datetime | None:
|
|
240
|
+
"""When was the position of the current playing media valid."""
|
|
241
|
+
return self._position_updated_at
|
|
242
|
+
|
|
243
|
+
@property
|
|
244
|
+
def supported_features(self) -> any | None:
|
|
245
|
+
"""Flag media player features that are supported."""
|
|
246
|
+
try:
|
|
247
|
+
return self._source_state["availableOptions"]
|
|
248
|
+
except (KeyError, TypeError):
|
|
249
|
+
return None
|
|
250
|
+
|
|
251
|
+
@property
|
|
252
|
+
def source(self) -> str | None:
|
|
253
|
+
"""Return the current input source."""
|
|
254
|
+
try:
|
|
255
|
+
source_id = self._source_state["source"]["sourceId"]
|
|
256
|
+
device_id = self._source_state["source"]["deviceId"]
|
|
257
|
+
|
|
258
|
+
# Devialet Arch has a different source description.
|
|
259
|
+
for source in self._sources["sources"]:
|
|
260
|
+
if source["sourceId"] == source_id and source["deviceId"] == device_id:
|
|
261
|
+
source_type = source["type"]
|
|
262
|
+
|
|
263
|
+
if (
|
|
264
|
+
source_type == "optical" or source_type == "opticaljack"
|
|
265
|
+
) and self.device_role in SPEAKER_POSITIONS:
|
|
266
|
+
for role, position in SPEAKER_POSITIONS.items():
|
|
267
|
+
if (device_id == self.device_id and role == self.device_role) or (
|
|
268
|
+
device_id != self.device_id and role != self.device_role
|
|
269
|
+
):
|
|
270
|
+
source_type = source_type + "_" + position
|
|
271
|
+
|
|
272
|
+
break
|
|
273
|
+
except (KeyError, TypeError):
|
|
274
|
+
return None
|
|
275
|
+
|
|
276
|
+
return source_type
|
|
277
|
+
|
|
278
|
+
@property
|
|
279
|
+
def night_mode(self) -> bool | None:
|
|
280
|
+
"""Return the current nightmode state."""
|
|
281
|
+
try:
|
|
282
|
+
return self._night_mode["nightMode"] == "on"
|
|
283
|
+
except (KeyError, TypeError):
|
|
284
|
+
return None
|
|
285
|
+
|
|
286
|
+
@property
|
|
287
|
+
def equalizer(self) -> str | None:
|
|
288
|
+
"""Return the current equalizer preset."""
|
|
289
|
+
try:
|
|
290
|
+
if self._equalizer["enabled"]:
|
|
291
|
+
return self._equalizer["preset"]
|
|
292
|
+
except (KeyError, TypeError):
|
|
293
|
+
return None
|
|
294
|
+
|
|
295
|
+
async def async_get_diagnostics(self) -> any | None:
|
|
296
|
+
"""Return the diagnostic data."""
|
|
297
|
+
return {
|
|
298
|
+
"is_available": self._is_available,
|
|
299
|
+
"general_info": self._general_info,
|
|
300
|
+
"sources": self._sources,
|
|
301
|
+
"source_state": self._source_state,
|
|
302
|
+
"volume": self._volume,
|
|
303
|
+
"night_mode": self._night_mode,
|
|
304
|
+
"equalizer": self._equalizer,
|
|
305
|
+
"source_list": self.source_list,
|
|
306
|
+
"source": self.source,
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
async def async_volume_up(self) -> None:
|
|
310
|
+
"""Volume up media player."""
|
|
311
|
+
await self.post_request(UrlSuffix.VOLUME_UP, {})
|
|
312
|
+
|
|
313
|
+
async def async_volume_down(self) -> None:
|
|
314
|
+
"""Volume down media player."""
|
|
315
|
+
await self.post_request(UrlSuffix.VOLUME_DOWN, {})
|
|
316
|
+
|
|
317
|
+
async def async_set_volume_level(self, volume: float) -> None:
|
|
318
|
+
"""Set volume level, range 0..1."""
|
|
319
|
+
await self.post_request(
|
|
320
|
+
UrlSuffix.VOLUME_SET,
|
|
321
|
+
{"volume": volume * 100},
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
async def async_mute_volume(self, mute: bool) -> None:
|
|
325
|
+
"""Mute (true) or unmute (false) media player."""
|
|
326
|
+
if mute:
|
|
327
|
+
await self.post_request(UrlSuffix.MUTE, {})
|
|
328
|
+
else:
|
|
329
|
+
await self.post_request(UrlSuffix.UNMUTE, {})
|
|
330
|
+
|
|
331
|
+
async def async_media_play(self) -> None:
|
|
332
|
+
"""Play media player."""
|
|
333
|
+
await self.post_request(UrlSuffix.PLAY, {})
|
|
334
|
+
|
|
335
|
+
async def async_media_pause(self) -> None:
|
|
336
|
+
"""Pause media player."""
|
|
337
|
+
await self.post_request(UrlSuffix.PAUSE, {})
|
|
338
|
+
|
|
339
|
+
async def async_media_stop(self) -> None:
|
|
340
|
+
"""Pause media player."""
|
|
341
|
+
await self.post_request(UrlSuffix.PAUSE, {})
|
|
342
|
+
|
|
343
|
+
async def async_media_next_track(self) -> None:
|
|
344
|
+
"""Send the next track command."""
|
|
345
|
+
await self.post_request(UrlSuffix.NEXT_TRACK, {})
|
|
346
|
+
|
|
347
|
+
async def async_media_previous_track(self) -> None:
|
|
348
|
+
"""Send the previous track command."""
|
|
349
|
+
await self.post_request(UrlSuffix.PREVIOUS_TRACK, {})
|
|
350
|
+
|
|
351
|
+
async def async_media_seek(self, position: float) -> None:
|
|
352
|
+
"""Send seek command."""
|
|
353
|
+
|
|
354
|
+
await self.post_request(
|
|
355
|
+
UrlSuffix.SEEK,
|
|
356
|
+
{"position": int(position)},
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
async def async_set_night_mode(self, night_mode: bool) -> None:
|
|
360
|
+
"""Set the night mode."""
|
|
361
|
+
if night_mode:
|
|
362
|
+
mode = "on"
|
|
363
|
+
else:
|
|
364
|
+
mode = "off"
|
|
365
|
+
|
|
366
|
+
await self.post_request(
|
|
367
|
+
UrlSuffix.NIGHT_MODE,
|
|
368
|
+
{"nightMode": mode},
|
|
369
|
+
)
|
|
370
|
+
|
|
371
|
+
async def async_set_equalizer(self, preset: str) -> None:
|
|
372
|
+
"""Set the equalizer preset."""
|
|
373
|
+
|
|
374
|
+
await self.post_request(
|
|
375
|
+
UrlSuffix.EQUALIZER,
|
|
376
|
+
{"preset": preset},
|
|
377
|
+
)
|
|
378
|
+
|
|
379
|
+
async def async_turn_off(self) -> None:
|
|
380
|
+
"""Turn off media player."""
|
|
381
|
+
await self.post_request(UrlSuffix.TURN_OFF, {})
|
|
382
|
+
|
|
383
|
+
async def async_select_source(self, source: str) -> None:
|
|
384
|
+
"""Select input source."""
|
|
385
|
+
source_id = None
|
|
386
|
+
|
|
387
|
+
try:
|
|
388
|
+
name = NORMAL_INPUTS[source]
|
|
389
|
+
except KeyError:
|
|
390
|
+
LOGGER.error("Unknown source %s selected", source)
|
|
391
|
+
return
|
|
392
|
+
|
|
393
|
+
if "_" in name:
|
|
394
|
+
name_split = name.split("_")
|
|
395
|
+
|
|
396
|
+
for role, position in SPEAKER_POSITIONS.items():
|
|
397
|
+
if position == name_split[1]:
|
|
398
|
+
if role == self.device_role:
|
|
399
|
+
for _source in self._sources["sources"]:
|
|
400
|
+
if (
|
|
401
|
+
_source["deviceId"] == self.device_id
|
|
402
|
+
and _source["type"] == name_split[0]
|
|
403
|
+
):
|
|
404
|
+
source_id = _source["sourceId"]
|
|
405
|
+
break
|
|
406
|
+
else:
|
|
407
|
+
for _source in self._sources["sources"]:
|
|
408
|
+
if (
|
|
409
|
+
_source["deviceId"] != self.device_id
|
|
410
|
+
and _source["type"] == name_split[0]
|
|
411
|
+
):
|
|
412
|
+
source_id = _source["sourceId"]
|
|
413
|
+
break
|
|
414
|
+
break
|
|
415
|
+
else:
|
|
416
|
+
for _source in self._sources["sources"]:
|
|
417
|
+
if _source["type"] == name:
|
|
418
|
+
source_id = _source["sourceId"]
|
|
419
|
+
|
|
420
|
+
if source_id is None:
|
|
421
|
+
LOGGER.error("Source %s is not available", source)
|
|
422
|
+
return
|
|
423
|
+
|
|
424
|
+
await self.post_request(
|
|
425
|
+
str(UrlSuffix.SELECT_SOURCE).replace("%SOURCE_ID%", source_id), {}
|
|
426
|
+
)
|
|
427
|
+
|
|
428
|
+
async def get_request(self, suffix=str) -> any | None:
|
|
429
|
+
"""Generic GET method."""
|
|
430
|
+
|
|
431
|
+
url = "http://" + self._host + str(suffix)
|
|
432
|
+
|
|
433
|
+
try:
|
|
434
|
+
async with self._session.get(
|
|
435
|
+
url=url, allow_redirects=False, timeout=2
|
|
436
|
+
) as response:
|
|
437
|
+
response = await response.read()
|
|
438
|
+
LOGGER.debug(
|
|
439
|
+
"Host %s: HTTP Response data: %s",
|
|
440
|
+
self._host,
|
|
441
|
+
response,
|
|
442
|
+
)
|
|
443
|
+
|
|
444
|
+
response_json = json.loads(response)
|
|
445
|
+
self._is_available = True
|
|
446
|
+
|
|
447
|
+
if "error" in response_json:
|
|
448
|
+
LOGGER.debug(response_json["error"])
|
|
449
|
+
return None
|
|
450
|
+
|
|
451
|
+
return response_json
|
|
452
|
+
|
|
453
|
+
except aiohttp.ClientConnectorError as conn_err:
|
|
454
|
+
LOGGER.debug("Host %s: Connection error %s", self._host, str(conn_err))
|
|
455
|
+
self._is_available = False
|
|
456
|
+
return None
|
|
457
|
+
except asyncio.TimeoutError:
|
|
458
|
+
self._is_available = False
|
|
459
|
+
LOGGER.debug(
|
|
460
|
+
"Devialet connection timeout exception. Please check the connection"
|
|
461
|
+
)
|
|
462
|
+
return None
|
|
463
|
+
except (TypeError, json.JSONDecodeError):
|
|
464
|
+
LOGGER.debug("Devialet: JSON error")
|
|
465
|
+
return None
|
|
466
|
+
except Exception: # pylint: disable=bare-except
|
|
467
|
+
LOGGER.debug("Devialet: unknown exception occurred")
|
|
468
|
+
return None
|
|
469
|
+
|
|
470
|
+
async def post_request(self, suffix=str, body=str) -> any | None:
|
|
471
|
+
"""Generic POST method."""
|
|
472
|
+
|
|
473
|
+
url = "http://" + self._host + str(suffix)
|
|
474
|
+
|
|
475
|
+
try:
|
|
476
|
+
async with self._session.post(
|
|
477
|
+
url=url, json=body, allow_redirects=False, timeout=2
|
|
478
|
+
) as response:
|
|
479
|
+
response = await response.read()
|
|
480
|
+
LOGGER.debug(
|
|
481
|
+
"Host %s: HTTP Response data: %s",
|
|
482
|
+
self._host,
|
|
483
|
+
response,
|
|
484
|
+
)
|
|
485
|
+
|
|
486
|
+
return True
|
|
487
|
+
|
|
488
|
+
except aiohttp.ClientConnectorError as conn_err:
|
|
489
|
+
LOGGER.debug("Host %s: Connection error %s", self._host, str(conn_err))
|
|
490
|
+
return False
|
|
491
|
+
except asyncio.TimeoutError:
|
|
492
|
+
LOGGER.debug(
|
|
493
|
+
"Devialet connection timeout exception. Please check the connection"
|
|
494
|
+
)
|
|
495
|
+
return False
|
|
496
|
+
except (TypeError, json.JSONDecodeError):
|
|
497
|
+
LOGGER.debug("Devialet: JSON error")
|
|
498
|
+
return False
|
|
499
|
+
except Exception: # pylint: disable=bare-except
|
|
500
|
+
LOGGER.debug("Devialet: unknown exception occurred")
|
|
501
|
+
return False
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 fwestenberg
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: devialet
|
|
3
|
+
Version: 1.4.4
|
|
4
|
+
Summary: Devialet API
|
|
5
|
+
Home-page: https://github.com/fwestenberg/devialet
|
|
6
|
+
Download-URL: https://github.com/fwestenberg/devialet/releases/latest
|
|
7
|
+
Author: fwestenberg
|
|
8
|
+
Author-email:
|
|
9
|
+
License: MIT
|
|
10
|
+
Keywords: Reolink,Home-Assistant
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: aiohttp
|
|
23
|
+
|
|
24
|
+
Devialet API
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
devialet/__init__.py,sha256=Ok4v1T96nPkYBM8IGVo9OMtLV25SbYYaNt4YR_h42GY,79
|
|
2
|
+
devialet/const.py,sha256=vQ_baKkjIiOUX6mWf0sll8um-X2vB9mQnoQuRLk6_c4,2666
|
|
3
|
+
devialet/devialet_api.py,sha256=0DcMOPunlcmDw5JJ0lh0gqdXbGRjZ1jYaUkVb_8URDg,16876
|
|
4
|
+
devialet-1.4.4.dist-info/LICENSE,sha256=GiaPSPqphDHCOMuTSyrHZdv-AGEJuSrhzu2cFMNCQVE,1068
|
|
5
|
+
devialet-1.4.4.dist-info/METADATA,sha256=P6g1LUz6AXarTudxWOpmKCvtN2EHosl2GsfogrImUT0,818
|
|
6
|
+
devialet-1.4.4.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
7
|
+
devialet-1.4.4.dist-info/top_level.txt,sha256=Mv2jSu_LoH4qRVM75aZFNdbhV5OBzQJjFd-UQ3UqtZ8,9
|
|
8
|
+
devialet-1.4.4.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
devialet
|