Use new enums in homematic (#61765)

Co-authored-by: Pascal Vizeli <pascal.vizeli@syshack.ch>
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-12-14 10:53:47 +01:00 committed by GitHub
parent 8fc69b7242
commit b7c0b21c6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 73 deletions

View File

@ -1,10 +1,6 @@
"""Support for HomeMatic binary sensors."""
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_MOTION,
DEVICE_CLASS_OPENING,
DEVICE_CLASS_PRESENCE,
DEVICE_CLASS_SMOKE,
BinarySensorDeviceClass,
BinarySensorEntity,
)
@ -12,24 +8,24 @@ from .const import ATTR_DISCOVER_DEVICES, ATTR_DISCOVERY_TYPE, DISCOVER_BATTERY
from .entity import HMDevice
SENSOR_TYPES_CLASS = {
"IPShutterContact": DEVICE_CLASS_OPENING,
"IPShutterContactSabotage": DEVICE_CLASS_OPENING,
"MaxShutterContact": DEVICE_CLASS_OPENING,
"Motion": DEVICE_CLASS_MOTION,
"MotionV2": DEVICE_CLASS_MOTION,
"PresenceIP": DEVICE_CLASS_PRESENCE,
"IPShutterContact": BinarySensorDeviceClass.OPENING,
"IPShutterContactSabotage": BinarySensorDeviceClass.OPENING,
"MaxShutterContact": BinarySensorDeviceClass.OPENING,
"Motion": BinarySensorDeviceClass.MOTION,
"MotionV2": BinarySensorDeviceClass.MOTION,
"PresenceIP": BinarySensorDeviceClass.MOTION,
"Remote": None,
"RemoteMotion": None,
"ShutterContact": DEVICE_CLASS_OPENING,
"Smoke": DEVICE_CLASS_SMOKE,
"SmokeV2": DEVICE_CLASS_SMOKE,
"ShutterContact": BinarySensorDeviceClass.OPENING,
"Smoke": BinarySensorDeviceClass.SMOKE,
"SmokeV2": BinarySensorDeviceClass.SMOKE,
"TiltSensor": None,
"WeatherSensor": None,
"IPContact": DEVICE_CLASS_OPENING,
"MotionIP": DEVICE_CLASS_MOTION,
"MotionIPV2": DEVICE_CLASS_MOTION,
"MotionIPContactSabotage": DEVICE_CLASS_MOTION,
"IPRemoteMotionV2": DEVICE_CLASS_MOTION,
"IPContact": BinarySensorDeviceClass.OPENING,
"MotionIP": BinarySensorDeviceClass.MOTION,
"MotionIPV2": BinarySensorDeviceClass.MOTION,
"MotionIPContactSabotage": BinarySensorDeviceClass.MOTION,
"IPRemoteMotionV2": BinarySensorDeviceClass.MOTION,
}
@ -63,7 +59,7 @@ class HMBinarySensor(HMDevice, BinarySensorEntity):
"""Return the class of this sensor from DEVICE_CLASSES."""
# If state is MOTION (Only RemoteMotion working)
if self._state == "MOTION":
return DEVICE_CLASS_MOTION
return BinarySensorDeviceClass.MOTION
return SENSOR_TYPES_CLASS.get(self._hmdevice.__class__.__name__)
def _init_data_struct(self):
@ -76,7 +72,7 @@ class HMBinarySensor(HMDevice, BinarySensorEntity):
class HMBatterySensor(HMDevice, BinarySensorEntity):
"""Representation of an HomeMatic low battery sensor."""
_attr_device_class = DEVICE_CLASS_BATTERY
_attr_device_class = BinarySensorDeviceClass.BATTERY
@property
def is_on(self):

View File

@ -2,7 +2,7 @@
from homeassistant.components.cover import (
ATTR_POSITION,
ATTR_TILT_POSITION,
DEVICE_CLASS_GARAGE,
CoverDeviceClass,
CoverEntity,
)
@ -112,7 +112,7 @@ class HMCover(HMDevice, CoverEntity):
class HMGarage(HMCover):
"""Represents a Homematic Garage cover. Homematic garage covers do not support position attributes."""
_attr_device_class = DEVICE_CLASS_GARAGE
_attr_device_class = CoverDeviceClass.GARAGE
@property
def current_cover_position(self):

View File

