mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
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:
parent
8fc69b7242
commit
b7c0b21c6c
@ -1,10 +1,6 @@
|
|||||||
"""Support for HomeMatic binary sensors."""
|
"""Support for HomeMatic binary sensors."""
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
DEVICE_CLASS_BATTERY,
|
BinarySensorDeviceClass,
|
||||||
DEVICE_CLASS_MOTION,
|
|
||||||
DEVICE_CLASS_OPENING,
|
|
||||||
DEVICE_CLASS_PRESENCE,
|
|
||||||
DEVICE_CLASS_SMOKE,
|
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -12,24 +8,24 @@ from .const import ATTR_DISCOVER_DEVICES, ATTR_DISCOVERY_TYPE, DISCOVER_BATTERY
|
|||||||
from .entity import HMDevice
|
from .entity import HMDevice
|
||||||
|
|
||||||
SENSOR_TYPES_CLASS = {
|
SENSOR_TYPES_CLASS = {
|
||||||
"IPShutterContact": DEVICE_CLASS_OPENING,
|
"IPShutterContact": BinarySensorDeviceClass.OPENING,
|
||||||
"IPShutterContactSabotage": DEVICE_CLASS_OPENING,
|
"IPShutterContactSabotage": BinarySensorDeviceClass.OPENING,
|
||||||
"MaxShutterContact": DEVICE_CLASS_OPENING,
|
"MaxShutterContact": BinarySensorDeviceClass.OPENING,
|
||||||
"Motion": DEVICE_CLASS_MOTION,
|
"Motion": BinarySensorDeviceClass.MOTION,
|
||||||
"MotionV2": DEVICE_CLASS_MOTION,
|
"MotionV2": BinarySensorDeviceClass.MOTION,
|
||||||
"PresenceIP": DEVICE_CLASS_PRESENCE,
|
"PresenceIP": BinarySensorDeviceClass.MOTION,
|
||||||
"Remote": None,
|
"Remote": None,
|
||||||
"RemoteMotion": None,
|
"RemoteMotion": None,
|
||||||
"ShutterContact": DEVICE_CLASS_OPENING,
|
"ShutterContact": BinarySensorDeviceClass.OPENING,
|
||||||
"Smoke": DEVICE_CLASS_SMOKE,
|
"Smoke": BinarySensorDeviceClass.SMOKE,
|
||||||
"SmokeV2": DEVICE_CLASS_SMOKE,
|
"SmokeV2": BinarySensorDeviceClass.SMOKE,
|
||||||
"TiltSensor": None,
|
"TiltSensor": None,
|
||||||
"WeatherSensor": None,
|
"WeatherSensor": None,
|
||||||
"IPContact": DEVICE_CLASS_OPENING,
|
"IPContact": BinarySensorDeviceClass.OPENING,
|
||||||
"MotionIP": DEVICE_CLASS_MOTION,
|
"MotionIP": BinarySensorDeviceClass.MOTION,
|
||||||
"MotionIPV2": DEVICE_CLASS_MOTION,
|
"MotionIPV2": BinarySensorDeviceClass.MOTION,
|
||||||
"MotionIPContactSabotage": DEVICE_CLASS_MOTION,
|
"MotionIPContactSabotage": BinarySensorDeviceClass.MOTION,
|
||||||
"IPRemoteMotionV2": DEVICE_CLASS_MOTION,
|
"IPRemoteMotionV2": BinarySensorDeviceClass.MOTION,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -63,7 +59,7 @@ class HMBinarySensor(HMDevice, BinarySensorEntity):
|
|||||||
"""Return the class of this sensor from DEVICE_CLASSES."""
|
"""Return the class of this sensor from DEVICE_CLASSES."""
|
||||||
# If state is MOTION (Only RemoteMotion working)
|
# If state is MOTION (Only RemoteMotion working)
|
||||||
if self._state == "MOTION":
|
if self._state == "MOTION":
|
||||||
return DEVICE_CLASS_MOTION
|
return BinarySensorDeviceClass.MOTION
|
||||||
return SENSOR_TYPES_CLASS.get(self._hmdevice.__class__.__name__)
|
return SENSOR_TYPES_CLASS.get(self._hmdevice.__class__.__name__)
|
||||||
|
|
||||||
def _init_data_struct(self):
|
def _init_data_struct(self):
|
||||||
@ -76,7 +72,7 @@ class HMBinarySensor(HMDevice, BinarySensorEntity):
|
|||||||
class HMBatterySensor(HMDevice, BinarySensorEntity):
|
class HMBatterySensor(HMDevice, BinarySensorEntity):
|
||||||
"""Representation of an HomeMatic low battery sensor."""
|
"""Representation of an HomeMatic low battery sensor."""
|
||||||
|
|
||||||
_attr_device_class = DEVICE_CLASS_BATTERY
|
_attr_device_class = BinarySensorDeviceClass.BATTERY
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
from homeassistant.components.cover import (
|
from homeassistant.components.cover import (
|
||||||
ATTR_POSITION,
|
ATTR_POSITION,
|
||||||
ATTR_TILT_POSITION,
|
ATTR_TILT_POSITION,
|
||||||
DEVICE_CLASS_GARAGE,
|
CoverDeviceClass,
|
||||||
CoverEntity,
|
CoverEntity,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ class HMCover(HMDevice, CoverEntity):
|
|||||||
class HMGarage(HMCover):
|
class HMGarage(HMCover):
|
||||||
"""Represents a Homematic Garage cover. Homematic garage covers do not support position attributes."""
|
"""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
|
@property
|
||||||
def current_cover_position(self):
|
def current_cover_position(self):
|
||||||
|
@ -5,25 +5,15 @@ from copy import copy
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
STATE_CLASS_MEASUREMENT,
|
SensorDeviceClass,
|
||||||
STATE_CLASS_TOTAL_INCREASING,
|
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_NAME,
|
ATTR_NAME,
|
||||||
CONCENTRATION_PARTS_PER_MILLION,
|
CONCENTRATION_PARTS_PER_MILLION,
|
||||||
DEGREE,
|
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_CURRENT_MILLIAMPERE,
|
||||||
ELECTRIC_POTENTIAL_VOLT,
|
ELECTRIC_POTENTIAL_VOLT,
|
||||||
ENERGY_WATT_HOUR,
|
ENERGY_WATT_HOUR,
|
||||||
@ -64,110 +54,110 @@ SENSOR_DESCRIPTIONS: dict[str, SensorEntityDescription] = {
|
|||||||
"HUMIDITY": SensorEntityDescription(
|
"HUMIDITY": SensorEntityDescription(
|
||||||
key="HUMIDITY",
|
key="HUMIDITY",
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
device_class=DEVICE_CLASS_HUMIDITY,
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
"ACTUAL_TEMPERATURE": SensorEntityDescription(
|
"ACTUAL_TEMPERATURE": SensorEntityDescription(
|
||||||
key="ACTUAL_TEMPERATURE",
|
key="ACTUAL_TEMPERATURE",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=TEMP_CELSIUS,
|
||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
"TEMPERATURE": SensorEntityDescription(
|
"TEMPERATURE": SensorEntityDescription(
|
||||||
key="TEMPERATURE",
|
key="TEMPERATURE",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=TEMP_CELSIUS,
|
||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
"LUX": SensorEntityDescription(
|
"LUX": SensorEntityDescription(
|
||||||
key="LUX",
|
key="LUX",
|
||||||
native_unit_of_measurement=LIGHT_LUX,
|
native_unit_of_measurement=LIGHT_LUX,
|
||||||
device_class=DEVICE_CLASS_ILLUMINANCE,
|
device_class=SensorDeviceClass.ILLUMINANCE,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
"CURRENT_ILLUMINATION": SensorEntityDescription(
|
"CURRENT_ILLUMINATION": SensorEntityDescription(
|
||||||
key="CURRENT_ILLUMINATION",
|
key="CURRENT_ILLUMINATION",
|
||||||
native_unit_of_measurement=LIGHT_LUX,
|
native_unit_of_measurement=LIGHT_LUX,
|
||||||
device_class=DEVICE_CLASS_ILLUMINANCE,
|
device_class=SensorDeviceClass.ILLUMINANCE,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
"ILLUMINATION": SensorEntityDescription(
|
"ILLUMINATION": SensorEntityDescription(
|
||||||
key="ILLUMINATION",
|
key="ILLUMINATION",
|
||||||
native_unit_of_measurement=LIGHT_LUX,
|
native_unit_of_measurement=LIGHT_LUX,
|
||||||
device_class=DEVICE_CLASS_ILLUMINANCE,
|
device_class=SensorDeviceClass.ILLUMINANCE,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
"AVERAGE_ILLUMINATION": SensorEntityDescription(
|
"AVERAGE_ILLUMINATION": SensorEntityDescription(
|
||||||
key="AVERAGE_ILLUMINATION",
|
key="AVERAGE_ILLUMINATION",
|
||||||
native_unit_of_measurement=LIGHT_LUX,
|
native_unit_of_measurement=LIGHT_LUX,
|
||||||
device_class=DEVICE_CLASS_ILLUMINANCE,
|
device_class=SensorDeviceClass.ILLUMINANCE,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
"LOWEST_ILLUMINATION": SensorEntityDescription(
|
"LOWEST_ILLUMINATION": SensorEntityDescription(
|
||||||
key="LOWEST_ILLUMINATION",
|
key="LOWEST_ILLUMINATION",
|
||||||
native_unit_of_measurement=LIGHT_LUX,
|
native_unit_of_measurement=LIGHT_LUX,
|
||||||
device_class=DEVICE_CLASS_ILLUMINANCE,
|
device_class=SensorDeviceClass.ILLUMINANCE,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
"HIGHEST_ILLUMINATION": SensorEntityDescription(
|
"HIGHEST_ILLUMINATION": SensorEntityDescription(
|
||||||
key="HIGHEST_ILLUMINATION",
|
key="HIGHEST_ILLUMINATION",
|
||||||
native_unit_of_measurement=LIGHT_LUX,
|
native_unit_of_measurement=LIGHT_LUX,
|
||||||
device_class=DEVICE_CLASS_ILLUMINANCE,
|
device_class=SensorDeviceClass.ILLUMINANCE,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
"POWER": SensorEntityDescription(
|
"POWER": SensorEntityDescription(
|
||||||
key="POWER",
|
key="POWER",
|
||||||
native_unit_of_measurement=POWER_WATT,
|
native_unit_of_measurement=POWER_WATT,
|
||||||
device_class=DEVICE_CLASS_POWER,
|
device_class=SensorDeviceClass.POWER,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
"IEC_POWER": SensorEntityDescription(
|
"IEC_POWER": SensorEntityDescription(
|
||||||
key="IEC_POWER",
|
key="IEC_POWER",
|
||||||
native_unit_of_measurement=POWER_WATT,
|
native_unit_of_measurement=POWER_WATT,
|
||||||
device_class=DEVICE_CLASS_POWER,
|
device_class=SensorDeviceClass.POWER,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
"CURRENT": SensorEntityDescription(
|
"CURRENT": SensorEntityDescription(
|
||||||
key="CURRENT",
|
key="CURRENT",
|
||||||
native_unit_of_measurement=ELECTRIC_CURRENT_MILLIAMPERE,
|
native_unit_of_measurement=ELECTRIC_CURRENT_MILLIAMPERE,
|
||||||
device_class=DEVICE_CLASS_CURRENT,
|
device_class=SensorDeviceClass.CURRENT,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
"CONCENTRATION": SensorEntityDescription(
|
"CONCENTRATION": SensorEntityDescription(
|
||||||
key="CONCENTRATION",
|
key="CONCENTRATION",
|
||||||
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
|
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
|
||||||
device_class=DEVICE_CLASS_CO2,
|
device_class=SensorDeviceClass.CO2,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
"ENERGY_COUNTER": SensorEntityDescription(
|
"ENERGY_COUNTER": SensorEntityDescription(
|
||||||
key="ENERGY_COUNTER",
|
key="ENERGY_COUNTER",
|
||||||
native_unit_of_measurement=ENERGY_WATT_HOUR,
|
native_unit_of_measurement=ENERGY_WATT_HOUR,
|
||||||
device_class=DEVICE_CLASS_ENERGY,
|
device_class=SensorDeviceClass.ENERGY,
|
||||||
state_class=STATE_CLASS_TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
),
|
),
|
||||||
"IEC_ENERGY_COUNTER": SensorEntityDescription(
|
"IEC_ENERGY_COUNTER": SensorEntityDescription(
|
||||||
key="IEC_ENERGY_COUNTER",
|
key="IEC_ENERGY_COUNTER",
|
||||||
native_unit_of_measurement=ENERGY_WATT_HOUR,
|
native_unit_of_measurement=ENERGY_WATT_HOUR,
|
||||||
device_class=DEVICE_CLASS_ENERGY,
|
device_class=SensorDeviceClass.ENERGY,
|
||||||
state_class=STATE_CLASS_TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
),
|
),
|
||||||
"VOLTAGE": SensorEntityDescription(
|
"VOLTAGE": SensorEntityDescription(
|
||||||
key="VOLTAGE",
|
key="VOLTAGE",
|
||||||
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||||
device_class=DEVICE_CLASS_VOLTAGE,
|
device_class=SensorDeviceClass.VOLTAGE,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
"GAS_POWER": SensorEntityDescription(
|
"GAS_POWER": SensorEntityDescription(
|
||||||
key="GAS_POWER",
|
key="GAS_POWER",
|
||||||
native_unit_of_measurement=VOLUME_CUBIC_METERS,
|
native_unit_of_measurement=VOLUME_CUBIC_METERS,
|
||||||
device_class=DEVICE_CLASS_GAS,
|
device_class=SensorDeviceClass.GAS,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
"GAS_ENERGY_COUNTER": SensorEntityDescription(
|
"GAS_ENERGY_COUNTER": SensorEntityDescription(
|
||||||
key="GAS_ENERGY_COUNTER",
|
key="GAS_ENERGY_COUNTER",
|
||||||
native_unit_of_measurement=VOLUME_CUBIC_METERS,
|
native_unit_of_measurement=VOLUME_CUBIC_METERS,
|
||||||
device_class=DEVICE_CLASS_GAS,
|
device_class=SensorDeviceClass.GAS,
|
||||||
state_class=STATE_CLASS_TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
),
|
),
|
||||||
"RAIN_COUNTER": SensorEntityDescription(
|
"RAIN_COUNTER": SensorEntityDescription(
|
||||||
key="RAIN_COUNTER",
|
key="RAIN_COUNTER",
|
||||||
@ -193,8 +183,8 @@ SENSOR_DESCRIPTIONS: dict[str, SensorEntityDescription] = {
|
|||||||
"AIR_PRESSURE": SensorEntityDescription(
|
"AIR_PRESSURE": SensorEntityDescription(
|
||||||
key="AIR_PRESSURE",
|
key="AIR_PRESSURE",
|
||||||
native_unit_of_measurement=PRESSURE_HPA,
|
native_unit_of_measurement=PRESSURE_HPA,
|
||||||
device_class=DEVICE_CLASS_PRESSURE,
|
device_class=SensorDeviceClass.PRESSURE,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
"FREQUENCY": SensorEntityDescription(
|
"FREQUENCY": SensorEntityDescription(
|
||||||
key="FREQUENCY",
|
key="FREQUENCY",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user