SAIC-iSmart-API / saic-python-mqtt-gateway

A service that queries the data from an MG iSMART account and publishes the data over MQTT and to other sources
MIT License
71 stars 23 forks source link

HA Addon crashes unexpectedly #128

Closed alexbricknell closed 9 months ago

alexbricknell commented 10 months ago

Logs below:

2024-01-16 08:09:12,046 [WARNING ] Executing <Task finished name='Task-1' coro=<MqttGateway.run() done, defined at /usr/src/app/./mqtt_gateway.py:297> exception=ValueError('non-hexadecimal number found in fromhex() arg at position 55') created at /usr/local/lib/python3.11/asyncio/runners.py:100> took 0.182 seconds - asyncio 2024-01-16 08:09:12,046 [ DEBUG ] Looking for jobs to run - apscheduler.scheduler 2024-01-16 08:09:12,047 [ DEBUG ] No jobs; waiting until a job is added - apscheduler.scheduler Traceback (most recent call last): File "/usr/src/app/./mqtt_gateway.py", line 712, in asyncio.run(mqtt_gateway.run(), debug=debug_log_enabled()) File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/usr/src/app/./mqtt_gateway.py", line 301, in run login_response_message = self.saic_api.login() ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 119, in login self.message_v1_1_coder.decode_response(login_response_hex, login_response_message) File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/ota_v1_1/Message.py", line 13, in decode_response super().decode_response(message, decoded_message) File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/common_model.py", line 401, in decode_response buffered_message_bytes = io.BytesIO(bytes.fromhex(message[5:])) ^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: non-hexadecimal number found in fromhex() arg at position 55

jfreves commented 9 months ago

I started having this issue today, the addon stopped working and when checking the log I found this error.

enrico1036 commented 9 months ago

Same non-hexadecimal error for me. I experienced this 2/3 times in the past 2 months, but starting from today I can't let the plug-in run because the error comes out at startup

newbuilder22 commented 9 months ago

Same here

lbourdel commented 9 months ago

Exception seems in mqtt_gateway.py : def get_vehicle_status(self, vin_info: VinInfo, event_id: str = None) -> MessageV2: ... vehicle_status_rsp_hex = self.send_request(vehicle_status_req_hex, urllib.parse.urljoin(self.saic_uri, '/TAP.Web/ota.mpv30'))

When i debug by setting a breakpoint

vehicle_status_rsp_hex variable value is 'Blocked by Sentinel (flow limiting)'

GamEased commented 9 months ago

I get:

2024-01-27 00:03:53,097 [ ERROR ] 'handle_vehicle_XXXXXXXXXXXXXXXX' task crashed with an exception - main Traceback (most recent call last): File "/usr/src/app/./mqtt_gateway.py", line 90, in handle_vehicle vehicle_status = self.update_vehicle_status() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/app/./mqtt_gateway.py", line 110, in update_vehicle_status vehicle_status_rsp_msg = self.saic_api.get_vehicle_status_with_retry(self.vin_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 193, in get_vehicle_status_with_retry return self.handle_retry(self.get_vehicle_status, vin_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 457, in handle_retry return self.__handle_retry_with_app_data(func, vin_info=vin_info, max_retries=max_retries) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 488, in __handle_retry_with_app_data rsp = func(vin_info) ^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 188, in get_vehicle_status self.message_V2_1_coder.decode_response(vehicle_status_rsp_hex, vehicle_status_rsp_msg) File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/ota_v2_1/Message.py", line 12, in decode_response return super().decode_response(message, decoded_message) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/common_model.py", line 495, in decode_response buffered_message_bytes = io.BytesIO(bytes.fromhex(message[5:])) ^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: non-hexadecimal number found in fromhex() arg at position 4

Any solution to this?

