Skip to content

Commit

Permalink
added better edge case handling
Browse files Browse the repository at this point in the history
  • Loading branch information
natankeddem committed Sep 8, 2024
1 parent 05ee6dc commit 0cb2455
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions hush/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ async def _calc(self):
mqtt_sensor = Sensor(mqtt_sensor_settings)
mqtt_sensor.set_state(meas_temp)
temperatures[sensor] = meas_temp
if storage.algo_sensor(self._host, sensor)["type"] == "pid":
pid = Pid(self._host, sensor)
speed = round(-1 * pid.controller(meas_temp))
logger.debug(f"{control.hostname} Temperature={meas_temp} Speed={speed}")
else:
curve = Curve(self._host, sensor)
speed = curve.calc(meas_temp)
logger.debug(f"{control.hostname} Temperature={meas_temp} Speed={speed} Speeds={curve.speeds}")
if control is not None:
if storage.algo_sensor(self._host, sensor)["type"] == "pid":
pid = Pid(self._host, sensor)
speed = round(-1 * pid.controller(meas_temp))
logger.debug(f"{control.hostname} Temperature={meas_temp} Speed={speed}")
else:
curve = Curve(self._host, sensor)
speed = curve.calc(meas_temp)
logger.debug(f"{control.hostname} Temperature={meas_temp} Speed={speed} Speeds={curve.speeds}")
if speed is not None:
if isinstance(speed, str) is True:
current_speed = curve.speeds.index(speed)
Expand Down
2 changes: 1 addition & 1 deletion hush/hardware/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def driver(
host: str,
group: str,
) -> Optional[hardware.Device]:
name = storage.host(host)[group]
name = storage.host(host).get(group, "None")
if host not in cls.drivers:
cls.drivers[host] = {}
if group not in cls.drivers[host]:
Expand Down

0 comments on commit 0cb2455

Please sign in to comment.