Skip to content

Commit

Permalink
Merge pull request #81 from cdesouza71/master
Browse files Browse the repository at this point in the history
Fix datetime serialization issue
  • Loading branch information
cdesouza71 authored Apr 1, 2024
2 parents 9517b51 + 5a52bf5 commit 577a22f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions moisture_sensor_data_mqtt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ week.

## Version information

- v0.0.4
- Fix datetime serialization issue
- v0.0.3
- Fixed issue with sensor rename and last_reading
- v0.0.2
Expand Down
4 changes: 4 additions & 0 deletions moisture_sensor_data_mqtt/moisture_sensor_data_mqtt-docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ <h2>Retention period</h2>
<h2>Version information</h2>

<ul>
<li>v0.0.4
<ul>
<li>Fix datetime serialization issue</li>
</ul></li>
<li>v0.0.3
<ul>
<li>Fixed issue with sensor rename and last_reading</li>
Expand Down
17 changes: 10 additions & 7 deletions moisture_sensor_data_mqtt/moisture_sensor_data_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from webpages import ProtectedPage # Needed for security

import datetime
import copy
import os
from plugins import mqtt

Expand Down Expand Up @@ -152,7 +153,6 @@ def mqtt_reader(client, msg):
reading = round(reading)

# Store reading for display purposes
# TODO save settings
last_reading[sensor] = {"ts": ts, "reading": reading}

# Send msd signal
Expand Down Expand Up @@ -259,14 +259,16 @@ class get_settings(ProtectedPage):
"""

def GET(self):
# Inject last reading as it is currently not saved
# If we add this to settings we run into datetime
# serialization issues when dumping settings, hence the copy.
display_sensors = copy.deepcopy(settings["sensors"])

for sensor in last_reading.keys():
settings["sensors"][sensor]["reading_ts"] = last_reading[sensor]["ts"]
settings["sensors"][sensor]["reading_value"] = last_reading[sensor][
"reading"
]
display_sensors[sensor]["reading_ts"] = last_reading[sensor]["ts"]
display_sensors[sensor]["reading_value"] = last_reading[sensor]["reading"]

# open settings page
return template_render.moisture_sensor_data_mqtt(settings["sensors"])
return template_render.moisture_sensor_data_mqtt(display_sensors)


class save_settings(ProtectedPage):
Expand All @@ -291,6 +293,7 @@ def GET(self):
global settings

qdict = web.input()

new_settings = {}

index = 0
Expand Down

0 comments on commit 577a22f

Please sign in to comment.