lghorizon 0.7.2__tar.gz → 0.7.3b1__tar.gz

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.
Files changed (31) hide show
  1. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/PKG-INFO +1 -1
  2. lghorizon-0.7.3b1/lghorizon/__init__.py +19 -0
  3. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/lghorizon/lghorizon_api.py +28 -14
  4. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/lghorizon/models.py +18 -3
  5. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/lghorizon.egg-info/PKG-INFO +1 -1
  6. lghorizon-0.7.3b1/secrets_stub.json +7 -0
  7. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/test.py +6 -1
  8. lghorizon-0.7.2/lghorizon/__init__.py +0 -5
  9. lghorizon-0.7.2/secrets_stub.json +0 -5
  10. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/.coverage +0 -0
  11. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/.flake8 +0 -0
  12. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/.github/workflows/build-on-pr.yml +0 -0
  13. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/.github/workflows/publish-to-pypi.yml +0 -0
  14. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/.gitignore +0 -0
  15. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/LICENSE +0 -0
  16. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/README.md +0 -0
  17. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/instructions.txt +0 -0
  18. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/lghorizon/const.py +0 -0
  19. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/lghorizon/exceptions.py +0 -0
  20. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/lghorizon/helpers.py +0 -0
  21. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/lghorizon/py.typed +0 -0
  22. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/lghorizon.egg-info/SOURCES.txt +0 -0
  23. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/lghorizon.egg-info/dependency_links.txt +0 -0
  24. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/lghorizon.egg-info/not-zip-safe +0 -0
  25. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/lghorizon.egg-info/requires.txt +0 -0
  26. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/lghorizon.egg-info/top_level.txt +0 -0
  27. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/lib64 +0 -0
  28. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/pyvenv.cfg +0 -0
  29. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/renovate.json +0 -0
  30. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/setup.cfg +0 -0
  31. {lghorizon-0.7.2 → lghorizon-0.7.3b1}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lghorizon
3
- Version: 0.7.2
3
+ Version: 0.7.3b1
4
4
  Summary: Python client for Liberty Global Horizon settop boxes
5
5
  Home-page: https://github.com/sholofly/LGHorizon-python
6
6
  Author: Rudolf Offereins
@@ -0,0 +1,19 @@
1
+ """Python client for LG Horizon."""
2
+
3
+ from .lghorizon_api import LGHorizonApi
4
+ from .models import (
5
+ LGHorizonBox,
6
+ LGHorizonRecordingListSeasonShow,
7
+ LGHorizonRecordingSingle,
8
+ LGHorizonRecordingShow,
9
+ LGHorizonRecordingEpisode,
10
+ LGHorizonCustomer,
11
+ )
12
+ from .exceptions import LGHorizonApiUnauthorizedError, LGHorizonApiConnectionError
13
+ from .const import (
14
+ ONLINE_RUNNING,
15
+ ONLINE_STANDBY,
16
+ RECORDING_TYPE_SHOW,
17
+ RECORDING_TYPE_SEASON,
18
+ RECORDING_TYPE_SINGLE,
19
+ ) # noqa
@@ -47,7 +47,7 @@ class LGHorizonApi:
47
47
  _auth: LGHorizonAuth = None
48
48
  _session: Session = None
49
49
  settop_boxes: Dict[str, LGHorizonBox] = None
50
- _customer: LGHorizonCustomer = None
50
+ customer: LGHorizonCustomer = None
51
51
  _mqttClient: LGHorizonMqttClient = None
52
52
  _channels: Dict[str, LGHorizonChannel] = None
53
53
  _country_settings = None
@@ -57,6 +57,7 @@ class LGHorizonApi:
57
57
  _identifier: str = None
58
58
  _config: str = None
59
59
  _refresh_callback: Callable = None
60
+ _profile_id: str = None
60
61
 
61
62
  def __init__(
62
63
  self,
@@ -65,6 +66,7 @@ class LGHorizonApi:
65
66
  country_code: str = "nl",
66
67
  identifier: str = None,
67
68
  refresh_token=None,
69
+ profile_id=None,
68
70
  ) -> None:
69
71
  """Create LGHorizon API."""
70
72
  self.username = username
@@ -78,6 +80,7 @@ class LGHorizonApi:
78
80
  self._channels = {}
79
81
  self._entitlements = []
80
82
  self._identifier = identifier
83
+ self._profile_id = profile_id
81
84
 
