Skip to content

Commit

Permalink
More forgiving of missing preset modes.
Browse files Browse the repository at this point in the history
Bit more error logging.
  • Loading branch information
JeffSteinbok committed Jul 19, 2023
1 parent b417c71 commit 854dba1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
10 changes: 8 additions & 2 deletions custom_components/dreo/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ def preset_modes(self) -> list[str]:
@property
def preset_mode(self) -> str | None:
"""Get the current preset mode."""
return self.device.preset_mode
if (self.device.supports_preset_modes):
return self.device.preset_mode
else:
return None

@property
def extra_state_attributes(self) -> dict[str, Any]:
Expand All @@ -94,7 +97,10 @@ def extra_state_attributes(self) -> dict[str, Any]:
@property
def supported_features(self) -> int:
"""Return the list of supported features."""
supported_features = FanEntityFeature.SET_SPEED | FanEntityFeature.PRESET_MODE
supported_features = FanEntityFeature.SET_SPEED

if (self.device.supports_preset_modes):
supported_features = supported_features | FanEntityFeature.PRESET_MODE
if (self.device.supports_oscillation):
supported_features = supported_features | FanEntityFeature.OSCILLATE

Expand Down
4 changes: 2 additions & 2 deletions custom_components/dreo/pydreo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DreoFanDetails:
"DR-HTF008S": DreoFanDetails(
preset_modes=[FAN_MODE_NORMAL, FAN_MODE_NATURAL, FAN_MODE_SLEEP, FAN_MODE_AUTO],
speed_range=(1, 5),
),
),
}

SUPPORTED_AIR_CIRCULATOR_FANS = {
Expand All @@ -53,5 +53,5 @@ class DreoFanDetails:
"DR-HAF004S": DreoFanDetails(
preset_modes=[FAN_MODE_NORMAL, FAN_MODE_NATURAL, FAN_MODE_SLEEP, FAN_MODE_AUTO, FAN_MODE_TURBO],
speed_range=(1, 9)
)
),
}
4 changes: 4 additions & 0 deletions custom_components/dreo/pydreo/pydreoaircirculatorfan.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def is_on(self):
"""Returns `True` if the device is on, `False` otherwise."""
return self._is_on

@property
def supports_preset_modes(self):
return self._wind_mode is not None

@property
def preset_mode(self):
return self._fan_definition.preset_modes[self._wind_mode - 1]
Expand Down
2 changes: 1 addition & 1 deletion custom_components/dreo/pydreo/pydreobasedevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def get_state_update_value(self, state: dict, key: str):
if (keyValObject is not None):
return keyValObject[STATE_KEY]

_LOGGER.debug("Expected state value {0} not present. Device: {1}".format(key, self.name))
_LOGGER.error("Expected state value ({0}) not present. Device: {1}".format(key, self.name))
return None

def update_state(self, state: dict):
Expand Down
4 changes: 4 additions & 0 deletions custom_components/dreo/pydreo/pydreofan.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def preset_mode(self):
def temperature(self):
return self._temperature

@property
def supports_preset_modes(self):
pass

@property
def supports_oscillation(self):
pass
Expand Down
4 changes: 4 additions & 0 deletions custom_components/dreo/pydreo/pydreotowerfan.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def handle_server_update(self, message: dict):
valShakeHorizon = self.get_server_update_key_value(message, SHAKEHORIZON_KEY)
if (isinstance(valShakeHorizon, bool)):
self._oscillating = valShakeHorizon

@property
def supports_preset_modes(self):
return self._windType is not None

@property
def preset_mode(self):
Expand Down

0 comments on commit 854dba1

Please sign in to comment.