Skip to content

Commit

Permalink
Bump version to v0.1.10 (#14)
Browse files Browse the repository at this point in the history
* Bump version to v0.1.10

* Correct device connector

* Fix tests

* Filter connector name updates
  • Loading branch information
jbouwh authored Sep 2, 2022
1 parent ef87f63 commit 4ad5806
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
7 changes: 4 additions & 3 deletions custom_components/elro_connects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down
12 changes: 7 additions & 5 deletions custom_components/elro_connects/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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
6 changes: 4 additions & 2 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.9
0.1.10

0 comments on commit 4ad5806

Please sign in to comment.