JohNan / home-assistant-flichub

Custom HomeAssistant integration for FlicHub
MIT License
8 stars 3 forks source link

Buttons not being added #21

Closed alexander-cato closed 4 months ago

alexander-cato commented 1 year ago

Somewhat of a continuation of Issue #19 @JohNan

After updating to 1.0.7 #20 Manual setup is one again working as expected and the Hub is added to home assistant. Buttons however, are not being added by the integration. Homeassistant logs below:

2023-10-26 23:07:33.606 INFO (MainThread) [pyflichub.client] Trying to connect to ('192.168.1.12', '8124')
2023-10-26 23:07:33.778 INFO (MainThread) [pyflichub.client] Disconnected
2023-10-26 23:07:33.779 INFO (MainThread) [pyflichub.client] Trying to connect to ('192.168.1.12', '8124')
2023-10-26 23:07:33.779 INFO (MainThread) [pyflichub.client] Connection lost
2023-10-26 23:07:33.905 WARNING (MainThread) [pyflichub.client] 'server_info'
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/pyflichub/client.py", line 152, in data_received
    self._handle_command(Command(**msg))
  File "/usr/local/lib/python3.11/site-packages/pyflichub/client.py", line 172, in _handle_command
    if self._data_ready[cmd.command] is not None and cmd.data is not None:
       ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'server_info'
2023-10-26 23:07:33.907 WARNING (MainThread) [pyflichub.client] Unable to decode received data
2023-10-26 23:07:34.313 WARNING (MainThread) [pyflichub.client] Unterminated string starting at: line 1 column 1442 (char 1441)
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/pyflichub/client.py", line 148, in data_received
    msg = json.loads(data_part, cls=_JSONDecoder)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 1442 (char 1441)
2023-10-26 23:07:34.319 WARNING (MainThread) [pyflichub.client] Unable to decode received data
2023-10-26 23:07:34.321 WARNING (MainThread) [pyflichub.client] Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/pyflichub/client.py", line 148, in data_received
    msg = json.loads(data_part, cls=_JSONDecoder)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
2023-10-26 23:07:34.325 WARNING (MainThread) [pyflichub.client] Unable to decode received data
2023-10-26 23:07:41.270 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.rest
2023-10-26 23:07:41.986 INFO (MainThread) [homeassistant.components.bluetooth_le_tracker.device_tracker] Discovered Bluetooth LE device 77:68:20:71:0E:87
2023-10-26 23:07:43.790 WARNING (MainThread) [pyflichub.client] Waited for 'server' data for 10.0 secs.
2023-10-26 23:07:43.790 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/flichub/__init__.py", line 104, in client_connected
    await client.get_server_info()
  File "/usr/local/lib/python3.11/site-packages/pyflichub/client.py", line 106, in get_server_info
    return command.data
           ^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'data'
2023-10-26 23:07:43.794 WARNING (MainThread) [pyflichub.client] Waited for 'buttons' data for 10.0 secs.
2023-10-26 23:07:43.805 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.flichub
2023-10-26 23:07:43.805 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.flichub
2023-10-26 23:07:43.806 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.flichub entity: binary_sensor.flichub_wifi
2023-10-26 23:07:43.806 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.flichub entity: binary_sensor.flichub_ethernet
JohNan commented 1 year ago

Thank you. Have you updated the script on the Hub?

Can you enable debug logs and paste them here as well?

alexander-cato commented 11 months ago

The script is updated to the latest version.

Home assistant debug logs below:

2023-11-22 23:05:19.041 INFO (MainThread) [pyflichub.client] Disconnected
2023-11-22 23:05:19.041 INFO (MainThread) [pyflichub.client] Connection lost
2023-11-22 23:05:19.041 DEBUG (MainThread) [custom_components.flichub] Disconnected!
2023-11-22 23:05:19.044 INFO (MainThread) [pyflichub.client] Trying to connect to ('192.168.1.12', '8124')
2023-11-22 23:05:19.095 DEBUG (MainThread) [pyflichub.client] Connection made
2023-11-22 23:05:19.096 DEBUG (MainThread) [custom_components.flichub] Connected!
2023-11-22 23:05:19.294 DEBUG (MainThread) [pyflichub.client] Data received: '{"command":"server_info","data":{"version":"0.1.8"}}\n'
2023-11-22 23:05:19.294 WARNING (MainThread) [pyflichub.client] 'server_info'
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/pyflichub/client.py", line 152, in data_received
    self._handle_command(Command(**msg))
  File "/usr/local/lib/python3.11/site-packages/pyflichub/client.py", line 172, in _handle_command
    if self._data_ready[cmd.command] is not None and cmd.data is not None:
       ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'server_info'
