From 5c5fd746fd42f7e33271c3dbb0f12488297b7d0c Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Wed, 22 Jun 2022 16:38:45 -0400 Subject: [PATCH] Add digital loggers as a Belkin supported brand (#72515) --- homeassistant/components/wemo/manifest.json | 5 ++++- homeassistant/components/wemo/wemo_device.py | 15 +++++++++++++-- tests/components/wemo/conftest.py | 15 +++++++++++++++ tests/components/wemo/test_wemo_device.py | 9 +++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/wemo/manifest.json b/homeassistant/components/wemo/manifest.json index b324ba060ea..5486a192787 100644 --- a/homeassistant/components/wemo/manifest.json +++ b/homeassistant/components/wemo/manifest.json @@ -14,5 +14,8 @@ }, "codeowners": ["@esev"], "iot_class": "local_push", - "loggers": ["pywemo"] + "loggers": ["pywemo"], + "supported_brands": { + "digital_loggers": "Digital Loggers" + } } diff --git a/homeassistant/components/wemo/wemo_device.py b/homeassistant/components/wemo/wemo_device.py index 1f3e07881c8..826df24a108 100644 --- a/homeassistant/components/wemo/wemo_device.py +++ b/homeassistant/components/wemo/wemo_device.py @@ -9,6 +9,8 @@ from pywemo.subscribe import EVENT_TYPE_LONG_PRESS from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( + ATTR_CONFIGURATION_URL, + ATTR_IDENTIFIERS, CONF_DEVICE_ID, CONF_NAME, CONF_PARAMS, @@ -42,7 +44,7 @@ class DeviceCoordinator(DataUpdateCoordinator): self.hass = hass self.wemo = wemo self.device_id = device_id - self.device_info = _device_info(wemo) + self.device_info = _create_device_info(wemo) self.supports_long_press = wemo.supports_long_press() self.update_lock = asyncio.Lock() @@ -124,6 +126,15 @@ class DeviceCoordinator(DataUpdateCoordinator): raise UpdateFailed("WeMo update failed") from err +def _create_device_info(wemo: WeMoDevice) -> DeviceInfo: + """Create device information. Modify if special device.""" + _dev_info = _device_info(wemo) + if wemo.model_name == "DLI emulated Belkin Socket": + _dev_info[ATTR_CONFIGURATION_URL] = f"http://{wemo.host}" + _dev_info[ATTR_IDENTIFIERS] = {(DOMAIN, wemo.serialnumber[:-1])} + return _dev_info + + def _device_info(wemo: WeMoDevice) -> DeviceInfo: return DeviceInfo( connections={(CONNECTION_UPNP, wemo.udn)}, @@ -144,7 +155,7 @@ async def async_register_device( device_registry = async_get_device_registry(hass) entry = device_registry.async_get_or_create( - config_entry_id=config_entry.entry_id, **_device_info(wemo) + config_entry_id=config_entry.entry_id, **_create_device_info(wemo) ) device = DeviceCoordinator(hass, wemo, entry.id) diff --git a/tests/components/wemo/conftest.py b/tests/components/wemo/conftest.py index 1a5998c1f94..6dc7b1e5d2c 100644 --- a/tests/components/wemo/conftest.py +++ b/tests/components/wemo/conftest.py @@ -97,6 +97,15 @@ def pywemo_device_fixture(pywemo_registry, pywemo_model): yield pywemo_device +@pytest.fixture(name="pywemo_dli_device") +def pywemo_dli_device_fixture(pywemo_registry, pywemo_model): + """Fixture for Digital Loggers emulated instances.""" + with create_pywemo_device(pywemo_registry, pywemo_model) as pywemo_dli_device: + pywemo_dli_device.model_name = "DLI emulated Belkin Socket" + pywemo_dli_device.serialnumber = "1234567891" + yield pywemo_dli_device + + @pytest.fixture(name="wemo_entity_suffix") def wemo_entity_suffix_fixture(): """Fixture to select a specific entity for wemo_entity.""" @@ -129,3 +138,9 @@ async def async_create_wemo_entity(hass, pywemo_device, wemo_entity_suffix): async def async_wemo_entity_fixture(hass, pywemo_device, wemo_entity_suffix): """Fixture for a Wemo entity in hass.""" return await async_create_wemo_entity(hass, pywemo_device, wemo_entity_suffix) + + +@pytest.fixture(name="wemo_dli_entity") +async def async_wemo_dli_entity_fixture(hass, pywemo_dli_device, wemo_entity_suffix): + """Fixture for a Wemo entity in hass.""" + return await async_create_wemo_entity(hass, pywemo_dli_device, wemo_entity_suffix) diff --git a/tests/components/wemo/test_wemo_device.py b/tests/components/wemo/test_wemo_device.py index 9bd3367aeee..a16efb173ae 100644 --- a/tests/components/wemo/test_wemo_device.py +++ b/tests/components/wemo/test_wemo_device.py @@ -168,6 +168,15 @@ async def test_device_info(hass, wemo_entity): assert device_entries[0].sw_version == MOCK_FIRMWARE_VERSION +async def test_dli_device_info(hass, wemo_dli_entity): + """Verify the DeviceInfo data for Digital Loggers emulated wemo device.""" + dr = device_registry.async_get(hass) + device_entries = list(dr.devices.values()) + + assert device_entries[0].configuration_url == "http://127.0.0.1" + assert device_entries[0].identifiers == {(DOMAIN, "123456789")} + + class TestInsight: """Tests specific to the WeMo Insight device."""