82
85
  @backoff.on_exception(
83
86
  backoff.expo, LGHorizonApiConnectionError, max_tries=3, logger=_logger
@@ -149,7 +152,7 @@ class LGHorizonApi:
149
152
  self._session.cookies["ACCESSTOKEN"] = self._auth.accessToken
150
153
 
151
154
  if self._refresh_callback:
152
- self._refresh_callback ()
155
+ self._refresh_callback()
153
156
 
154
157
  _logger.debug("Authorization succeeded")
155
158
 
@@ -246,6 +249,7 @@ class LGHorizonApi:
246
249
  self._on_mqtt_connected,
247
250
  self._on_mqtt_message,
248
251
  )
252
+
249
253
  self._register_customer_and_boxes()
250
254
  self._mqttClient.connect()
251
255
 
@@ -265,7 +269,7 @@ class LGHorizonApi:
265
269
  def _on_mqtt_message(self, message: str, topic: str) -> None:
266
270
  if "source" in message:
267
271
  deviceId = message["source"]
268
- if not isinstance(deviceId,str):
272
+ if not isinstance(deviceId, str):
269
273
  _logger.debug("ignoring message - not a string")
270
274
  return
271
275
  if not deviceId in self.settop_boxes.keys():
@@ -346,7 +350,7 @@ class LGHorizonApi:
346
350
  last_speed_change_time = playerState["lastSpeedChangeTime"]
347
351
  relative_position = playerState["relativePosition"]
348
352
  raw_vod = self._do_api_call(
349
- f"{self._config['vodService']['URL']}/v2/detailscreen/{titleId}?language={self._country_settings['language']}&profileId=4504e28d-c1cb-4284-810b-f5eaab06f034&cityId={self._customer.cityId}"
353
+ f"{self._config['vodService']['URL']}/v2/detailscreen/{titleId}?language={self._country_settings['language']}&profileId=4504e28d-c1cb-4284-810b-f5eaab06f034&cityId={self.customer.cityId}"
350
354
  )
351
355
  vod = LGHorizonVod(raw_vod)
