Use problem, presence and plug device class constants in various integrations (#39973)

pull/39962/head^2
springstan 2020-09-12 20:23:24 +02:00 committed by GitHub
parent 3d4ef8cfe1
commit 827711bcd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 13 deletions

View File

@ -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)

View File

@ -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"

View File

@ -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

View File

@ -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",
}

View File

@ -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."""