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

MIT License
66 stars 20 forks source link

Not publishing to homeassistant topic for auto-discovery #213

Closed ZionFox closed 4 months ago

ZionFox commented 4 months ago

Possibly unrelated to my previous posted issue regarding the saic_user escape character fix, but after performing my quick fix in 0.6.0rc25, I am not getting any entries into the homeassistant MQTT topic.

Environment

Debian 12 bookworm running Docker 25 Home Assistant 2024.4.3 in docker Mosquitto 2.0.18 in docker saic-mqtt-gateway 0.6.0rc25 (with my publish character escape patch) in docker

The logs do actually show that it makes an attempt, but starts to fail after 2 submittions (which don't actually make it) and that then loops.

2024-04-14 19:29:41,653 [ DEBUG  ] Publishing Home Assistant discovery messages - integrations.home_assistant.discovery
2024-04-14 19:29:41,654 [ DEBUG  ] Sending PUBLISH (q0), 'b'homeassistant/select/LSJW*********2049_mg/LSJW*********2049_gateway_refresh_mode/config'', ... (943 bytes) - gmqtt.mqtt.package
2024-04-14 19:29:41,654 [ DEBUG  ] Sending PUBLISH (q0), 'b'homeassistant/number/LSJW*********2049_mg/LSJW*********2049_gateway_active_refresh_period/config'', ... (1000 bytes) - gmqtt.mqtt.package
2024-04-14 19:29:41,655 [ DEBUG  ] Sending PUBLISH (q0), 'b'homeassistant/number/LSJW*********2049_mg/LSJW*********2049_gateway_inactive_refresh_period/config'', ... (1014 bytes) - gmqtt.mqtt.package
2024-04-14 19:29:41,656 [WARNING ] [TRYING WRITE TO CLOSED SOCKET] - gmqtt.mqtt.protocol
2024-04-14 19:29:41,656 [ DEBUG  ] Sending PUBLISH (q0), 'b'homeassistant/number/LSJW*********2049_mg/LSJW*********2049_gateway_refresh_period_after_car_shutdown/config'', ... (1051 bytes) - gmqtt.mqtt.package
2024-04-14 19:29:41,656 [WARNING ] [TRYING WRITE TO CLOSED SOCKET] - gmqtt.mqtt.protocol
2024-04-14 19:29:41,657 [ DEBUG  ] Sending PUBLISH (q0), 'b'homeassistant/number/LSJW*********2049_mg/LSJW*********2049_gateway_grace_period_after_car_shutdown/config'', ... (1045 bytes) - gmqtt.mqtt.package
2024-04-14 19:29:41,657 [WARNING ] [TRYING WRITE TO CLOSED SOCKET] - gmqtt.mqtt.protocol
2024-04-14 19:29:41,657 [ DEBUG  ] Sending PUBLISH (q0), 'b'homeassistant/sensor/LSJW*********2049_mg/LSJW*********2049_gateway_charging_refresh_period/config'', ... (827 bytes) - gmqtt.mqtt.package
2024-04-14 19:29:41,658 [WARNING ] [TRYING WRITE TO CLOSED SOCKET] - gmqtt.mqtt.protocol
2024-04-14 19:29:41,658 [ DEBUG  ] Sending PUBLISH (q0), 'b'homeassistant/sensor/LSJW*********2049_mg/LSJW*********2049_gateway_error_refresh_period/config'', ... (815 bytes) - gmqtt.mqtt.package
2024-04-14 19:29:41,658 [WARNING ] [TRYING WRITE TO CLOSED SOCKET] - gmqtt.mqtt.protocol
2024-04-14 19:29:41,659 [ DEBUG  ] Sending PUBLISH (q0), 'b'homeassistant/sensor/LSJW*********2049_mg/LSJW*********2049_last_car_activity/config'', ... (760 bytes) - gmqtt.mqtt.package
2024-04-14 19:29:41,659 [WARNING ] [TRYING WRITE TO CLOSED SOCKET] - gmqtt.mqtt.protocol
2024-04-14 19:29:41,659 [ DEBUG  ] Sending PUBLISH (q0), 'b'homeassistant/sensor/LSJW*********2049_mg/LSJW*********2049_last_charge_state/config'', ... (763 bytes) - gmqtt.mqtt.package
2024-04-14 19:29:41,659 [WARNING ] [TRYING WRITE TO CLOSED SOCKET] - gmqtt.mqtt.protocol
2024-04-14 19:29:41,660 [ DEBUG  ] Sending PUBLISH (q0), 'b'homeassistant/sensor/LSJW*********2049_mg/LSJW*********2049_last_vehicle_state/config'', ... (767 bytes) - gmqtt.mqtt.package
2024-04-14 19:29:41,660 [WARNING ] [TRYING WRITE TO CLOSED SOCKET] - gmqtt.mqtt.protocol
2024-04-14 19:29:41,660 [ DEBUG  ] Sending PUBLISH (q0), 'b'homeassistant/sensor/LSJW*********2049_mg/LSJW*********2049_last_poll_error/config'', ... (751 bytes) - gmqtt.mqtt.package
2024-04-14 19:29:41,661 [WARNING ] [TRYING WRITE TO CLOSED SOCKET] - gmqtt.mqtt.protocol
2024-04-14 19:29:41,661 [ DEBUG  ] Sending PUBLISH (q0), 'b'homeassistant/switch/LSJW*********2049_mg/LSJW*********2049_front_window_defroster_heating/config'', ... (1169 bytes) - gmqtt.mqtt.package
2024-04-14 19:29:41,661 [WARNING ] [TRYING WRITE TO CLOSED SOCKET] - gmqtt.mqtt.protocol
2024-04-14 19:29:41,662 [ DEBUG  ] Sending PUBLISH (q0), 'b'homeassistant/switch/LSJW*********2049_mg/LSJW*********2049_vehicle_climate_fan_only/config'', ... (1161 bytes) - gmqtt.mqtt.package

Strangely, even the two requestst that do seem to make it don't appear in MQTT. I can't really see anything that's making this fail, but it possibly is related to subscriptions or string escaping again.

tosate commented 4 months ago

Hi @ZionFox,

it's me again. The Home Assistant auto-discovery messages contain the MQTT topics that tell HA where to fetch information. Consequently, we also have to remove the special characters in those topics.

tosate commented 4 months ago

Please have a look at pull request #214 for further information!

ZionFox commented 4 months ago

Can confirm that PR https://github.com/SAIC-iSmart-API/saic-python-mqtt-gateway/pull/214 does indeed resolve this issue. String sanitation that was omitted was not playing nicely when publishing or fetching data to MQTT.