PyThermostat: Refactor autotune
- Use auto() for PIDAutotuneState Enum - Shorten if-conditional statement
This commit is contained in:
parent
9868ca4447
commit
6a06a38bb7
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user