1
0
mirror of https://github.com/home-assistant/core.git synced 2026-06-02 05:34:15 +01:00

Velbus mark entities unavailable when connection is terminated (#160143)

This commit is contained in:
Maikel Punie
2026-01-02 17:43:33 +01:00
committed by GitHub
parent dd98a85300
commit ebd6ae7e80
4 changed files with 71 additions and 2 deletions
@@ -69,6 +69,11 @@ class VelbusEntity(Entity):
"""Handle status updates from the channel."""
self.async_write_ha_state()
@property
def available(self) -> bool:
"""Return if entity is available."""
return self._channel.is_connected()
def api_call[_T: VelbusEntity, **_P](
func: Callable[Concatenate[_T, _P], Awaitable[None]],
@@ -21,13 +21,12 @@ rules:
test-before-configure: done
test-before-setup: done
unique-config-entry: done
# Silver
action-exceptions: done
config-entry-unloading: done
docs-configuration-parameters: done
docs-installation-parameters: done
entity-unavailable: todo
entity-unavailable: done
integration-owner: done
log-when-unavailable: done
parallel-updates: done
@@ -47,3 +47,51 @@
'state': 'on',
})
# ---
# name: test_switch_disabled[switch.living_room_relayname-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'switch',
'entity_category': None,
'entity_id': 'switch.living_room_relayname',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'RelayName',
'platform': 'velbus',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': 'qwerty123-55',
'unit_of_measurement': None,
})
# ---
# name: test_switch_disabled[switch.living_room_relayname-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Living room RelayName',
}),
'context': <ANY>,
'entity_id': 'switch.living_room_relayname',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'unavailable',
})
# ---
+17
View File
@@ -32,6 +32,23 @@ async def test_entities(
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
async def test_switch_disabled(
hass: HomeAssistant,
snapshot: SnapshotAssertion,
mock_relay: AsyncMock,
config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test disabled switch entity."""
# make sure the valbuasio channel is_connected method returns false
mock_relay.is_connected.return_value = False
with patch("homeassistant.components.velbus.PLATFORMS", [Platform.SWITCH]):
await init_integration(hass, config_entry)
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
async def test_switch_on_off(
hass: HomeAssistant,
mock_relay: AsyncMock,