mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Fix Arve availability on failed updates (#185494)
This commit is contained in:
@@ -42,10 +42,9 @@ class ArveDeviceEntity(CoordinatorEntity[ArveCoordinator]):
|
||||
|
||||
@property
|
||||
@override
|
||||
# pylint: disable-next=home-assistant-coordinator-entity-available
|
||||
def available(self) -> bool:
|
||||
"""Check if device is available."""
|
||||
return super()._attr_available and (
|
||||
return super().available and (
|
||||
self.device_serial_number in self.coordinator.data
|
||||
)
|
||||
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
"""Test for Arve sensors."""
|
||||
|
||||
from datetime import timedelta
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from asyncarve import ArveConnectionError
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.const import STATE_UNAVAILABLE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import async_init_integration
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
||||
SENSORS = (
|
||||
"air_quality_index",
|
||||
@@ -41,3 +45,35 @@ async def test_sensors(
|
||||
assert entry
|
||||
assert entry.device_id
|
||||
assert entry == snapshot(name=f"entry_{sensor}")
|
||||
|
||||
|
||||
async def test_sensor_unavailable_on_update_failure(
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_arve: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test the sensor becomes unavailable when the update fails."""
|
||||
entity_id = "sensor.test_sensor_temperature"
|
||||
await async_init_integration(hass, mock_config_entry)
|
||||
|
||||
assert (state := hass.states.get(entity_id))
|
||||
assert state.state == "26.02"
|
||||
|
||||
mock_arve.get_devices.side_effect = ArveConnectionError
|
||||
|
||||
freezer.tick(timedelta(seconds=60))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
assert (state := hass.states.get(entity_id))
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
mock_arve.get_devices.side_effect = None
|
||||
|
||||
freezer.tick(timedelta(seconds=60))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
assert (state := hass.states.get(entity_id))
|
||||
assert state.state == "26.02"
|
||||
|
||||
Reference in New Issue
Block a user