2023-11-22 23:05:19.296 WARNING (MainThread) [pyflichub.client] Unable to decode received data
2023-11-22 23:05:19.300 DEBUG (MainThread) [pyflichub.client] Data received: '{"command":"buttons","data":[{"bdaddr":"80:e4:da:7a:7a:c5","serialNumber":"BH25-D79618","color":"","name":"Living Room Left End Ta","activeDisconnect":false,"connected":true,"ready":true,"batteryStatus":100,"batteryTimestamp":1700711352727,"uuid":"4e462a51b33d4dac9154d83221c143db","flicVersion":2,"firmwareVersion":11,"key":"3e29b34b1f789d3edebce7d4c73d100fa4c7c7e4","passiveMode":false},{"bdaddr":"80:e4:da:7a:7a:d2","serialNumber":"BH25-D79571","color":"","name":"Upstairs Master Bedroom","activeDisconnect":false,"connected":true,"ready":true,"batteryStatus":100,"batteryTimestamp":1700711303338,"uuid":"9a9bf316e36d412fbd6434cc45d6440b","flicVersion":2,"firmwareVersion":11,"key":"7733b93b9a96e90efd90471454333537ccf060f0","passiveMode":false},{"bdaddr":"80:e4:da:7a:7e:ad","serialNumber":"BH25-D80507","color":"","name":"Kitchen Dinette Lamp Fl","activeDisconnect":false,"connected":true,"ready":true,"batteryStatus":100,"batteryTimestamp":1700711820732,"uuid":"ac3d2ca366874bf1abed894d25793c8b","flicVersion":2,"firmwareVersion":11,"key":"7f1f8d97578721bcccd7a4c4223a5105a889af82","passiveMode":false},{"bdaddr":"80:e4:da:7a:7e:b1","serialNumber":"BH25-D80503","color":"","name":"Upstairs Master Bedroom","activeDisconnect":false,"connected":true,"ready":true,"batteryStatus":100,"batteryTimestamp":1700711343643,"uuid":"ae3276217e86455e96e0efbb68320c9a","flicVersion":2,"firmwareVersion":11,"key":"44f657fe58c8f583ba678316786236d5ac585172",'
2023-11-22 23:05:19.300 WARNING (MainThread) [pyflichub.client] Expecting property name enclosed in double quotes: line 1 column 1449 (char 1448)
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/pyflichub/client.py", line 148, in data_received
    msg = json.loads(data_part, cls=_JSONDecoder)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 1449 (char 1448)
2023-11-22 23:05:19.301 WARNING (MainThread) [pyflichub.client] Unable to decode received data
2023-11-22 23:05:19.307 DEBUG (MainThread) [pyflichub.client] Data received: '"passiveMode":false},{"bdaddr":"80:e4:da:7a:7e:b3","serialNumber":"BH25-D80501","color":"","name":"Alexander\'s Bedroom Dre","activeDisconnect":false,"connected":true,"ready":true,"batteryStatus":100,"batteryTimestamp":1700711376036,"uuid":"4af709adc32746978a37a920e1a4893d","flicVersion":2,"firmwareVersion":11,"key":"b51cde9b377fe8335788bab9ec15dc8d5e9a75e5","passiveMode":false},{"bdaddr":"80:e4:da:7a:7e:d8","serialNumber":"BH25-D80812","color":"","name":"Living Room Right End T","activeDisconnect":false,"connected":true,"ready":true,"batteryStatus":100,"batteryTimestamp":1700711239913,"uuid":"b8301a6591674e63b557e513d830632f","flicVersion":2,"firmwareVersion":11,"key":"a7dcae27172c456b2afff0d7ce27e6d905afe7db","passiveMode":false},{"bdaddr":"80:e4:da:7a:7e:f0","serialNumber":"BH25-D80059","color":"","name":"Sun Room Duck Lamp Flic","activeDisconnect":false,"connected":true,"ready":true,"batteryStatus":100,"batteryTimestamp":1700711519151,"uuid":"9e25eae63c9540f1b619c6734041b68a","flicVersion":2,"firmwareVersion":11,"key":"aff62e73be1e84a4712c18c00b595c25dce87f35","passiveMode":false},{"bdaddr":"80:e4:da:7a:7e:fb","serialNumber":"BH25-D80054","color":"","name":"Dining Room China Cabin","activeDisconnect":false,"connected":true,"ready":true,"batteryStatus":100,"batteryTimestamp":1700711295735,"uuid":"2dff2e407ad5488b829f1d3612008bb0","flicVersion":2,"firmwareVersion":11,"key":"143bb8ae565bd13d55a41d57150188563b89a001","passiveMode":false},{"bdaddr":"80:e4:da:7a:7e:fd","serialNumber":"BH25-D80052","color":"","name":"Sun Room Bunny Lamp Fli","activeDisconnect":false,"connected":true,"ready":true,"batteryStatus":100,"batteryTimestamp":1700711407283,"uuid":"cdb737989d7c4758a22b415dea1273d1","flicVersion":2,"firmwareVersion":11,"key":"ea951bdb78a486d213666c9413268e1572d940d4","passiveMode":false},{"bdaddr":"80:e4:da:7a:a5:0c","serialNumber":"BH39-D09352","color":"","name":"Downstairs Hallway Mini","activeDisconnect":false,"connected":false,"ready":false,"batteryStatus":27,"batteryTimestamp":1700709692145,"uuid":"ff40b12c5d61489291112adfc77ebfd3","flicVersion":2,"firmwareVersion":11,"key":"54452a4a86e819c6651a99cc32dd60482bcc710d","passiveMode":false},{"bdaddr":"80:e4:da:7a:aa:f9","serialNumber":"BH39-D10020","color":"","name":"Back Entry Lamp Flic","activeDisconnect":false,"connected":true,"ready":true,"batteryStatus":100,"batteryTimestamp":1700711360398,"uuid":"f65340393baa46b88bfaa72c136563d0","flicVersion":2,"firmwareVersion":11,"key":"7dcfba90234562e0ad024a3c317d289722965131","passiveMode":false},{"bdaddr":"80:e4:da:7a:ac:2f","serialNumber":"BH39-D11349","color":"","name":"Sun Room Bird Lamp Flic","activeDisconnect":false,"connected":true,"ready":true,"batteryStatus":100,"batteryTimestamp":1700711237834,"uuid":"9191b6ad9c474ea49141499269652652","flicVersion":2,"firmwareVersion":11,"key":"ec1d33f4684eaae401a853a42b9b3ba5c1e5b1bd","passiveMode":fals'
2023-11-22 23:05:19.307 WARNING (MainThread) [pyflichub.client] Extra data: line 1 column 14 (char 13)
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/pyflichub/client.py", line 148, in data_received
    msg = json.loads(data_part, cls=_JSONDecoder)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/decoder.py", line 340, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 14 (char 13)
