Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add None guard for zwave_js humidifier entity #69667

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions homeassistant/components/zwave_js/humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,9 @@ def __init__(
@property
def is_on(self) -> bool | None:
"""Return True if entity is on."""
return int(self._current_mode.value) in [
self.entity_description.on_mode,
HumidityControlMode.AUTO,
]
if (value := self._current_mode.value) is None:
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved
return None
return int(value) in [self.entity_description.on_mode, HumidityControlMode.AUTO]

def _supports_inverse_mode(self) -> bool:
return (
Expand All @@ -163,7 +162,9 @@ def _supports_inverse_mode(self) -> bool:

async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on device."""
mode = int(self._current_mode.value)
if (value := self._current_mode.value) is None:
return
mode = int(value)
if mode == HumidityControlMode.OFF:
new_mode = self.entity_description.on_mode
elif mode == self.entity_description.inverse_mode:
Expand All @@ -175,7 +176,9 @@ async def async_turn_on(self, **kwargs: Any) -> None:

async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn off device."""
mode = int(self._current_mode.value)
if (value := self._current_mode.value) is None:
return
mode = int(value)
if mode == HumidityControlMode.AUTO:
if self._supports_inverse_mode():
new_mode = self.entity_description.inverse_mode
Expand All @@ -191,7 +194,7 @@ async def async_turn_off(self, **kwargs: Any) -> None:
@property
def target_humidity(self) -> int | None:
"""Return the humidity we try to reach."""
if not self._setpoint:
if not self._setpoint or self._setpoint.value is None:
return None
return int(self._setpoint.value)

Expand Down