Skip to content

Commit

Permalink
Switch to format_mac
Browse files Browse the repository at this point in the history
  • Loading branch information
ejpenney committed Apr 12, 2023
1 parent e8e9235 commit 7631db5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
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.lower())
hass.config_entries.async_update_entry(entry, unique_id=format_mac(device_mac))

entry.version = 2

Expand Down
7 changes: 4 additions & 3 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_NAME, 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 @@ -75,7 +76,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.lower())
await self.async_set_unique_id(format_mac(device_mac))
self._abort_if_unique_id_configured()

return self.async_create_entry(
Expand All @@ -102,7 +103,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.lower())
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 Expand Up @@ -145,7 +146,7 @@ async def async_step_import(self, config: dict[str, Any]) -> FlowResult:

if pyobihai := await async_validate_creds(self.hass, config):
device_mac = await self.hass.async_add_executor_job(pyobihai.get_device_mac)
await self.async_set_unique_id(device_mac.lower())
await self.async_set_unique_id(format_mac(device_mac))
self._abort_if_unique_id_configured()

return self.async_create_entry(
Expand Down

0 comments on commit 7631db5

Please sign in to comment.