From 6a06a38bb781b08fb2f60a21ea464acd7f062081 Mon Sep 17 00:00:00 2001 From: atse Date: Mon, 20 Jan 2025 11:35:17 +0800 Subject: [PATCH] PyThermostat: Refactor autotune - Use auto() for PIDAutotuneState Enum - Shorten if-conditional statement --- pythermostat/pythermostat/autotune.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pythermostat/pythermostat/autotune.py b/pythermostat/pythermostat/autotune.py index 0cd45a4..0ad6e00 100644 --- a/pythermostat/pythermostat/autotune.py +++ b/pythermostat/pythermostat/autotune.py @@ -2,7 +2,7 @@ import math import logging import time from collections import deque, namedtuple -from enum import Enum +from enum import Enum, auto from pythermostat.client import Client @@ -13,11 +13,11 @@ from pythermostat.client import Client class PIDAutotuneState(Enum): - STATE_OFF = 'off' - STATE_RELAY_STEP_UP = 'relay step up' - STATE_RELAY_STEP_DOWN = 'relay step down' - STATE_SUCCEEDED = 'succeeded' - STATE_FAILED = 'failed' + STATE_OFF = auto() + STATE_RELAY_STEP_UP = auto() + STATE_RELAY_STEP_DOWN = auto() + STATE_SUCCEEDED = auto() + STATE_FAILED = auto() class PIDAutotune: @@ -94,9 +94,11 @@ class PIDAutotune: """ now = time_input * 1000 - if (self._state == PIDAutotuneState.STATE_OFF - or self._state == PIDAutotuneState.STATE_SUCCEEDED - or self._state == PIDAutotuneState.STATE_FAILED): + if self._state in { + PIDAutotuneState.STATE_OFF, + PIDAutotuneState.STATE_SUCCEEDED, + PIDAutotuneState.STATE_FAILED, + }: self._state = PIDAutotuneState.STATE_RELAY_STEP_UP self._last_run_timestamp = now