Emit warning when current/voltage limits are near zero #76

Merged
sb10q merged 1 commits from esavkin/thermostat:72-warning-on-zeroed-limits into master 2023-03-23 17:01:29 +08:00
1 changed files with 9 additions and 0 deletions
Showing only changes of commit e3e3237d2f - Show all commits

View File

@ -1,5 +1,6 @@
import socket import socket
import json import json
import logging
class CommandError(Exception): class CommandError(Exception):
pass pass
@ -8,6 +9,14 @@ class Client:
def __init__(self, host="192.168.1.26", port=23, timeout=None): def __init__(self, host="192.168.1.26", port=23, timeout=None):
self._socket = socket.create_connection((host, port), timeout) self._socket = socket.create_connection((host, port), timeout)
self._lines = [""] self._lines = [""]
self._check_zero_limits()
def _check_zero_limits(self):
pwm_report = self.get_pwm()
for pwm_channel in pwm_report:
for limit in ["max_i_neg", "max_i_pos", "max_v"]:
if pwm_channel[limit]["value"] == 0.0:
logging.warning("`{}` limit is set to zero on channel {}".format(limit, pwm_channel["channel"]))
Outdated
Review

rel_tol is not the correct one to use here. Please read the Python manual carefully or just write the formula explicitly, I don't think there's much of a point to math.isclose.

Did you even test this?

>>> isclose(0.00000000000000001, 0.0, rel_tol=1e-6)
False
``rel_tol`` is not the correct one to use here. Please read the Python manual carefully or just write the formula explicitly, I don't think there's much of a point to ``math.isclose``. Did you even test this? ``` >>> isclose(0.00000000000000001, 0.0, rel_tol=1e-6) False ```
Outdated
Review

Isn't just == 0.0 sufficient for the purpose explained in the Issue?

Isn't just ``== 0.0`` sufficient for the purpose explained in the Issue?

Looks like it's quite safe to do so

Looks like it's quite safe to do so
Outdated
Review

on channel

on channel
def _read_line(self): def _read_line(self):
# read more lines # read more lines