mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
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:
parent
8cead00bc7
commit
daa4ddabfe
@ -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
|
||||
)
|
||||
|
||||
|
||||
|
@ -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
|
||||
)
|
||||
|
||||
|
||||
|
39
tests/components/switchbot_cloud/test_binary_sensor.py
Normal file
39
tests/components/switchbot_cloud/test_binary_sensor.py
Normal 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
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user