Use shorthand attributes in Wolflink (#99921)

This commit is contained in:
Joost Lekkerkerker 2023-09-08 14:38:09 +02:00 committed by GitHub
parent 5ddaf52b27
commit 5f6f2c2cab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -57,14 +57,10 @@ class WolfLinkSensor(CoordinatorEntity, SensorEntity):
"""Initialize."""
super().__init__(coordinator)
self.wolf_object = wolf_object
self.device_id = device_id
self._attr_name = wolf_object.name
self._attr_unique_id = f"{device_id}:{wolf_object.parameter_id}"
self._state = None
@property
def name(self):
"""Return the name."""
return f"{self.wolf_object.name}"
@property
def native_value(self):
"""Return the state. Wolf Client is returning only changed values so we need to store old value here."""
@ -83,52 +79,26 @@ class WolfLinkSensor(CoordinatorEntity, SensorEntity):
"parent": self.wolf_object.parent,
}
@property
def unique_id(self):
"""Return a unique_id for this entity."""
return f"{self.device_id}:{self.wolf_object.parameter_id}"
class WolfLinkHours(WolfLinkSensor):
"""Class for hour based entities."""
@property
def icon(self):
"""Icon to display in the front Aend."""
return "mdi:clock"
@property
def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return UnitOfTime.HOURS
_attr_icon = "mdi:clock"
_attr_native_unit_of_measurement = UnitOfTime.HOURS
class WolfLinkTemperature(WolfLinkSensor):
"""Class for temperature based entities."""
@property
def device_class(self):
"""Return the device_class."""
return SensorDeviceClass.TEMPERATURE
@property
def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return UnitOfTemperature.CELSIUS
_attr_device_class = SensorDeviceClass.TEMPERATURE
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
class WolfLinkPressure(WolfLinkSensor):
"""Class for pressure based entities."""
@property
def device_class(self):
"""Return the device_class."""
return SensorDeviceClass.PRESSURE
@property
def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return UnitOfPressure.BAR
_attr_device_class = SensorDeviceClass.PRESSURE
_attr_native_unit_of_measurement = UnitOfPressure.BAR
class WolfLinkPercentage(WolfLinkSensor):