@ -5,25 +5,15 @@ from copy import copy
import logging
from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.const import (
ATTR_NAME,
CONCENTRATION_PARTS_PER_MILLION,
DEGREE,
DEVICE_CLASS_CO2,
DEVICE_CLASS_CURRENT,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_GAS,
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_POWER,
DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_VOLTAGE,
ELECTRIC_CURRENT_MILLIAMPERE,
ELECTRIC_POTENTIAL_VOLT,
ENERGY_WATT_HOUR,
@ -64,110 +54,110 @@ SENSOR_DESCRIPTIONS: dict[str, SensorEntityDescription] = {
"HUMIDITY": SensorEntityDescription(
key="HUMIDITY",
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_HUMIDITY,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.HUMIDITY,
state_class=SensorStateClass.MEASUREMENT,
),
"ACTUAL_TEMPERATURE": SensorEntityDescription(
key="ACTUAL_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,
),
"TEMPERATURE": SensorEntityDescription(
key="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,
),
"LUX": SensorEntityDescription(
key="LUX",
native_unit_of_measurement=LIGHT_LUX,
device_class=DEVICE_CLASS_ILLUMINANCE,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.ILLUMINANCE,
state_class=SensorStateClass.MEASUREMENT,
),
"CURRENT_ILLUMINATION": SensorEntityDescription(
key="CURRENT_ILLUMINATION",
native_unit_of_measurement=LIGHT_LUX,
device_class=DEVICE_CLASS_ILLUMINANCE,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.ILLUMINANCE,
state_class=SensorStateClass.MEASUREMENT,
),
"ILLUMINATION": SensorEntityDescription(
key="ILLUMINATION",
native_unit_of_measurement=LIGHT_LUX,
device_class=DEVICE_CLASS_ILLUMINANCE,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.ILLUMINANCE,
state_class=SensorStateClass.MEASUREMENT,
),
"AVERAGE_ILLUMINATION": SensorEntityDescription(
key="AVERAGE_ILLUMINATION",
native_unit_of_measurement=LIGHT_LUX,
device_class=DEVICE_CLASS_ILLUMINANCE,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.ILLUMINANCE,
state_class=SensorStateClass.MEASUREMENT,
),
"LOWEST_ILLUMINATION": SensorEntityDescription(
key="LOWEST_ILLUMINATION",
native_unit_of_measurement=LIGHT_LUX,
device_class=DEVICE_CLASS_ILLUMINANCE,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.ILLUMINANCE,
state_class=SensorStateClass.MEASUREMENT,
),
"HIGHEST_ILLUMINATION": SensorEntityDescription(
key="HIGHEST_ILLUMINATION",
native_unit_of_measurement=LIGHT_LUX,
device_class=DEVICE_CLASS_ILLUMINANCE,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.ILLUMINANCE,
state_class=SensorStateClass.MEASUREMENT,
),
"POWER": SensorEntityDescription(
key="POWER",
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
),
"IEC_POWER": SensorEntityDescription(
key="IEC_POWER",
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
),
"CURRENT": SensorEntityDescription(
key="CURRENT",
native_unit_of_measurement=ELECTRIC_CURRENT_MILLIAMPERE,
device_class=DEVICE_CLASS_CURRENT,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.CURRENT,
state_class=SensorStateClass.MEASUREMENT,
),
"CONCENTRATION": SensorEntityDescription(
key="CONCENTRATION",
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,
),
"ENERGY_COUNTER": SensorEntityDescription(
key="ENERGY_COUNTER",
native_unit_of_measurement=ENERGY_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
"IEC_ENERGY_COUNTER": SensorEntityDescription(
key="IEC_ENERGY_COUNTER",
native_unit_of_measurement=ENERGY_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
"VOLTAGE": SensorEntityDescription(
key="VOLTAGE",
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
),
"GAS_POWER": SensorEntityDescription(
key="GAS_POWER",
native_unit_of_measurement=VOLUME_CUBIC_METERS,
device_class=DEVICE_CLASS_GAS,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.GAS,
state_class=SensorStateClass.MEASUREMENT,
),
"GAS_ENERGY_COUNTER": SensorEntityDescription(
key="GAS_ENERGY_COUNTER",
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,
),
"RAIN_COUNTER": SensorEntityDescription(
key="RAIN_COUNTER",
@ -193,8 +183,8 @@ SENSOR_DESCRIPTIONS: dict[str, SensorEntityDescription] = {
"AIR_PRESSURE": SensorEntityDescription(
key="AIR_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,
),
"FREQUENCY": SensorEntityDescription(
key="FREQUENCY",