From 422f0ad7a92bfac1f8c6989f65fc8a65d687d73c Mon Sep 17 00:00:00 2001 From: marecabo <23156476+marecabo@users.noreply.github.com> Date: Mon, 1 Mar 2021 00:55:32 +0100 Subject: [PATCH] Add constants for device classes of binary_sensor (#1549) --- esphome/components/binary_sensor/__init__.py | 20 +++++++++++---- esphome/const.py | 26 ++++++++++++++++++-- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/esphome/components/binary_sensor/__init__.py b/esphome/components/binary_sensor/__init__.py index 753010310c..da1dc697a2 100644 --- a/esphome/components/binary_sensor/__init__.py +++ b/esphome/components/binary_sensor/__init__.py @@ -7,16 +7,26 @@ from esphome.const import CONF_DEVICE_CLASS, CONF_FILTERS, \ CONF_ID, CONF_INTERNAL, CONF_INVALID_COOLDOWN, CONF_INVERTED, \ CONF_MAX_LENGTH, CONF_MIN_LENGTH, CONF_ON_CLICK, \ CONF_ON_DOUBLE_CLICK, CONF_ON_MULTI_CLICK, CONF_ON_PRESS, CONF_ON_RELEASE, CONF_ON_STATE, \ - CONF_STATE, CONF_TIMING, CONF_TRIGGER_ID, CONF_FOR, CONF_NAME, CONF_MQTT_ID + CONF_STATE, CONF_TIMING, CONF_TRIGGER_ID, CONF_FOR, CONF_NAME, CONF_MQTT_ID, \ + DEVICE_CLASS_EMPTY, DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY_CHARGING, DEVICE_CLASS_COLD, \ + DEVICE_CLASS_CONNECTIVITY, DEVICE_CLASS_DOOR, DEVICE_CLASS_GARAGE_DOOR, DEVICE_CLASS_GAS, \ + DEVICE_CLASS_HEAT, DEVICE_CLASS_LIGHT, DEVICE_CLASS_LOCK, DEVICE_CLASS_MOISTURE, \ + DEVICE_CLASS_MOTION, DEVICE_CLASS_MOVING, DEVICE_CLASS_OCCUPANCY, DEVICE_CLASS_OPENING, \ + DEVICE_CLASS_PLUG, DEVICE_CLASS_POWER, DEVICE_CLASS_PRESENCE, DEVICE_CLASS_PROBLEM, \ + DEVICE_CLASS_SAFETY, DEVICE_CLASS_SMOKE, DEVICE_CLASS_SOUND, DEVICE_CLASS_VIBRATION, \ + DEVICE_CLASS_WINDOW from esphome.core import CORE, coroutine, coroutine_with_priority from esphome.util import Registry CODEOWNERS = ['@esphome/core'] DEVICE_CLASSES = [ - '', 'battery', 'cold', 'connectivity', 'door', 'garage_door', 'gas', - 'heat', 'light', 'lock', 'moisture', 'motion', 'moving', 'occupancy', - 'opening', 'plug', 'power', 'presence', 'problem', 'safety', 'smoke', - 'sound', 'vibration', 'window' + DEVICE_CLASS_EMPTY, DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY_CHARGING, DEVICE_CLASS_COLD, + DEVICE_CLASS_CONNECTIVITY, DEVICE_CLASS_DOOR, DEVICE_CLASS_GARAGE_DOOR, DEVICE_CLASS_GAS, + DEVICE_CLASS_HEAT, DEVICE_CLASS_LIGHT, DEVICE_CLASS_LOCK, DEVICE_CLASS_MOISTURE, + DEVICE_CLASS_MOTION, DEVICE_CLASS_MOVING, DEVICE_CLASS_OCCUPANCY, DEVICE_CLASS_OPENING, + DEVICE_CLASS_PLUG, DEVICE_CLASS_POWER, DEVICE_CLASS_PRESENCE, DEVICE_CLASS_PROBLEM, + DEVICE_CLASS_SAFETY, DEVICE_CLASS_SMOKE, DEVICE_CLASS_SOUND, DEVICE_CLASS_VIBRATION, + DEVICE_CLASS_WINDOW ] IS_PLATFORM_COMPONENT = True diff --git a/esphome/const.py b/esphome/const.py index 345cac89dd..f652cc1b6d 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -666,18 +666,40 @@ UNIT_VOLT_AMPS_REACTIVE = 'VAR' UNIT_WATT = 'W' UNIT_WATT_HOURS = 'Wh' +# device classes of binary_sensor component +DEVICE_CLASS_BATTERY_CHARGING = 'battery_charging' +DEVICE_CLASS_COLD = 'cold' DEVICE_CLASS_CONNECTIVITY = 'connectivity' +DEVICE_CLASS_DOOR = 'door' +DEVICE_CLASS_GARAGE_DOOR = 'garage_door' +DEVICE_CLASS_GAS = 'gas' +DEVICE_CLASS_HEAT = 'heat' +DEVICE_CLASS_LIGHT = 'light' +DEVICE_CLASS_LOCK = 'lock' +DEVICE_CLASS_MOISTURE = 'moisture' +DEVICE_CLASS_MOTION = 'motion' DEVICE_CLASS_MOVING = 'moving' - +DEVICE_CLASS_OCCUPANCY = 'occupancy' +DEVICE_CLASS_OPENING = 'opening' +DEVICE_CLASS_PLUG = 'plug' +DEVICE_CLASS_PRESENCE = 'presence' +DEVICE_CLASS_PROBLEM = 'problem' +DEVICE_CLASS_SAFETY = 'safety' +DEVICE_CLASS_SMOKE = 'smoke' +DEVICE_CLASS_SOUND = 'sound' +DEVICE_CLASS_VIBRATION = 'vibration' +DEVICE_CLASS_WINDOW = 'window' +# device classes of both binary_sensor and sensor component DEVICE_CLASS_EMPTY = '' DEVICE_CLASS_BATTERY = 'battery' +DEVICE_CLASS_POWER = 'power' +# device classes of sensor component DEVICE_CLASS_CURRENT = 'current' DEVICE_CLASS_ENERGY = 'energy' DEVICE_CLASS_HUMIDITY = 'humidity' DEVICE_CLASS_ILLUMINANCE = 'illuminance' DEVICE_CLASS_SIGNAL_STRENGTH = 'signal_strength' DEVICE_CLASS_TEMPERATURE = 'temperature' -DEVICE_CLASS_POWER = 'power' DEVICE_CLASS_POWER_FACTOR = 'power_factor' DEVICE_CLASS_PRESSURE = 'pressure' DEVICE_CLASS_TIMESTAMP = 'timestamp'