mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Improve handling of invalid serial numbers in HomeKit Controller (#58723)
Fixes #58719
This commit is contained in:
parent
e97133613a
commit
061b1abd1b
@ -19,7 +19,7 @@ from homeassistant.exceptions import ConfigEntryNotReady
|
|||||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||||
|
|
||||||
from .config_flow import normalize_hkid
|
from .config_flow import normalize_hkid
|
||||||
from .connection import HKDevice
|
from .connection import HKDevice, valid_serial_number
|
||||||
from .const import (
|
from .const import (
|
||||||
CONTROLLER,
|
CONTROLLER,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -141,7 +141,7 @@ class HomeKitEntity(Entity):
|
|||||||
"""Return the ID of this device."""
|
"""Return the ID of this device."""
|
||||||
info = self.accessory_info
|
info = self.accessory_info
|
||||||
serial = info.value(CharacteristicsTypes.SERIAL_NUMBER)
|
serial = info.value(CharacteristicsTypes.SERIAL_NUMBER)
|
||||||
if serial:
|
if valid_serial_number(serial):
|
||||||
return f"homekit-{serial}-{self._iid}"
|
return f"homekit-{serial}-{self._iid}"
|
||||||
# Some accessories do not have a serial number
|
# Some accessories do not have a serial number
|
||||||
return f"homekit-{self._accessory.unique_id}-{self._aid}-{self._iid}"
|
return f"homekit-{self._accessory.unique_id}-{self._aid}-{self._iid}"
|
||||||
@ -161,7 +161,7 @@ class HomeKitEntity(Entity):
|
|||||||
"""Return the device info."""
|
"""Return the device info."""
|
||||||
info = self.accessory_info
|
info = self.accessory_info
|
||||||
accessory_serial = info.value(CharacteristicsTypes.SERIAL_NUMBER)
|
accessory_serial = info.value(CharacteristicsTypes.SERIAL_NUMBER)
|
||||||
if accessory_serial:
|
if valid_serial_number(accessory_serial):
|
||||||
# Some accessories do not have a serial number
|
# Some accessories do not have a serial number
|
||||||
identifier = (DOMAIN, IDENTIFIER_SERIAL_NUMBER, accessory_serial)
|
identifier = (DOMAIN, IDENTIFIER_SERIAL_NUMBER, accessory_serial)
|
||||||
else:
|
else:
|
||||||
|
@ -36,6 +36,16 @@ MAX_POLL_FAILURES_TO_DECLARE_UNAVAILABLE = 3
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def valid_serial_number(serial):
|
||||||
|
"""Return if the serial number appears to be valid."""
|
||||||
|
if not serial:
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
return float("".join(serial.rsplit(".", 1))) > 1
|
||||||
|
except ValueError:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def get_accessory_information(accessory):
|
def get_accessory_information(accessory):
|
||||||
"""Obtain the accessory information service of a HomeKit device."""
|
"""Obtain the accessory information service of a HomeKit device."""
|
||||||
result = {}
|
result = {}
|
||||||
@ -211,7 +221,7 @@ class HKDevice:
|
|||||||
|
|
||||||
serial_number = info.value(CharacteristicsTypes.SERIAL_NUMBER)
|
serial_number = info.value(CharacteristicsTypes.SERIAL_NUMBER)
|
||||||
|
|
||||||
if serial_number:
|
if valid_serial_number(serial_number):
|
||||||
identifiers = {(DOMAIN, IDENTIFIER_SERIAL_NUMBER, serial_number)}
|
identifiers = {(DOMAIN, IDENTIFIER_SERIAL_NUMBER, serial_number)}
|
||||||
else:
|
else:
|
||||||
# Some accessories do not have a serial number
|
# Some accessories do not have a serial number
|
||||||
|
@ -19,7 +19,7 @@ async def test_ryse_smart_bridge_setup(hass):
|
|||||||
# Check that the cover.master_bath_south is correctly found and set up
|
# Check that the cover.master_bath_south is correctly found and set up
|
||||||
cover_id = "cover.master_bath_south"
|
cover_id = "cover.master_bath_south"
|
||||||
cover = entity_registry.async_get(cover_id)
|
cover = entity_registry.async_get(cover_id)
|
||||||
assert cover.unique_id == "homekit-1.0.0-48"
|
assert cover.unique_id == "homekit-00:00:00:00:00:00-2-48"
|
||||||
|
|
||||||
cover_helper = Helper(
|
cover_helper = Helper(
|
||||||
hass,
|
hass,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user