Skip to content

Commit 59ab0e6

Browse files
committed
Further fix for UniledDiscovery property errors
1 parent eeccca5 commit 59ab0e6

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

custom_components/uniled/config_flow.py

+23-20
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,15 @@ async def async_step_init(
241241
"""Manage the options."""
242242

243243
if self.config_entry.entry_id in self.hass.data[DOMAIN]:
244-
self.coordinator: UniledUpdateCoordinator = self.hass.data[DOMAIN][self.config_entry.entry_id]
244+
self.coordinator: UniledUpdateCoordinator = self.hass.data[DOMAIN][
245+
self.config_entry.entry_id
246+
]
245247
else:
246248
return self.async_abort(reason="unknown")
247249

248-
#self.coordinator: UniledUpdateCoordinator = self.hass.data[DOMAIN][
250+
# self.coordinator: UniledUpdateCoordinator = self.hass.data[DOMAIN][
249251
# self.config_entry.entry_id
250-
#]
252+
# ]
251253

252254
if self.config_entry.data.get(CONF_TRANSPORT) == UNILED_TRANSPORT_ZNG:
253255
self._mesh_set_context()
@@ -714,14 +716,14 @@ async def _async_set_discovered_mac(
714716
discovery since the dhcp mac can be one digit off from
715717
the udp discovery mac for devices with multiple network interfaces
716718
"""
717-
mac_address = device[ATTR_UL_MAC_ADDRESS]
719+
mac_address = device.mac_address # [ATTR_UL_MAC_ADDRESS]
718720
assert mac_address is not None
719721
# mac = UniledNetDevice.format_mac(mac_address)
720722
mac = dr.format_mac(mac_address)
721723
await self.async_set_unique_id(mac)
722724
for entry in self._async_current_entries(include_ignore=True):
723725
if not (
724-
entry.data.get(CONF_HOST) == device[ATTR_UL_IP_ADDRESS]
726+
entry.data.get(CONF_HOST) == device.ip_address # [ATTR_UL_IP_ADDRESS]
725727
or (
726728
entry.unique_id
727729
and ":" in entry.unique_id
@@ -754,33 +756,34 @@ async def _async_set_discovered_mac(
754756
_LOGGER.debug(
755757
"Discovered '%s' (id=%d, model=%s) from '%s' @ %s",
756758
async_name_from_discovery(device),
757-
device[ATTR_UL_MODEL_CODE],
758-
device[ATTR_UL_MODEL_NAME],
759-
device[ATTR_UL_SOURCE],
760-
device[ATTR_UL_IP_ADDRESS],
759+
device.model_code, # [ATTR_UL_MODEL_CODE],
760+
device.model_name, # [ATTR_UL_MODEL_NAME],
761+
device.source, # [ATTR_UL_SOURCE],
762+
device.ip_address, # [ATTR_UL_IP_ADDRESS],
761763
)
762764

763765
async def _async_network_discovery(self) -> FlowResult:
764766
"""Handle network discovery."""
765767
assert self._discovered_device is not None
766768
device = self._discovered_device
767769
await self._async_set_discovered_mac(device, self._allow_update_mac)
768-
host = device[ATTR_UL_IP_ADDRESS]
770+
host = device.ip_address # [ATTR_UL_IP_ADDRESS]
769771
for progress in self._async_in_progress():
770772
if progress.get("context", {}).get(CONF_HOST) == host:
771773
return self.async_abort(reason="already_in_progress")
772774

773-
if not device[ATTR_UL_MODEL_NAME]:
774-
mac_address = device[ATTR_UL_MAC_ADDRESS]
775+
if not device.model_name: # [ATTR_UL_MODEL_NAME]:
776+
mac_address = device.mac_address # [ATTR_UL_MAC_ADDRESS]
775777
assert mac_address is not None
776778
# mac = UniledNetDevice.format_mac(mac_address)
777779
mac = dr.format_mac(mac_address)
778780
try:
779781
device = await async_discover_device(self.hass, host)
780782
except Exception:
781783
return self.async_abort(reason="cannot_connect")
782-
discovered_mac = device[ATTR_UL_MAC_ADDRESS]
783-
if device[ATTR_UL_MODEL_NAME] or (
784+
discovered_mac = device.mac_address # [ATTR_UL_MAC_ADDRESS]
785+
# if device[ATTR_UL_MODEL_NAME] or (
786+
if device.model_name or (
784787
discovered_mac is not None
785788
and (
786789
# formatted_discovered_mac := UniledNetDevice.format_mac(
@@ -802,17 +805,17 @@ async def async_step_network_confirm(
802805
"""Confirm network discovery."""
803806
assert self._discovered_device is not None
804807
device = self._discovered_device
805-
mac_address = device[ATTR_UL_MAC_ADDRESS]
808+
mac_address = device.mac_address # [ATTR_UL_MAC_ADDRESS]
806809
assert mac_address is not None
807-
model = device[ATTR_UL_MODEL_NAME]
808-
code = device[ATTR_UL_MODEL_CODE]
809-
name = device[ATTR_UL_LOCAL_NAME]
810+
model = device.model_name # [ATTR_UL_MODEL_NAME]
811+
code = device.model_code # [ATTR_UL_MODEL_CODE]
812+
name = device.local_name # [ATTR_UL_LOCAL_NAME]
810813

811814
placeholders = {
812815
"name": async_name_from_discovery(device),
813816
"device_name": name or mac_address,
814817
"model": f"({model})" if model else f"ID#: {code}",
815-
"ip": device[ATTR_UL_IP_ADDRESS],
818+
"ip": device.ip_address, # [ATTR_UL_IP_ADDRESS],
816819
}
817820
self.context["title_placeholders"] = placeholders
818821

@@ -826,7 +829,7 @@ async def async_step_network_confirm(
826829
@callback
827830
def _async_network_create_entry(self, device: UniledDiscovery):
828831
"""Create network entry"""
829-
if device[ATTR_UL_MODEL_NAME] is None:
832+
if device.model_name is None: # [ATTR_UL_MODEL_NAME] is None:
830833
raise AbortFlow("not_supported")
831834
# data: dict[str, Any] = {CONF_TRANSPORT: UNILED_TRANSPORT_NET}
832835
data: dict[str, Any] = {}

custom_components/uniled/discovery.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ async def async_discover_devices(
186186
return [
187187
device
188188
for device in scanner.get_device_info()
189-
if device[ATTR_UL_IP_ADDRESS] == address
189+
if device.ip_address == address
190190
]
191191

192192

@@ -199,7 +199,7 @@ async def async_discover_device(
199199
for device in await async_discover_devices(
200200
hass, UNILED_DISCOVERY_DIRECTED_TIMEOUT, host
201201
):
202-
if device[ATTR_UL_IP_ADDRESS] == host:
202+
if device.ip_address == host:
203203
return device
204204
return None
205205

@@ -258,9 +258,9 @@ def async_name_from_discovery(
258258
) -> str:
259259
"""Convert a UNILED discovery to a human readable name."""
260260
return UniledDevice.human_readable_name(
261-
device[ATTR_UL_LOCAL_NAME],
262-
device[ATTR_UL_MODEL_NAME],
263-
device[ATTR_UL_MAC_ADDRESS],
261+
device.local_name, #[ATTR_UL_LOCAL_NAME],
262+
device.model_name, #[ATTR_UL_MODEL_NAME],
263+
device.mac_address #[ATTR_UL_MAC_ADDRESS],
264264
)
265265

266266

@@ -291,7 +291,7 @@ def async_update_entry_from_discovery(
291291
) -> bool:
292292
"""Update a config entry from a UNILED discovery."""
293293
data_updates: dict[str, Any] = {}
294-
mac_address = device[ATTR_UL_MAC_ADDRESS]
294+
mac_address = device.mac_address # [ATTR_UL_MAC_ADDRESS]
295295
assert mac_address is not None
296296
formatted_mac = UniledDevice.format_mac(mac_address)
297297
updates: dict[str, Any] = {}

0 commit comments

Comments
 (0)