mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
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:
parent
f6d3b0618e
commit
9eac0458dd
@ -3,6 +3,7 @@
|
|||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.device_registry import format_mac
|
||||||
|
|
||||||
from .connectivity import ObihaiConnection
|
from .connectivity import ObihaiConnection
|
||||||
from .const import LOGGER, PLATFORMS
|
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)
|
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
|
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
|
entry.version = 2
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ from homeassistant.config_entries import ConfigFlow
|
|||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
from homeassistant.helpers.device_registry import format_mac
|
||||||
|
|
||||||
from .connectivity import validate_auth
|
from .connectivity import validate_auth
|
||||||
from .const import DEFAULT_PASSWORD, DEFAULT_USERNAME, DOMAIN
|
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(
|
device_mac = await self.hass.async_add_executor_job(
|
||||||
pyobihai.get_device_mac
|
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()
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
@ -104,7 +105,7 @@ class ObihaiFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Attempt to confirm."""
|
"""Attempt to confirm."""
|
||||||
assert self._dhcp_discovery_info
|
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()
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
if user_input is None:
|
if user_input is None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user