Use sound, vibration and safety device class constants in various integrations (#39952)

* Use sound, vibration and safety device class constants in various integrations

* Fix wrong imports
pull/39960/head
springstan 2020-09-12 02:37:33 +02:00 committed by GitHub
parent ee5c1ea3f7
commit ac2e290d97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 19 deletions

View File

@ -7,6 +7,7 @@ import requests
import voluptuous as vol
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_SAFETY,
DEVICE_CLASSES,
PLATFORM_SCHEMA,
BinarySensorEntity,
@ -87,7 +88,7 @@ def get_opening_type(zone):
if "MOTION" in zone["name"]:
return "motion"
if "KEY" in zone["name"]:
return "safety"
return DEVICE_CLASS_SAFETY
if "SMOKE" in zone["name"]:
return "smoke"
if "WATER" in zone["name"]:

View File

@ -4,7 +4,7 @@ import logging
import haffmpeg.sensor as ffmpeg_sensor
import voluptuous as vol
from homeassistant.components.binary_sensor import PLATFORM_SCHEMA
from homeassistant.components.binary_sensor import DEVICE_CLASS_SOUND, PLATFORM_SCHEMA
from homeassistant.components.ffmpeg import (
CONF_EXTRA_ARGUMENTS,
CONF_INITIAL_STATE,
@ -84,4 +84,4 @@ class FFmpegNoise(FFmpegBinarySensor):
@property
def device_class(self):
"""Return the class of this sensor, from DEVICE_CLASSES."""
return "sound"
return DEVICE_CLASS_SOUND

View File

@ -5,7 +5,11 @@ import logging
from meteoalertapi import Meteoalert
import voluptuous as vol
from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorEntity
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_SAFETY,
PLATFORM_SCHEMA,
BinarySensorEntity,
)
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME
import homeassistant.helpers.config_validation as cv
@ -17,7 +21,6 @@ CONF_COUNTRY = "country"
CONF_LANGUAGE = "language"
CONF_PROVINCE = "province"
DEFAULT_DEVICE_CLASS = "safety"
DEFAULT_NAME = "meteoalarm"
SCAN_INTERVAL = timedelta(minutes=30)
@ -78,7 +81,7 @@ class MeteoAlertBinarySensor(BinarySensorEntity):
@property
def device_class(self):
"""Return the device class of this binary sensor."""
return DEFAULT_DEVICE_CLASS
return DEVICE_CLASS_SAFETY
def update(self):
"""Update device state."""

View File

@ -1,6 +1,9 @@
"""Support for MySensors binary sensors."""
from homeassistant.components import mysensors
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_SAFETY,
DEVICE_CLASS_SOUND,
DEVICE_CLASS_VIBRATION,
DEVICE_CLASSES,
DOMAIN,
BinarySensorEntity,
@ -11,10 +14,10 @@ SENSORS = {
"S_DOOR": "door",
"S_MOTION": "motion",
"S_SMOKE": "smoke",
"S_SPRINKLER": "safety",
"S_WATER_LEAK": "safety",
"S_SOUND": "sound",
"S_VIBRATION": "vibration",
"S_SPRINKLER": DEVICE_CLASS_SAFETY,
"S_WATER_LEAK": DEVICE_CLASS_SAFETY,
"S_SOUND": DEVICE_CLASS_SOUND,
"S_VIBRATION": DEVICE_CLASS_VIBRATION,
"S_MOISTURE": "moisture",
}

View File

@ -2,7 +2,10 @@
from itertools import chain
import logging
from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_SOUND,
BinarySensorEntity,
)
from homeassistant.const import CONF_MONITORED_CONDITIONS
from . import CONF_BINARY_SENSORS, DATA_NEST, DATA_NEST_CONFIG, NestSensorDevice
@ -20,7 +23,7 @@ CLIMATE_BINARY_TYPES = {
CAMERA_BINARY_TYPES = {
"motion_detected": "motion",
"sound_detected": "sound",
"sound_detected": DEVICE_CLASS_SOUND,
"person_detected": "occupancy",
}

View File

@ -3,7 +3,10 @@ from typing import Optional, Sequence
from pysmartthings import Attribute, Capability
from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_SOUND,
BinarySensorEntity,
)
from . import SmartThingsEntity
from .const import DATA_BROKERS, DOMAIN
@ -25,7 +28,7 @@ ATTRIB_TO_CLASS = {
Attribute.filter_status: "problem",
Attribute.motion: "motion",
Attribute.presence: "presence",
Attribute.sound: "sound",
Attribute.sound: DEVICE_CLASS_SOUND,
Attribute.tamper: "problem",
Attribute.valve: "opening",
Attribute.water: "moisture",

View File

@ -3,7 +3,11 @@ import logging
import pywink
from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_SOUND,
DEVICE_CLASS_VIBRATION,
BinarySensorEntity,
)
from . import DOMAIN, WinkDevice
@ -12,17 +16,17 @@ _LOGGER = logging.getLogger(__name__)
# These are the available sensors mapped to binary_sensor class
SENSOR_TYPES = {
"brightness": "light",
"capturing_audio": "sound",
"capturing_audio": DEVICE_CLASS_SOUND,
"capturing_video": None,
"co_detected": "gas",
"liquid_detected": "moisture",
"loudness": "sound",
"loudness": DEVICE_CLASS_SOUND,
"motion": "motion",
"noise": "sound",
"noise": DEVICE_CLASS_SOUND,
"opened": "opening",
"presence": "occupancy",
"smoke_detected": "smoke",
"vibration": "vibration",
"vibration": DEVICE_CLASS_VIBRATION,
}