Add digital loggers as a Belkin supported brand (#72515)

This commit is contained in:
Robert Hillis 2022-06-22 16:38:45 -04:00 committed by GitHub
parent a8a033681f
commit 5c5fd746fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 3 deletions

View file

@ -14,5 +14,8 @@
},
"codeowners": ["@esev"],
"iot_class": "local_push",
"loggers": ["pywemo"]
"loggers": ["pywemo"],
"supported_brands": {
"digital_loggers": "Digital Loggers"
}
}

View file

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

View file

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

View file

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