2023-11-22 23:05:19.310 WARNING (MainThread) [pyflichub.client] Unable to decode received data
2023-11-22 23:05:19.326 DEBUG (MainThread) [pyflichub.client] Data received: 'e},{"bdaddr":"80:e4:da:7b:e5:50","serialNumber":"BH18-E91874","color":"","name":"Upstairs Sitting Room M","activeDisconnect":false,"connected":true,"ready":true,"batteryStatus":100,"batteryTimestamp":1700711367533,"uuid":"99568ae711384418b413128eb9649fd9","flicVersion":2,"firmwareVersion":11,"key":"e551d7931c42227d26af22bd4ce6c7bd428635c2","passiveMode":false}]}\n'
2023-11-22 23:05:19.326 WARNING (MainThread) [pyflichub.client] Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/pyflichub/client.py", line 148, in data_received
    msg = json.loads(data_part, cls=_JSONDecoder)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
2023-11-22 23:05:19.328 WARNING (MainThread) [pyflichub.client] Unable to decode received data
2023-11-22 23:05:29.097 WARNING (MainThread) [pyflichub.client] Waited for 'server' data for 10.0 secs.
2023-11-22 23:05:29.097 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/flichub/__init__.py", line 104, in client_connected
    await client.get_server_info()
  File "/usr/local/lib/python3.11/site-packages/pyflichub/client.py", line 106, in get_server_info
    return command.data
           ^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'data'
2023-11-22 23:05:29.098 WARNING (MainThread) [pyflichub.client] Waited for 'buttons' data for 10.0 secs.
2023-11-22 23:05:29.107 DEBUG (MainThread) [pyflichub.client] Data received: '{"command":"network","data":{"dhcp":{"wifi":{"connected":true,"ip":"192.168.1.12","mac":"56:EF:33:53:56:6C"},"ethernet":{"connected":false,"ip":null,"mac":"1E:5B:0C:71:03:89"}},"wifiState":{"state":"COMPLETED","ssid":[67,97,116,111,32,78,101,116,119,111,114,107,32,76,111,99,97,108,83,109,97,114,116]}}}\n'
2023-11-22 23:05:29.108 DEBUG (MainThread) [custom_components.flichub] Command: network, data: FlicHubInfo()
2023-11-22 23:05:29.108 DEBUG (MainThread) [custom_components.flichub] Finished fetching Ruth Flic Hub data in 10.011 seconds (success: True)
2023-11-22 23:05:29.108 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.flichub
2023-11-22 23:05:29.108 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.flichub
JohNan commented 10 months ago

Sorry for the late response. I think the problem is the single quote in the name of the button. Remove it and try again.

blade5502 commented 8 months ago

Experience the same issue - I've tried to experiment a bit with the pyflichub-tcpclient library without HomeAssistant and it looks like the buttons message gets split up as it doesn't fit in a single IP packet (MTU size) and the client library tries to json.loads() each part seperately which fails. There is room for 4 buttons in one packet, if there are more than 4 buttons set up in hub it fails