Obihai to have common unique_ids with DHCP or without (#91239)

* DHCPInfo and get_mac_address case mismatch

* Switch to format_mac

* Run black
This commit is contained in:
Emory Penney 2023-05-30 18:40:59 -07:00 committed by GitHub
parent f6d3b0618e
commit 9eac0458dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -3,6 +3,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import format_mac
from .connectivity import ObihaiConnection
from .const import LOGGER, PLATFORMS
@ -29,10 +30,10 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
)
await hass.async_add_executor_job(requester.update)
new_unique_id = await hass.async_add_executor_job(
device_mac = await hass.async_add_executor_job(
requester.pyobihai.get_device_mac
)
hass.config_entries.async_update_entry(entry, unique_id=new_unique_id)
hass.config_entries.async_update_entry(entry, unique_id=format_mac(device_mac))
entry.version = 2

View File

@ -13,6 +13,7 @@ from homeassistant.config_entries import ConfigFlow
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.device_registry import format_mac
from .connectivity import validate_auth
from .const import DEFAULT_PASSWORD, DEFAULT_USERNAME, DOMAIN
@ -77,7 +78,7 @@ class ObihaiFlowHandler(ConfigFlow, domain=DOMAIN):
device_mac = await self.hass.async_add_executor_job(
pyobihai.get_device_mac
)
await self.async_set_unique_id(device_mac)
await self.async_set_unique_id(format_mac(device_mac))
self._abort_if_unique_id_configured()
return self.async_create_entry(
@ -104,7 +105,7 @@ class ObihaiFlowHandler(ConfigFlow, domain=DOMAIN):
) -> FlowResult:
"""Attempt to confirm."""
assert self._dhcp_discovery_info
await self.async_set_unique_id(self._dhcp_discovery_info.macaddress)
await self.async_set_unique_id(format_mac(self._dhcp_discovery_info.macaddress))
self._abort_if_unique_id_configured()
if user_input is None: