Use new enums in homekit-controller (#61689)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
3118bfdfab
commit
10f57cf1f5
5 changed files with 50 additions and 66 deletions
|
@ -8,26 +8,14 @@ from aiohomekit.model.characteristics import Characteristic, CharacteristicsType
|
|||
from aiohomekit.model.services import ServicesTypes
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
DEVICE_CLASS_AQI,
|
||||
DEVICE_CLASS_BATTERY,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_ILLUMINANCE,
|
||||
DEVICE_CLASS_NITROGEN_DIOXIDE,
|
||||
DEVICE_CLASS_OZONE,
|
||||
DEVICE_CLASS_PM10,
|
||||
DEVICE_CLASS_PM25,
|
||||
DEVICE_CLASS_POWER,
|
||||
DEVICE_CLASS_PRESSURE,
|
||||
DEVICE_CLASS_SULPHUR_DIOXIDE,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS,
|
||||
LIGHT_LUX,
|
||||
PERCENTAGE,
|
||||
POWER_WATT,
|
||||
|
@ -52,36 +40,36 @@ SIMPLE_SENSOR: dict[str, HomeKitSensorEntityDescription] = {
|
|||
CharacteristicsTypes.Vendor.EVE_ENERGY_WATT: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.EVE_ENERGY_WATT,
|
||||
name="Real Time Energy",
|
||||
device_class=DEVICE_CLASS_POWER,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.KOOGEEK_REALTIME_ENERGY: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.KOOGEEK_REALTIME_ENERGY,
|
||||
name="Real Time Energy",
|
||||
device_class=DEVICE_CLASS_POWER,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.KOOGEEK_REALTIME_ENERGY_2: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.KOOGEEK_REALTIME_ENERGY_2,
|
||||
name="Real Time Energy",
|
||||
device_class=DEVICE_CLASS_POWER,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
),
|
||||
CharacteristicsTypes.Vendor.EVE_DEGREE_AIR_PRESSURE: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.Vendor.EVE_DEGREE_AIR_PRESSURE,
|
||||
name="Air Pressure",
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.PRESSURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=PRESSURE_HPA,
|
||||
),
|
||||
CharacteristicsTypes.TEMPERATURE_CURRENT: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.TEMPERATURE_CURRENT,
|
||||
name="Current Temperature",
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
# This sensor is only for temperature characteristics that are not part
|
||||
# of a temperature sensor service.
|
||||
|
@ -93,8 +81,8 @@ SIMPLE_SENSOR: dict[str, HomeKitSensorEntityDescription] = {
|
|||
CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT,
|
||||
name="Current Humidity",
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.HUMIDITY,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
# This sensor is only for humidity characteristics that are not part
|
||||
# of a humidity sensor service.
|
||||
|
@ -106,49 +94,49 @@ SIMPLE_SENSOR: dict[str, HomeKitSensorEntityDescription] = {
|
|||
CharacteristicsTypes.AIR_QUALITY: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.AIR_QUALITY,
|
||||
name="Air Quality",
|
||||
device_class=DEVICE_CLASS_AQI,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.AQI,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
CharacteristicsTypes.DENSITY_PM25: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.DENSITY_PM25,
|
||||
name="PM2.5 Density",
|
||||
device_class=DEVICE_CLASS_PM25,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.PM25,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
),
|
||||
CharacteristicsTypes.DENSITY_PM10: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.DENSITY_PM10,
|
||||
name="PM10 Density",
|
||||
device_class=DEVICE_CLASS_PM10,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.PM10,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
),
|
||||
CharacteristicsTypes.DENSITY_OZONE: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.DENSITY_OZONE,
|
||||
name="Ozone Density",
|
||||
device_class=DEVICE_CLASS_OZONE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.OZONE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
),
|
||||
CharacteristicsTypes.DENSITY_NO2: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.DENSITY_NO2,
|
||||
name="Nitrogen Dioxide Density",
|
||||
device_class=DEVICE_CLASS_NITROGEN_DIOXIDE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.NITROGEN_DIOXIDE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
),
|
||||
CharacteristicsTypes.DENSITY_SO2: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.DENSITY_SO2,
|
||||
name="Sulphur Dioxide Density",
|
||||
device_class=DEVICE_CLASS_SULPHUR_DIOXIDE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.SULPHUR_DIOXIDE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
),
|
||||
CharacteristicsTypes.DENSITY_VOC: HomeKitSensorEntityDescription(
|
||||
key=CharacteristicsTypes.DENSITY_VOC,
|
||||
name="Volatile Organic Compound Density",
|
||||
device_class=DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
),
|
||||
}
|
||||
|
@ -166,7 +154,7 @@ for k, v in list(SIMPLE_SENSOR.items()):
|
|||
class HomeKitHumiditySensor(HomeKitEntity, SensorEntity):
|
||||
"""Representation of a Homekit humidity sensor."""
|
||||
|
||||
_attr_device_class = DEVICE_CLASS_HUMIDITY
|
||||
_attr_device_class = SensorDeviceClass.HUMIDITY
|
||||
_attr_native_unit_of_measurement = PERCENTAGE
|
||||
|
||||
def get_characteristic_types(self):
|
||||
|
@ -187,7 +175,7 @@ class HomeKitHumiditySensor(HomeKitEntity, SensorEntity):
|
|||
class HomeKitTemperatureSensor(HomeKitEntity, SensorEntity):
|
||||
"""Representation of a Homekit temperature sensor."""
|
||||
|
||||
_attr_device_class = DEVICE_CLASS_TEMPERATURE
|
||||
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
||||
_attr_native_unit_of_measurement = TEMP_CELSIUS
|
||||
|
||||
def get_characteristic_types(self):
|
||||
|
@ -208,7 +196,7 @@ class HomeKitTemperatureSensor(HomeKitEntity, SensorEntity):
|
|||
class HomeKitLightSensor(HomeKitEntity, SensorEntity):
|
||||
"""Representation of a Homekit light level sensor."""
|
||||
|
||||
_attr_device_class = DEVICE_CLASS_ILLUMINANCE
|
||||
_attr_device_class = SensorDeviceClass.ILLUMINANCE
|
||||
_attr_native_unit_of_measurement = LIGHT_LUX
|
||||
|
||||
def get_characteristic_types(self):
|
||||
|
@ -250,7 +238,7 @@ class HomeKitCarbonDioxideSensor(HomeKitEntity, SensorEntity):
|
|||
class HomeKitBatterySensor(HomeKitEntity, SensorEntity):
|
||||
"""Representation of a Homekit battery sensor."""
|
||||
|
||||
_attr_device_class = DEVICE_CLASS_BATTERY
|
||||
_attr_device_class = SensorDeviceClass.BATTERY
|
||||
_attr_native_unit_of_measurement = PERCENTAGE
|
||||
|
||||
def get_characteristic_types(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue