mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Normalise unique ID in Axis integration (#45203)
* Move adding unique id to config entry from setup_entry to migrate_entry * Normalise unique ID * MQTT subscribe should still use the serial number in the way the device itself expects
This commit is contained in:
@@ -74,8 +74,8 @@ class AxisNetworkDevice:
|
||||
return self.config_entry.data[CONF_NAME]
|
||||
|
||||
@property
|
||||
def serial(self):
|
||||
"""Return the serial number of this device."""
|
||||
def unique_id(self):
|
||||
"""Return the unique ID (serial number) of this device."""
|
||||
return self.config_entry.unique_id
|
||||
|
||||
# Options
|
||||
@@ -102,17 +102,17 @@ class AxisNetworkDevice:
|
||||
@property
|
||||
def signal_reachable(self):
|
||||
"""Device specific event to signal a change in connection status."""
|
||||
return f"axis_reachable_{self.serial}"
|
||||
return f"axis_reachable_{self.unique_id}"
|
||||
|
||||
@property
|
||||
def signal_new_event(self):
|
||||
"""Device specific event to signal new device event available."""
|
||||
return f"axis_new_event_{self.serial}"
|
||||
return f"axis_new_event_{self.unique_id}"
|
||||
|
||||
@property
|
||||
def signal_new_address(self):
|
||||
"""Device specific event to signal a change in device address."""
|
||||
return f"axis_new_address_{self.serial}"
|
||||
return f"axis_new_address_{self.unique_id}"
|
||||
|
||||
# Callbacks
|
||||
|
||||
@@ -151,8 +151,8 @@ class AxisNetworkDevice:
|
||||
device_registry = await self.hass.helpers.device_registry.async_get_registry()
|
||||
device_registry.async_get_or_create(
|
||||
config_entry_id=self.config_entry.entry_id,
|
||||
connections={(CONNECTION_NETWORK_MAC, self.serial)},
|
||||
identifiers={(AXIS_DOMAIN, self.serial)},
|
||||
connections={(CONNECTION_NETWORK_MAC, self.unique_id)},
|
||||
identifiers={(AXIS_DOMAIN, self.unique_id)},
|
||||
manufacturer=ATTR_MANUFACTURER,
|
||||
model=f"{self.model} {self.product_type}",
|
||||
name=self.name,
|
||||
@@ -169,7 +169,9 @@ class AxisNetworkDevice:
|
||||
|
||||
if status.get("data", {}).get("status", {}).get("state") == "active":
|
||||
self.listeners.append(
|
||||
await mqtt.async_subscribe(hass, f"{self.serial}/#", self.mqtt_message)
|
||||
await mqtt.async_subscribe(
|
||||
hass, f"{self.api.vapix.serial_number}/#", self.mqtt_message
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
|
||||
Reference in New Issue
Block a user