From e55035b2f96da2f92296ef9c298609503db1fc9d Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Sat, 12 Sep 2020 23:20:30 +0200 Subject: [PATCH] Use DEVICE_CLASS_MOTION in various integrations (#39962) --- .../android_ip_webcam/binary_sensor.py | 7 ++++-- .../components/concord232/binary_sensor.py | 3 ++- .../components/demo/binary_sensor.py | 9 ++++++-- .../components/egardia/binary_sensor.py | 5 ++-- .../components/ffmpeg_motion/binary_sensor.py | 8 +++++-- .../components/fibaro/binary_sensor.py | 5 ++-- .../components/hikvision/binary_sensor.py | 23 ++++++++++--------- .../components/hive/binary_sensor.py | 3 ++- .../components/mysensors/binary_sensor.py | 3 ++- .../components/nest/binary_sensor.py | 5 ++-- .../components/ring/binary_sensor.py | 7 +++++- .../components/skybell/binary_sensor.py | 3 ++- .../components/smartthings/binary_sensor.py | 3 ++- homeassistant/components/spc/binary_sensor.py | 3 ++- .../components/wink/binary_sensor.py | 3 ++- 15 files changed, 59 insertions(+), 31 deletions(-) diff --git a/homeassistant/components/android_ip_webcam/binary_sensor.py b/homeassistant/components/android_ip_webcam/binary_sensor.py index 14384565718..377ecfec667 100644 --- a/homeassistant/components/android_ip_webcam/binary_sensor.py +++ b/homeassistant/components/android_ip_webcam/binary_sensor.py @@ -1,5 +1,8 @@ """Support for Android IP Webcam binary sensors.""" -from homeassistant.components.binary_sensor import BinarySensorEntity +from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_MOTION, + BinarySensorEntity, +) from . import CONF_HOST, CONF_NAME, DATA_IP_WEBCAM, KEY_MAP, AndroidIPCamEntity @@ -47,4 +50,4 @@ class IPWebcamBinarySensor(AndroidIPCamEntity, BinarySensorEntity): @property def device_class(self): """Return the class of this device, from component DEVICE_CLASSES.""" - return "motion" + return DEVICE_CLASS_MOTION diff --git a/homeassistant/components/concord232/binary_sensor.py b/homeassistant/components/concord232/binary_sensor.py index 3b2e980b777..1288b9472ed 100644 --- a/homeassistant/components/concord232/binary_sensor.py +++ b/homeassistant/components/concord232/binary_sensor.py @@ -7,6 +7,7 @@ import requests import voluptuous as vol from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_MOTION, DEVICE_CLASS_OPENING, DEVICE_CLASS_SAFETY, DEVICE_CLASS_SMOKE, @@ -88,7 +89,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): def get_opening_type(zone): """Return the result of the type guessing from name.""" if "MOTION" in zone["name"]: - return "motion" + return DEVICE_CLASS_MOTION if "KEY" in zone["name"]: return DEVICE_CLASS_SAFETY if "SMOKE" in zone["name"]: diff --git a/homeassistant/components/demo/binary_sensor.py b/homeassistant/components/demo/binary_sensor.py index 04d8e72f9a8..26a7ca98a7e 100644 --- a/homeassistant/components/demo/binary_sensor.py +++ b/homeassistant/components/demo/binary_sensor.py @@ -1,5 +1,8 @@ """Demo platform that has two fake binary sensors.""" -from homeassistant.components.binary_sensor import BinarySensorEntity +from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_MOTION, + BinarySensorEntity, +) from . import DOMAIN @@ -9,7 +12,9 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= async_add_entities( [ DemoBinarySensor("binary_1", "Basement Floor Wet", False, "moisture"), - DemoBinarySensor("binary_2", "Movement Backyard", True, "motion"), + DemoBinarySensor( + "binary_2", "Movement Backyard", True, DEVICE_CLASS_MOTION + ), ] ) diff --git a/homeassistant/components/egardia/binary_sensor.py b/homeassistant/components/egardia/binary_sensor.py index f4bb5097625..6882171b67f 100644 --- a/homeassistant/components/egardia/binary_sensor.py +++ b/homeassistant/components/egardia/binary_sensor.py @@ -2,6 +2,7 @@ import logging from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_MOTION, DEVICE_CLASS_OPENING, BinarySensorEntity, ) @@ -12,9 +13,9 @@ from . import ATTR_DISCOVER_DEVICES, EGARDIA_DEVICE _LOGGER = logging.getLogger(__name__) EGARDIA_TYPE_TO_DEVICE_CLASS = { - "IR Sensor": "motion", + "IR Sensor": DEVICE_CLASS_MOTION, "Door Contact": DEVICE_CLASS_OPENING, - "IR": "motion", + "IR": DEVICE_CLASS_MOTION, } diff --git a/homeassistant/components/ffmpeg_motion/binary_sensor.py b/homeassistant/components/ffmpeg_motion/binary_sensor.py index a8842f9c401..9b4218c011c 100644 --- a/homeassistant/components/ffmpeg_motion/binary_sensor.py +++ b/homeassistant/components/ffmpeg_motion/binary_sensor.py @@ -4,7 +4,11 @@ import logging import haffmpeg.sensor as ffmpeg_sensor import voluptuous as vol -from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorEntity +from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_MOTION, + PLATFORM_SCHEMA, + BinarySensorEntity, +) from homeassistant.components.ffmpeg import ( CONF_EXTRA_ARGUMENTS, CONF_INITIAL_STATE, @@ -119,4 +123,4 @@ class FFmpegMotion(FFmpegBinarySensor): @property def device_class(self): """Return the class of this sensor, from DEVICE_CLASSES.""" - return "motion" + return DEVICE_CLASS_MOTION diff --git a/homeassistant/components/fibaro/binary_sensor.py b/homeassistant/components/fibaro/binary_sensor.py index 42783df9df6..21ce22ea8e3 100644 --- a/homeassistant/components/fibaro/binary_sensor.py +++ b/homeassistant/components/fibaro/binary_sensor.py @@ -3,6 +3,7 @@ import logging from homeassistant.components.binary_sensor import ( DEVICE_CLASS_DOOR, + DEVICE_CLASS_MOTION, DEVICE_CLASS_SMOKE, DEVICE_CLASS_WINDOW, DOMAIN, @@ -16,11 +17,11 @@ _LOGGER = logging.getLogger(__name__) SENSOR_TYPES = { "com.fibaro.floodSensor": ["Flood", "mdi:water", "flood"], - "com.fibaro.motionSensor": ["Motion", "mdi:run", "motion"], + "com.fibaro.motionSensor": ["Motion", "mdi:run", DEVICE_CLASS_MOTION], "com.fibaro.doorSensor": ["Door", "mdi:window-open", DEVICE_CLASS_DOOR], "com.fibaro.windowSensor": ["Window", "mdi:window-open", DEVICE_CLASS_WINDOW], "com.fibaro.smokeSensor": ["Smoke", "mdi:smoking", DEVICE_CLASS_SMOKE], - "com.fibaro.FGMS001": ["Motion", "mdi:run", "motion"], + "com.fibaro.FGMS001": ["Motion", "mdi:run", DEVICE_CLASS_MOTION], "com.fibaro.heatDetector": ["Heat", "mdi:fire", "heat"], } diff --git a/homeassistant/components/hikvision/binary_sensor.py b/homeassistant/components/hikvision/binary_sensor.py index f10a11b317b..c0da593a039 100644 --- a/homeassistant/components/hikvision/binary_sensor.py +++ b/homeassistant/components/hikvision/binary_sensor.py @@ -7,6 +7,7 @@ import voluptuous as vol from homeassistant.components.binary_sensor import ( DEVICE_CLASS_CONNECTIVITY, + DEVICE_CLASS_MOTION, PLATFORM_SCHEMA, BinarySensorEntity, ) @@ -38,11 +39,11 @@ DEFAULT_DELAY = 0 ATTR_DELAY = "delay" DEVICE_CLASS_MAP = { - "Motion": "motion", - "Line Crossing": "motion", - "Field Detection": "motion", + "Motion": DEVICE_CLASS_MOTION, + "Line Crossing": DEVICE_CLASS_MOTION, + "Field Detection": DEVICE_CLASS_MOTION, "Video Loss": None, - "Tamper Detection": "motion", + "Tamper Detection": DEVICE_CLASS_MOTION, "Shelter Alarm": None, "Disk Full": None, "Disk Error": None, @@ -51,15 +52,15 @@ DEVICE_CLASS_MAP = { "Illegal Access": None, "Video Mismatch": None, "Bad Video": None, - "PIR Alarm": "motion", - "Face Detection": "motion", - "Scene Change Detection": "motion", + "PIR Alarm": DEVICE_CLASS_MOTION, + "Face Detection": DEVICE_CLASS_MOTION, + "Scene Change Detection": DEVICE_CLASS_MOTION, "I/O": None, - "Unattended Baggage": "motion", - "Attended Baggage": "motion", + "Unattended Baggage": DEVICE_CLASS_MOTION, + "Attended Baggage": DEVICE_CLASS_MOTION, "Recording Failure": None, - "Exiting Region": "motion", - "Entering Region": "motion", + "Exiting Region": DEVICE_CLASS_MOTION, + "Entering Region": DEVICE_CLASS_MOTION, } CUSTOMIZE_SCHEMA = vol.Schema( diff --git a/homeassistant/components/hive/binary_sensor.py b/homeassistant/components/hive/binary_sensor.py index bc71939bf6a..120148a8f81 100644 --- a/homeassistant/components/hive/binary_sensor.py +++ b/homeassistant/components/hive/binary_sensor.py @@ -1,5 +1,6 @@ """Support for the Hive binary sensors.""" from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_MOTION, DEVICE_CLASS_OPENING, BinarySensorEntity, ) @@ -7,7 +8,7 @@ from homeassistant.components.binary_sensor import ( from . import DATA_HIVE, DOMAIN, HiveEntity DEVICETYPE_DEVICE_CLASS = { - "motionsensor": "motion", + "motionsensor": DEVICE_CLASS_MOTION, "contactsensor": DEVICE_CLASS_OPENING, } diff --git a/homeassistant/components/mysensors/binary_sensor.py b/homeassistant/components/mysensors/binary_sensor.py index 406f82c845e..fc9d0263441 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_MOTION, DEVICE_CLASS_SAFETY, DEVICE_CLASS_SOUND, DEVICE_CLASS_VIBRATION, @@ -12,7 +13,7 @@ from homeassistant.const import STATE_ON SENSORS = { "S_DOOR": "door", - "S_MOTION": "motion", + "S_MOTION": DEVICE_CLASS_MOTION, "S_SMOKE": "smoke", "S_SPRINKLER": DEVICE_CLASS_SAFETY, "S_WATER_LEAK": DEVICE_CLASS_SAFETY, diff --git a/homeassistant/components/nest/binary_sensor.py b/homeassistant/components/nest/binary_sensor.py index 31603f37cc2..0e9198a0220 100644 --- a/homeassistant/components/nest/binary_sensor.py +++ b/homeassistant/components/nest/binary_sensor.py @@ -4,6 +4,7 @@ import logging from homeassistant.components.binary_sensor import ( DEVICE_CLASS_CONNECTIVITY, + DEVICE_CLASS_MOTION, DEVICE_CLASS_OCCUPANCY, DEVICE_CLASS_SOUND, BinarySensorEntity, @@ -24,7 +25,7 @@ CLIMATE_BINARY_TYPES = { } CAMERA_BINARY_TYPES = { - "motion_detected": "motion", + "motion_detected": DEVICE_CLASS_MOTION, "sound_detected": DEVICE_CLASS_SOUND, "person_detected": DEVICE_CLASS_OCCUPANCY, } @@ -158,7 +159,7 @@ class NestActivityZoneSensor(NestBinarySensor): @property def device_class(self): """Return the device class of the binary sensor.""" - return "motion" + return DEVICE_CLASS_MOTION def update(self): """Retrieve latest state.""" diff --git a/homeassistant/components/ring/binary_sensor.py b/homeassistant/components/ring/binary_sensor.py index 876caad3f85..ccec9e6ad36 100644 --- a/homeassistant/components/ring/binary_sensor.py +++ b/homeassistant/components/ring/binary_sensor.py @@ -3,6 +3,7 @@ from datetime import datetime import logging from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_MOTION, DEVICE_CLASS_OCCUPANCY, BinarySensorEntity, ) @@ -16,7 +17,11 @@ _LOGGER = logging.getLogger(__name__) # Sensor types: Name, category, device_class SENSOR_TYPES = { "ding": ["Ding", ["doorbots", "authorized_doorbots"], DEVICE_CLASS_OCCUPANCY], - "motion": ["Motion", ["doorbots", "authorized_doorbots", "stickup_cams"], "motion"], + "motion": [ + "Motion", + ["doorbots", "authorized_doorbots", "stickup_cams"], + DEVICE_CLASS_MOTION, + ], } diff --git a/homeassistant/components/skybell/binary_sensor.py b/homeassistant/components/skybell/binary_sensor.py index 38cf0a98f40..94f64a4eb43 100644 --- a/homeassistant/components/skybell/binary_sensor.py +++ b/homeassistant/components/skybell/binary_sensor.py @@ -5,6 +5,7 @@ import logging import voluptuous as vol from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_MOTION, DEVICE_CLASS_OCCUPANCY, PLATFORM_SCHEMA, BinarySensorEntity, @@ -21,7 +22,7 @@ SCAN_INTERVAL = timedelta(seconds=5) # Sensor types: Name, device_class, event SENSOR_TYPES = { "button": ["Button", DEVICE_CLASS_OCCUPANCY, "device:sensor:button"], - "motion": ["Motion", "motion", "device:sensor:motion"], + "motion": ["Motion", DEVICE_CLASS_MOTION, "device:sensor:motion"], } PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( diff --git a/homeassistant/components/smartthings/binary_sensor.py b/homeassistant/components/smartthings/binary_sensor.py index b51cc06b617..47ca6879701 100644 --- a/homeassistant/components/smartthings/binary_sensor.py +++ b/homeassistant/components/smartthings/binary_sensor.py @@ -4,6 +4,7 @@ from typing import Optional, Sequence from pysmartthings import Attribute, Capability from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_MOTION, DEVICE_CLASS_OPENING, DEVICE_CLASS_PRESENCE, DEVICE_CLASS_PROBLEM, @@ -29,7 +30,7 @@ ATTRIB_TO_CLASS = { Attribute.acceleration: "moving", Attribute.contact: DEVICE_CLASS_OPENING, Attribute.filter_status: DEVICE_CLASS_PROBLEM, - Attribute.motion: "motion", + Attribute.motion: DEVICE_CLASS_MOTION, Attribute.presence: DEVICE_CLASS_PRESENCE, Attribute.sound: DEVICE_CLASS_SOUND, Attribute.tamper: DEVICE_CLASS_PROBLEM, diff --git a/homeassistant/components/spc/binary_sensor.py b/homeassistant/components/spc/binary_sensor.py index 4ee8ffad77e..1fda59207ec 100644 --- a/homeassistant/components/spc/binary_sensor.py +++ b/homeassistant/components/spc/binary_sensor.py @@ -4,6 +4,7 @@ import logging from pyspcwebgw.const import ZoneInput, ZoneType from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_MOTION, DEVICE_CLASS_OPENING, DEVICE_CLASS_SMOKE, BinarySensorEntity, @@ -18,7 +19,7 @@ _LOGGER = logging.getLogger(__name__) def _get_device_class(zone_type): return { - ZoneType.ALARM: "motion", + ZoneType.ALARM: DEVICE_CLASS_MOTION, ZoneType.ENTRY_EXIT: DEVICE_CLASS_OPENING, ZoneType.FIRE: DEVICE_CLASS_SMOKE, ZoneType.TECHNICAL: "power", diff --git a/homeassistant/components/wink/binary_sensor.py b/homeassistant/components/wink/binary_sensor.py index 742ed9d020d..04117758c54 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_MOTION, DEVICE_CLASS_OCCUPANCY, DEVICE_CLASS_OPENING, DEVICE_CLASS_SMOKE, @@ -24,7 +25,7 @@ SENSOR_TYPES = { "co_detected": "gas", "liquid_detected": "moisture", "loudness": DEVICE_CLASS_SOUND, - "motion": "motion", + "motion": DEVICE_CLASS_MOTION, "noise": DEVICE_CLASS_SOUND, "opened": DEVICE_CLASS_OPENING, "presence": DEVICE_CLASS_OCCUPANCY,