Skip to content

Commit

Permalink
Merge pull request #69 from mvdwetering/fix_connection_link_by_mac
Browse files Browse the repository at this point in the history
Fix connection by mac feature
  • Loading branch information
mvdwetering authored Sep 21, 2023
2 parents 4c7fd6e + f316090 commit 3fc7225
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions custom_components/huesyncbox/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC

from .const import DOMAIN, LOGGER, MANUFACTURER_NAME

Expand All @@ -23,6 +24,9 @@ async def update_device_registry(
name=api.device.name,
model=api.device.device_type,
sw_version=api.device.firmware_version,
# Uniqueid seems to be the mac. Adding the connection allows other integrations
# like e.g. Mikrotik Router to link their entities to this device
connections={(CONNECTION_NETWORK_MAC, api.device.unique_id)},
)


Expand Down
17 changes: 16 additions & 1 deletion tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,28 @@
CONF_PORT,
CONF_UNIQUE_ID,
)
from homeassistant.helpers import entity_registry, issue_registry
from homeassistant.helpers import entity_registry, issue_registry, device_registry


from pytest_homeassistant_custom_component.common import MockConfigEntry # type: ignore

from .conftest import setup_integration


async def test_device_info(hass: HomeAssistant, mock_api):
integration = await setup_integration(hass, mock_api)

dr = device_registry.async_get(hass)
device = dr.async_get_device(identifiers={(huesyncbox.DOMAIN, "unique_id")})

assert device is not None
assert device.name == "Name"
assert device.manufacturer == "Signify"
assert device.model == "HSB1"
assert device.sw_version == "firmwareversion"
assert device.connections == {("mac", "unique_id")}


async def test_handle_authentication_error_during_setup(hass: HomeAssistant, mock_api):
mock_api.initialize.side_effect = aiohuesyncbox.Unauthorized
integration = await setup_integration(hass, mock_api)
Expand Down

0 comments on commit 3fc7225

Please sign in to comment.