Skip to content

Commit

Permalink
Merge pull request #80 from cdesouza71/master
Browse files Browse the repository at this point in the history
Fix issues with renaming sensors
  • Loading branch information
cdesouza71 authored Mar 26, 2024
2 parents 86181ce + bf7ffa6 commit 9517b51
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions moisture_sensor_control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ following values:

## Version information

- v0.0.3
- Fix renamed sensor not being saved
- v0.0.2
- Ignore RUN ONCE programs
- Improved documentation
Expand Down
4 changes: 4 additions & 0 deletions moisture_sensor_control/moisture_sensor_control-docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ <h2>For developers</h2>
<h2>Version information</h2>

<ul>
<li>v0.0.3
<ul>
<li>Fix renamed sensor not being saved</li>
</ul></li>
<li>v0.0.2
<ul>
<li>Ignore RUN ONCE programs</li>
Expand Down
10 changes: 8 additions & 2 deletions moisture_sensor_control/moisture_sensor_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def validate_int(int_list):
return tuple(validated_list)


def settings_save():
with open(CONFIG_FILE_PATH, "w") as f:
f.write(json.dumps(moisture_sensor_settings, indent=2))


def trigger_run_once(sensor, value):
"""Processes a new reading. Checks if all the required fields are
set, checks to see if the pause and threshold values apply and if
Expand Down Expand Up @@ -128,12 +133,14 @@ def notify_moisture_sensor_data(action, **kw):
moisture_sensor_settings["settings"][k] = data["sensor"]
moisture_sensor_data[data["sensor"]] = moisture_sensor_data[data["old_sensor"]]
del moisture_sensor_data[data["old_sensor"]]
settings_save()

elif action == "delete":
for k, v in moisture_sensor_settings["settings"].items():
if re.match(r"sensor\d+", k) and v == data["sensor"]:
moisture_sensor_settings["settings"][k] = ""
del moisture_sensor_data[data["sensor"]]
settings_save()

else:
print(f"notify_moisture_sensor_data unknown action {action} {data}")
Expand Down Expand Up @@ -259,8 +266,7 @@ def GET(self):

moisture_sensor_settings["settings"] = qdict

with open(CONFIG_FILE_PATH, "w") as f:
f.write(json.dumps(moisture_sensor_settings, indent=2))
settings_save()

# Redisplay the plugin page
raise web.seeother("/moisture_sensor_control")
Expand Down
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.3
- Fixed issue with sensor rename and last_reading
- v0.0.2
- Fixed check for valid topic before creating MQTT reader
- Fixed setting updated check
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.3
<ul>
<li>Fixed issue with sensor rename and last_reading</li>
</ul></li>
<li>v0.0.2
<ul>
<li>Fixed check for valid topic before creating MQTT reader</li>
Expand Down
3 changes: 2 additions & 1 deletion moisture_sensor_data_mqtt/moisture_sensor_data_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,11 @@ def GET(self):
)
if os.path.isfile(old_file) and not os.path.isfile(new_file):
os.rename(old_file, new_file)
if old_sensor in last_reading:
last_reading[new_sensor] = last_reading.pop(old_sensor)

else:
if updated:
print("updated")
# Case: Attributes updated
stop_mqtt_reader(old_sensor)
create_mqtt_reader(new_setting)
Expand Down

0 comments on commit 9517b51

Please sign in to comment.