mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Mark entities as unavailable when they don't have a value in Husqvarna Automower (#148563)
This commit is contained in:
parent
75c803e376
commit
ec544b0430
@ -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."""
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user