Skip to content

Commit

Permalink
Process profile update in channel list (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sholofly authored Oct 25, 2024
1 parent 628ed9a commit 13d809f
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lghorizon/lghorizon_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,11 @@ def _on_mqtt_connected(self) -> None:
box.register_mqtt()

def _on_mqtt_message(self, message: str, topic: str) -> None:
if "source" in message:
if "action" in message and message["action"] == "OPS.getProfilesUpdate":
self._update_customer()
self._channels.clear()
self._get_channels()
elif "source" in message:
deviceId = message["source"]
if not isinstance(deviceId, str):
_logger.debug("ignoring message - not a string")
Expand All @@ -289,6 +293,7 @@ def _on_mqtt_message(self, message: str, topic: str) -> None:
self.settop_boxes[deviceId].update_state(message)
if "status" in message:
self._handle_box_update(deviceId, message)

except Exception:
_logger.exception("Could not handle status message")
_logger.warning(f"Full message: {str(message)}")
Expand Down Expand Up @@ -388,14 +393,9 @@ def _do_api_call(self, url: str, tries: int = 0) -> str:
return json_response

def _register_customer_and_boxes(self):
_logger.info("Get personalisation info...")
personalisation_result = self._do_api_call(
f"{self._config['personalizationService']['URL']}/v1/customer/{self._auth.householdId}?with=profiles%2Cdevices"
)
_logger.debug("Personalisation result: %s ", personalisation_result)
self.customer = LGHorizonCustomer(personalisation_result)
self._update_customer()
self._get_channels()
if "assignedDevices" not in personalisation_result:
if len(self.customer.settop_boxes) == 0:
_logger.warning("No boxes found.")
return
_logger.info("Registering boxes")
Expand All @@ -416,6 +416,14 @@ def _register_customer_and_boxes(self):
self.settop_boxes[box.deviceId] = box
_logger.info("Box %s registered...", box.deviceId)

def _update_customer(self):
_logger.info("Get customer data")
personalisation_result = self._do_api_call(
f"{self._config['personalizationService']['URL']}/v1/customer/{self._auth.householdId}?with=profiles%2Cdevices"
)
_logger.debug("Personalisation result: %s ", personalisation_result)
self.customer = LGHorizonCustomer(personalisation_result)

def _get_channels(self):
self._update_entitlements()
_logger.info("Retrieving channels...")
Expand Down

0 comments on commit 13d809f

Please sign in to comment.