Sholofly / lghorizon

Custom integration to control LG Horizon settop boxes for Ziggo(NL), Magenta(AT), UPC(CH), Virgin(GB, IE), Telenet(BE)
GNU General Public License v3.0
60 stars 14 forks source link

Uncaught exception starting a local rcording #133

Open ColinRobbins opened 1 week ago

ColinRobbins commented 1 week ago

Describe the bug When I started a local recording on the Virgin Tivo Box (GB), from an iPad app, it triggered the following error in the HA logs.

To Reproduce Start a local recording.

Expected behavior The situation is handled without error

Version of the component v0.6.0

Logging

Log Details (ERROR)
Logger: root
Source: /usr/src/homeassistant/homeassistant/bootstrap.py:592
First occurred: 18:53:35 (1 occurrences)
Last logged: 18:53:35

Uncaught thread exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 3591, in _thread_main
    self.loop_forever(retry_first_connection=True)
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 1756, in loop_forever
    rc = self._loop(timeout)
         ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 1164, in _loop
    rc = self.loop_read()
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 1556, in loop_read
    rc = self._packet_read()
         ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 2439, in _packet_read
    rc = self._packet_handle()
         ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 3033, in _packet_handle
    return self._handle_publish()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 3327, in _handle_publish
    self._handle_on_message(message)
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 3570, in _handle_on_message
    on_message(self, self._userdata, message)
  File "/usr/local/lib/python3.12/site-packages/lghorizon/models.py", line 396, in _on_client_message
    self._on_message_callback(jsonPayload, message.topic)
  File "/usr/local/lib/python3.12/site-packages/lghorizon/lghorizon_api.py", line 258, in _on_mqtt_message
    if not deviceId in self.settop_boxes.keys():
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unhashable type: 'dict'

Additional context Prior to the error in the logs, the following MQTT message was received...

2024-10-12 18:53:35.912 DEBUG (Thread-2 (_thread_main)) [lghorizon.models] Message: {'id': 'XXX', 'source': {'clientId': 'XXXX', 'profileId': 'XXXX'}, 'messageType': 'CPE.newRemote', 'runtimeType': 'book', 'data': {'source': 'single', 'eventId': 'crid:~~2F~~2Fgn.tv~~2F28439669~~2FEP012802800687,imi:1cc3dcb46fff631aa13b0f8ca26635d8c172ea2c', 'channelId': '2188', 'seriesId': None, 'startTime': 1728753600, 'prePaddingOffset': 15, 'postPaddingOffset': 300, 'seasonNumber': None, 'episodeNumber': None, 'serieType': None, 'update': False, 'retention': 0, 'numberToKeep': None, 'autoDeleteProtected': True}, 'version': '1.0.9'}
Sholofly commented 1 week ago

Dang, that's something i can't reproduce. i'm wondering what that runtime type is...

ColinRobbins commented 1 week ago

Maybe just move the “if” statement generating the error down a line, so its inside the ”try…”

It’ll then catch the issue, and handle better. Does not see to be that important, everything has carried on working.

Sholofly commented 1 week ago

Does it fail on all recordings?

ColinRobbins commented 1 week ago

Not sure about all recordings - this is actually a programme I want to record, so better not play just yet.

I think the issue is that the parameter "source" is returned as a dict. Whereas usually the "source" in the messages is usually returned as an string form of ID and that's what the code is expecting.

'source': {'clientId': 'XXXX', 'profileId': 'XXXX'},

Maybe change the if too...

if isinstance(deviceId,str) and not deviceId in self.settop_boxes.keys():

I think all the the MQTT message is telling us, is that some user has started a background recording - so we don't really care, so can ignore the message,