Log availability of devices in devolo Home Control (#147091)

This commit is contained in:
Guido Schmitz 2025-07-04 22:59:38 +02:00 committed by GitHub
parent 8f24ebe967
commit 79683c8267
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 2 deletions

View File

@ -87,7 +87,22 @@ class DevoloDeviceEntity(Entity):
self._value = message[1]
elif len(message) == 3 and message[2] == "status":
# Maybe the API wants to tell us, that the device went on- or offline.
self._attr_available = self._device_instance.is_online()
state = self._device_instance.is_online()
if state != self.available and not state:
_LOGGER.info(
"Device %s is unavailable",
self._device_instance.settings_property[
"general_device_settings"
].name,
)
if state != self.available and state:
_LOGGER.info(
"Device %s is back online",
self._device_instance.settings_property[
"general_device_settings"
].name,
)
self._attr_available = state
elif message[1] == "del" and self.platform.config_entry:
device_registry = dr.async_get(self.hass)
device = device_registry.async_get_device(

View File

@ -2,6 +2,7 @@
from unittest.mock import patch
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
@ -20,7 +21,10 @@ from .mocks import HomeControlMock, HomeControlMockSwitch
async def test_switch(
hass: HomeAssistant, entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test setup and state change of a switch device."""
entry = configure_integration(hass)
@ -69,6 +73,14 @@ async def test_switch(
test_gateway.publisher.dispatch("Test", ("Status", False, "status"))
await hass.async_block_till_done()
assert hass.states.get(f"{SWITCH_DOMAIN}.test").state == STATE_UNAVAILABLE
assert "Device Test is unavailable" in caplog.text
# Emulate websocket message: device went back online
test_gateway.devices["Test"].status = 0
test_gateway.publisher.dispatch("Test", ("Status", False, "status"))
await hass.async_block_till_done()
assert hass.states.get(f"{SWITCH_DOMAIN}.test").state == STATE_ON
assert "Device Test is back online" in caplog.text
async def test_remove_from_hass(hass: HomeAssistant) -> None: