From e0b3c5eb5c4b44fe650d07fa00841df1a4cba73c Mon Sep 17 00:00:00 2001 From: Phil Bruckner Date: Mon, 19 Feb 2024 14:18:38 -0600 Subject: [PATCH] Do not add serial number to device info in HA before 2023.11 (#18) --- custom_components/google_maps/device_tracker.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/custom_components/google_maps/device_tracker.py b/custom_components/google_maps/device_tracker.py index 854ccbf..bce07bc 100644 --- a/custom_components/google_maps/device_tracker.py +++ b/custom_components/google_maps/device_tracker.py @@ -28,6 +28,10 @@ ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import config_validation as cv, entity_registry as er +from homeassistant.helpers.device_registry import ( + STORAGE_VERSION_MAJOR, + STORAGE_VERSION_MINOR, +) # DeviceInfo moved in 2023.9.0b0 try: @@ -275,11 +279,13 @@ def extra_state_attributes(self) -> Mapping[str, Any] | None: @property def device_info(self) -> DeviceInfo | None: """Return device specific attributes.""" - return DeviceInfo( + info = DeviceInfo( identifiers={(DOMAIN, cast(str, self.unique_id))}, name=self._full_name, - serial_number=self.unique_id, ) + if (STORAGE_VERSION_MAJOR, STORAGE_VERSION_MINOR) >= (1, 4): + info["serial_number"] = self.unique_id + return info @property def entity_picture(self) -> str | None: