From 621526bbae04603970747b6a640fff1985edc384 Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Sun, 13 Sep 2020 16:33:54 +0200 Subject: [PATCH] Use moisture and moving device class in various integrations (#39963) --- homeassistant/components/ads/binary_sensor.py | 3 ++- homeassistant/components/bloomsky/binary_sensor.py | 8 ++++++-- homeassistant/components/demo/binary_sensor.py | 5 ++++- homeassistant/components/digital_ocean/binary_sensor.py | 9 ++++++--- homeassistant/components/guardian/binary_sensor.py | 3 ++- homeassistant/components/linode/binary_sensor.py | 9 ++++++--- homeassistant/components/mysensors/binary_sensor.py | 3 ++- homeassistant/components/notion/binary_sensor.py | 3 ++- homeassistant/components/smartthings/binary_sensor.py | 6 ++++-- homeassistant/components/wink/binary_sensor.py | 3 ++- homeassistant/components/xiaomi_aqara/binary_sensor.py | 3 ++- 11 files changed, 38 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/ads/binary_sensor.py b/homeassistant/components/ads/binary_sensor.py index df8a74dc1d5..d481420b4d4 100644 --- a/homeassistant/components/ads/binary_sensor.py +++ b/homeassistant/components/ads/binary_sensor.py @@ -4,6 +4,7 @@ import logging import voluptuous as vol from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_MOVING, DEVICE_CLASSES_SCHEMA, PLATFORM_SCHEMA, BinarySensorEntity, @@ -43,7 +44,7 @@ class AdsBinarySensor(AdsEntity, BinarySensorEntity): def __init__(self, ads_hub, name, ads_var, device_class): """Initialize ADS binary sensor.""" super().__init__(ads_hub, name, ads_var) - self._device_class = device_class or "moving" + self._device_class = device_class or DEVICE_CLASS_MOVING async def async_added_to_hass(self): """Register device notification.""" diff --git a/homeassistant/components/bloomsky/binary_sensor.py b/homeassistant/components/bloomsky/binary_sensor.py index 077171006bf..43c5614679c 100644 --- a/homeassistant/components/bloomsky/binary_sensor.py +++ b/homeassistant/components/bloomsky/binary_sensor.py @@ -3,7 +3,11 @@ import logging import voluptuous as vol -from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorEntity +from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_MOISTURE, + PLATFORM_SCHEMA, + BinarySensorEntity, +) from homeassistant.const import CONF_MONITORED_CONDITIONS import homeassistant.helpers.config_validation as cv @@ -11,7 +15,7 @@ from . import DOMAIN _LOGGER = logging.getLogger(__name__) -SENSOR_TYPES = {"Rain": "moisture", "Night": None} +SENSOR_TYPES = {"Rain": DEVICE_CLASS_MOISTURE, "Night": None} PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { diff --git a/homeassistant/components/demo/binary_sensor.py b/homeassistant/components/demo/binary_sensor.py index 26a7ca98a7e..c4186eae505 100644 --- a/homeassistant/components/demo/binary_sensor.py +++ b/homeassistant/components/demo/binary_sensor.py @@ -1,5 +1,6 @@ """Demo platform that has two fake binary sensors.""" from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_MOISTURE, DEVICE_CLASS_MOTION, BinarySensorEntity, ) @@ -11,7 +12,9 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= """Set up the Demo binary sensor platform.""" async_add_entities( [ - DemoBinarySensor("binary_1", "Basement Floor Wet", False, "moisture"), + DemoBinarySensor( + "binary_1", "Basement Floor Wet", False, DEVICE_CLASS_MOISTURE + ), DemoBinarySensor( "binary_2", "Movement Backyard", True, DEVICE_CLASS_MOTION ), diff --git a/homeassistant/components/digital_ocean/binary_sensor.py b/homeassistant/components/digital_ocean/binary_sensor.py index d076dae9210..eb1345df45c 100644 --- a/homeassistant/components/digital_ocean/binary_sensor.py +++ b/homeassistant/components/digital_ocean/binary_sensor.py @@ -3,7 +3,11 @@ import logging import voluptuous as vol -from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorEntity +from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_MOVING, + PLATFORM_SCHEMA, + BinarySensorEntity, +) from homeassistant.const import ATTR_ATTRIBUTION import homeassistant.helpers.config_validation as cv @@ -25,7 +29,6 @@ from . import ( _LOGGER = logging.getLogger(__name__) DEFAULT_NAME = "Droplet" -DEFAULT_DEVICE_CLASS = "moving" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( {vol.Required(CONF_DROPLETS): vol.All(cv.ensure_list, [cv.string])} ) @@ -73,7 +76,7 @@ class DigitalOceanBinarySensor(BinarySensorEntity): @property def device_class(self): """Return the class of this sensor.""" - return DEFAULT_DEVICE_CLASS + return DEVICE_CLASS_MOVING @property def device_state_attributes(self): diff --git a/homeassistant/components/guardian/binary_sensor.py b/homeassistant/components/guardian/binary_sensor.py index 4d8c429a9d1..7942dba361e 100644 --- a/homeassistant/components/guardian/binary_sensor.py +++ b/homeassistant/components/guardian/binary_sensor.py @@ -5,6 +5,7 @@ from aioguardian import Client from homeassistant.components.binary_sensor import ( DEVICE_CLASS_CONNECTIVITY, + DEVICE_CLASS_MOISTURE, BinarySensorEntity, ) from homeassistant.config_entries import ConfigEntry @@ -26,7 +27,7 @@ SENSOR_KIND_AP_INFO = "ap_enabled" SENSOR_KIND_LEAK_DETECTED = "leak_detected" SENSORS = [ (SENSOR_KIND_AP_INFO, "Onboard AP Enabled", DEVICE_CLASS_CONNECTIVITY), - (SENSOR_KIND_LEAK_DETECTED, "Leak Detected", "moisture"), + (SENSOR_KIND_LEAK_DETECTED, "Leak Detected", DEVICE_CLASS_MOISTURE), ] diff --git a/homeassistant/components/linode/binary_sensor.py b/homeassistant/components/linode/binary_sensor.py index c4a14210d32..bb81a022891 100644 --- a/homeassistant/components/linode/binary_sensor.py +++ b/homeassistant/components/linode/binary_sensor.py @@ -3,7 +3,11 @@ import logging import voluptuous as vol -from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorEntity +from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_MOVING, + PLATFORM_SCHEMA, + BinarySensorEntity, +) import homeassistant.helpers.config_validation as cv from . import ( @@ -22,7 +26,6 @@ from . import ( _LOGGER = logging.getLogger(__name__) DEFAULT_NAME = "Node" -DEFAULT_DEVICE_CLASS = "moving" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( {vol.Required(CONF_NODES): vol.All(cv.ensure_list, [cv.string])} ) @@ -69,7 +72,7 @@ class LinodeBinarySensor(BinarySensorEntity): @property def device_class(self): """Return the class of this sensor.""" - return DEFAULT_DEVICE_CLASS + return DEVICE_CLASS_MOVING @property def device_state_attributes(self): diff --git a/homeassistant/components/mysensors/binary_sensor.py b/homeassistant/components/mysensors/binary_sensor.py index fc9d0263441..4ec3c6e0abd 100644 --- a/homeassistant/components/mysensors/binary_sensor.py +++ b/homeassistant/components/mysensors/binary_sensor.py @@ -1,6 +1,7 @@ """Support for MySensors binary sensors.""" from homeassistant.components import mysensors from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_MOISTURE, DEVICE_CLASS_MOTION, DEVICE_CLASS_SAFETY, DEVICE_CLASS_SOUND, @@ -19,7 +20,7 @@ SENSORS = { "S_WATER_LEAK": DEVICE_CLASS_SAFETY, "S_SOUND": DEVICE_CLASS_SOUND, "S_VIBRATION": DEVICE_CLASS_VIBRATION, - "S_MOISTURE": "moisture", + "S_MOISTURE": DEVICE_CLASS_MOISTURE, } diff --git a/homeassistant/components/notion/binary_sensor.py b/homeassistant/components/notion/binary_sensor.py index 5bae2592b6c..3702688eb94 100644 --- a/homeassistant/components/notion/binary_sensor.py +++ b/homeassistant/components/notion/binary_sensor.py @@ -5,6 +5,7 @@ from typing import Callable from homeassistant.components.binary_sensor import ( DEVICE_CLASS_CONNECTIVITY, DEVICE_CLASS_DOOR, + DEVICE_CLASS_MOISTURE, DEVICE_CLASS_SMOKE, DEVICE_CLASS_WINDOW, BinarySensorEntity, @@ -34,7 +35,7 @@ BINARY_SENSOR_TYPES = { SENSOR_BATTERY: ("Low Battery", "battery"), SENSOR_DOOR: ("Door", DEVICE_CLASS_DOOR), SENSOR_GARAGE_DOOR: ("Garage Door", "garage_door"), - SENSOR_LEAK: ("Leak Detector", "moisture"), + SENSOR_LEAK: ("Leak Detector", DEVICE_CLASS_MOISTURE), SENSOR_MISSING: ("Missing", DEVICE_CLASS_CONNECTIVITY), SENSOR_SAFE: ("Safe", DEVICE_CLASS_DOOR), SENSOR_SLIDING: ("Sliding Door/Window", DEVICE_CLASS_DOOR), diff --git a/homeassistant/components/smartthings/binary_sensor.py b/homeassistant/components/smartthings/binary_sensor.py index 47ca6879701..41e915d5c95 100644 --- a/homeassistant/components/smartthings/binary_sensor.py +++ b/homeassistant/components/smartthings/binary_sensor.py @@ -4,7 +4,9 @@ from typing import Optional, Sequence from pysmartthings import Attribute, Capability from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_MOISTURE, DEVICE_CLASS_MOTION, + DEVICE_CLASS_MOVING, DEVICE_CLASS_OPENING, DEVICE_CLASS_PRESENCE, DEVICE_CLASS_PROBLEM, @@ -27,7 +29,7 @@ CAPABILITY_TO_ATTRIB = { Capability.water_sensor: Attribute.water, } ATTRIB_TO_CLASS = { - Attribute.acceleration: "moving", + Attribute.acceleration: DEVICE_CLASS_MOVING, Attribute.contact: DEVICE_CLASS_OPENING, Attribute.filter_status: DEVICE_CLASS_PROBLEM, Attribute.motion: DEVICE_CLASS_MOTION, @@ -35,7 +37,7 @@ ATTRIB_TO_CLASS = { Attribute.sound: DEVICE_CLASS_SOUND, Attribute.tamper: DEVICE_CLASS_PROBLEM, Attribute.valve: DEVICE_CLASS_OPENING, - Attribute.water: "moisture", + Attribute.water: DEVICE_CLASS_MOISTURE, } diff --git a/homeassistant/components/wink/binary_sensor.py b/homeassistant/components/wink/binary_sensor.py index 04117758c54..77ff464a5bf 100644 --- a/homeassistant/components/wink/binary_sensor.py +++ b/homeassistant/components/wink/binary_sensor.py @@ -4,6 +4,7 @@ import logging import pywink from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_MOISTURE, DEVICE_CLASS_MOTION, DEVICE_CLASS_OCCUPANCY, DEVICE_CLASS_OPENING, @@ -23,7 +24,7 @@ SENSOR_TYPES = { "capturing_audio": DEVICE_CLASS_SOUND, "capturing_video": None, "co_detected": "gas", - "liquid_detected": "moisture", + "liquid_detected": DEVICE_CLASS_MOISTURE, "loudness": DEVICE_CLASS_SOUND, "motion": DEVICE_CLASS_MOTION, "noise": DEVICE_CLASS_SOUND, diff --git a/homeassistant/components/xiaomi_aqara/binary_sensor.py b/homeassistant/components/xiaomi_aqara/binary_sensor.py index f8d1622ae92..d63be7824ed 100644 --- a/homeassistant/components/xiaomi_aqara/binary_sensor.py +++ b/homeassistant/components/xiaomi_aqara/binary_sensor.py @@ -2,6 +2,7 @@ import logging from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_MOISTURE, DEVICE_CLASS_OPENING, BinarySensorEntity, ) @@ -352,7 +353,7 @@ class XiaomiWaterLeakSensor(XiaomiBinarySensor): "Water Leak Sensor", xiaomi_hub, data_key, - "moisture", + DEVICE_CLASS_MOISTURE, config_entry, )