lghorizon 0.7.3b1__py3-none-any.whl → 0.7.3b3__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.
- lghorizon/__init__.py +5 -1
- lghorizon/exceptions.py +10 -4
- lghorizon/lghorizon_api.py +32 -14
- {lghorizon-0.7.3b1.dist-info → lghorizon-0.7.3b3.dist-info}/METADATA +1 -1
- lghorizon-0.7.3b3.dist-info/RECORD +12 -0
- lghorizon-0.7.3b1.dist-info/RECORD +0 -12
- {lghorizon-0.7.3b1.dist-info → lghorizon-0.7.3b3.dist-info}/LICENSE +0 -0
- {lghorizon-0.7.3b1.dist-info → lghorizon-0.7.3b3.dist-info}/WHEEL +0 -0
- {lghorizon-0.7.3b1.dist-info → lghorizon-0.7.3b3.dist-info}/top_level.txt +0 -0
lghorizon/__init__.py
CHANGED
|
@@ -9,7 +9,11 @@ from .models import (
|
|
|
9
9
|
LGHorizonRecordingEpisode,
|
|
10
10
|
LGHorizonCustomer,
|
|
11
11
|
)
|
|
12
|
-
from .exceptions import
|
|
12
|
+
from .exceptions import (
|
|
13
|
+
LGHorizonApiUnauthorizedError,
|
|
14
|
+
LGHorizonApiConnectionError,
|
|
15
|
+
LGHorizonApiLockedError,
|
|
16
|
+
)
|
|
13
17
|
from .const import (
|
|
14
18
|
ONLINE_RUNNING,
|
|
15
19
|
ONLINE_STANDBY,
|
lghorizon/exceptions.py
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
"""Exceptions for the LGHorizon API."""
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
class LGHorizonApiError(Exception):
|
|
4
|
-
"""Generic
|
|
5
|
+
"""Generic LGHorizon exception."""
|
|
6
|
+
|
|
5
7
|
|
|
6
8
|
class LGHorizonApiConnectionError(LGHorizonApiError):
|
|
7
|
-
"""Generic
|
|
9
|
+
"""Generic LGHorizon exception."""
|
|
10
|
+
|
|
8
11
|
|
|
9
12
|
class LGHorizonApiUnauthorizedError(Exception):
|
|
10
|
-
"""Generic
|
|
11
|
-
|
|
13
|
+
"""Generic LGHorizon exception."""
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class LGHorizonApiLockedError(LGHorizonApiUnauthorizedError):
|
|
17
|
+
"""Generic LGHorizon exception."""
|
lghorizon/lghorizon_api.py
CHANGED
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
import logging
|
|
4
4
|
import json
|
|
5
5
|
import sys, traceback
|
|
6
|
-
from .exceptions import
|
|
6
|
+
from .exceptions import (
|
|
7
|
+
LGHorizonApiUnauthorizedError,
|
|
8
|
+
LGHorizonApiConnectionError,
|
|
9
|
+
LGHorizonApiLockedError,
|
|
10
|
+
)
|
|
7
11
|
import backoff
|
|
8
12
|
from requests import Session, exceptions as request_exceptions
|
|
9
13
|
from paho.mqtt.client import WebsocketConnectionError
|
|
@@ -82,9 +86,6 @@ class LGHorizonApi:
|
|
|
82
86
|
self._identifier = identifier
|
|
83
87
|
self._profile_id = profile_id
|
|
84
88
|
|
|
85
|
-
@backoff.on_exception(
|
|
86
|
-
backoff.expo, LGHorizonApiConnectionError, max_tries=3, logger=_logger
|
|
87
|
-
)
|
|
88
89
|
def _authorize(self) -> None:
|
|
89
90
|
ctry_code = self._country_code[0:2]
|
|
90
91
|
if ctry_code == "be":
|
|
@@ -111,6 +112,8 @@ class LGHorizonApi:
|
|
|
111
112
|
error = error_json["error"]
|
|
112
113
|
if error and error["statusCode"] == 97401:
|
|
113
114
|
raise LGHorizonApiUnauthorizedError("Invalid credentials")
|
|
115
|
+
elif error and error["statusCode"] == 97117:
|
|
116
|
+
raise LGHorizonApiLockedError("Account locked")
|
|
114
117
|
elif error:
|
|
115
118
|
raise LGHorizonApiConnectionError(error["message"])
|
|
116
119
|
else:
|
|
@@ -236,7 +239,14 @@ class LGHorizonApi:
|
|
|
236
239
|
_logger.debug(f"MQTT token: {self._auth.mqttToken}")
|
|
237
240
|
|
|
238
241
|
@backoff.on_exception(
|
|
239
|
-
backoff.expo,
|
|
242
|
+
backoff.expo,
|
|
243
|
+
BaseException,
|
|
244
|
+
jitter=None,
|
|
245
|
+
max_tries=3,
|
|
246
|
+
logger=_logger,
|
|
247
|
+
giveup=lambda e: isinstance(
|
|
248
|
+
e, (LGHorizonApiLockedError, LGHorizonApiUnauthorizedError)
|
|
249
|
+
),
|
|
240
250
|
)
|
|
241
251
|
def connect(self) -> None:
|
|
242
252
|
self._config = self._get_config(self._country_code)
|
|
@@ -256,7 +266,7 @@ class LGHorizonApi:
|
|
|
256
266
|
def disconnect(self):
|
|
257
267
|
"""Disconnect."""
|
|
258
268
|
_logger.debug("Disconnect from API")
|
|
259
|
-
if not self._mqttClient.is_connected:
|
|
269
|
+
if not self._mqttClient or not self._mqttClient.is_connected:
|
|
260
270
|
return
|
|
261
271
|
self._mqttClient.disconnect()
|
|
262
272
|
|
|
@@ -267,7 +277,11 @@ class LGHorizonApi:
|
|
|
267
277
|
box.register_mqtt()
|
|
268
278
|
|
|
269
279
|
def _on_mqtt_message(self, message: str, topic: str) -> None:
|
|
270
|
-
if "
|
|
280
|
+
if "action" in message and message["action"] == "OPS.getProfilesUpdate":
|
|
281
|
+
self._update_customer()
|
|
282
|
+
self._channels.clear()
|
|
283
|
+
self._get_channels()
|
|
284
|
+
elif "source" in message:
|
|
271
285
|
deviceId = message["source"]
|
|
272
286
|
if not isinstance(deviceId, str):
|
|
273
287
|
_logger.debug("ignoring message - not a string")
|
|
@@ -279,6 +293,7 @@ class LGHorizonApi:
|
|
|
279
293
|
self.settop_boxes[deviceId].update_state(message)
|
|
280
294
|
if "status" in message:
|
|
281
295
|
self._handle_box_update(deviceId, message)
|
|
296
|
+
|
|
282
297
|
except Exception:
|
|
283
298
|
_logger.exception("Could not handle status message")
|
|
284
299
|
_logger.warning(f"Full message: {str(message)}")
|
|
@@ -378,14 +393,9 @@ class LGHorizonApi:
|
|
|
378
393
|
return json_response
|
|
379
394
|
|
|
380
395
|
def _register_customer_and_boxes(self):
|
|
381
|
-
|
|
382
|
-
personalisation_result = self._do_api_call(
|
|
383
|
-
f"{self._config['personalizationService']['URL']}/v1/customer/{self._auth.householdId}?with=profiles%2Cdevices"
|
|
384
|
-
)
|
|
385
|
-
_logger.debug("Personalisation result: %s ", personalisation_result)
|
|
386
|
-
self.customer = LGHorizonCustomer(personalisation_result)
|
|
396
|
+
self._update_customer()
|
|
387
397
|
self._get_channels()
|
|
388
|
-
if
|
|
398
|
+
if len(self.customer.settop_boxes) == 0:
|
|
389
399
|
_logger.warning("No boxes found.")
|
|
390
400
|
return
|
|
391
401
|
_logger.info("Registering boxes")
|
|
@@ -406,6 +416,14 @@ class LGHorizonApi:
|
|
|
406
416
|
self.settop_boxes[box.deviceId] = box
|
|
407
417
|
_logger.info("Box %s registered...", box.deviceId)
|
|
408
418
|
|
|
419
|
+
def _update_customer(self):
|
|
420
|
+
_logger.info("Get customer data")
|
|
421
|
+
personalisation_result = self._do_api_call(
|
|
422
|
+
f"{self._config['personalizationService']['URL']}/v1/customer/{self._auth.householdId}?with=profiles%2Cdevices"
|
|
423
|
+
)
|
|
424
|
+
_logger.debug("Personalisation result: %s ", personalisation_result)
|
|
425
|
+
self.customer = LGHorizonCustomer(personalisation_result)
|
|
426
|
+
|
|
409
427
|
def _get_channels(self):
|
|
410
428
|
self._update_entitlements()
|
|
411
429
|
_logger.info("Retrieving channels...")
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
lghorizon/__init__.py,sha256=XqePG0hj8NnudOcfCtEWqPsWP5l2headzrQhkfuDlv8,544
|
|
2
|
+
lghorizon/const.py,sha256=S8UWatG7JPCqd1zk-iOoILTvFDEj7YhLcEXxLGhyJXs,4755
|
|
3
|
+
lghorizon/exceptions.py,sha256=-6v55KDTogBldGAg1wV9Mrxm5L5BsaVguhBgVMOeJHk,404
|
|
4
|
+
lghorizon/helpers.py,sha256=ZWpi7B3hBvwGV02KWQQHVyj7FLLUDtIvKc-Iqsj5VHA,263
|
|
5
|
+
lghorizon/lghorizon_api.py,sha256=9cgTOMY5OI3BDBTPRz-q3AA1LUZ3ri1JFj7S6VgdOcw,21823
|
|
6
|
+
lghorizon/models.py,sha256=lUKUJiebK65l0lfOwAzDvn0fC6UIvvQS6HI6a0ROZ_8,24437
|
|
7
|
+
lghorizon/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
lghorizon-0.7.3b3.dist-info/LICENSE,sha256=6Dh2tur1gMX3r3rITjVwUONBEJxyyPZDY8p6DZXtimE,1059
|
|
9
|
+
lghorizon-0.7.3b3.dist-info/METADATA,sha256=MCqR616SRzYkwOezY9mV3s3lyfFJACi24-Owhio8ByE,1039
|
|
10
|
+
lghorizon-0.7.3b3.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
|
11
|
+
lghorizon-0.7.3b3.dist-info/top_level.txt,sha256=usii76_AxGfPI6gjrrh-NyZxcQQuF1B8_Q9kd7sID8Q,10
|
|
12
|
+
lghorizon-0.7.3b3.dist-info/RECORD,,
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
lghorizon/__init__.py,sha256=Vu9KXNPKpZOqZOk1pXdptYzpXNwM77OjlSJNUOpukKQ,502
|
|
2
|
-
lghorizon/const.py,sha256=S8UWatG7JPCqd1zk-iOoILTvFDEj7YhLcEXxLGhyJXs,4755
|
|
3
|
-
lghorizon/exceptions.py,sha256=spEjRvbNdce2fauQiOFromAbV1QcfA0uMUt0nRVnnkM,318
|
|
4
|
-
lghorizon/helpers.py,sha256=ZWpi7B3hBvwGV02KWQQHVyj7FLLUDtIvKc-Iqsj5VHA,263
|
|
5
|
-
lghorizon/lghorizon_api.py,sha256=WyOVTXxvFHv6wj0niA4WxcUEHgLy_2D5Vi3-I00WRQM,21364
|
|
6
|
-
lghorizon/models.py,sha256=lUKUJiebK65l0lfOwAzDvn0fC6UIvvQS6HI6a0ROZ_8,24437
|
|
7
|
-
lghorizon/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
-
lghorizon-0.7.3b1.dist-info/LICENSE,sha256=6Dh2tur1gMX3r3rITjVwUONBEJxyyPZDY8p6DZXtimE,1059
|
|
9
|
-
lghorizon-0.7.3b1.dist-info/METADATA,sha256=kk5Pb-r7v35saP0gsIqTXIrhaimWoiwCNSKbhohHuVs,1039
|
|
10
|
-
lghorizon-0.7.3b1.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
|
11
|
-
lghorizon-0.7.3b1.dist-info/top_level.txt,sha256=usii76_AxGfPI6gjrrh-NyZxcQQuF1B8_Q9kd7sID8Q,10
|
|
12
|
-
lghorizon-0.7.3b1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|