Skip to content

Commit b176a8d

Browse files
Fix power-on key None guard in fan base class (#553)
When neither POWERON_KEY nor FANON_KEY is in the initial state, _power_on_key was set to None. This caused _send_command(None, value) in the is_on setter. Now preserves existing key or defaults to POWERON_KEY, and adds a guard in the setter. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e10f177 commit b176a8d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

custom_components/dreo/pydreo/pydreofanbase.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ def is_on(self):
127127
def is_on(self, value: bool):
128128
"""Set if the fan is on or off"""
129129
_LOGGER.debug("is_on: is_on.setter - %s", value)
130+
if self._power_on_key is None:
131+
_LOGGER.error("is_on: Cannot set power state — power on key is unknown")
132+
return
130133
self._send_command(self._power_on_key, value)
131134

132135
@property
@@ -346,7 +349,9 @@ def update_state(self, state: dict):
346349
self._power_on_key = FANON_KEY
347350
else:
348351
_LOGGER.error("update_state: Unable to get power on state from state. Check debug logs for more information.")
349-
self._power_on_key = None
352+
# Default to POWERON_KEY so is_on setter doesn't send None key
353+
if self._power_on_key is None:
354+
self._power_on_key = POWERON_KEY
350355

351356
self._fan_speed = self.get_state_update_value(state, WINDLEVEL_KEY)
352357
if self._fan_speed is None:

0 commit comments

Comments
 (0)