Use new BinarySensorDeviceClass in isy994 (#61825)

This commit is contained in:
epenet 2021-12-16 02:11:46 +01:00 committed by GitHub
parent d68946f568
commit f72b2e71ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 50 deletions

View File

@ -13,15 +13,8 @@ from pyisy.constants import (
from pyisy.nodes import Group, Node from pyisy.nodes import Group, Node
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_COLD,
DEVICE_CLASS_HEAT,
DEVICE_CLASS_LIGHT,
DEVICE_CLASS_MOISTURE,
DEVICE_CLASS_MOTION,
DEVICE_CLASS_OPENING,
DEVICE_CLASS_PROBLEM,
DOMAIN as BINARY_SENSOR, DOMAIN as BINARY_SENSOR,
BinarySensorDeviceClass,
BinarySensorEntity, BinarySensorEntity,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
@ -52,9 +45,9 @@ from .entity import ISYNodeEntity, ISYProgramEntity
from .helpers import migrate_old_unique_ids from .helpers import migrate_old_unique_ids
DEVICE_PARENT_REQUIRED = [ DEVICE_PARENT_REQUIRED = [
DEVICE_CLASS_OPENING, BinarySensorDeviceClass.OPENING,
DEVICE_CLASS_MOISTURE, BinarySensorDeviceClass.MOISTURE,
DEVICE_CLASS_MOTION, BinarySensorDeviceClass.MOTION,
] ]
@ -94,11 +87,15 @@ async def async_setup_entry(
# detected after an ISY Restart, so we assume it's off. # detected after an ISY Restart, so we assume it's off.
# As soon as the ISY Event Stream connects if it has a # As soon as the ISY Event Stream connects if it has a
# valid state, it will be set. # valid state, it will be set.
device = ISYInsteonBinarySensorEntity(node, DEVICE_CLASS_COLD, False) device = ISYInsteonBinarySensorEntity(
node, BinarySensorDeviceClass.COLD, False
)
devices.append(device) devices.append(device)
elif subnode_id == SUBNODE_CLIMATE_HEAT: elif subnode_id == SUBNODE_CLIMATE_HEAT:
# Subnode 3 is the "Heat Control" sensor # Subnode 3 is the "Heat Control" sensor
device = ISYInsteonBinarySensorEntity(node, DEVICE_CLASS_HEAT, False) device = ISYInsteonBinarySensorEntity(
node, BinarySensorDeviceClass.HEAT, False
)
devices.append(device) devices.append(device)
continue continue
@ -113,7 +110,10 @@ async def async_setup_entry(
) )
continue continue
if device_class in (DEVICE_CLASS_OPENING, DEVICE_CLASS_MOISTURE): if device_class in (
BinarySensorDeviceClass.OPENING,
BinarySensorDeviceClass.MOISTURE,
):
# These sensors use an optional "negative" subnode 2 to # These sensors use an optional "negative" subnode 2 to
# snag all state changes # snag all state changes
if subnode_id == SUBNODE_NEGATIVE: if subnode_id == SUBNODE_NEGATIVE:
@ -126,7 +126,7 @@ async def async_setup_entry(
devices.append(device) devices.append(device)
continue continue
if ( if (
device_class == DEVICE_CLASS_MOTION device_class == BinarySensorDeviceClass.MOTION
and device_type is not None and device_type is not None
and any(device_type.startswith(t) for t in TYPE_INSTEON_MOTION) and any(device_type.startswith(t) for t in TYPE_INSTEON_MOTION)
): ):
@ -138,13 +138,15 @@ async def async_setup_entry(
initial_state = None if parent_device.state is None else False initial_state = None if parent_device.state is None else False
if subnode_id == SUBNODE_DUSK_DAWN: if subnode_id == SUBNODE_DUSK_DAWN:
# Subnode 2 is the Dusk/Dawn sensor # Subnode 2 is the Dusk/Dawn sensor
device = ISYInsteonBinarySensorEntity(node, DEVICE_CLASS_LIGHT) device = ISYInsteonBinarySensorEntity(
node, BinarySensorDeviceClass.LIGHT
)
devices.append(device) devices.append(device)
continue continue
if subnode_id == SUBNODE_LOW_BATTERY: if subnode_id == SUBNODE_LOW_BATTERY:
# Subnode 3 is the low battery node # Subnode 3 is the low battery node
device = ISYInsteonBinarySensorEntity( device = ISYInsteonBinarySensorEntity(
node, DEVICE_CLASS_BATTERY, initial_state node, BinarySensorDeviceClass.BATTERY, initial_state
) )
devices.append(device) devices.append(device)
continue continue
@ -152,7 +154,7 @@ async def async_setup_entry(
# Tamper Sub-node for MS II. Sometimes reported as "A" sometimes # Tamper Sub-node for MS II. Sometimes reported as "A" sometimes
# reported as "10", which translate from Hex to 10 and 16 resp. # reported as "10", which translate from Hex to 10 and 16 resp.
device = ISYInsteonBinarySensorEntity( device = ISYInsteonBinarySensorEntity(
node, DEVICE_CLASS_PROBLEM, initial_state node, BinarySensorDeviceClass.PROBLEM, initial_state
) )
devices.append(device) devices.append(device)
continue continue
@ -352,7 +354,7 @@ class ISYInsteonBinarySensorEntity(ISYBinarySensorEntity):
# Do this first so we don't invert None on moisture sensors # Do this first so we don't invert None on moisture sensors
return None return None
if self.device_class == DEVICE_CLASS_MOISTURE: if self.device_class == BinarySensorDeviceClass.MOISTURE:
return not self._computed_state return not self._computed_state
return self._computed_state return self._computed_state
@ -454,7 +456,7 @@ class ISYBinarySensorHeartbeat(ISYNodeEntity, BinarySensorEntity):
@property @property
def device_class(self) -> str: def device_class(self) -> str:
"""Get the class of this device.""" """Get the class of this device."""
return DEVICE_CLASS_BATTERY return BinarySensorDeviceClass.BATTERY
@property @property
def extra_state_attributes(self): def extra_state_attributes(self):

View File

@ -1,21 +1,7 @@
"""Constants for the ISY994 Platform.""" """Constants for the ISY994 Platform."""
import logging import logging
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import BinarySensorDeviceClass
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_COLD,
DEVICE_CLASS_DOOR,
DEVICE_CLASS_GAS,
DEVICE_CLASS_HEAT,
DEVICE_CLASS_MOISTURE,
DEVICE_CLASS_MOTION,
DEVICE_CLASS_OPENING,
DEVICE_CLASS_PROBLEM,
DEVICE_CLASS_SAFETY,
DEVICE_CLASS_SMOKE,
DEVICE_CLASS_SOUND,
DEVICE_CLASS_VIBRATION,
)
from homeassistant.components.climate.const import ( from homeassistant.components.climate.const import (
CURRENT_HVAC_COOL, CURRENT_HVAC_COOL,
CURRENT_HVAC_FAN, CURRENT_HVAC_FAN,
@ -651,8 +637,8 @@ HA_HVAC_TO_ISY = {
HA_FAN_TO_ISY = {FAN_ON: "on", FAN_AUTO: "auto"} HA_FAN_TO_ISY = {FAN_ON: "on", FAN_AUTO: "auto"}
BINARY_SENSOR_DEVICE_TYPES_ISY = { BINARY_SENSOR_DEVICE_TYPES_ISY = {
DEVICE_CLASS_MOISTURE: ["16.8.", "16.13.", "16.14."], BinarySensorDeviceClass.MOISTURE: ["16.8.", "16.13.", "16.14."],
DEVICE_CLASS_OPENING: [ BinarySensorDeviceClass.OPENING: [
"16.9.", "16.9.",
"16.6.", "16.6.",
"16.7.", "16.7.",
@ -661,22 +647,22 @@ BINARY_SENSOR_DEVICE_TYPES_ISY = {
"16.20.", "16.20.",
"16.21.", "16.21.",
], ],
DEVICE_CLASS_MOTION: ["16.1.", "16.4.", "16.5.", "16.3.", "16.22."], BinarySensorDeviceClass.MOTION: ["16.1.", "16.4.", "16.5.", "16.3.", "16.22."],
} }
BINARY_SENSOR_DEVICE_TYPES_ZWAVE = { BINARY_SENSOR_DEVICE_TYPES_ZWAVE = {
DEVICE_CLASS_SAFETY: ["137", "172", "176", "177", "178"], BinarySensorDeviceClass.SAFETY: ["137", "172", "176", "177", "178"],
DEVICE_CLASS_SMOKE: ["138", "156"], BinarySensorDeviceClass.SMOKE: ["138", "156"],
DEVICE_CLASS_PROBLEM: ["148", "149", "157", "158", "164", "174", "175"], BinarySensorDeviceClass.PROBLEM: ["148", "149", "157", "158", "164", "174", "175"],
DEVICE_CLASS_GAS: ["150", "151"], BinarySensorDeviceClass.GAS: ["150", "151"],
DEVICE_CLASS_SOUND: ["153"], BinarySensorDeviceClass.SOUND: ["153"],
DEVICE_CLASS_COLD: ["152", "168"], BinarySensorDeviceClass.COLD: ["152", "168"],
DEVICE_CLASS_HEAT: ["154", "166", "167"], BinarySensorDeviceClass.HEAT: ["154", "166", "167"],
DEVICE_CLASS_MOISTURE: ["159", "169"], BinarySensorDeviceClass.MOISTURE: ["159", "169"],
DEVICE_CLASS_DOOR: ["160"], BinarySensorDeviceClass.DOOR: ["160"],
DEVICE_CLASS_BATTERY: ["162"], BinarySensorDeviceClass.BATTERY: ["162"],
DEVICE_CLASS_MOTION: ["155"], BinarySensorDeviceClass.MOTION: ["155"],
DEVICE_CLASS_VIBRATION: ["173"], BinarySensorDeviceClass.VIBRATION: ["173"],
} }