Fix lutron_caseta handling of 'None' serials for RA3/QSX zones (#77553)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Kevin Addeman 2022-08-30 14:46:54 -04:00 committed by GitHub
parent 8936c91f50
commit 05264cedfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -343,7 +343,7 @@ class LutronCasetaDevice(Entity):
area, name = _area_and_name_from_name(device["name"])
self._attr_name = full_name = f"{area} {name}"
info = DeviceInfo(
identifiers={(DOMAIN, self.serial)},
identifiers={(DOMAIN, self._handle_none_serial(self.serial))},
manufacturer=MANUFACTURER,
model=f"{device['model']} ({device['type']})",
name=full_name,
@ -358,6 +358,12 @@ class LutronCasetaDevice(Entity):
"""Register callbacks."""
self._smartbridge.add_subscriber(self.device_id, self.async_write_ha_state)
def _handle_none_serial(self, serial: str | None) -> str | int:
"""Handle None serial returned by RA3 and QSX processors."""
if serial is None:
return f"{self._bridge_unique_id}_{self.device_id}"
return serial
@property
def device_id(self):
"""Return the device ID used for calling pylutron_caseta."""
@ -369,9 +375,9 @@ class LutronCasetaDevice(Entity):
return self._device["serial"]
@property
def unique_id(self):
def unique_id(self) -> str:
"""Return the unique ID of the device (serial)."""
return str(self.serial)
return str(self._handle_none_serial(self.serial))
@property
def extra_state_attributes(self):
@ -387,13 +393,6 @@ class LutronCasetaDeviceUpdatableEntity(LutronCasetaDevice):
self._device = self._smartbridge.get_device_by_id(self.device_id)
_LOGGER.debug(self._device)
@property
def unique_id(self):
"""Return a unique identifier if serial number is None."""
if self.serial is None:
return f"{self._bridge_unique_id}_{self.device_id}"
return super().unique_id
def _id_to_identifier(lutron_id: str) -> tuple[str, str]:
"""Convert a lutron caseta identifier to a device identifier."""