From 96aaa25aadea329a9289346b029b3b18b134858f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 14 Apr 2020 13:37:54 -0500 Subject: [PATCH] Add DEVICE_CLASS_BATTERY_CHARGING to binary_sensor (#34203) In order to make this automatically discoverable via the registry there needs to be a DEVICE_CLASS_BATTERY_CHARING in binary sensor so we can tell what is a battery and what is a charge sensor. --- homeassistant/components/binary_sensor/__init__.py | 4 ++++ .../components/binary_sensor/device_condition.py | 9 +++++++++ homeassistant/components/binary_sensor/device_trigger.py | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/homeassistant/components/binary_sensor/__init__.py b/homeassistant/components/binary_sensor/__init__.py index 73d5e0be458..7dc5d958537 100644 --- a/homeassistant/components/binary_sensor/__init__.py +++ b/homeassistant/components/binary_sensor/__init__.py @@ -23,6 +23,9 @@ ENTITY_ID_FORMAT = DOMAIN + ".{}" # On means low, Off means normal DEVICE_CLASS_BATTERY = "battery" +# On means charging, Off means not charging +DEVICE_CLASS_BATTERY_CHARGING = "battery_charging" + # On means cold, Off means normal DEVICE_CLASS_COLD = "cold" @@ -91,6 +94,7 @@ DEVICE_CLASS_WINDOW = "window" DEVICE_CLASSES = [ DEVICE_CLASS_BATTERY, + DEVICE_CLASS_BATTERY_CHARGING, DEVICE_CLASS_COLD, DEVICE_CLASS_CONNECTIVITY, DEVICE_CLASS_DOOR, diff --git a/homeassistant/components/binary_sensor/device_condition.py b/homeassistant/components/binary_sensor/device_condition.py index e17869f6cfa..999a62b3a80 100644 --- a/homeassistant/components/binary_sensor/device_condition.py +++ b/homeassistant/components/binary_sensor/device_condition.py @@ -15,6 +15,7 @@ from homeassistant.helpers.typing import ConfigType from . import ( DEVICE_CLASS_BATTERY, + DEVICE_CLASS_BATTERY_CHARGING, DEVICE_CLASS_COLD, DEVICE_CLASS_CONNECTIVITY, DEVICE_CLASS_DOOR, @@ -44,6 +45,8 @@ DEVICE_CLASS_NONE = "none" CONF_IS_BAT_LOW = "is_bat_low" CONF_IS_NOT_BAT_LOW = "is_not_bat_low" +CONF_IS_CHARGING = "is_charging" +CONF_IS_NOT_CHARGING = "is_not_charging" CONF_IS_COLD = "is_cold" CONF_IS_NOT_COLD = "is_not_cold" CONF_IS_CONNECTED = "is_connected" @@ -85,6 +88,7 @@ CONF_IS_NOT_OPEN = "is_not_open" IS_ON = [ CONF_IS_BAT_LOW, + CONF_IS_CHARGING, CONF_IS_COLD, CONF_IS_CONNECTED, CONF_IS_GAS, @@ -109,6 +113,7 @@ IS_ON = [ IS_OFF = [ CONF_IS_NOT_BAT_LOW, + CONF_IS_NOT_CHARGING, CONF_IS_NOT_COLD, CONF_IS_NOT_CONNECTED, CONF_IS_NOT_HOT, @@ -136,6 +141,10 @@ ENTITY_CONDITIONS = { {CONF_TYPE: CONF_IS_BAT_LOW}, {CONF_TYPE: CONF_IS_NOT_BAT_LOW}, ], + DEVICE_CLASS_BATTERY_CHARGING: [ + {CONF_TYPE: CONF_IS_CHARGING}, + {CONF_TYPE: CONF_IS_NOT_CHARGING}, + ], DEVICE_CLASS_COLD: [{CONF_TYPE: CONF_IS_COLD}, {CONF_TYPE: CONF_IS_NOT_COLD}], DEVICE_CLASS_CONNECTIVITY: [ {CONF_TYPE: CONF_IS_CONNECTED}, diff --git a/homeassistant/components/binary_sensor/device_trigger.py b/homeassistant/components/binary_sensor/device_trigger.py index e5e1f9061e6..d50cc20c1ae 100644 --- a/homeassistant/components/binary_sensor/device_trigger.py +++ b/homeassistant/components/binary_sensor/device_trigger.py @@ -13,6 +13,7 @@ from homeassistant.helpers.entity_registry import async_entries_for_device from . import ( DEVICE_CLASS_BATTERY, + DEVICE_CLASS_BATTERY_CHARGING, DEVICE_CLASS_COLD, DEVICE_CLASS_CONNECTIVITY, DEVICE_CLASS_DOOR, @@ -44,6 +45,8 @@ DEVICE_CLASS_NONE = "none" CONF_BAT_LOW = "bat_low" CONF_NOT_BAT_LOW = "not_bat_low" +CONF_CHARGING = "charging" +CONF_NOT_CHARGING = "not_charging" CONF_COLD = "cold" CONF_NOT_COLD = "not_cold" CONF_CONNECTED = "connected" @@ -135,6 +138,10 @@ TURNED_OFF = [ ENTITY_TRIGGERS = { DEVICE_CLASS_BATTERY: [{CONF_TYPE: CONF_BAT_LOW}, {CONF_TYPE: CONF_NOT_BAT_LOW}], + DEVICE_CLASS_BATTERY_CHARGING: [ + {CONF_TYPE: CONF_CHARGING}, + {CONF_TYPE: CONF_NOT_CHARGING}, + ], DEVICE_CLASS_COLD: [{CONF_TYPE: CONF_COLD}, {CONF_TYPE: CONF_NOT_COLD}], DEVICE_CLASS_CONNECTIVITY: [ {CONF_TYPE: CONF_CONNECTED},