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 logging
|
||||||
import time
|
import time
|
||||||
from collections import deque, namedtuple
|
from collections import deque, namedtuple
|
||||||
from enum import Enum
|
from enum import Enum, auto
|
||||||
|
|
||||||
from pythermostat.client import Client
|
from pythermostat.client import Client
|
||||||
|
|
||||||
@ -13,11 +13,11 @@ from pythermostat.client import Client
|
|||||||
|
|
||||||
|
|
||||||
class PIDAutotuneState(Enum):
|
class PIDAutotuneState(Enum):
|
||||||
STATE_OFF = 'off'
|
STATE_OFF = auto()
|
||||||
STATE_RELAY_STEP_UP = 'relay step up'
|
STATE_RELAY_STEP_UP = auto()
|
||||||
STATE_RELAY_STEP_DOWN = 'relay step down'
|
STATE_RELAY_STEP_DOWN = auto()
|
||||||
STATE_SUCCEEDED = 'succeeded'
|
STATE_SUCCEEDED = auto()
|
||||||
STATE_FAILED = 'failed'
|
STATE_FAILED = auto()
|
||||||
|
|
||||||
|
|
||||||
class PIDAutotune:
|
class PIDAutotune:
|
||||||
@ -94,9 +94,11 @@ class PIDAutotune:
|
|||||||
"""
|
"""
|
||||||
now = time_input * 1000
|
now = time_input * 1000
|
||||||
|
|
||||||
if (self._state == PIDAutotuneState.STATE_OFF
|
if self._state in {
|
||||||
or self._state == PIDAutotuneState.STATE_SUCCEEDED
|
PIDAutotuneState.STATE_OFF,
|
||||||
or self._state == PIDAutotuneState.STATE_FAILED):
|
PIDAutotuneState.STATE_SUCCEEDED,
|
||||||
|
PIDAutotuneState.STATE_FAILED,
|
||||||
|
}:
|
||||||
self._state = PIDAutotuneState.STATE_RELAY_STEP_UP
|
self._state = PIDAutotuneState.STATE_RELAY_STEP_UP
|
||||||
|
|
||||||
self._last_run_timestamp = now
|
self._last_run_timestamp = now
|
||||||
|
Loading…
Reference in New Issue
Block a user