PyThermostat: Modify PIDAutotune for GUI usage #162
@ -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,27 +94,28 @@ class PIDAutotune:
|
|||||||
"""
|
"""
|
||||||
now = time_input * 1000
|
now = time_input * 1000
|
||||||
|
|
||||||
if (self._state == PIDAutotuneState.STATE_OFF
|
if self._state not in {
|
||||||
or self._state == PIDAutotuneState.STATE_SUCCEEDED
|
PIDAutotuneState.STATE_RELAY_STEP_DOWN,
|
||||||
or self._state == PIDAutotuneState.STATE_FAILED):
|
PIDAutotuneState.STATE_RELAY_STEP_UP,
|
||||||
|
}:
|
||||||
self._state = PIDAutotuneState.STATE_RELAY_STEP_UP
|
self._state = PIDAutotuneState.STATE_RELAY_STEP_UP
|
||||||
|
|
||||||
self._last_run_timestamp = now
|
self._last_run_timestamp = now
|
||||||
|
|
||||||
# check input and change relay state if necessary
|
# check input and change relay state if necessary
|
||||||
if (self._state == PIDAutotuneState.STATE_RELAY_STEP_UP
|
if self._state == PIDAutotuneState.STATE_RELAY_STEP_UP
|
||||||
and input_val > self._setpoint + self._noiseband):
|
and input_val > self._setpoint + self._noiseband:
|
||||||
self._state = PIDAutotuneState.STATE_RELAY_STEP_DOWN
|
self._state = PIDAutotuneState.STATE_RELAY_STEP_DOWN
|
||||||
logging.debug('switched state: {0}'.format(self._state))
|
logging.debug('switched state: {0}'.format(self._state))
|
||||||
logging.debug('input: {0}'.format(input_val))
|
logging.debug('input: {0}'.format(input_val))
|
||||||
elif (self._state == PIDAutotuneState.STATE_RELAY_STEP_DOWN
|
elif self._state == PIDAutotuneState.STATE_RELAY_STEP_DOWN
|
||||||
and input_val < self._setpoint - self._noiseband):
|
and input_val < self._setpoint - self._noiseband:
|
||||||
self._state = PIDAutotuneState.STATE_RELAY_STEP_UP
|
self._state = PIDAutotuneState.STATE_RELAY_STEP_UP
|
||||||
esavkin
commented
Isn't there a way to shorten it? Isn't there a way to shorten it?
atse
commented
Yep, did it in the latest force-push to Yep, did it in the latest force-push to 828648ed76.
esavkin
commented
Wouldn't the negative logic be applicable here? Like Wouldn't the negative logic be applicable here? Like `not in (STEP_UP, STEP_DOWN)`.
atse
commented
Humm, that's true. Was worried about Humm, that's true. Was worried about `self._state` being set to a non-`PIDAutotuneState` value, but that shouldn't happen under normal circumstances.
atse
commented
Done in force-push to Done in force-push to f4c1dab00f.
|
|||||||
logging.debug('switched state: {0}'.format(self._state))
|
logging.debug('switched state: {0}'.format(self._state))
|
||||||
logging.debug('input: {0}'.format(input_val))
|
logging.debug('input: {0}'.format(input_val))
|
||||||
|
|
||||||
# set output
|
# set output
|
||||||
if (self._state == PIDAutotuneState.STATE_RELAY_STEP_UP):
|
if self._state == PIDAutotuneState.STATE_RELAY_STEP_UP:
|
||||||
self._output = self._initial_output - self._outputstep
|
self._output = self._initial_output - self._outputstep
|
||||||
elif self._state == PIDAutotuneState.STATE_RELAY_STEP_DOWN:
|
elif self._state == PIDAutotuneState.STATE_RELAY_STEP_DOWN:
|
||||||
self._output = self._initial_output + self._outputstep
|
self._output = self._initial_output + self._outputstep
|
||||||
|
Loading…
Reference in New Issue
Block a user
Inconsistent string delimiter.
Can't it just use
auto()
anyway?Actually yes, switched to
auto()
in force-push to828648ed76
.Then I believe #71 would be unnecessary since the string values aren't used anywhere.
Also just realised this highlights the verbosity of the
STATE_
prefix.Refactored in force-push to
869922c928
.