Use new DeviceClass enums in homekit (#61665)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
d3710c7ba6
commit
931d51949d
9 changed files with 70 additions and 83 deletions
|
@ -7,13 +7,9 @@ from pyhap.const import CATEGORY_OTHER
|
|||
from pyhap.util import callback as pyhap_callback
|
||||
|
||||
from homeassistant.components import cover
|
||||
from homeassistant.components.cover import (
|
||||
DEVICE_CLASS_GARAGE,
|
||||
DEVICE_CLASS_GATE,
|
||||
DEVICE_CLASS_WINDOW,
|
||||
)
|
||||
from homeassistant.components.media_player import DEVICE_CLASS_TV
|
||||
from homeassistant.components.media_player import MediaPlayerDeviceClass
|
||||
from homeassistant.components.remote import SUPPORT_ACTIVITY
|
||||
from homeassistant.components.sensor import SensorDeviceClass
|
||||
from homeassistant.const import (
|
||||
ATTR_BATTERY_CHARGING,
|
||||
ATTR_BATTERY_LEVEL,
|
||||
|
@ -27,11 +23,6 @@ from homeassistant.const import (
|
|||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
CONF_NAME,
|
||||
CONF_TYPE,
|
||||
DEVICE_CLASS_CO,
|
||||
DEVICE_CLASS_CO2,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_ILLUMINANCE,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
LIGHT_LUX,
|
||||
PERCENTAGE,
|
||||
STATE_ON,
|
||||
|
@ -58,7 +49,6 @@ from .const import (
|
|||
CONF_LINKED_BATTERY_SENSOR,
|
||||
CONF_LOW_BATTERY_THRESHOLD,
|
||||
DEFAULT_LOW_BATTERY_THRESHOLD,
|
||||
DEVICE_CLASS_PM25,
|
||||
DOMAIN,
|
||||
EVENT_HOMEKIT_CHANGED,
|
||||
HK_CHARGING,
|
||||
|
@ -126,12 +116,17 @@ def get_accessory(hass, driver, state, aid, config): # noqa: C901
|
|||
elif state.domain == "cover":
|
||||
device_class = state.attributes.get(ATTR_DEVICE_CLASS)
|
||||
|
||||
if device_class in (DEVICE_CLASS_GARAGE, DEVICE_CLASS_GATE) and features & (
|
||||
cover.SUPPORT_OPEN | cover.SUPPORT_CLOSE
|
||||
if (
|
||||
device_class
|
||||
in (
|
||||
cover.CoverDeviceClass.GARAGE,
|
||||
cover.CoverDeviceClass.GATE,
|
||||
)
|
||||
and features & (cover.SUPPORT_OPEN | cover.SUPPORT_CLOSE)
|
||||
):
|
||||
a_type = "GarageDoorOpener"
|
||||
elif (
|
||||
device_class == DEVICE_CLASS_WINDOW
|
||||
device_class == cover.CoverDeviceClass.WINDOW
|
||||
and features & cover.SUPPORT_SET_POSITION
|
||||
):
|
||||
a_type = "Window"
|
||||
|
@ -161,7 +156,7 @@ def get_accessory(hass, driver, state, aid, config): # noqa: C901
|
|||
device_class = state.attributes.get(ATTR_DEVICE_CLASS)
|
||||
feature_list = config.get(CONF_FEATURE_LIST, [])
|
||||
|
||||
if device_class == DEVICE_CLASS_TV:
|
||||
if device_class == MediaPlayerDeviceClass.TV:
|
||||
a_type = "TelevisionMediaPlayer"
|
||||
elif validate_media_player_features(state, feature_list):
|
||||
a_type = "MediaPlayer"
|
||||
|
@ -170,20 +165,23 @@ def get_accessory(hass, driver, state, aid, config): # noqa: C901
|
|||
device_class = state.attributes.get(ATTR_DEVICE_CLASS)
|
||||
unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
|
||||
if device_class == DEVICE_CLASS_TEMPERATURE or unit in (
|
||||
if device_class == SensorDeviceClass.TEMPERATURE or unit in (
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
):
|
||||
a_type = "TemperatureSensor"
|
||||
elif device_class == DEVICE_CLASS_HUMIDITY and unit == PERCENTAGE:
|
||||
elif device_class == SensorDeviceClass.HUMIDITY and unit == PERCENTAGE:
|
||||
a_type = "HumiditySensor"
|
||||
elif device_class == DEVICE_CLASS_PM25 or DEVICE_CLASS_PM25 in state.entity_id:
|
||||
elif (
|
||||
device_class == SensorDeviceClass.PM25
|
||||
or SensorDeviceClass.PM25 in state.entity_id
|
||||
):
|
||||
a_type = "AirQualitySensor"
|
||||
elif device_class == DEVICE_CLASS_CO:
|
||||
elif device_class == SensorDeviceClass.CO:
|
||||
a_type = "CarbonMonoxideSensor"
|
||||
elif device_class == DEVICE_CLASS_CO2 or "co2" in state.entity_id:
|
||||
elif device_class == SensorDeviceClass.CO2 or "co2" in state.entity_id:
|
||||
a_type = "CarbonDioxideSensor"
|
||||
elif device_class == DEVICE_CLASS_ILLUMINANCE or unit in ("lm", LIGHT_LUX):
|
||||
elif device_class == SensorDeviceClass.ILLUMINANCE or unit in ("lm", LIGHT_LUX):
|
||||
a_type = "LightSensor"
|
||||
|
||||
elif state.domain == "switch":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue