Use shorthand attributes in Kostal Plenticore (#99581)

This commit is contained in:
Joost Lekkerkerker 2023-09-05 15:26:23 +02:00 committed by GitHub
parent 447a9f4aad
commit 1f648feaef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 25 deletions

View file

@ -745,16 +745,16 @@ class PlenticoreDataSensor(
super().__init__(coordinator)
self.entity_description = description
self.entry_id = entry_id
self.platform_name = platform_name
self.module_id = description.module_id
self.data_id = description.key
self._sensor_name = description.name
self._formatter: Callable[[str], Any] = PlenticoreDataFormatter.get_method(
description.formatter
)
self._device_info = device_info
self._attr_device_info = device_info
self._attr_unique_id = f"{entry_id}_{self.module_id}_{self.data_id}"
self._attr_name = f"{platform_name} {description.name}"
@property
def available(self) -> bool:
@ -778,21 +778,6 @@ class PlenticoreDataSensor(
self.coordinator.stop_fetch_data(self.module_id, self.data_id)
await super().async_will_remove_from_hass()
@property
def device_info(self) -> DeviceInfo:
"""Return the device info."""
return self._device_info
@property
def unique_id(self) -> str:
"""Return the unique id of this Sensor Entity."""
return f"{self.entry_id}_{self.module_id}_{self.data_id}"
@property
def name(self) -> str:
"""Return the name of this Sensor Entity."""
return f"{self.platform_name} {self._sensor_name}"
@property
def native_value(self) -> StateType:
"""Return the state of the sensor."""

View file

@ -116,7 +116,6 @@ class PlenticoreDataSwitch(
"""Create a new Switch Entity for Plenticore process data."""
super().__init__(coordinator)
self.entity_description = description
self.entry_id = entry_id
self.platform_name = platform_name
self.module_id = description.module_id
self.data_id = description.key
@ -129,7 +128,7 @@ class PlenticoreDataSwitch(
self.off_label = description.off_label
self._attr_unique_id = f"{entry_id}_{description.module_id}_{description.key}"
self._device_info = device_info
self._attr_device_info = device_info
@property
def available(self) -> bool:
@ -171,11 +170,6 @@ class PlenticoreDataSwitch(
)
await self.coordinator.async_request_refresh()
@property
def device_info(self) -> DeviceInfo:
"""Return the device info."""
return self._device_info
@property
def is_on(self) -> bool:
"""Return true if device is on."""