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

MIT License
67 stars 20 forks source link

Persist Gateway interval configuration after restart #142

Closed jfreves closed 4 months ago

jfreves commented 8 months ago

I usually change the Gateway inactive refresh period to a different value than the default but whenever the addon is restarted the value changes back to the default value. Can this Gateway configuration be persisted instead?

nanomad commented 8 months ago

Technically it should already be handled vie the configure_by_message() function. If it is not working maybe it has to do with the MQTT client state not being cleared. Are you publishing those messges with the retain flag set?

jfreves commented 8 months ago

I have an input in my dashboard and use it to update the value, I'm not publishing messages directly.

image
pmannk commented 8 months ago

Technically it should already be handled vie the configure_by_message() function. If it is not working maybe it has to do with the MQTT client state not being cleared. Are you publishing those messges with the retain flag set?

I've tried (unsuccessfully) to retain the refresh period. YAML config of the entity:

    - name: mg4_refresh_active
      state_topic: "saic/xxx@gmail.com/vehicles/xxx/refresh/period/active"
      command_topic: "saic/xxx@gmail.com/vehicles/xxx/refresh/period/active/set"
      retain: true
      options:
        - "30"
        - "900"
        - "3600"

If I pick "900" as the value in HA I can see it's retained when I shut down the SAIC MQTT Gateway (Python) add-on. As soon as I start the add-on I see the MQTT value revert to 30, and in the SAIC logs I see: 2024-01-30 22:22:13,590 [ INFO ] Setting active query interval in vehicle handler for VIN xxx to 0:00:30 - vehicle

nanomad commented 4 months ago

@pmannk Found a potential root cause. Tentative fix scheduled for 0.6.2-rc12.

Please try it out and let me know

pmannk commented 4 months ago

Thanks @nanomad ! I'm in Australia, so stuck on the legacy gateway unfortunately. I'll see if I can merge just those changes from vehicle.py into my local install

nanomad commented 4 months ago

Ah that's a shame, if you manage to retrofit it feel free to open a PR. We can create an ad-hoc maintenance branch for it