Mark FGLAir entities unavailable if they are reporting to be offline (#135202)
parent
246a9f95a3
commit
9388879b78
|
@ -48,10 +48,16 @@ class FGLairCoordinator(DataUpdateCoordinator[dict[str, FujitsuHVAC]]):
|
||||||
raise ConfigEntryAuthFailed("Credentials expired for Ayla IoT API") from e
|
raise ConfigEntryAuthFailed("Credentials expired for Ayla IoT API") from e
|
||||||
|
|
||||||
if not listening_entities:
|
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:
|
else:
|
||||||
devices = [
|
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:
|
try:
|
||||||
|
|
|
@ -27,6 +27,11 @@ class FGLairEntity(CoordinatorEntity[FGLairCoordinator]):
|
||||||
sw_version=device.property_values["mcu_firmware_version"],
|
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
|
@property
|
||||||
def device(self) -> FujitsuHVAC:
|
def device(self) -> FujitsuHVAC:
|
||||||
"""Return the device object from the coordinator data."""
|
"""Return the device object from the coordinator data."""
|
||||||
|
|
|
@ -7,6 +7,7 @@ from ayla_iot_unofficial.fujitsu_consts import FGLAIR_APP_CREDENTIALS
|
||||||
from freezegun.api import FrozenDateTimeFactory
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.components.climate import HVACMode
|
||||||
from homeassistant.components.fujitsu_fglair.const import (
|
from homeassistant.components.fujitsu_fglair.const import (
|
||||||
API_REFRESH,
|
API_REFRESH,
|
||||||
API_TIMEOUT,
|
API_TIMEOUT,
|
||||||
|
@ -124,6 +125,26 @@ async def test_device_auth_failure(
|
||||||
assert hass.states.get(entity_id(mock_devices[1])).state == STATE_UNAVAILABLE
|
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(
|
async def test_token_expired(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_ayla_api: AsyncMock,
|
mock_ayla_api: AsyncMock,
|
||||||
|
|
Loading…
Reference in New Issue