mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Log availability of devices in devolo Home Control (#147091)
This commit is contained in:
parent
8f24ebe967
commit
79683c8267
@ -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(
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user