Use format_mac correctly for acaia (#132062)

This commit is contained in:
Josef Zweck 2024-12-02 12:38:39 +01:00 committed by GitHub
parent ea7f1b2a4e
commit 1cf00d9bbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 8 deletions

View File

@ -42,7 +42,7 @@ class AcaiaConfigFlow(ConfigFlow, domain=DOMAIN):
errors: dict[str, str] = {} errors: dict[str, str] = {}
if user_input is not None: if user_input is not None:
mac = format_mac(user_input[CONF_ADDRESS]) mac = user_input[CONF_ADDRESS]
try: try:
is_new_style_scale = await is_new_scale(mac) is_new_style_scale = await is_new_scale(mac)
except AcaiaDeviceNotFound: except AcaiaDeviceNotFound:
@ -53,12 +53,12 @@ class AcaiaConfigFlow(ConfigFlow, domain=DOMAIN):
except AcaiaUnknownDevice: except AcaiaUnknownDevice:
return self.async_abort(reason="unsupported_device") return self.async_abort(reason="unsupported_device")
else: else:
await self.async_set_unique_id(mac) await self.async_set_unique_id(format_mac(mac))
self._abort_if_unique_id_configured() self._abort_if_unique_id_configured()
if not errors: if not errors:
return self.async_create_entry( return self.async_create_entry(
title=self._discovered_devices[user_input[CONF_ADDRESS]], title=self._discovered_devices[mac],
data={ data={
CONF_ADDRESS: mac, CONF_ADDRESS: mac,
CONF_IS_NEW_STYLE_SCALE: is_new_style_scale, CONF_IS_NEW_STYLE_SCALE: is_new_style_scale,
@ -99,10 +99,10 @@ class AcaiaConfigFlow(ConfigFlow, domain=DOMAIN):
) -> ConfigFlowResult: ) -> ConfigFlowResult:
"""Handle a discovered Bluetooth device.""" """Handle a discovered Bluetooth device."""
self._discovered[CONF_ADDRESS] = mac = format_mac(discovery_info.address) self._discovered[CONF_ADDRESS] = discovery_info.address
self._discovered[CONF_NAME] = discovery_info.name self._discovered[CONF_NAME] = discovery_info.name
await self.async_set_unique_id(mac) await self.async_set_unique_id(format_mac(discovery_info.address))
self._abort_if_unique_id_configured() self._abort_if_unique_id_configured()
try: try:

View File

@ -2,7 +2,7 @@
from dataclasses import dataclass from dataclasses import dataclass
from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.device_registry import DeviceInfo, format_mac
from homeassistant.helpers.entity import EntityDescription from homeassistant.helpers.entity import EntityDescription
from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.helpers.update_coordinator import CoordinatorEntity
@ -25,10 +25,11 @@ class AcaiaEntity(CoordinatorEntity[AcaiaCoordinator]):
super().__init__(coordinator) super().__init__(coordinator)
self.entity_description = entity_description self.entity_description = entity_description
self._scale = coordinator.scale self._scale = coordinator.scale
self._attr_unique_id = f"{self._scale.mac}_{entity_description.key}" formatted_mac = format_mac(self._scale.mac)
self._attr_unique_id = f"{formatted_mac}_{entity_description.key}"
self._attr_device_info = DeviceInfo( self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self._scale.mac)}, identifiers={(DOMAIN, formatted_mac)},
manufacturer="Acaia", manufacturer="Acaia",
model=self._scale.model, model=self._scale.model,
suggested_area="Kitchen", suggested_area="Kitchen",