Skip to content

Commit

Permalink
Fix sensor state on reload
Browse files Browse the repository at this point in the history
Need to write the state file on reload so we don't read the old
state file on init, since the state was only written on shutdown
previously.

Signed-off-by: Nathan Bahr <nabahr@users.noreply.github.com>
  • Loading branch information
nabahr committed Nov 10, 2022
1 parent 33575fe commit aa00568
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions wyzesense2mqtt/wyzesense2mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,11 @@ def on_message_remove(MQTT_CLIENT, userdata, msg):
# Process message to reload sensors
def on_message_reload(MQTT_CLIENT, userdata, msg):
LOGGER.info(f"In on_message_reload: {msg.payload.decode()}")

# Save off the last known state so we don't overwrite new state by re-reading the previously saved file
LOGGER.info("Writing Sensors State File")
write_yaml_file(os.path.join(CONFIG_PATH, SENSORS_STATE_FILE), SENSORS_STATE)

# We are in a mqtt callback so cannot wait for new messages to publish
init_sensors(wait=False)

Expand Down

0 comments on commit aa00568

Please sign in to comment.