Skip to content

Commit

Permalink
Further fix for UniledDiscovery property errors
Browse files Browse the repository at this point in the history
  • Loading branch information
monty68 committed Dec 5, 2024
1 parent eeccca5 commit 59ab0e6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
43 changes: 23 additions & 20 deletions custom_components/uniled/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,15 @@ async def async_step_init(
"""Manage the options."""

if self.config_entry.entry_id in self.hass.data[DOMAIN]:
self.coordinator: UniledUpdateCoordinator = self.hass.data[DOMAIN][self.config_entry.entry_id]
self.coordinator: UniledUpdateCoordinator = self.hass.data[DOMAIN][
self.config_entry.entry_id
]
else:
return self.async_abort(reason="unknown")

#self.coordinator: UniledUpdateCoordinator = self.hass.data[DOMAIN][
# self.coordinator: UniledUpdateCoordinator = self.hass.data[DOMAIN][
# self.config_entry.entry_id
#]
# ]

if self.config_entry.data.get(CONF_TRANSPORT) == UNILED_TRANSPORT_ZNG:
self._mesh_set_context()
Expand Down Expand Up @@ -714,14 +716,14 @@ async def _async_set_discovered_mac(
discovery since the dhcp mac can be one digit off from
the udp discovery mac for devices with multiple network interfaces
"""
mac_address = device[ATTR_UL_MAC_ADDRESS]
mac_address = device.mac_address # [ATTR_UL_MAC_ADDRESS]
assert mac_address is not None
# mac = UniledNetDevice.format_mac(mac_address)
mac = dr.format_mac(mac_address)
await self.async_set_unique_id(mac)
for entry in self._async_current_entries(include_ignore=True):
if not (
entry.data.get(CONF_HOST) == device[ATTR_UL_IP_ADDRESS]
entry.data.get(CONF_HOST) == device.ip_address # [ATTR_UL_IP_ADDRESS]
or (
entry.unique_id
and ":" in entry.unique_id
Expand Down Expand Up @@ -754,33 +756,34 @@ async def _async_set_discovered_mac(
_LOGGER.debug(
"Discovered '%s' (id=%d, model=%s) from '%s' @ %s",
async_name_from_discovery(device),
device[ATTR_UL_MODEL_CODE],
device[ATTR_UL_MODEL_NAME],
device[ATTR_UL_SOURCE],
device[ATTR_UL_IP_ADDRESS],
device.model_code, # [ATTR_UL_MODEL_CODE],
device.model_name, # [ATTR_UL_MODEL_NAME],
device.source, # [ATTR_UL_SOURCE],
device.ip_address, # [ATTR_UL_IP_ADDRESS],
)

async def _async_network_discovery(self) -> FlowResult:
"""Handle network discovery."""
assert self._discovered_device is not None
device = self._discovered_device
await self._async_set_discovered_mac(device, self._allow_update_mac)
host = device[ATTR_UL_IP_ADDRESS]
host = device.ip_address # [ATTR_UL_IP_ADDRESS]
for progress in self._async_in_progress():
if progress.get("context", {}).get(CONF_HOST) == host:
return self.async_abort(reason="already_in_progress")

if not device[ATTR_UL_MODEL_NAME]:
mac_address = device[ATTR_UL_MAC_ADDRESS]
if not device.model_name: # [ATTR_UL_MODEL_NAME]:
mac_address = device.mac_address # [ATTR_UL_MAC_ADDRESS]
assert mac_address is not None
# mac = UniledNetDevice.format_mac(mac_address)
mac = dr.format_mac(mac_address)
try:
device = await async_discover_device(self.hass, host)
except Exception:
return self.async_abort(reason="cannot_connect")
discovered_mac = device[ATTR_UL_MAC_ADDRESS]
if device[ATTR_UL_MODEL_NAME] or (
discovered_mac = device.mac_address # [ATTR_UL_MAC_ADDRESS]
# if device[ATTR_UL_MODEL_NAME] or (
if device.model_name or (
discovered_mac is not None
and (
# formatted_discovered_mac := UniledNetDevice.format_mac(
Expand All @@ -802,17 +805,17 @@ async def async_step_network_confirm(
"""Confirm network discovery."""
assert self._discovered_device is not None
device = self._discovered_device
mac_address = device[ATTR_UL_MAC_ADDRESS]
mac_address = device.mac_address # [ATTR_UL_MAC_ADDRESS]
assert mac_address is not None
model = device[ATTR_UL_MODEL_NAME]
code = device[ATTR_UL_MODEL_CODE]
name = device[ATTR_UL_LOCAL_NAME]
model = device.model_name # [ATTR_UL_MODEL_NAME]
code = device.model_code # [ATTR_UL_MODEL_CODE]
name = device.local_name # [ATTR_UL_LOCAL_NAME]

placeholders = {
"name": async_name_from_discovery(device),
"device_name": name or mac_address,
"model": f"({model})" if model else f"ID#: {code}",
"ip": device[ATTR_UL_IP_ADDRESS],
"ip": device.ip_address, # [ATTR_UL_IP_ADDRESS],
}
self.context["title_placeholders"] = placeholders

Expand All @@ -826,7 +829,7 @@ async def async_step_network_confirm(
@callback
def _async_network_create_entry(self, device: UniledDiscovery):
"""Create network entry"""
if device[ATTR_UL_MODEL_NAME] is None:
if device.model_name is None: # [ATTR_UL_MODEL_NAME] is None:
raise AbortFlow("not_supported")
# data: dict[str, Any] = {CONF_TRANSPORT: UNILED_TRANSPORT_NET}
data: dict[str, Any] = {}
Expand Down
12 changes: 6 additions & 6 deletions custom_components/uniled/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ async def async_discover_devices(
return [
device
for device in scanner.get_device_info()
if device[ATTR_UL_IP_ADDRESS] == address
if device.ip_address == address
]


Expand All @@ -199,7 +199,7 @@ async def async_discover_device(
for device in await async_discover_devices(
hass, UNILED_DISCOVERY_DIRECTED_TIMEOUT, host
):
if device[ATTR_UL_IP_ADDRESS] == host:
if device.ip_address == host:
return device
return None

Expand Down Expand Up @@ -258,9 +258,9 @@ def async_name_from_discovery(
) -> str:
"""Convert a UNILED discovery to a human readable name."""
return UniledDevice.human_readable_name(
device[ATTR_UL_LOCAL_NAME],
device[ATTR_UL_MODEL_NAME],
device[ATTR_UL_MAC_ADDRESS],
device.local_name, #[ATTR_UL_LOCAL_NAME],
device.model_name, #[ATTR_UL_MODEL_NAME],
device.mac_address #[ATTR_UL_MAC_ADDRESS],
)


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

0 comments on commit 59ab0e6

Please sign in to comment.