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

This commit is contained in:
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 ( from homeassistant.components.binary_sensor import (
DEVICE_CLASS_OPENING, DEVICE_CLASS_OPENING,
DEVICE_CLASS_PLUG,
DEVICE_CLASS_PROBLEM,
BinarySensorEntity, BinarySensorEntity,
) )
from homeassistant.const import ATTR_ATTRIBUTION, LENGTH_KILOMETERS from homeassistant.const import ATTR_ATTRIBUTION, LENGTH_KILOMETERS
@ -19,13 +21,21 @@ SENSOR_TYPES = {
"windows": ["Windows", DEVICE_CLASS_OPENING, "mdi:car-door"], "windows": ["Windows", DEVICE_CLASS_OPENING, "mdi:car-door"],
"door_lock_state": ["Door lock state", "lock", "mdi:car-key"], "door_lock_state": ["Door lock state", "lock", "mdi:car-key"],
"lights_parking": ["Parking lights", "light", "mdi:car-parking-lights"], "lights_parking": ["Parking lights", "light", "mdi:car-parking-lights"],
"condition_based_services": ["Condition based services", "problem", "mdi:wrench"], "condition_based_services": [
"check_control_messages": ["Control messages", "problem", "mdi:car-tire-alert"], "Condition based services",
DEVICE_CLASS_PROBLEM,
"mdi:wrench",
],
"check_control_messages": [
"Control messages",
DEVICE_CLASS_PROBLEM,
"mdi:car-tire-alert",
],
} }
SENSOR_TYPES_ELEC = { SENSOR_TYPES_ELEC = {
"charging_status": ["Charging status", "power", "mdi:ev-station"], "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) SENSOR_TYPES_ELEC.update(SENSOR_TYPES)

View file

@ -1,6 +1,7 @@
"""Constants for the opentherm_gw integration.""" """Constants for the opentherm_gw integration."""
import pyotgw.vars as gw_vars import pyotgw.vars as gw_vars
from homeassistant.components.binary_sensor import DEVICE_CLASS_PROBLEM
from homeassistant.const import ( from homeassistant.const import (
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
PERCENTAGE, PERCENTAGE,
@ -23,7 +24,6 @@ DATA_OPENTHERM_GW = "opentherm_gw"
DEVICE_CLASS_COLD = "cold" DEVICE_CLASS_COLD = "cold"
DEVICE_CLASS_HEAT = "heat" DEVICE_CLASS_HEAT = "heat"
DEVICE_CLASS_PROBLEM = "problem"
DOMAIN = "opentherm_gw" DOMAIN = "opentherm_gw"

View file

@ -1,7 +1,10 @@
"""Support for monitoring a Smappee appliance binary sensor.""" """Support for monitoring a Smappee appliance binary sensor."""
import logging import logging
from homeassistant.components.binary_sensor import BinarySensorEntity from homeassistant.components.binary_sensor import (
DEVICE_CLASS_PRESENCE,
BinarySensorEntity,
)
from .const import DOMAIN from .const import DOMAIN
@ -58,7 +61,7 @@ class SmappeePresence(BinarySensorEntity):
@property @property
def device_class(self): def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES.""" """Return the class of this device, from component DEVICE_CLASSES."""
return "presence" return DEVICE_CLASS_PRESENCE
@property @property
def unique_id( def unique_id(
@ -68,7 +71,7 @@ class SmappeePresence(BinarySensorEntity):
return ( return (
f"{self._service_location.device_serial_number}-" f"{self._service_location.device_serial_number}-"
f"{self._service_location.service_location_id}-" f"{self._service_location.service_location_id}-"
f"presence" f"{DEVICE_CLASS_PRESENCE}"
) )
@property @property

View file

@ -5,6 +5,8 @@ from pysmartthings import Attribute, Capability
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
DEVICE_CLASS_OPENING, DEVICE_CLASS_OPENING,
DEVICE_CLASS_PRESENCE,
DEVICE_CLASS_PROBLEM,
DEVICE_CLASS_SOUND, DEVICE_CLASS_SOUND,
BinarySensorEntity, BinarySensorEntity,
) )
@ -26,11 +28,11 @@ CAPABILITY_TO_ATTRIB = {
ATTRIB_TO_CLASS = { ATTRIB_TO_CLASS = {
Attribute.acceleration: "moving", Attribute.acceleration: "moving",
Attribute.contact: DEVICE_CLASS_OPENING, Attribute.contact: DEVICE_CLASS_OPENING,
Attribute.filter_status: "problem", Attribute.filter_status: DEVICE_CLASS_PROBLEM,
Attribute.motion: "motion", Attribute.motion: "motion",
Attribute.presence: "presence", Attribute.presence: DEVICE_CLASS_PRESENCE,
Attribute.sound: DEVICE_CLASS_SOUND, Attribute.sound: DEVICE_CLASS_SOUND,
Attribute.tamper: "problem", Attribute.tamper: DEVICE_CLASS_PROBLEM,
Attribute.valve: DEVICE_CLASS_OPENING, Attribute.valve: DEVICE_CLASS_OPENING,
Attribute.water: "moisture", Attribute.water: "moisture",
} }

View file

@ -2,7 +2,10 @@
import logging 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.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -83,7 +86,9 @@ class AlarmSensor(SmartyBinarySensor):
def __init__(self, name, smarty): def __init__(self, name, smarty):
"""Alarm Sensor Init.""" """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: def update(self) -> None:
"""Update state.""" """Update state."""
@ -96,7 +101,9 @@ class WarningSensor(SmartyBinarySensor):
def __init__(self, name, smarty): def __init__(self, name, smarty):
"""Warning Sensor Init.""" """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: def update(self) -> None:
"""Update state.""" """Update state."""