Collection of changing entity properties to class attributes (#51248)

* Collection of changing entity properties to class attributes

* Apply suggestions from code review

Co-authored-by: Erik Montnemery <erik@montnemery.com>

Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
Franck Nijhof 2021-05-31 10:50:11 +02:00 committed by GitHub
parent 5acc3a1083
commit 258b388f41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 106 additions and 305 deletions

View file

@ -43,15 +43,13 @@ SIMPLE_SENSOR = {
class HomeKitHumiditySensor(HomeKitEntity, SensorEntity):
"""Representation of a Homekit humidity sensor."""
_attr_device_class = DEVICE_CLASS_HUMIDITY
_attr_unit_of_measurement = PERCENTAGE
def get_characteristic_types(self):
"""Define the homekit characteristics the entity is tracking."""
return [CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT]
@property
def device_class(self) -> str:
"""Return the device class of the sensor."""
return DEVICE_CLASS_HUMIDITY
@property
def name(self):
"""Return the name of the device."""
@ -62,11 +60,6 @@ class HomeKitHumiditySensor(HomeKitEntity, SensorEntity):
"""Return the sensor icon."""
return HUMIDITY_ICON
@property
def unit_of_measurement(self):
"""Return units for the sensor."""
return PERCENTAGE
@property
def state(self):
"""Return the current humidity."""
@ -76,15 +69,13 @@ class HomeKitHumiditySensor(HomeKitEntity, SensorEntity):
class HomeKitTemperatureSensor(HomeKitEntity, SensorEntity):
"""Representation of a Homekit temperature sensor."""
_attr_device_class = DEVICE_CLASS_TEMPERATURE
_attr_unit_of_measurement = TEMP_CELSIUS
def get_characteristic_types(self):
"""Define the homekit characteristics the entity is tracking."""
return [CharacteristicsTypes.TEMPERATURE_CURRENT]
@property
def device_class(self) -> str:
"""Return the device class of the sensor."""
return DEVICE_CLASS_TEMPERATURE
@property
def name(self):
"""Return the name of the device."""
@ -95,11 +86,6 @@ class HomeKitTemperatureSensor(HomeKitEntity, SensorEntity):
"""Return the sensor icon."""
return TEMP_C_ICON
@property
def unit_of_measurement(self):
"""Return units for the sensor."""
return TEMP_CELSIUS
@property
def state(self):
"""Return the current temperature in Celsius."""
@ -109,15 +95,13 @@ class HomeKitTemperatureSensor(HomeKitEntity, SensorEntity):
class HomeKitLightSensor(HomeKitEntity, SensorEntity):
"""Representation of a Homekit light level sensor."""
_attr_device_class = DEVICE_CLASS_ILLUMINANCE
_attr_unit_of_measurement = LIGHT_LUX
def get_characteristic_types(self):
"""Define the homekit characteristics the entity is tracking."""
return [CharacteristicsTypes.LIGHT_LEVEL_CURRENT]
@property
def device_class(self) -> str:
"""Return the device class of the sensor."""
return DEVICE_CLASS_ILLUMINANCE
@property
def name(self):
"""Return the name of the device."""
@ -128,11 +112,6 @@ class HomeKitLightSensor(HomeKitEntity, SensorEntity):
"""Return the sensor icon."""
return BRIGHTNESS_ICON
@property
def unit_of_measurement(self):
"""Return units for the sensor."""
return LIGHT_LUX
@property
def state(self):
"""Return the current light level in lux."""
@ -142,6 +121,9 @@ class HomeKitLightSensor(HomeKitEntity, SensorEntity):
class HomeKitCarbonDioxideSensor(HomeKitEntity, SensorEntity):
"""Representation of a Homekit Carbon Dioxide sensor."""
_attr_icon = CO2_ICON
_attr_unit_of_measurement = CONCENTRATION_PARTS_PER_MILLION
def get_characteristic_types(self):
"""Define the homekit characteristics the entity is tracking."""
return [CharacteristicsTypes.CARBON_DIOXIDE_LEVEL]
@ -151,16 +133,6 @@ class HomeKitCarbonDioxideSensor(HomeKitEntity, SensorEntity):
"""Return the name of the device."""
return f"{super().name} CO2"
@property
def icon(self):
"""Return the sensor icon."""
return CO2_ICON
@property
def unit_of_measurement(self):
"""Return units for the sensor."""
return CONCENTRATION_PARTS_PER_MILLION
@property
def state(self):
"""Return the current CO2 level in ppm."""
@ -170,6 +142,9 @@ class HomeKitCarbonDioxideSensor(HomeKitEntity, SensorEntity):
class HomeKitBatterySensor(HomeKitEntity, SensorEntity):
"""Representation of a Homekit battery sensor."""
_attr_device_class = DEVICE_CLASS_BATTERY
_attr_unit_of_measurement = PERCENTAGE
def get_characteristic_types(self):
"""Define the homekit characteristics the entity is tracking."""
return [
@ -178,11 +153,6 @@ class HomeKitBatterySensor(HomeKitEntity, SensorEntity):
CharacteristicsTypes.CHARGING_STATE,
]
@property
def device_class(self) -> str:
"""Return the device class of the sensor."""
return DEVICE_CLASS_BATTERY
@property
def name(self):
"""Return the name of the device."""
@ -210,11 +180,6 @@ class HomeKitBatterySensor(HomeKitEntity, SensorEntity):
return icon
@property
def unit_of_measurement(self):
"""Return units for the sensor."""
return PERCENTAGE
@property
def is_low_battery(self):
"""Return true if battery level is low."""