Skip to content

Commit

Permalink
Merge pull request #190 from marcolivierarsenault/fix_deadband
Browse files Browse the repository at this point in the history
Fix deadband
  • Loading branch information
marcolivierarsenault authored Aug 17, 2024
2 parents 42cc263 + 24d0837 commit 735dd9e
Show file tree
Hide file tree
Showing 7 changed files with 508 additions and 440 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"[python]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "charliermarsh.ruff"
}
},
"cSpell.enabled": true
}
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.2.8
v1.2.9
902 changes: 473 additions & 429 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tefnut"
version = "1.2.8"
version = "1.2.9"
description = "Tefnut is a control system to manage central humidificatior."
authors = ["Marc-Olivier Arsenault <[email protected]>"]
license = "MIT"
Expand Down
12 changes: 8 additions & 4 deletions tefnut/control/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ def controler_loop(self):
if self.state["humidity delay"] >= delay:
logger.info("Capturing humidity")
current_values["humidity"] = self.ecobee.get_humidity()
current_values[
"humidity freshness"
] = self.ecobee.get_latest_freshness()
current_values["humidity freshness"] = (
self.ecobee.get_latest_freshness()
)
logger.debug("humidity: %s", current_values["humidity"])
current_values["humidity time"] = time.time()
else:
Expand Down Expand Up @@ -104,7 +104,7 @@ def goodbye(self):
logger.info("GOODBYE")
self.humidifier.shutdown()

def humidifier_controller(self):
def humidifier_controller(self, force=False):
logger.debug("Starting control")
if self.state["humidity"] is not None:
logger.debug("humidity is currently %d", self.state["humidity"])
Expand Down Expand Up @@ -155,6 +155,10 @@ def humidifier_controller(self):
self.state["target_humidity"] = self.compute_automated_target(
self.state["target_temp"]
)
elif force:
self.state["target_humidity"] = self.compute_automated_target(
self.state["target_temp"] - 2
)

deadband = settings.get("GENERAL.deadband", default=2)

Expand Down
2 changes: 1 addition & 1 deletion tefnut/webui/webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def get_state():

app.logger.info("Changing Humidifier mode: %s", new_data["mode"])
settings.set("GENERAL.mode", new_data["mode"], persist=persist)
tefnut_controller.humidifier_controller()
tefnut_controller.humidifier_controller(force=True)
return tefnut_controller.state

if "manual_target" in new_data:
Expand Down
25 changes: 22 additions & 3 deletions tests/control/test_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,23 +667,24 @@ def test_dead_temp_band(control, state_with_data):
state_with_data["target_temp"] = 5.5 # deadspot
control.state = state_with_data
control.humidifier_controller()
control.state["target_humidity"] = 55
assert control.state["target_humidity"] == 55


def test_dead_temp_band_int(control, state_with_data):
state_with_data["target_humidity"] = 55
state_with_data["target_temp"] = -10 # deadspot
control.state = state_with_data
control.humidifier_controller()
control.state["target_humidity"] = 55
assert control.state["target_humidity"] == 55


def test_valid_temp_change_humidity(control, state_with_data):
settings.set("GENERAL.mode", "AUTO", persist=False)
state_with_data["target_humidity"] = 55
state_with_data["target_temp"] = -5 # valid spot
control.state = state_with_data
control.humidifier_controller()
control.state["target_humidity"] = 40
assert control.state["target_humidity"] == 40


def test_is_active(control):
Expand Down Expand Up @@ -782,3 +783,21 @@ def test_ecobee_Exception(ecobee, data_collection_logic, control, caplog):
def test_goodbye(control, caplog):
control.goodbye()
assert "GOODBYE" in caplog.text


def test_from_manual_to_auto(control, state_with_data):
settings.set("GENERAL.mode", "MANUAL", persist=False)
state_with_data["state"] = tef_control.STATE.OFF
state_with_data["humidity"] = 45
state_with_data["target_temp"] = -10
settings.set("GENERAL.manual_target", 60, persist=False)
control.state = state_with_data

assert control.humidifier_controller() == 1
assert control.state["state"] == tef_control.STATE.ON
assert control.state["target_humidity"] == 60

settings.set("GENERAL.mode", "AUTO", persist=False)
assert control.humidifier_controller(force=True) == 2
print(control.state)
assert control.state["target_humidity"] == 35

0 comments on commit 735dd9e

Please sign in to comment.