Use shorthand attributes for Plaato (#99634)

Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
Joost Lekkerkerker 2023-09-05 19:01:51 +02:00 committed by GitHub
parent e9062bb1b3
commit 5ccf866e22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,7 +30,18 @@ class PlaatoEntity(entity.Entity):
self._device_id = data[DEVICE][DEVICE_ID]
self._device_type = data[DEVICE][DEVICE_TYPE]
self._device_name = data[DEVICE][DEVICE_NAME]
self._state = 0
self._attr_unique_id = f"{self._device_id}_{self._sensor_type}"
self._attr_name = f"{DOMAIN} {self._device_type} {self._device_name} {self._sensor_name}".title()
sw_version = None
if firmware := self._sensor_data.firmware_version:
sw_version = firmware
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self._device_id)},
manufacturer="Plaato",
model=self._device_type,
name=self._device_name,
sw_version=sw_version,
)
@property
def _attributes(self) -> dict:
@ -46,28 +57,6 @@ class PlaatoEntity(entity.Entity):
return self._coordinator.data
return self._entry_data[SENSOR_DATA]
@property
def name(self):
"""Return the name of the sensor."""
return f"{DOMAIN} {self._device_type} {self._device_name} {self._sensor_name}".title()
@property
def unique_id(self):
"""Return the unique ID of this sensor."""
return f"{self._device_id}_{self._sensor_type}"
@property
def device_info(self) -> DeviceInfo:
"""Get device info."""
sw_version = self._sensor_data.firmware_version
return DeviceInfo(
identifiers={(DOMAIN, self._device_id)},
manufacturer="Plaato",
model=self._device_type,
name=self._device_name,
sw_version=sw_version if sw_version != "" else None,
)
@property
def extra_state_attributes(self):
"""Return the state attributes of the monitored installation."""