Mark FGLAir entities unavailable if they are reporting to be offline (#135202)

pull/135292/head
Antoine Reversat 2025-01-10 07:24:33 -05:00 committed by GitHub
parent 246a9f95a3
commit 9388879b78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 2 deletions

View File

@ -48,10 +48,16 @@ class FGLairCoordinator(DataUpdateCoordinator[dict[str, FujitsuHVAC]]):
raise ConfigEntryAuthFailed("Credentials expired for Ayla IoT API") from e
if not listening_entities:
devices = [dev for dev in devices if isinstance(dev, FujitsuHVAC)]
devices = [
dev
for dev in devices
if isinstance(dev, FujitsuHVAC) and dev.is_online()
]
else:
devices = [
dev for dev in devices if dev.device_serial_number in listening_entities
dev
for dev in devices
if dev.device_serial_number in listening_entities and dev.is_online()
]
try:

View File

@ -27,6 +27,11 @@ class FGLairEntity(CoordinatorEntity[FGLairCoordinator]):
sw_version=device.property_values["mcu_firmware_version"],
)
@property
def available(self) -> bool:
"""Return if entity is available."""
return super().available and self.coordinator_context in self.coordinator.data
@property
def device(self) -> FujitsuHVAC:
"""Return the device object from the coordinator data."""

View File

@ -7,6 +7,7 @@ from ayla_iot_unofficial.fujitsu_consts import FGLAIR_APP_CREDENTIALS
from freezegun.api import FrozenDateTimeFactory
import pytest
from homeassistant.components.climate import HVACMode
from homeassistant.components.fujitsu_fglair.const import (
API_REFRESH,
API_TIMEOUT,
@ -124,6 +125,26 @@ async def test_device_auth_failure(
assert hass.states.get(entity_id(mock_devices[1])).state == STATE_UNAVAILABLE
async def test_device_offline(
hass: HomeAssistant,
freezer: FrozenDateTimeFactory,
mock_ayla_api: AsyncMock,
mock_config_entry: MockConfigEntry,
mock_devices: list[AsyncMock],
) -> None:
"""Test entities become unavailable if device if offline."""
await setup_integration(hass, mock_config_entry)
mock_ayla_api.async_get_devices.return_value[0].is_online.return_value = False
freezer.tick(API_REFRESH)
async_fire_time_changed(hass)
await hass.async_block_till_done()
assert hass.states.get(entity_id(mock_devices[0])).state == STATE_UNAVAILABLE
assert hass.states.get(entity_id(mock_devices[1])).state == HVACMode.COOL
async def test_token_expired(
hass: HomeAssistant,
mock_ayla_api: AsyncMock,