Switchbot Cloud: Fix device type filtering in sensor (#146945)

* Add Smart Lock Ultra support and fix device type filtering in sensor integration

* Adding fix in binary sensor

* Fix

---------

Co-authored-by: Joostlek <joostlek@outlook.com>
This commit is contained in:
Ravaka Razafimanantsoa
2025-06-22 14:12:09 +02:00
committed by GitHub
co-authored by Joostlek
parent 8cead00bc7
commit daa4ddabfe
4 changed files with 67 additions and 0 deletions
@@ -0,0 +1,39 @@
"""Test for the switchbot_cloud binary sensors."""
from unittest.mock import patch
from switchbot_api import Device
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from . import configure_integration
async def test_unsupported_device_type(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_list_devices,
mock_get_status,
) -> None:
"""Test that unsupported device types do not create sensors."""
mock_list_devices.return_value = [
Device(
version="V1.0",
deviceId="unsupported-id-1",
deviceName="unsupported-device",
deviceType="UnsupportedDevice",
hubDeviceId="test-hub-id",
),
]
mock_get_status.return_value = {}
with patch(
"homeassistant.components.switchbot_cloud.PLATFORMS", [Platform.BINARY_SENSOR]
):
entry = await configure_integration(hass)
# Assert no binary sensor entities were created for unsupported device type
entities = er.async_entries_for_config_entry(entity_registry, entry.entry_id)
assert len([e for e in entities if e.domain == "binary_sensor"]) == 0
@@ -67,3 +67,29 @@ async def test_meter_no_coordinator_data(
entry = await configure_integration(hass)
await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)
async def test_unsupported_device_type(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_list_devices,
mock_get_status,
) -> None:
"""Test that unsupported device types do not create sensors."""
mock_list_devices.return_value = [
Device(
version="V1.0",
deviceId="unsupported-id-1",
deviceName="unsupported-device",
deviceType="UnsupportedDevice",
hubDeviceId="test-hub-id",
),
]
mock_get_status.return_value = {}
with patch("homeassistant.components.switchbot_cloud.PLATFORMS", [Platform.SENSOR]):
entry = await configure_integration(hass)
# Assert no sensor entities were created for unsupported device type
entities = er.async_entries_for_config_entry(entity_registry, entry.entry_id)
assert len([e for e in entities if e.domain == "sensor"]) == 0