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 21:12:09 +09:00 committed by GitHub
parent 8cead00bc7
commit daa4ddabfe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 67 additions and 0 deletions

View File

@ -69,6 +69,7 @@ async def async_setup_entry(
for description in BINARY_SENSOR_DESCRIPTIONS_BY_DEVICE_TYPES[
device.device_type
]
if device.device_type in BINARY_SENSOR_DESCRIPTIONS_BY_DEVICE_TYPES
)

View File

@ -151,6 +151,7 @@ async def async_setup_entry(
SwitchBotCloudSensor(data.api, device, coordinator, description)
for device, coordinator in data.devices.sensors
for description in SENSOR_DESCRIPTIONS_BY_DEVICE_TYPES[device.device_type]
if device.device_type in SENSOR_DESCRIPTIONS_BY_DEVICE_TYPES
)

View File

@ -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

View File

@ -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