Use new enums in homekit-controller (#61689)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-12-13 17:04:21 +01:00 committed by GitHub
parent 3118bfdfab
commit 10f57cf1f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 66 deletions

View file

@ -3,12 +3,7 @@ from aiohomekit.model.characteristics import CharacteristicsTypes
from aiohomekit.model.services import ServicesTypes
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_GAS,
DEVICE_CLASS_MOISTURE,
DEVICE_CLASS_MOTION,
DEVICE_CLASS_OCCUPANCY,
DEVICE_CLASS_OPENING,
DEVICE_CLASS_SMOKE,
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.core import callback
@ -19,7 +14,7 @@ from . import KNOWN_DEVICES, HomeKitEntity
class HomeKitMotionSensor(HomeKitEntity, BinarySensorEntity):
"""Representation of a Homekit motion sensor."""
_attr_device_class = DEVICE_CLASS_MOTION
_attr_device_class = BinarySensorDeviceClass.MOTION
def get_characteristic_types(self):
"""Define the homekit characteristics the entity is tracking."""
@ -34,7 +29,7 @@ class HomeKitMotionSensor(HomeKitEntity, BinarySensorEntity):
class HomeKitContactSensor(HomeKitEntity, BinarySensorEntity):
"""Representation of a Homekit contact sensor."""
_attr_device_class = DEVICE_CLASS_OPENING
_attr_device_class = BinarySensorDeviceClass.OPENING
def get_characteristic_types(self):
"""Define the homekit characteristics the entity is tracking."""
@ -49,7 +44,7 @@ class HomeKitContactSensor(HomeKitEntity, BinarySensorEntity):
class HomeKitSmokeSensor(HomeKitEntity, BinarySensorEntity):
"""Representation of a Homekit smoke sensor."""
_attr_device_class = DEVICE_CLASS_SMOKE
_attr_device_class = BinarySensorDeviceClass.SMOKE
def get_characteristic_types(self):
"""Define the homekit characteristics the entity is tracking."""
@ -64,7 +59,7 @@ class HomeKitSmokeSensor(HomeKitEntity, BinarySensorEntity):
class HomeKitCarbonMonoxideSensor(HomeKitEntity, BinarySensorEntity):
"""Representation of a Homekit BO sensor."""
_attr_device_class = DEVICE_CLASS_GAS
_attr_device_class = BinarySensorDeviceClass.GAS
def get_characteristic_types(self):
"""Define the homekit characteristics the entity is tracking."""
@ -79,7 +74,7 @@ class HomeKitCarbonMonoxideSensor(HomeKitEntity, BinarySensorEntity):
class HomeKitOccupancySensor(HomeKitEntity, BinarySensorEntity):
"""Representation of a Homekit occupancy sensor."""
_attr_device_class = DEVICE_CLASS_OCCUPANCY
_attr_device_class = BinarySensorDeviceClass.OCCUPANCY
def get_characteristic_types(self):
"""Define the homekit characteristics the entity is tracking."""
@ -94,7 +89,7 @@ class HomeKitOccupancySensor(HomeKitEntity, BinarySensorEntity):
class HomeKitLeakSensor(HomeKitEntity, BinarySensorEntity):
"""Representation of a Homekit leak sensor."""
_attr_device_class = DEVICE_CLASS_MOISTURE
_attr_device_class = BinarySensorDeviceClass.MOISTURE
def get_characteristic_types(self):
"""Define the homekit characteristics the entity is tracking."""

View file

@ -15,8 +15,8 @@ from homeassistant.components.button import (
ButtonEntity,
ButtonEntityDescription,
)
from homeassistant.const import ENTITY_CATEGORY_CONFIG
from homeassistant.core import callback
from homeassistant.helpers.entity import EntityCategory
from . import KNOWN_DEVICES, CharacteristicEntity
@ -33,14 +33,14 @@ BUTTON_ENTITIES: dict[str, HomeKitButtonEntityDescription] = {
key=CharacteristicsTypes.Vendor.HAA_SETUP,
name="Setup",
icon="mdi:cog",
entity_category=ENTITY_CATEGORY_CONFIG,
entity_category=EntityCategory.CONFIG,
write_value="#HAA@trcmd",
),
CharacteristicsTypes.Vendor.HAA_UPDATE: HomeKitButtonEntityDescription(
key=CharacteristicsTypes.Vendor.HAA_UPDATE,
name="Update",
device_class=ButtonDeviceClass.UPDATE,
entity_category=ENTITY_CATEGORY_CONFIG,
entity_category=EntityCategory.CONFIG,
write_value="#HAA@trcmd",
),
}

View file

@ -4,10 +4,8 @@ from __future__ import annotations
from aiohomekit.model.characteristics import CharacteristicsTypes
from aiohomekit.model.services import ServicesTypes
from homeassistant.components.humidifier import HumidifierEntity
from homeassistant.components.humidifier import HumidifierDeviceClass, HumidifierEntity
from homeassistant.components.humidifier.const import (
DEVICE_CLASS_DEHUMIDIFIER,
DEVICE_CLASS_HUMIDIFIER,
MODE_AUTO,
MODE_NORMAL,
SUPPORT_MODES,
@ -35,7 +33,7 @@ HA_MODE_TO_HK = {
class HomeKitHumidifier(HomeKitEntity, HumidifierEntity):
"""Representation of a HomeKit Controller Humidifier."""
_attr_device_class = DEVICE_CLASS_HUMIDIFIER
_attr_device_class = HumidifierDeviceClass.HUMIDIFIER
def get_characteristic_types(self):
"""Define the homekit characteristics the entity cares about."""
@ -136,7 +134,7 @@ class HomeKitHumidifier(HomeKitEntity, HumidifierEntity):
class HomeKitDehumidifier(HomeKitEntity, HumidifierEntity):
"""Representation of a HomeKit Controller Humidifier."""
_attr_device_class = DEVICE_CLASS_DEHUMIDIFIER
_attr_device_class = HumidifierDeviceClass.DEHUMIDIFIER
def get_characteristic_types(self):
"""Define the homekit characteristics the entity cares about."""

View file

@ -10,7 +10,10 @@ from aiohomekit.model.characteristics import (
from aiohomekit.model.services import ServicesTypes
from aiohomekit.utils import clamp_enum_to_char
from homeassistant.components.media_player import DEVICE_CLASS_TV, MediaPlayerEntity
from homeassistant.components.media_player import (
MediaPlayerDeviceClass,
MediaPlayerEntity,
)
from homeassistant.components.media_player.const import (
SUPPORT_PAUSE,
SUPPORT_PLAY,
@ -57,7 +60,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity):
"""Representation of a HomeKit Controller Television."""
_attr_device_class = DEVICE_CLASS_TV
_attr_device_class = MediaPlayerDeviceClass.TV
def get_characteristic_types(self):
"""Define the homekit characteristics the entity cares about."""

View file

@ -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):