From 4ad580667d472b9df300d7d02c20d7e641e287a2 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Fri, 2 Sep 2022 14:36:33 +0200 Subject: [PATCH] Bump version to v0.1.10 (#14) * Bump version to v0.1.10 * Correct device connector * Fix tests * Filter connector name updates --- custom_components/elro_connects/__init__.py | 7 ++++--- custom_components/elro_connects/device.py | 12 +++++++----- tests/test_init.py | 6 ++++-- version | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/custom_components/elro_connects/__init__.py b/custom_components/elro_connects/__init__.py index 3f13d54..bc8aa4a 100644 --- a/custom_components/elro_connects/__init__.py +++ b/custom_components/elro_connects/__init__.py @@ -6,7 +6,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant -from homeassistant.helpers.device_registry import DeviceEntry +from homeassistant.helpers.device_registry import DeviceEntry, format_mac from .const import DOMAIN from .device import ElroConnectsK1 @@ -50,9 +50,10 @@ async def async_remove_config_entry_device( """Allow manual removal of a device if not in use.""" elro_connects_api: ElroConnectsK1 = hass.data[DOMAIN][entry.entry_id] device_unique_id: str = device_entry.identifiers.copy().pop()[1] - device_id_str = device_unique_id[len(elro_connects_api.connector_id) + 1 :] - if not device_id_str: + mac_address = format_mac(elro_connects_api.connector_id[3:]) + if mac_address == device_unique_id: return False + device_id_str = device_unique_id[len(elro_connects_api.connector_id) + 1 :] device_id = int(device_id_str) # Do not remove if the device_id is in the connector_data if ( diff --git a/custom_components/elro_connects/device.py b/custom_components/elro_connects/device.py index eccd2be..f8503c3 100644 --- a/custom_components/elro_connects/device.py +++ b/custom_components/elro_connects/device.py @@ -138,10 +138,14 @@ async def _async_device_updated(self, event: Event) -> None: device_registry = dr.async_get(self.hass) device_entry = device_registry.async_get(event.data["device_id"]) device_unique_id: str = device_entry.identifiers.copy().pop()[1] - device_id_str = device_unique_id[len(self.connector_id) + 1 :] - if self._entry.entry_id not in device_entry.config_entries or not device_id_str: + mac_address = format_mac(self.connector_id[3:]) + if ( + (dr.CONNECTION_NETWORK_MAC, mac_address) in device_entry.identifiers + or self._entry.entry_id not in device_entry.config_entries + ): # Not a valid device name or not a related entry return + device_id_str = device_unique_id[len(self.connector_id) + 1 :] device_id = int(device_id_str) if not self.connector_data or device_id not in self.connector_data: # the device is not in the connector data hence we cannot update it @@ -219,7 +223,6 @@ def __init__( """Initialize the Elro connects entity.""" super().__init__(elro_connects_api) - # TODO: Initiƫle data can de coordinator is nog niet beschikbaar op dit punt self.data: dict = elro_connects_api.connector_data[device_id] self._connector_id = elro_connects_api.connector_id @@ -255,7 +258,6 @@ def device_info(self) -> DeviceInfo: model="K1 (SF40GA)", config_entry_id=self._entry.entry_id, identifiers={ - (DOMAIN, self._connector_id), (dr.CONNECTION_NETWORK_MAC, mac_address), }, manufacturer="Elro", @@ -271,6 +273,6 @@ def device_info(self) -> DeviceInfo: else device_type, name=self.name, # Link to K1 connector - via_device=(DOMAIN, self._connector_id), + via_device=(dr.CONNECTION_NETWORK_MAC, mac_address), ) return device_info diff --git a/tests/test_init.py b/tests/test_init.py index 9fc65e6..da537a2 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -13,6 +13,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr +from homeassistant.helpers.device_registry import format_mac from homeassistant.setup import async_setup_component from homeassistant.util import dt @@ -173,8 +174,9 @@ async def test_remove_device_from_config_entry( assert not await async_remove_config_entry_device(hass, mock_entry, device_entry) # Test removing the the K1 connector device will not work + mac_address = format_mac(connector_id[3:]) device_entry = device_registry.async_get_device( - identifiers={(DOMAIN, f"{connector_id}")} + identifiers={(dr.CONNECTION_NETWORK_MAC, mac_address)} ) assert device_entry assert not await async_remove_config_entry_device(hass, mock_entry, device_entry) @@ -258,7 +260,7 @@ async def test_update_device_name( # update the K1 connector name device_entry = device_registry.async_get_device( - identifiers={(DOMAIN, f"{connector_id}")} + identifiers={(dr.CONNECTION_NETWORK_MAC, f"{format_mac(connector_id[3:])}")} ) assert device_entry mock_k1_connector["result"].reset_mock() diff --git a/version b/version index 82551ad..345f8cc 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.1.9 \ No newline at end of file +0.1.10 \ No newline at end of file