Use enums in xiaomi_miio (#61979)
This commit is contained in:
parent
32e1a3d063
commit
83cb2d11d5
6 changed files with 101 additions and 115 deletions
|
@ -6,14 +6,12 @@ from dataclasses import dataclass
|
|||
import logging
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DEVICE_CLASS_CONNECTIVITY,
|
||||
DEVICE_CLASS_PLUG,
|
||||
DEVICE_CLASS_PROBLEM,
|
||||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
BinarySensorEntityDescription,
|
||||
)
|
||||
from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
|
||||
from . import VacuumCoordinatorDataAttributes
|
||||
from .const import (
|
||||
|
@ -56,21 +54,21 @@ BINARY_SENSOR_TYPES = (
|
|||
key=ATTR_NO_WATER,
|
||||
name="Water Tank Empty",
|
||||
icon="mdi:water-off-outline",
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
XiaomiMiioBinarySensorDescription(
|
||||
key=ATTR_WATER_TANK_DETACHED,
|
||||
name="Water Tank",
|
||||
icon="mdi:car-coolant-level",
|
||||
device_class=DEVICE_CLASS_CONNECTIVITY,
|
||||
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
||||
value=lambda value: not value,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
XiaomiMiioBinarySensorDescription(
|
||||
key=ATTR_POWERSUPPLY_ATTACHED,
|
||||
name="Power Supply",
|
||||
device_class=DEVICE_CLASS_PLUG,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
device_class=BinarySensorDeviceClass.PLUG,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -83,8 +81,8 @@ VACUUM_SENSORS = {
|
|||
icon="mdi:square-rounded",
|
||||
parent_key=VacuumCoordinatorDataAttributes.status,
|
||||
entity_registry_enabled_default=True,
|
||||
device_class=DEVICE_CLASS_CONNECTIVITY,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
ATTR_WATER_BOX_ATTACHED: XiaomiMiioBinarySensorDescription(
|
||||
key=ATTR_WATER_BOX_ATTACHED,
|
||||
|
@ -92,8 +90,8 @@ VACUUM_SENSORS = {
|
|||
icon="mdi:water",
|
||||
parent_key=VacuumCoordinatorDataAttributes.status,
|
||||
entity_registry_enabled_default=True,
|
||||
device_class=DEVICE_CLASS_CONNECTIVITY,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
ATTR_WATER_SHORTAGE: XiaomiMiioBinarySensorDescription(
|
||||
key=ATTR_WATER_SHORTAGE,
|
||||
|
@ -101,8 +99,8 @@ VACUUM_SENSORS = {
|
|||
icon="mdi:water",
|
||||
parent_key=VacuumCoordinatorDataAttributes.status,
|
||||
entity_registry_enabled_default=True,
|
||||
device_class=DEVICE_CLASS_PROBLEM,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
device_class=BinarySensorDeviceClass.PROBLEM,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
}
|
||||
|
||||
|
@ -114,8 +112,8 @@ VACUUM_SENSORS_SEPARATE_MOP = {
|
|||
icon="mdi:square-rounded",
|
||||
parent_key=VacuumCoordinatorDataAttributes.status,
|
||||
entity_registry_enabled_default=True,
|
||||
device_class=DEVICE_CLASS_CONNECTIVITY,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
}
|
||||
|
||||
|
|
|
@ -6,11 +6,8 @@ from miio.airhumidifier import OperationMode as AirhumidifierOperationMode
|
|||
from miio.airhumidifier_miot import OperationMode as AirhumidifierMiotOperationMode
|
||||
from miio.airhumidifier_mjjsq import OperationMode as AirhumidifierMjjsqOperationMode
|
||||
|
||||
from homeassistant.components.humidifier import HumidifierEntity
|
||||
from homeassistant.components.humidifier.const import (
|
||||
DEVICE_CLASS_HUMIDIFIER,
|
||||
SUPPORT_MODES,
|
||||
)
|
||||
from homeassistant.components.humidifier import HumidifierDeviceClass, HumidifierEntity
|
||||
from homeassistant.components.humidifier.const import SUPPORT_MODES
|
||||
from homeassistant.const import ATTR_MODE
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.util.percentage import percentage_to_ranged_value
|
||||
|
@ -105,7 +102,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
class XiaomiGenericHumidifier(XiaomiCoordinatedMiioEntity, HumidifierEntity):
|
||||
"""Representation of a generic Xiaomi humidifier device."""
|
||||
|
||||
_attr_device_class = DEVICE_CLASS_HUMIDIFIER
|
||||
_attr_device_class = HumidifierDeviceClass.HUMIDIFIER
|
||||
_attr_supported_features = SUPPORT_MODES
|
||||
|
||||
def __init__(self, name, device, entry, unique_id, coordinator):
|
||||
|
|
|
@ -4,8 +4,9 @@ from __future__ import annotations
|
|||
from dataclasses import dataclass
|
||||
|
||||
from homeassistant.components.number import NumberEntity, NumberEntityDescription
|
||||
from homeassistant.const import DEGREE, ENTITY_CATEGORY_CONFIG, TIME_MINUTES
|
||||
from homeassistant.const import DEGREE, TIME_MINUTES
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
|
||||
from .const import (
|
||||
CONF_DEVICE,
|
||||
|
@ -106,7 +107,7 @@ NUMBER_TYPES = {
|
|||
step=10,
|
||||
available_with_device_off=False,
|
||||
method="async_set_motor_speed",
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
FEATURE_SET_FAVORITE_LEVEL: XiaomiMiioNumberDescription(
|
||||
key=ATTR_FAVORITE_LEVEL,
|
||||
|
@ -116,7 +117,7 @@ NUMBER_TYPES = {
|
|||
max_value=17,
|
||||
step=1,
|
||||
method="async_set_favorite_level",
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
FEATURE_SET_FAN_LEVEL: XiaomiMiioNumberDescription(
|
||||
key=ATTR_FAN_LEVEL,
|
||||
|
@ -126,7 +127,7 @@ NUMBER_TYPES = {
|
|||
max_value=3,
|
||||
step=1,
|
||||
method="async_set_fan_level",
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
FEATURE_SET_VOLUME: XiaomiMiioNumberDescription(
|
||||
key=ATTR_VOLUME,
|
||||
|
@ -136,7 +137,7 @@ NUMBER_TYPES = {
|
|||
max_value=100,
|
||||
step=1,
|
||||
method="async_set_volume",
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
FEATURE_SET_OSCILLATION_ANGLE: XiaomiMiioNumberDescription(
|
||||
key=ATTR_OSCILLATION_ANGLE,
|
||||
|
@ -147,7 +148,7 @@ NUMBER_TYPES = {
|
|||
max_value=120,
|
||||
step=1,
|
||||
method="async_set_oscillation_angle",
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
FEATURE_SET_DELAY_OFF_COUNTDOWN: XiaomiMiioNumberDescription(
|
||||
key=ATTR_DELAY_OFF_COUNTDOWN,
|
||||
|
@ -158,7 +159,7 @@ NUMBER_TYPES = {
|
|||
max_value=480,
|
||||
step=1,
|
||||
method="async_set_delay_off_countdown",
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
FEATURE_SET_LED_BRIGHTNESS: XiaomiMiioNumberDescription(
|
||||
key=ATTR_LED_BRIGHTNESS,
|
||||
|
@ -168,7 +169,7 @@ NUMBER_TYPES = {
|
|||
max_value=100,
|
||||
step=1,
|
||||
method="async_set_led_brightness",
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
FEATURE_SET_LED_BRIGHTNESS_LEVEL: XiaomiMiioNumberDescription(
|
||||
key=ATTR_LED_BRIGHTNESS_LEVEL,
|
||||
|
@ -178,7 +179,7 @@ NUMBER_TYPES = {
|
|||
max_value=8,
|
||||
step=1,
|
||||
method="async_set_led_brightness_level",
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
FEATURE_SET_FAVORITE_RPM: XiaomiMiioNumberDescription(
|
||||
key=ATTR_FAVORITE_RPM,
|
||||
|
@ -189,7 +190,7 @@ NUMBER_TYPES = {
|
|||
max_value=2200,
|
||||
step=10,
|
||||
method="async_set_favorite_rpm",
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ from miio.airpurifier_miot import LedBrightness as AirpurifierMiotLedBrightness
|
|||
from miio.fan import LedBrightness as FanLedBrightness
|
||||
|
||||
from homeassistant.components.select import SelectEntity, SelectEntityDescription
|
||||
from homeassistant.const import ENTITY_CATEGORY_CONFIG
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
|
||||
from .const import (
|
||||
CONF_DEVICE,
|
||||
|
@ -63,7 +63,7 @@ SELECTOR_TYPES = {
|
|||
icon="mdi:brightness-6",
|
||||
device_class="xiaomi_miio__led_brightness",
|
||||
options=("bright", "dim", "off"),
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
}
|
||||
|
||||
|
|
|
@ -15,10 +15,10 @@ from miio.gateway.gateway import (
|
|||
)
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
STATE_CLASS_TOTAL_INCREASING,
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
AREA_SQUARE_METERS,
|
||||
|
@ -28,17 +28,6 @@ from homeassistant.const import (
|
|||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
CONF_HOST,
|
||||
CONF_TOKEN,
|
||||
DEVICE_CLASS_BATTERY,
|
||||
DEVICE_CLASS_CO2,
|
||||
DEVICE_CLASS_GAS,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_ILLUMINANCE,
|
||||
DEVICE_CLASS_PM25,
|
||||
DEVICE_CLASS_POWER,
|
||||
DEVICE_CLASS_PRESSURE,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
DEVICE_CLASS_TIMESTAMP,
|
||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
LIGHT_LUX,
|
||||
PERCENTAGE,
|
||||
POWER_WATT,
|
||||
|
@ -49,6 +38,7 @@ from homeassistant.const import (
|
|||
VOLUME_CUBIC_METERS,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from . import VacuumCoordinatorDataAttributes
|
||||
|
@ -148,137 +138,137 @@ SENSOR_TYPES = {
|
|||
key=ATTR_TEMPERATURE,
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
ATTR_HUMIDITY: XiaomiMiioSensorDescription(
|
||||
key=ATTR_HUMIDITY,
|
||||
name="Humidity",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.HUMIDITY,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
ATTR_PRESSURE: XiaomiMiioSensorDescription(
|
||||
key=ATTR_PRESSURE,
|
||||
name="Pressure",
|
||||
native_unit_of_measurement=PRESSURE_HPA,
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.PRESSURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
ATTR_LOAD_POWER: XiaomiMiioSensorDescription(
|
||||
key=ATTR_LOAD_POWER,
|
||||
name="Load Power",
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
device_class=DEVICE_CLASS_POWER,
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
),
|
||||
ATTR_WATER_LEVEL: XiaomiMiioSensorDescription(
|
||||
key=ATTR_WATER_LEVEL,
|
||||
name="Water Level",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
icon="mdi:water-check",
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
ATTR_ACTUAL_SPEED: XiaomiMiioSensorDescription(
|
||||
key=ATTR_ACTUAL_SPEED,
|
||||
name="Actual Speed",
|
||||
native_unit_of_measurement="rpm",
|
||||
icon="mdi:fast-forward",
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
ATTR_MOTOR_SPEED: XiaomiMiioSensorDescription(
|
||||
key=ATTR_MOTOR_SPEED,
|
||||
name="Motor Speed",
|
||||
native_unit_of_measurement="rpm",
|
||||
icon="mdi:fast-forward",
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
ATTR_MOTOR2_SPEED: XiaomiMiioSensorDescription(
|
||||
key=ATTR_MOTOR2_SPEED,
|
||||
name="Second Motor Speed",
|
||||
native_unit_of_measurement="rpm",
|
||||
icon="mdi:fast-forward",
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
ATTR_USE_TIME: XiaomiMiioSensorDescription(
|
||||
key=ATTR_USE_TIME,
|
||||
name="Use Time",
|
||||
native_unit_of_measurement=TIME_SECONDS,
|
||||
icon="mdi:progress-clock",
|
||||
state_class=STATE_CLASS_TOTAL_INCREASING,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
ATTR_ILLUMINANCE: XiaomiMiioSensorDescription(
|
||||
key=ATTR_ILLUMINANCE,
|
||||
name="Illuminance",
|
||||
native_unit_of_measurement=UNIT_LUMEN,
|
||||
device_class=DEVICE_CLASS_ILLUMINANCE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.ILLUMINANCE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
ATTR_ILLUMINANCE_LUX: XiaomiMiioSensorDescription(
|
||||
key=ATTR_ILLUMINANCE,
|
||||
name="Illuminance",
|
||||
native_unit_of_measurement=LIGHT_LUX,
|
||||
device_class=DEVICE_CLASS_ILLUMINANCE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.ILLUMINANCE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
ATTR_AIR_QUALITY: XiaomiMiioSensorDescription(
|
||||
key=ATTR_AIR_QUALITY,
|
||||
native_unit_of_measurement="AQI",
|
||||
icon="mdi:cloud",
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
ATTR_PM25: XiaomiMiioSensorDescription(
|
||||
key=ATTR_AQI,
|
||||
name="PM2.5",
|
||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
device_class=DEVICE_CLASS_PM25,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.PM25,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
ATTR_FILTER_LIFE_REMAINING: XiaomiMiioSensorDescription(
|
||||
key=ATTR_FILTER_LIFE_REMAINING,
|
||||
name="Filter Life Remaining",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
icon="mdi:air-filter",
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
attributes=("filter_type",),
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
ATTR_FILTER_USE: XiaomiMiioSensorDescription(
|
||||
key=ATTR_FILTER_HOURS_USED,
|
||||
name="Filter Use",
|
||||
native_unit_of_measurement=TIME_HOURS,
|
||||
icon="mdi:clock-outline",
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
ATTR_CARBON_DIOXIDE: XiaomiMiioSensorDescription(
|
||||
key=ATTR_CARBON_DIOXIDE,
|
||||
name="Carbon Dioxide",
|
||||
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
|
||||
device_class=DEVICE_CLASS_CO2,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
device_class=SensorDeviceClass.CO2,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
ATTR_PURIFY_VOLUME: XiaomiMiioSensorDescription(
|
||||
key=ATTR_PURIFY_VOLUME,
|
||||
name="Purify Volume",
|
||||
native_unit_of_measurement=VOLUME_CUBIC_METERS,
|
||||
device_class=DEVICE_CLASS_GAS,
|
||||
state_class=STATE_CLASS_TOTAL_INCREASING,
|
||||
device_class=SensorDeviceClass.GAS,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
ATTR_BATTERY: XiaomiMiioSensorDescription(
|
||||
key=ATTR_BATTERY,
|
||||
name="Battery",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
device_class=DEVICE_CLASS_BATTERY,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
device_class=SensorDeviceClass.BATTERY,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
}
|
||||
|
||||
|
@ -408,35 +398,35 @@ VACUUM_SENSORS = {
|
|||
key=ATTR_DND_START,
|
||||
icon="mdi:minus-circle-off",
|
||||
name="DnD Start",
|
||||
device_class=DEVICE_CLASS_TIMESTAMP,
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
parent_key=VacuumCoordinatorDataAttributes.dnd_status,
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
f"dnd_{ATTR_DND_END}": XiaomiMiioSensorDescription(
|
||||
key=ATTR_DND_END,
|
||||
icon="mdi:minus-circle-off",
|
||||
name="DnD End",
|
||||
device_class=DEVICE_CLASS_TIMESTAMP,
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
parent_key=VacuumCoordinatorDataAttributes.dnd_status,
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
f"last_clean_{ATTR_LAST_CLEAN_START}": XiaomiMiioSensorDescription(
|
||||
key=ATTR_LAST_CLEAN_START,
|
||||
icon="mdi:clock-time-twelve",
|
||||
name="Last Clean Start",
|
||||
device_class=DEVICE_CLASS_TIMESTAMP,
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
parent_key=VacuumCoordinatorDataAttributes.last_clean_details,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
f"last_clean_{ATTR_LAST_CLEAN_END}": XiaomiMiioSensorDescription(
|
||||
key=ATTR_LAST_CLEAN_END,
|
||||
icon="mdi:clock-time-twelve",
|
||||
device_class=DEVICE_CLASS_TIMESTAMP,
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
parent_key=VacuumCoordinatorDataAttributes.last_clean_details,
|
||||
name="Last Clean End",
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
f"last_clean_{ATTR_LAST_CLEAN_TIME}": XiaomiMiioSensorDescription(
|
||||
native_unit_of_measurement=TIME_SECONDS,
|
||||
|
@ -444,7 +434,7 @@ VACUUM_SENSORS = {
|
|||
key=ATTR_LAST_CLEAN_TIME,
|
||||
parent_key=VacuumCoordinatorDataAttributes.last_clean_details,
|
||||
name="Last Clean Duration",
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
f"last_clean_{ATTR_LAST_CLEAN_AREA}": XiaomiMiioSensorDescription(
|
||||
native_unit_of_measurement=AREA_SQUARE_METERS,
|
||||
|
@ -452,7 +442,7 @@ VACUUM_SENSORS = {
|
|||
key=ATTR_LAST_CLEAN_AREA,
|
||||
parent_key=VacuumCoordinatorDataAttributes.last_clean_details,
|
||||
name="Last Clean Area",
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
f"clean_history_{ATTR_CLEAN_HISTORY_TOTAL_DURATION}": XiaomiMiioSensorDescription(
|
||||
native_unit_of_measurement=TIME_SECONDS,
|
||||
|
@ -461,7 +451,7 @@ VACUUM_SENSORS = {
|
|||
parent_key=VacuumCoordinatorDataAttributes.clean_history_status,
|
||||
name="Total duration",
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
f"clean_history_{ATTR_CLEAN_HISTORY_TOTAL_AREA}": XiaomiMiioSensorDescription(
|
||||
native_unit_of_measurement=AREA_SQUARE_METERS,
|
||||
|
@ -470,17 +460,17 @@ VACUUM_SENSORS = {
|
|||
parent_key=VacuumCoordinatorDataAttributes.clean_history_status,
|
||||
name="Total Clean Area",
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
f"clean_history_{ATTR_CLEAN_HISTORY_COUNT}": XiaomiMiioSensorDescription(
|
||||
native_unit_of_measurement="",
|
||||
icon="mdi:counter",
|
||||
state_class=STATE_CLASS_TOTAL_INCREASING,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
key=ATTR_CLEAN_HISTORY_COUNT,
|
||||
parent_key=VacuumCoordinatorDataAttributes.clean_history_status,
|
||||
name="Total Clean Count",
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
f"clean_history_{ATTR_CLEAN_HISTORY_DUST_COLLECTION_COUNT}": XiaomiMiioSensorDescription(
|
||||
native_unit_of_measurement="",
|
||||
|
@ -490,7 +480,7 @@ VACUUM_SENSORS = {
|
|||
parent_key=VacuumCoordinatorDataAttributes.clean_history_status,
|
||||
name="Total Dust Collection Count",
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
f"consumable_{ATTR_CONSUMABLE_STATUS_MAIN_BRUSH_LEFT}": XiaomiMiioSensorDescription(
|
||||
native_unit_of_measurement=TIME_SECONDS,
|
||||
|
@ -499,7 +489,7 @@ VACUUM_SENSORS = {
|
|||
parent_key=VacuumCoordinatorDataAttributes.consumable_status,
|
||||
name="Main Brush Left",
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
f"consumable_{ATTR_CONSUMABLE_STATUS_SIDE_BRUSH_LEFT}": XiaomiMiioSensorDescription(
|
||||
native_unit_of_measurement=TIME_SECONDS,
|
||||
|
@ -508,7 +498,7 @@ VACUUM_SENSORS = {
|
|||
parent_key=VacuumCoordinatorDataAttributes.consumable_status,
|
||||
name="Side Brush Left",
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
f"consumable_{ATTR_CONSUMABLE_STATUS_FILTER_LEFT}": XiaomiMiioSensorDescription(
|
||||
native_unit_of_measurement=TIME_SECONDS,
|
||||
|
@ -517,7 +507,7 @@ VACUUM_SENSORS = {
|
|||
parent_key=VacuumCoordinatorDataAttributes.consumable_status,
|
||||
name="Filter Left",
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
f"consumable_{ATTR_CONSUMABLE_STATUS_SENSOR_DIRTY_LEFT}": XiaomiMiioSensorDescription(
|
||||
native_unit_of_measurement=TIME_SECONDS,
|
||||
|
@ -526,7 +516,7 @@ VACUUM_SENSORS = {
|
|||
parent_key=VacuumCoordinatorDataAttributes.consumable_status,
|
||||
name="Sensor Dirty Left",
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
}
|
||||
|
||||
|
@ -700,7 +690,7 @@ class XiaomiGenericSensor(XiaomiCoordinatedMiioEntity, SensorEntity):
|
|||
)
|
||||
|
||||
if (
|
||||
self.device_class == DEVICE_CLASS_TIMESTAMP
|
||||
self.device_class == SensorDeviceClass.TIMESTAMP
|
||||
and native_value is not None
|
||||
and (native_datetime := dt_util.parse_datetime(str(native_value)))
|
||||
is not None
|
||||
|
|
|
@ -11,7 +11,7 @@ from miio.powerstrip import PowerMode
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.switch import (
|
||||
DEVICE_CLASS_SWITCH,
|
||||
SwitchDeviceClass,
|
||||
SwitchEntity,
|
||||
SwitchEntityDescription,
|
||||
)
|
||||
|
@ -21,10 +21,10 @@ from homeassistant.const import (
|
|||
ATTR_TEMPERATURE,
|
||||
CONF_HOST,
|
||||
CONF_TOKEN,
|
||||
ENTITY_CATEGORY_CONFIG,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
|
||||
from .const import (
|
||||
CONF_DEVICE,
|
||||
|
@ -206,7 +206,7 @@ SWITCH_TYPES = (
|
|||
icon="mdi:volume-high",
|
||||
method_on="async_set_buzzer_on",
|
||||
method_off="async_set_buzzer_off",
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
XiaomiMiioSwitchDescription(
|
||||
key=ATTR_CHILD_LOCK,
|
||||
|
@ -215,7 +215,7 @@ SWITCH_TYPES = (
|
|||
icon="mdi:lock",
|
||||
method_on="async_set_child_lock_on",
|
||||
method_off="async_set_child_lock_off",
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
XiaomiMiioSwitchDescription(
|
||||
key=ATTR_DRY,
|
||||
|
@ -224,7 +224,7 @@ SWITCH_TYPES = (
|
|||
icon="mdi:hair-dryer",
|
||||
method_on="async_set_dry_on",
|
||||
method_off="async_set_dry_off",
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
XiaomiMiioSwitchDescription(
|
||||
key=ATTR_CLEAN,
|
||||
|
@ -234,7 +234,7 @@ SWITCH_TYPES = (
|
|||
method_on="async_set_clean_on",
|
||||
method_off="async_set_clean_off",
|
||||
available_with_device_off=False,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
XiaomiMiioSwitchDescription(
|
||||
key=ATTR_LED,
|
||||
|
@ -243,7 +243,7 @@ SWITCH_TYPES = (
|
|||
icon="mdi:led-outline",
|
||||
method_on="async_set_led_on",
|
||||
method_off="async_set_led_off",
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
XiaomiMiioSwitchDescription(
|
||||
key=ATTR_LEARN_MODE,
|
||||
|
@ -252,7 +252,7 @@ SWITCH_TYPES = (
|
|||
icon="mdi:school-outline",
|
||||
method_on="async_set_learn_mode_on",
|
||||
method_off="async_set_learn_mode_off",
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
XiaomiMiioSwitchDescription(
|
||||
key=ATTR_AUTO_DETECT,
|
||||
|
@ -260,7 +260,7 @@ SWITCH_TYPES = (
|
|||
name="Auto Detect",
|
||||
method_on="async_set_auto_detect_on",
|
||||
method_off="async_set_auto_detect_off",
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
XiaomiMiioSwitchDescription(
|
||||
key=ATTR_IONIZER,
|
||||
|
@ -269,7 +269,7 @@ SWITCH_TYPES = (
|
|||
icon="mdi:shimmer",
|
||||
method_on="async_set_ionizer_on",
|
||||
method_off="async_set_ionizer_off",
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -621,7 +621,7 @@ class XiaomiGenericCoordinatedSwitch(XiaomiCoordinatedMiioEntity, SwitchEntity):
|
|||
class XiaomiGatewaySwitch(XiaomiGatewayDevice, SwitchEntity):
|
||||
"""Representation of a XiaomiGatewaySwitch."""
|
||||
|
||||
_attr_device_class = DEVICE_CLASS_SWITCH
|
||||
_attr_device_class = SwitchDeviceClass.SWITCH
|
||||
|
||||
def __init__(self, coordinator, sub_device, entry, variable):
|
||||
"""Initialize the XiaomiSensor."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue