Mark entities as unavailable when they don't have a value in Husqvarna Automower (#148563)

This commit is contained in:
Thomas55555 2025-07-18 12:49:50 +02:00 committed by GitHub
parent 75c803e376
commit ec544b0430
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View File

@ -541,6 +541,11 @@ class AutomowerSensorEntity(AutomowerBaseEntity, SensorEntity):
"""Return the state attributes."""
return self.entity_description.extra_state_attributes_fn(self.mower_attributes)
@property
def available(self) -> bool:
"""Return the available attribute of the entity."""
return super().available and self.native_value is not None
class WorkAreaSensorEntity(WorkAreaAvailableEntity, SensorEntity):
"""Defining the Work area sensors with WorkAreaSensorEntityDescription."""

View File

@ -10,7 +10,7 @@ import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.husqvarna_automower.coordinator import SCAN_INTERVAL
from homeassistant.const import STATE_UNKNOWN, Platform
from homeassistant.const import STATE_UNAVAILABLE, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
@ -39,7 +39,7 @@ async def test_sensor_unknown_states(
async_fire_time_changed(hass)
await hass.async_block_till_done()
state = hass.states.get("sensor.test_mower_1_mode")
assert state.state == STATE_UNKNOWN
assert state.state == STATE_UNAVAILABLE
async def test_cutting_blade_usage_time_sensor(
@ -78,7 +78,7 @@ async def test_next_start_sensor(
async_fire_time_changed(hass)
await hass.async_block_till_done()
state = hass.states.get("sensor.test_mower_1_next_start")
assert state.state == STATE_UNKNOWN
assert state.state == STATE_UNAVAILABLE
async def test_work_area_sensor(