From 827711bcd153279ec56527927eaba4815bcde1d4 Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Sat, 12 Sep 2020 20:23:24 +0200 Subject: [PATCH] Use problem, presence and plug device class constants in various integrations (#39973) --- .../bmw_connected_drive/binary_sensor.py | 16 +++++++++++++--- homeassistant/components/opentherm_gw/const.py | 2 +- .../components/smappee/binary_sensor.py | 9 ++++++--- .../components/smartthings/binary_sensor.py | 8 +++++--- homeassistant/components/smarty/binary_sensor.py | 13 ++++++++++--- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/bmw_connected_drive/binary_sensor.py b/homeassistant/components/bmw_connected_drive/binary_sensor.py index 5cc3964ccee..31ef2dacf3a 100644 --- a/homeassistant/components/bmw_connected_drive/binary_sensor.py +++ b/homeassistant/components/bmw_connected_drive/binary_sensor.py @@ -5,6 +5,8 @@ from bimmer_connected.state import ChargingState, LockState from homeassistant.components.binary_sensor import ( DEVICE_CLASS_OPENING, + DEVICE_CLASS_PLUG, + DEVICE_CLASS_PROBLEM, BinarySensorEntity, ) from homeassistant.const import ATTR_ATTRIBUTION, LENGTH_KILOMETERS @@ -19,13 +21,21 @@ SENSOR_TYPES = { "windows": ["Windows", DEVICE_CLASS_OPENING, "mdi:car-door"], "door_lock_state": ["Door lock state", "lock", "mdi:car-key"], "lights_parking": ["Parking lights", "light", "mdi:car-parking-lights"], - "condition_based_services": ["Condition based services", "problem", "mdi:wrench"], - "check_control_messages": ["Control messages", "problem", "mdi:car-tire-alert"], + "condition_based_services": [ + "Condition based services", + DEVICE_CLASS_PROBLEM, + "mdi:wrench", + ], + "check_control_messages": [ + "Control messages", + DEVICE_CLASS_PROBLEM, + "mdi:car-tire-alert", + ], } SENSOR_TYPES_ELEC = { "charging_status": ["Charging status", "power", "mdi:ev-station"], - "connection_status": ["Connection status", "plug", "mdi:car-electric"], + "connection_status": ["Connection status", DEVICE_CLASS_PLUG, "mdi:car-electric"], } SENSOR_TYPES_ELEC.update(SENSOR_TYPES) diff --git a/homeassistant/components/opentherm_gw/const.py b/homeassistant/components/opentherm_gw/const.py index 0b696ed9339..a32a2199760 100644 --- a/homeassistant/components/opentherm_gw/const.py +++ b/homeassistant/components/opentherm_gw/const.py @@ -1,6 +1,7 @@ """Constants for the opentherm_gw integration.""" import pyotgw.vars as gw_vars +from homeassistant.components.binary_sensor import DEVICE_CLASS_PROBLEM from homeassistant.const import ( DEVICE_CLASS_TEMPERATURE, PERCENTAGE, @@ -23,7 +24,6 @@ DATA_OPENTHERM_GW = "opentherm_gw" DEVICE_CLASS_COLD = "cold" DEVICE_CLASS_HEAT = "heat" -DEVICE_CLASS_PROBLEM = "problem" DOMAIN = "opentherm_gw" diff --git a/homeassistant/components/smappee/binary_sensor.py b/homeassistant/components/smappee/binary_sensor.py index ecc00f12370..49d21f2b2c1 100644 --- a/homeassistant/components/smappee/binary_sensor.py +++ b/homeassistant/components/smappee/binary_sensor.py @@ -1,7 +1,10 @@ """Support for monitoring a Smappee appliance binary sensor.""" import logging -from homeassistant.components.binary_sensor import BinarySensorEntity +from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_PRESENCE, + BinarySensorEntity, +) from .const import DOMAIN @@ -58,7 +61,7 @@ class SmappeePresence(BinarySensorEntity): @property def device_class(self): """Return the class of this device, from component DEVICE_CLASSES.""" - return "presence" + return DEVICE_CLASS_PRESENCE @property def unique_id( @@ -68,7 +71,7 @@ class SmappeePresence(BinarySensorEntity): return ( f"{self._service_location.device_serial_number}-" f"{self._service_location.service_location_id}-" - f"presence" + f"{DEVICE_CLASS_PRESENCE}" ) @property diff --git a/homeassistant/components/smartthings/binary_sensor.py b/homeassistant/components/smartthings/binary_sensor.py index baeac063598..b51cc06b617 100644 --- a/homeassistant/components/smartthings/binary_sensor.py +++ b/homeassistant/components/smartthings/binary_sensor.py @@ -5,6 +5,8 @@ from pysmartthings import Attribute, Capability from homeassistant.components.binary_sensor import ( DEVICE_CLASS_OPENING, + DEVICE_CLASS_PRESENCE, + DEVICE_CLASS_PROBLEM, DEVICE_CLASS_SOUND, BinarySensorEntity, ) @@ -26,11 +28,11 @@ CAPABILITY_TO_ATTRIB = { ATTRIB_TO_CLASS = { Attribute.acceleration: "moving", Attribute.contact: DEVICE_CLASS_OPENING, - Attribute.filter_status: "problem", + Attribute.filter_status: DEVICE_CLASS_PROBLEM, Attribute.motion: "motion", - Attribute.presence: "presence", + Attribute.presence: DEVICE_CLASS_PRESENCE, Attribute.sound: DEVICE_CLASS_SOUND, - Attribute.tamper: "problem", + Attribute.tamper: DEVICE_CLASS_PROBLEM, Attribute.valve: DEVICE_CLASS_OPENING, Attribute.water: "moisture", } diff --git a/homeassistant/components/smarty/binary_sensor.py b/homeassistant/components/smarty/binary_sensor.py index f8b9114ae0e..965102f07f7 100644 --- a/homeassistant/components/smarty/binary_sensor.py +++ b/homeassistant/components/smarty/binary_sensor.py @@ -2,7 +2,10 @@ import logging -from homeassistant.components.binary_sensor import BinarySensorEntity +from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_PROBLEM, + BinarySensorEntity, +) from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -83,7 +86,9 @@ class AlarmSensor(SmartyBinarySensor): def __init__(self, name, smarty): """Alarm Sensor Init.""" - super().__init__(name=f"{name} Alarm", device_class="problem", smarty=smarty) + super().__init__( + name=f"{name} Alarm", device_class=DEVICE_CLASS_PROBLEM, smarty=smarty + ) def update(self) -> None: """Update state.""" @@ -96,7 +101,9 @@ class WarningSensor(SmartyBinarySensor): def __init__(self, name, smarty): """Warning Sensor Init.""" - super().__init__(name=f"{name} Warning", device_class="problem", smarty=smarty) + super().__init__( + name=f"{name} Warning", device_class=DEVICE_CLASS_PROBLEM, smarty=smarty + ) def update(self) -> None: """Update state."""