Dielee / volvo2mqtt

Home Assistant addon for connecting AAOS Volvos
MIT License
157 stars 38 forks source link

TypeError: can only concatenate str (not "NoneType") to str #230

Closed nickcampbell18 closed 1 month ago

nickcampbell18 commented 1 month ago

Describe the bug

I'm seeing this in the logs when starting:

volvo2mqtt  | Sep 12 10:46:32 volvo2mqtt [1] - INFO: Starting volvo2mqtt version v1.9.6
volvo2mqtt  | Sep 12 10:46:32 volvo2mqtt [1] - INFO: Using login from token file
...
volvo2mqtt  | Sep 12 10:46:42 volvo2mqtt [1] - INFO: Sending mqtt update...
volvo2mqtt  | Traceback (most recent call last):
volvo2mqtt  | Traceback (most recent call last):
volvo2mqtt  |   File "/volvoAAOS2mqtt/./main.py", line 16, in <module>
volvo2mqtt  |   File "/volvoAAOS2mqtt/./main.py", line 16, in <module>
volvo2mqtt  |     update_loop()
volvo2mqtt  |   File "/volvoAAOS2mqtt/mqtt.py", line 295, in update_loop
volvo2mqtt  |     update_loop()
volvo2mqtt  |   File "/volvoAAOS2mqtt/mqtt.py", line 295, in update_loop
volvo2mqtt  |     update_car_data()
volvo2mqtt  |   File "/volvoAAOS2mqtt/mqtt.py", line 361, in update_car_data
volvo2mqtt  |     update_car_data()
volvo2mqtt  |   File "/volvoAAOS2mqtt/mqtt.py", line 361, in update_car_data
volvo2mqtt  |     update_ha_device(entity, vin, state)
volvo2mqtt  |   File "/volvoAAOS2mqtt/mqtt.py", line 381, in update_ha_device
volvo2mqtt  |     update_ha_device(entity, vin, state)
volvo2mqtt  |   File "/volvoAAOS2mqtt/mqtt.py", line 381, in update_ha_device
volvo2mqtt  |     logging.debug("Updating icon to " + icon + " for " + entity["id"])
volvo2mqtt  | TypeError: can only concatenate str (not "NoneType") to str
volvo2mqtt  |     logging.debug("Updating icon to " + icon + " for " + entity["id"])
volvo2mqtt  | TypeError: can only concatenate str (not "NoneType") to str

It doesn't seem to be fatal since events are still being emitted over MQTT. Maybe there needs to be a null check somewhere?

Also, this event is being emitted twice, I'm wondering if there should be a mutex or something around the update loop to prevent it running in parallel.

My car is an EX30, if that helps!

Dielee commented 1 month ago

Please enable Debug and send some logs

denkyem commented 1 month ago

I'm having this error also

image

It seems random the time it takes since restart the addon until the error happens.

I've activated the debug, as soon as it happens again and I have more info, I'll post it here

FYI, My car is also a Volvo EX30

killabeenl commented 1 month ago

I also had this issue last week. But it seems that I get this when the car is charging. Also a Volvo EX30. When the car is not charging the addon is running fine.

nickcampbell18 commented 1 month ago

Nice find @killabeenl!

I see this in my debug logs right before the crash:

volvo2mqtt  | }
volvo2mqtt  | Sep 16 14:37:32 volvo2mqtt [1] - DEBUG: Entity battery_charge_level state 39.5
volvo2mqtt  | Traceback (most recent call last):
volvo2mqtt  |   File "/volvoAAOS2mqtt/./main.py", line 16, in <module>
volvo2mqtt  |     update_loop()
volvo2mqtt  |   File "/volvoAAOS2mqtt/mqtt.py", line 295, in update_loop
volvo2mqtt  |     update_car_data()
volvo2mqtt  |   File "/volvoAAOS2mqtt/mqtt.py", line 361, in update_car_data
volvo2mqtt  |     update_ha_device(entity, vin, state)
volvo2mqtt  |   File "/volvoAAOS2mqtt/mqtt.py", line 381, in update_ha_device
volvo2mqtt  |     logging.debug("Updating icon to " + icon + " for " + entity["id"])
volvo2mqtt  | TypeError: can only concatenate str (not "NoneType") to str

Found it. get_icon_between can return None because these boundaries are not exclusive:

>>> get_icon_between(icon_states["battery_charge_level"], 39)
'battery-30'
>>> get_icon_between(icon_states["battery_charge_level"], 39.5)
>>> get_icon_between(icon_states["battery_charge_level"], 40)
'battery-40'

@Dielee would you like me to send a PR?

Dielee commented 1 month ago

Fixed with V1.9.7