Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obihai to have common unique_ids with DHCP or without #91239

Merged
merged 3 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions homeassistant/components/obihai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/obihai/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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
Expand Down Expand Up @@ -77,7 +78,7 @@ async def async_step_user(
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(
Expand All @@ -104,7 +105,7 @@ async def async_step_dhcp_confirm(
) -> 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:
Expand Down