bexem commented 9 months ago
2024-01-26 18:46:32,432 [WARNING ] Run time of job "Check for new messages (trigger: interval[0:01:00], next run at: 2024-01-26 18:47:11 GMT)" was missed by 0:00:20.490606 - apscheduler.executors.default
2024-01-27 00:03:38,260 [  INFO  ] Connected to MQTT broker - mqtt_publisher
2024-01-27 00:03:38,262 [  INFO  ] Scheduler started - apscheduler.scheduler
2024-01-27 00:03:38,555 [  INFO  ] Registering for abnormal messages - __main__
2024-01-27 00:03:38,703 [  INFO  ] Registering for moving messages - __main__
2024-01-27 00:03:38,855 [  INFO  ] Registering for region messages - __main__
2024-01-27 00:03:39,002 [  INFO  ] Registering for engineStart messages - __main__
2024-01-27 00:03:39,169 [  INFO  ] Registering for startVehicleStatus messages - __main__
2024-01-27 00:03:39,296 [  INFO  ] Registering for offCar messages - __main__
2024-01-27 00:03:39,424 [  INFO  ] Registering for speeding messages - __main__
2024-01-27 00:03:39,446 [  INFO  ] Added job "Check for new messages" to job store "default" - apscheduler.scheduler
2024-01-27 00:03:49,458 [  INFO  ] Setting active query interval in vehicle handler for VIN XXXXXXXXXXXXXXXXX to 0:00:30 - vehicle
2024-01-27 00:03:49,458 [  INFO  ] Setting charging query interval in vehicle handler for VIN XXXXXXXXXXXXXXXXX to 0:00:00 - vehicle
2024-01-27 00:03:49,459 [  INFO  ] Setting after shutdown query interval in vehicle handler for VIN XXXXXXXXXXXXXXXXX to 0:02:00 - vehicle
2024-01-27 00:03:49,459 [  INFO  ] Setting inactive query interval in vehicle handler for VIN XXXXXXXXXXXXXXXXX to 1 day, 0:00:00 - vehicle
2024-01-27 00:03:49,459 [  INFO  ] Setting charging query interval in vehicle handler for VIN XXXXXXXXXXXXXXXXX to 0:00:00 - vehicle
2024-01-27 00:03:49,459 [  INFO  ] Setting refresh mode to periodic - vehicle
2024-01-27 00:03:49,459 [  INFO  ] Updating vehicle status - __main__
2024-01-27 00:03:49,566 [ ERROR  ] 'handle_vehicle_XXXXXXXXXXXXXXXXX' task crashed with an exception - __main__
Traceback (most recent call last):
  File "/usr/src/app/./mqtt_gateway.py", line 90, in handle_vehicle
    vehicle_status = self.update_vehicle_status()
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/app/./mqtt_gateway.py", line 110, in update_vehicle_status
    vehicle_status_rsp_msg = self.saic_api.get_vehicle_status_with_retry(self.vin_info)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 193, in get_vehicle_status_with_retry
    return self.handle_retry(self.get_vehicle_status, vin_info)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 457, in handle_retry
    return self.__handle_retry_with_app_data(func, vin_info=vin_info, max_retries=max_retries)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 488, in __handle_retry_with_app_data
    rsp = func(vin_info)
          ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 188, in get_vehicle_status
    self.message_V2_1_coder.decode_response(vehicle_status_rsp_hex, vehicle_status_rsp_msg)
  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/ota_v2_1/Message.py", line 12, in decode_response
    return super().decode_response(message, decoded_message)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/common_model.py", line 495, in decode_response
    buffered_message_bytes = io.BytesIO(bytes.fromhex(message[5:]))
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: non-hexadecimal number found in fromhex() arg at position 4

Same error but running it in a docker container. No changes made, it has been working fine till now.

latisen commented 9 months ago

Same isue here, running SAIC MQTT Gateway (Python) in HomeAssistant as an addon.

Traceback (most recent call last): File "/usr/src/app/./mqtt_gateway.py", line 90, in handle_vehicle vehicle_status = self.update_vehicle_status() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/app/./mqtt_gateway.py", line 110, in update_vehicle_status vehicle_status_rsp_msg = self.saic_api.get_vehicle_status_with_retry(self.vin_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 193, in get_vehicle_status_with_retry return self.handle_retry(self.get_vehicle_status, vin_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 457, in handle_retry return self.__handle_retry_with_app_data(func, vin_info=vin_info, max_retries=max_retries) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 488, in __handle_retry_with_app_data rsp = func(vin_info) ^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 188, in get_vehicle_status self.message_V2_1_coder.decode_response(vehicle_status_rsp_hex, vehicle_status_rsp_msg) File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/ota_v2_1/Message.py", line 12, in decode_response return super().decode_response(message, decoded_message) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/common_model.py", line 495, in decode_response buffered_message_bytes = io.BytesIO(bytes.fromhex(message[5:])) ^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: non-hexadecimal number found in fromhex() arg at position 4

ifilgud commented 9 months ago

Hi everyone, I'm having the same issue today. Just log in with the app once (my session got expired, I never use the app), make sure you obtain car data there (it took a while) and then restart the gateway. Maybe we are being blocked for some reason, app inactivity, token expiration or whatever.

After that everyting works again :)

bexem commented 9 months ago

Hi everyone, I'm having the same issue today. Just log in with the app once (mine session got expired, I never use the app), make sure you obtain car data there (it took a while) and then restart the gateway. Maybe we are being blocked for some reason, app inactivity, token expiration or whatever.

After that everyting works again :)

Can confirm is working again! Thank you for the update :)

I noticed on the community forum of Home Assistant someone had issues with the app as well.

GamEased commented 9 months ago

Confirmed! Such an easy solution 🙈 would've never drawn the connection if that happened to me haha

newbuilder22 commented 9 months ago

