Handle smarttub sensor values being None (#103385)

* [smarttub] handle sensor values being None

* empty commit to rerun CI

* lint

* use const in test

* reorder checks

* use None instead of STATE_UNKNOWN

* empty commit to rerun CI

* check for STATE_UNKNOWN in test

* empty commit to rerun CI
This commit is contained in:
Matt Zimmerman 2023-11-05 19:11:50 -08:00 committed by GitHub
parent f6cb7e1bc5
commit fd3d615c0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 4 deletions

View File

@ -7,5 +7,5 @@
"iot_class": "cloud_polling",
"loggers": ["smarttub"],
"quality_scale": "platinum",
"requirements": ["python-smarttub==0.0.33"]
"requirements": ["python-smarttub==0.0.35"]
}

View File

@ -89,10 +89,14 @@ class SmartTubSensor(SmartTubSensorBase, SensorEntity):
"""Generic class for SmartTub status sensors."""
@property
def native_value(self) -> str:
def native_value(self) -> str | None:
"""Return the current state of the sensor."""
if self._state is None:
return None
if isinstance(self._state, Enum):
return self._state.name.lower()
return self._state.lower()

View File

@ -2190,7 +2190,7 @@ python-ripple-api==0.0.3
python-roborock==0.35.0
# homeassistant.components.smarttub
python-smarttub==0.0.33
python-smarttub==0.0.35
# homeassistant.components.songpal
python-songpal==0.15.2

View File

@ -1634,7 +1634,7 @@ python-qbittorrent==0.4.3
python-roborock==0.35.0
# homeassistant.components.smarttub
python-smarttub==0.0.33
python-smarttub==0.0.35
# homeassistant.components.songpal
python-songpal==0.15.2

View File

@ -2,6 +2,7 @@
import pytest
import smarttub
from homeassistant.const import STATE_UNKNOWN
from homeassistant.core import HomeAssistant
@ -27,6 +28,27 @@ async def test_sensor(
assert state.state == expected_state
# https://github.com/home-assistant/core/issues/102339
async def test_null_blowoutcycle(
spa,
spa_state,
config_entry,
hass: HomeAssistant,
) -> None:
"""Test blowoutCycle having null value."""
spa_state.blowout_cycle = None
config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
entity_id = f"sensor.{spa.brand}_{spa.model}_blowout_cycle"
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_UNKNOWN
async def test_primary_filtration(
spa, spa_state, setup_entry, hass: HomeAssistant
) -> None: