KaSroka / Toshiba-AC-control

Python controller for Toshiba AC
Apache License 2.0
34 stars 12 forks source link

Fcu state change struct from AMQP seems to have a different format #50

Closed PatrickTaibel closed 1 month ago

PatrickTaibel commented 4 months ago

Got myself a Toshiba AC (Shorai Edge Black/White series), tried to integrate it into Homeassistant and found out that it behaves pretty weirdly.

Playing around with this library directly showed the following logs:

DEBUG:paho:Received PUBLISH (d0, q0, r0, m0), '$iothub/methods/POST/smmobile/?$rid=1c', ...  (254 bytes)
INFO:azure.iot.device.common.mqtt_transport:message received on $iothub/methods/POST/smmobile/?$rid=1c
DEBUG:azure.iot.device.common.pipeline.pipeline_thread:Starting _on_mqtt_message_received in pipeline thread
DEBUG:azure.iot.device.common.pipeline.pipeline_stages_mqtt:MQTTTransportStage: message received on topic $iothub/methods/POST/smmobile/?$rid=1c
DEBUG:azure.iot.device.common.pipeline.pipeline_thread:Starting _on_pipeline_event in callback thread
DEBUG:azure.iot.device.iothub.aio.async_handler_manager:HANDLER RUNNER (_on_method_request_received): Invoking handler
DEBUG:toshiba_ac.device:[Wohnzimmer] AC state from AMQP: ff421a41ffff00ffffffffffffffffffffffffffffff
WARNING:azure.iot.device.common.handle_exceptions:Exception caught in background thread.  Unable to handle.
WARNING:azure.iot.device.common.handle_exceptions:['azure.iot.device.iothub.sync_handler_manager.HandlerManagerException: HANDLER (CLIENT_EVENT): Error during invocation\n']

Manually trying to load the AQMP data displayed the following error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 456, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/usr/local/lib/python3.12/asyncio/__main__.py", line 34, in callback
    coro = func()
           ^^^^^^
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.12/site-packages/toshiba_ac/device/fcu_state.py", line 263, in from_hex_state
    state.decode(hex_state)
  File "/usr/local/lib/python3.12/site-packages/toshiba_ac/device/fcu_state.py", line 311, in decode
    data = self.ENCODING_STRUCT.unpack(bytes.fromhex(extended_hex_state))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
struct.error: unpack requires a buffer of 20 bytes

I guess that at least one field was added to the struct. Interesting enough, they seem to only have changed this for AMQP state changes. The HTTP calls work as expected (e.g. triggering a state_reload worked as expected). I've locally patched ToshibaAcDevice.handle_cmd_fcu_from_ac to truncate data to 38 "characters" (payload["data"][:38]). Now the homeassistant integration works as expected. I don't think that this is a proper solution but I could contribute it as a PR.

Wireless Adapter Firmware: 1.5.00 App version: 5.0.2

laurensk commented 4 months ago

Funny that we have caught this issue literally in the same hour xD I will try to properly update the library and create a PR.

My findings (edits) so far:

KaSroka commented 1 month ago

Thank you for reporting and investigation, this was fixed in v0.3.5