Working.Don’t remember ticking ‘accept conditions’ last time I logged in, wonder if that is why?On 27 Jan 2024, at 06:09, GamEased @.***> wrote: Confirmed! Such an easy solution 🙈 would've never drawn the connection if that happened to me haha

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

bexem commented 9 months ago
2024-01-27 16:10:37,355 [  INFO  ] Job "Check for new messages (trigger: interval[0:01:00], next run at: 2024-01-27 16:11:37 GMT)" executed successfully - apscheduler.executors.default
2024-01-27 16:10:44,875 [  INFO  ] A/C will be switched on - __main__
2024-01-27 16:10:44,998 [ ERROR  ] application ID: 510, protocol version: 25857, message: The service is not available,please try again later~ result code: 702 - saic_ismart_client.saic_api
2024-01-27 16:10:44,999 [ ERROR  ] return code: 702, message: The service is not available,please try again later~ - __main__
Traceback (most recent call last):
  File "/usr/src/app/./mqtt_gateway.py", line 175, in handle_mqtt_command
    self.saic_api.start_ac(self.vin_info,
  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 276, in start_ac
    return self.control_climate(vin_info, fan_speed=2, ac_on=None, temperature_idx=temperature_idx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 351, in control_climate
    return self.send_vehicle_ctrl_cmd_with_retry(vin_info, b'\x06', rcv_params, True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 438, in send_vehicle_ctrl_cmd_with_retry
    return self.handle_retry(
           ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 457, in handle_retry
    return self.__handle_retry_with_app_data(func, vin_info=vin_info, max_retries=max_retries)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 501, in __handle_retry_with_app_data
    self.handle_error(rsp_msg.body, iteration)
  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 880, in handle_error
    raise SaicApiException(message_body.error_message, message_body.result)
saic_ismart_client.exceptions.SaicApiException: return code: 702, message: **The service is not available,please try again later~**
2024-01-27 16:10:45,002 [  INFO  ] Setting remote climate target temperature to 25 - __main__
2024-01-27 16:10:45,002 [  INFO  ] Updating remote AC temperature to 25 - vehicle
2024-01-27 16:10:45,003 [  INFO  ] Setting refresh mode to force - vehicle

It seems to read the information just fine but when I try to turn on the A/C it gives me this error, different for sure and it doesn't crash. I can turn on the A/C remotely if I use the MG app instead.

bullas82 commented 9 months ago

2024-01-27 16:10:37,355 [  INFO  ] Job "Check for new messages (trigger: interval[0:01:00], next run at: 2024-01-27 16:11:37 GMT)" executed successfully - apscheduler.executors.default

2024-01-27 16:10:44,875 [  INFO  ] A/C will be switched on - __main__

2024-01-27 16:10:44,998 [ ERROR  ] application ID: 510, protocol version: 25857, message: The service is not available,please try again later~ result code: 702 - saic_ismart_client.saic_api

2024-01-27 16:10:44,999 [ ERROR  ] return code: 702, message: The service is not available,please try again later~ - __main__

Traceback (most recent call last):

  File "/usr/src/app/./mqtt_gateway.py", line 175, in handle_mqtt_command

    self.saic_api.start_ac(self.vin_info,

  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 276, in start_ac

    return self.control_climate(vin_info, fan_speed=2, ac_on=None, temperature_idx=temperature_idx)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 351, in control_climate

    return self.send_vehicle_ctrl_cmd_with_retry(vin_info, b'\x06', rcv_params, True)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 438, in send_vehicle_ctrl_cmd_with_retry

    return self.handle_retry(

           ^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 457, in handle_retry

    return self.__handle_retry_with_app_data(func, vin_info=vin_info, max_retries=max_retries)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 501, in __handle_retry_with_app_data

    self.handle_error(rsp_msg.body, iteration)

  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 880, in handle_error

    raise SaicApiException(message_body.error_message, message_body.result)

saic_ismart_client.exceptions.SaicApiException: return code: 702, message: **The service is not available,please try again later~**

2024-01-27 16:10:45,002 [  INFO  ] Setting remote climate target temperature to 25 - __main__

2024-01-27 16:10:45,002 [  INFO  ] Updating remote AC temperature to 25 - vehicle

2024-01-27 16:10:45,003 [  INFO  ] Setting refresh mode to force - vehicle

It seems to read the information just fine but when I try to turn on the A/C it gives me this error, different for sure and it doesn't crash. I can turn on the A/C remotely if I use the MG app instead.

I am experiencing the same. Trying to run my automation that runs my heating more then 10 minutes fails with the same error messages as above.

bexem commented 9 months ago

The new update fixed it! Just tried via home assistant. Thank you so much!

acmeGR commented 9 months ago

The new update fixed it! Just tried via home assistant. Thank you so much!

Which update? I didn't get any update info on HA. I am running 0.5.1

Tonno87 commented 9 months ago

0.5.2 is online now