Skip to content

Commit 6edfb67

Browse files
committed
Add Ke of PID at restore and to set_pid_gain service.
1 parent 2e5a711 commit 6edfb67

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

custom_components/smart_thermostat/climate.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,9 @@ def _async_startup(event):
417417
if old_state.attributes.get('Kd') is not None and self._pidController is not None:
418418
self._kd = float(old_state.attributes.get('Kd'))
419419
self._pidController.set_pid_param(kd=self._kd)
420-
if old_state.attributes.get('Ke') is not None:
420+
if old_state.attributes.get('Ke') is not None and self._pidController is not None:
421421
self._ke = float(old_state.attributes.get('Ke'))
422+
self._pidController.set_pid_param(ke=self._ke)
422423
if old_state.attributes.get('pid_mode') is not None and self._pidController is not None:
423424
self._pidController.mode = old_state.attributes.get('pid_mode')
424425

@@ -668,7 +669,7 @@ async def async_set_pid(self, **kwargs):
668669
self._kd = float(kd)
669670
if ke is not None:
670671
self._ke = float(ke)
671-
self._pidController.set_pid_param(self._kp, self._ki, self._kd)
672+
self._pidController.set_pid_param(self._kp, self._ki, self._kd, self._ke)
672673
await self._async_control_heating(calc_pid=True)
673674

674675
async def async_set_pid_mode(self, **kwargs):

custom_components/smart_thermostat/pid_controller/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,16 @@ def integral(self, i):
8989
self._integral = i
9090
self.I = i
9191

92-
def set_pid_param(self, kp=None, ki=None, kd=None):
92+
def set_pid_param(self, kp=None, ki=None, kd=None, ke=None):
9393
"""Set PID parameters."""
9494
if kp is not None and isinstance(kp, (int, float)):
9595
self._Kp = kp
9696
if ki is not None and isinstance(ki, (int, float)):
9797
self._Ki = ki
9898
if kd is not None and isinstance(kd, (int, float)):
9999
self._Kd = kd
100+
if ke is not None and isinstance(ke, (int, float)):
101+
self._Ke = ke
100102

101103
def clear_samples(self):
102104
"""Clear the samples values and timestamp to restart PID from clean state after

0 commit comments

Comments
 (0)