diff --git a/homeassistant/components/velbus/entity.py b/homeassistant/components/velbus/entity.py index aa221b3ca10..dcf6b65c80c 100644 --- a/homeassistant/components/velbus/entity.py +++ b/homeassistant/components/velbus/entity.py @@ -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]], diff --git a/homeassistant/components/velbus/quality_scale.yaml b/homeassistant/components/velbus/quality_scale.yaml index 81907f50c35..85bd351ff80 100644 --- a/homeassistant/components/velbus/quality_scale.yaml +++ b/homeassistant/components/velbus/quality_scale.yaml @@ -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 diff --git a/tests/components/velbus/snapshots/test_switch.ambr b/tests/components/velbus/snapshots/test_switch.ambr index 7eb886cdd7b..25551ed9071 100644 --- a/tests/components/velbus/snapshots/test_switch.ambr +++ b/tests/components/velbus/snapshots/test_switch.ambr @@ -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': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'switch', + 'entity_category': None, + 'entity_id': 'switch.living_room_relayname', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + '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': , + 'entity_id': 'switch.living_room_relayname', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unavailable', + }) +# --- diff --git a/tests/components/velbus/test_switch.py b/tests/components/velbus/test_switch.py index ebb1da084c4..ab8127557b3 100644 --- a/tests/components/velbus/test_switch.py +++ b/tests/components/velbus/test_switch.py @@ -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,