Skip to content

Commit ec544b0

Browse files
authored
Mark entities as unavailable when they don't have a value in Husqvarna Automower (home-assistant#148563)
1 parent 75c803e commit ec544b0

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

homeassistant/components/husqvarna_automower/sensor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,11 @@ def extra_state_attributes(self) -> Mapping[str, Any] | None:
541541
"""Return the state attributes."""
542542
return self.entity_description.extra_state_attributes_fn(self.mower_attributes)
543543

544+
@property
545+
def available(self) -> bool:
546+
"""Return the available attribute of the entity."""
547+
return super().available and self.native_value is not None
548+
544549

545550
class WorkAreaSensorEntity(WorkAreaAvailableEntity, SensorEntity):
546551
"""Defining the Work area sensors with WorkAreaSensorEntityDescription."""

tests/components/husqvarna_automower/test_sensor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from syrupy.assertion import SnapshotAssertion
1111

1212
from homeassistant.components.husqvarna_automower.coordinator import SCAN_INTERVAL
13-
from homeassistant.const import STATE_UNKNOWN, Platform
13+
from homeassistant.const import STATE_UNAVAILABLE, Platform
1414
from homeassistant.core import HomeAssistant
1515
from homeassistant.helpers import entity_registry as er
1616

@@ -39,7 +39,7 @@ async def test_sensor_unknown_states(
3939
async_fire_time_changed(hass)
4040
await hass.async_block_till_done()
4141
state = hass.states.get("sensor.test_mower_1_mode")
42-
assert state.state == STATE_UNKNOWN
42+
assert state.state == STATE_UNAVAILABLE
4343

4444

4545
async def test_cutting_blade_usage_time_sensor(
@@ -78,7 +78,7 @@ async def test_next_start_sensor(
7878
async_fire_time_changed(hass)
7979
await hass.async_block_till_done()
8080
state = hass.states.get("sensor.test_mower_1_next_start")
81-
assert state.state == STATE_UNKNOWN
81+
assert state.state == STATE_UNAVAILABLE
8282

8383

8484
async def test_work_area_sensor(

0 commit comments

Comments
 (0)