352
356
  self.settop_boxes[deviceId].update_with_vod(
@@ -378,36 +382,43 @@ class LGHorizonApi:
378
382
  personalisation_result = self._do_api_call(
379
383
  f"{self._config['personalizationService']['URL']}/v1/customer/{self._auth.householdId}?with=profiles%2Cdevices"
380
384
  )
381
- _logger.debug(f"Personalisation result: {personalisation_result}")
382
- self._customer = LGHorizonCustomer(personalisation_result)
385
+ _logger.debug("Personalisation result: %s ", personalisation_result)
386
+ self.customer = LGHorizonCustomer(personalisation_result)
383
387
  self._get_channels()
384
- if not "assignedDevices" in personalisation_result:
388
+ if "assignedDevices" not in personalisation_result:
385
389
  _logger.warning("No boxes found.")
386
390
  return
387
391
  _logger.info("Registering boxes")
388
- for device in personalisation_result["assignedDevices"]:
392
+ for device in self.customer.settop_boxes:
389
393
  platform_type = device["platformType"]
390
- if not platform_type in _supported_platforms:
394
+ if platform_type not in _supported_platforms:
391
395
  continue
392
396
  if (
393
397
  "platform_types" in self._country_settings
394
398
  and platform_type in self._country_settings["platform_types"]
395
399
  ):
396
- platformType = self._country_settings["platform_types"][platform_type]
400
+ platform_type = self._country_settings["platform_types"][platform_type]
397
401
  else:
398
- platformType = None
402
+ platform_type = None
399
403
  box = LGHorizonBox(
400
- device, platformType, self._mqttClient, self._auth, self._channels
404
+ device, platform_type, self._mqttClient, self._auth, self._channels
401
405
  )
402
406
  self.settop_boxes[box.deviceId] = box
403
- _logger.info(f"Box {box.deviceId} registered...")
407
+ _logger.info("Box %s registered...", box.deviceId)
404
408
 
405
409
  def _get_channels(self):
406
410
  self._update_entitlements()
407
411
  _logger.info("Retrieving channels...")
408
412
  channels_result = self._do_api_call(
409
- f"{self._config['linearService']['URL']}/v2/channels?cityId={self._customer.cityId}&language={self._country_settings['language']}&productClass=Orion-DASH"
413
+ f"{self._config['linearService']['URL']}/v2/channels?cityId={self.customer.cityId}&language={self._country_settings['language']}&productClass=Orion-DASH"
410
414
  )
415
+ profile_channels = []
416
+ if self._profile_id and self._profile_id in self.customer.profiles:
417
+ profile_channels = self.customer.profiles[
418
+ self._profile_id
419
+ ].favorite_channels
420
+
421
+ has_profile_channels = len(profile_channels) > 0
411
422
  for channel in channels_result:
412
423
  if "isRadio" in channel and channel["isRadio"]:
413
424
  continue
@@ -417,6 +428,9 @@ class LGHorizonApi:
417
428
  if len(common_entitlements) == 0:
418
429
  continue
419
430
  channel_id = channel["id"]
431
+ if has_profile_channels and channel_id not in profile_channels:
432
+ continue
433
+
420
434
  self._channels[channel_id] = LGHorizonChannel(channel)
421
435
  _logger.info(f"{len(self._channels)} retrieved.")
422
436
 
@@ -677,17 +677,32 @@ class LGHorizonBox:
677
677
  self._mqtt_client.publish_message(topic, json.dumps(payload))
678
678
 
679
679
 
680
+ class LGHorizonProfile:
681
+ profile_id: str = None
682
+ name: str = None
683
+ favorite_channels: [] = None
684
+
685
+ def __init__(self, json_payload):
686
+ self.profile_id = json_payload["profileId"]
687
+ self.name = json_payload["name"]
688
+ self.favorite_channels = json_payload["favoriteChannels"]
689
+
690
+
680
691
  class LGHorizonCustomer:
681
692
  customerId: str = None
682
693
  hashedCustomerId: str = None
683
694
  countryId: str = None
684
695
  cityId: int = 0
685
- settop_boxes: Dict[str, LGHorizonBox] = None
696
+ settop_boxes: [] = None
697
+ profiles: Dict[str, LGHorizonProfile] = {}
686
698
 
687
699
  def __init__(self, json_payload):
688
700
  self.customerId = json_payload["customerId"]
689
701
  self.hashedCustomerId = json_payload["hashedCustomerId"]
690
702
  self.countryId = json_payload["countryId"]
691
703
  self.cityId = json_payload["cityId"]
692
- if not "assignedDevices" in json_payload:
693
- return
704
+ if "assignedDevices" in json_payload:
705
+ self.settop_boxes = json_payload["assignedDevices"]
706
+ if "profiles" in json_payload:
707
+ for profile in json_payload["profiles"]:
708
+ self.profiles[profile["profileId"]] = LGHorizonProfile(profile)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lghorizon
3
- Version: 0.7.2
3
+ Version: 0.7.3b1
4
4
  Summary: Python client for Liberty Global Horizon settop boxes
5
5
  Home-page: https://github.com/sholofly/LGHorizon-python
6
6
  Author: Rudolf Offereins
@@ -0,0 +1,7 @@
1
+ {
2
+ "username": "your_username",
3
+ "password": "your_password",
4
+ "country": "your_country_code",
5
+ "profile_id":"your_profile_id"
6
+
7
+ }
@@ -57,12 +57,17 @@ if __name__ == "__main__":
57
57
  if "refresh_token" in secrets:
58
58
  refresh_token = secrets["refresh_token"]
59
59
 
60
+ profile_id = None
61
+ if "profile_id" in secrets:
62
+ profile_id = secrets["profile_id"]
63
+
60
64
  api = LGHorizonApi(
61
65
  secrets["username"],
62
66
  secrets["password"],
63
67
  secrets["country"],
64
68
  # identifier="DTV3907048",
65
- refresh_token = refresh_token,
69
+ refresh_token=refresh_token,
70
+ profile_id=profile_id
66
71
  )
67
72
  api.connect()
68
73
  event_loop()
@@ -1,5 +0,0 @@
1
- """Python client for LG Horizon."""
2
- from .lghorizon_api import LGHorizonApi
3
- from .models import LGHorizonBox, LGHorizonRecordingListSeasonShow, LGHorizonRecordingSingle, LGHorizonRecordingShow, LGHorizonRecordingEpisode
4
- from .exceptions import LGHorizonApiUnauthorizedError, LGHorizonApiConnectionError
5
- from .const import ONLINE_RUNNING, ONLINE_STANDBY, RECORDING_TYPE_SHOW, RECORDING_TYPE_SEASON, RECORDING_TYPE_SINGLE# noqa
@@ -1,5 +0,0 @@
1
- {
2
- "username": "your_username",
3
- "password": "your_password",
4
- "country": "your_country_code"
5
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes