Use enums in Point (#62070)
parent
74a9f8e81d
commit
32e1a3d063
|
@ -4,14 +4,8 @@ import logging
|
||||||
from pypoint import EVENTS
|
from pypoint import EVENTS
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
DEVICE_CLASS_BATTERY,
|
|
||||||
DEVICE_CLASS_COLD,
|
|
||||||
DEVICE_CLASS_CONNECTIVITY,
|
|
||||||
DEVICE_CLASS_HEAT,
|
|
||||||
DEVICE_CLASS_MOISTURE,
|
|
||||||
DEVICE_CLASS_MOTION,
|
|
||||||
DEVICE_CLASS_SOUND,
|
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
BinarySensorDeviceClass,
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
@ -25,17 +19,17 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEVICES = {
|
DEVICES = {
|
||||||
"alarm": {"icon": "mdi:alarm-bell"},
|
"alarm": {"icon": "mdi:alarm-bell"},
|
||||||
"battery": {"device_class": DEVICE_CLASS_BATTERY},
|
"battery": {"device_class": BinarySensorDeviceClass.BATTERY},
|
||||||
"button_press": {"icon": "mdi:gesture-tap-button"},
|
"button_press": {"icon": "mdi:gesture-tap-button"},
|
||||||
"cold": {"device_class": DEVICE_CLASS_COLD},
|
"cold": {"device_class": BinarySensorDeviceClass.COLD},
|
||||||
"connectivity": {"device_class": DEVICE_CLASS_CONNECTIVITY},
|
"connectivity": {"device_class": BinarySensorDeviceClass.CONNECTIVITY},
|
||||||
"dry": {"icon": "mdi:water"},
|
"dry": {"icon": "mdi:water"},
|
||||||
"glass": {"icon": "mdi:window-closed-variant"},
|
"glass": {"icon": "mdi:window-closed-variant"},
|
||||||
"heat": {"device_class": DEVICE_CLASS_HEAT},
|
"heat": {"device_class": BinarySensorDeviceClass.HEAT},
|
||||||
"moisture": {"device_class": DEVICE_CLASS_MOISTURE},
|
"moisture": {"device_class": BinarySensorDeviceClass.MOISTURE},
|
||||||
"motion": {"device_class": DEVICE_CLASS_MOTION},
|
"motion": {"device_class": BinarySensorDeviceClass.MOTION},
|
||||||
"noise": {"icon": "mdi:volume-high"},
|
"noise": {"icon": "mdi:volume-high"},
|
||||||
"sound": {"device_class": DEVICE_CLASS_SOUND},
|
"sound": {"device_class": BinarySensorDeviceClass.SOUND},
|
||||||
"tamper_old": {"icon": "mdi:shield-alert"},
|
"tamper_old": {"icon": "mdi:shield-alert"},
|
||||||
"tamper": {"icon": "mdi:shield-alert"},
|
"tamper": {"icon": "mdi:shield-alert"},
|
||||||
}
|
}
|
||||||
|
@ -118,7 +112,7 @@ class MinutPointBinarySensor(MinutPointEntity, BinarySensorEntity):
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return the state of the binary sensor."""
|
"""Return the state of the binary sensor."""
|
||||||
if self.device_class == DEVICE_CLASS_CONNECTIVITY:
|
if self.device_class == BinarySensorDeviceClass.CONNECTIVITY:
|
||||||
# connectivity is the other way around.
|
# connectivity is the other way around.
|
||||||
return not self._is_on
|
return not self._is_on
|
||||||
return self._is_on
|
return self._is_on
|
||||||
|
|
|
@ -6,16 +6,11 @@ import logging
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
SensorDeviceClass,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import PERCENTAGE, SOUND_PRESSURE_WEIGHTED_DBA, TEMP_CELSIUS
|
||||||
DEVICE_CLASS_HUMIDITY,
|
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
|
||||||
PERCENTAGE,
|
|
||||||
SOUND_PRESSURE_WEIGHTED_DBA,
|
|
||||||
TEMP_CELSIUS,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.util.dt import parse_datetime
|
from homeassistant.util.dt import parse_datetime
|
||||||
|
|
||||||
|
@ -45,13 +40,13 @@ SENSOR_TYPES: tuple[MinutPointSensorEntityDescription, ...] = (
|
||||||
MinutPointSensorEntityDescription(
|
MinutPointSensorEntityDescription(
|
||||||
key="temperature",
|
key="temperature",
|
||||||
precision=1,
|
precision=1,
|
||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=TEMP_CELSIUS,
|
||||||
),
|
),
|
||||||
MinutPointSensorEntityDescription(
|
MinutPointSensorEntityDescription(
|
||||||
key="humidity",
|
key="humidity",
|
||||||
precision=1,
|
precision=1,
|
||||||
device_class=DEVICE_CLASS_HUMIDITY,
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
),
|
),
|
||||||
MinutPointSensorEntityDescription(
|
MinutPointSensorEntityDescription(
|
||||||
|
|
Loading…
Reference in New Issue