Define entity attributes as entity class variables (#50925)

* Define entity attributes as entity class variables

* Example coronavirus integration

* Example verisure

* Cleanup/typing fixes

* Fix Coronavirus

* Revert "Fix Coronavirus"

This reverts commit 060843860f.

* Revert "Cleanup/typing fixes"

This reverts commit 659b79e75a.

* Define entity attributes as entity class variables (attr alternative)

* Example coronavirus

* Example nut

* Example verisure

* Mark private

* Cleanup after all reverting/cherrypicking/merging

* Implement all entity properties

* Update coronavirus example

* Update nut example

* Update verisure example

* Lets not talk about this one...

* Fix multiple class attribute
This commit is contained in:
Franck Nijhof 2021-05-22 18:13:50 +02:00 committed by GitHub
parent b9a0fb93eb
commit 38d095aa18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 80 additions and 173 deletions

View file

@ -98,11 +98,14 @@ class NUTSensor(CoordinatorEntity, SensorEntity):
self._firmware = firmware
self._model = model
self._device_name = name
self._name = f"{name} {SENSOR_TYPES[sensor_type][SENSOR_NAME]}"
self._unit = SENSOR_TYPES[sensor_type][SENSOR_UNIT]
self._data = data
self._unique_id = unique_id
self._attr_device_class = SENSOR_TYPES[self._type][SENSOR_DEVICE_CLASS]
self._attr_icon = SENSOR_TYPES[self._type][SENSOR_ICON]
self._attr_name = f"{name} {SENSOR_TYPES[sensor_type][SENSOR_NAME]}"
self._attr_unit_of_measurement = SENSOR_TYPES[sensor_type][SENSOR_UNIT]
@property
def device_info(self):
"""Device info for the ups."""
@ -127,25 +130,6 @@ class NUTSensor(CoordinatorEntity, SensorEntity):
return None
return f"{self._unique_id}_{self._type}"
@property
def name(self):
"""Return the name of the UPS sensor."""
return self._name
@property
def icon(self):
"""Icon to use in the frontend, if any."""
if SENSOR_TYPES[self._type][SENSOR_DEVICE_CLASS]:
# The UI will assign an icon
# if it has a class
return None
return SENSOR_TYPES[self._type][SENSOR_ICON]
@property
def device_class(self):
"""Device class of the sensor."""
return SENSOR_TYPES[self._type][SENSOR_DEVICE_CLASS]
@property
def state(self):
"""Return entity state from ups."""
@ -155,11 +139,6 @@ class NUTSensor(CoordinatorEntity, SensorEntity):
return _format_display_state(self._data.status)
return self._data.status.get(self._type)
@property
def unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any."""
return self._unit
@property
def extra_state_attributes(self):
"""Return the sensor attributes."""