From 3d4ef8cfe1b254d132cfd312f8460699da77ef20 Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Sat, 12 Sep 2020 20:21:57 +0200 Subject: [PATCH] Use connectivity device class constant in various integrations (#39972) --- .../components/ambient_station/__init__.py | 21 ++++++++++--------- .../components/cloud/binary_sensor.py | 7 +++++-- .../components/guardian/binary_sensor.py | 7 +++++-- .../components/hikvision/binary_sensor.py | 10 ++++++--- .../components/nest/binary_sensor.py | 3 ++- .../components/notion/binary_sensor.py | 3 ++- .../components/ping/binary_sensor.py | 9 +++++--- .../components/point/binary_sensor.py | 8 +++++-- .../components/uptimerobot/binary_sensor.py | 8 +++++-- .../components/zoneminder/binary_sensor.py | 7 +++++-- 10 files changed, 55 insertions(+), 28 deletions(-) diff --git a/homeassistant/components/ambient_station/__init__.py b/homeassistant/components/ambient_station/__init__.py index 9428449dc75..f8b2cd7348d 100644 --- a/homeassistant/components/ambient_station/__init__.py +++ b/homeassistant/components/ambient_station/__init__.py @@ -6,6 +6,7 @@ from aioambient import Client from aioambient.errors import WebsocketError import voluptuous as vol +from homeassistant.components.binary_sensor import DEVICE_CLASS_CONNECTIVITY from homeassistant.config_entries import SOURCE_IMPORT from homeassistant.const import ( ATTR_LOCATION, @@ -175,16 +176,16 @@ SENSOR_TYPES = { TYPE_LASTRAIN: ("Last Rain", None, TYPE_SENSOR, "timestamp"), TYPE_MAXDAILYGUST: ("Max Gust", SPEED_MILES_PER_HOUR, TYPE_SENSOR, None), TYPE_MONTHLYRAININ: ("Monthly Rain", "in", TYPE_SENSOR, None), - TYPE_RELAY10: ("Relay 10", None, TYPE_BINARY_SENSOR, "connectivity"), - TYPE_RELAY1: ("Relay 1", None, TYPE_BINARY_SENSOR, "connectivity"), - TYPE_RELAY2: ("Relay 2", None, TYPE_BINARY_SENSOR, "connectivity"), - TYPE_RELAY3: ("Relay 3", None, TYPE_BINARY_SENSOR, "connectivity"), - TYPE_RELAY4: ("Relay 4", None, TYPE_BINARY_SENSOR, "connectivity"), - TYPE_RELAY5: ("Relay 5", None, TYPE_BINARY_SENSOR, "connectivity"), - TYPE_RELAY6: ("Relay 6", None, TYPE_BINARY_SENSOR, "connectivity"), - TYPE_RELAY7: ("Relay 7", None, TYPE_BINARY_SENSOR, "connectivity"), - TYPE_RELAY8: ("Relay 8", None, TYPE_BINARY_SENSOR, "connectivity"), - TYPE_RELAY9: ("Relay 9", None, TYPE_BINARY_SENSOR, "connectivity"), + TYPE_RELAY10: ("Relay 10", None, TYPE_BINARY_SENSOR, DEVICE_CLASS_CONNECTIVITY), + TYPE_RELAY1: ("Relay 1", None, TYPE_BINARY_SENSOR, DEVICE_CLASS_CONNECTIVITY), + TYPE_RELAY2: ("Relay 2", None, TYPE_BINARY_SENSOR, DEVICE_CLASS_CONNECTIVITY), + TYPE_RELAY3: ("Relay 3", None, TYPE_BINARY_SENSOR, DEVICE_CLASS_CONNECTIVITY), + TYPE_RELAY4: ("Relay 4", None, TYPE_BINARY_SENSOR, DEVICE_CLASS_CONNECTIVITY), + TYPE_RELAY5: ("Relay 5", None, TYPE_BINARY_SENSOR, DEVICE_CLASS_CONNECTIVITY), + TYPE_RELAY6: ("Relay 6", None, TYPE_BINARY_SENSOR, DEVICE_CLASS_CONNECTIVITY), + TYPE_RELAY7: ("Relay 7", None, TYPE_BINARY_SENSOR, DEVICE_CLASS_CONNECTIVITY), + TYPE_RELAY8: ("Relay 8", None, TYPE_BINARY_SENSOR, DEVICE_CLASS_CONNECTIVITY), + TYPE_RELAY9: ("Relay 9", None, TYPE_BINARY_SENSOR, DEVICE_CLASS_CONNECTIVITY), TYPE_SOILHUM10: ("Soil Humidity 10", PERCENTAGE, TYPE_SENSOR, "humidity"), TYPE_SOILHUM1: ("Soil Humidity 1", PERCENTAGE, TYPE_SENSOR, "humidity"), TYPE_SOILHUM2: ("Soil Humidity 2", PERCENTAGE, TYPE_SENSOR, "humidity"), diff --git a/homeassistant/components/cloud/binary_sensor.py b/homeassistant/components/cloud/binary_sensor.py index baa63679d42..0e3b20fa011 100644 --- a/homeassistant/components/cloud/binary_sensor.py +++ b/homeassistant/components/cloud/binary_sensor.py @@ -1,7 +1,10 @@ """Support for Home Assistant Cloud binary sensors.""" import asyncio -from homeassistant.components.binary_sensor import BinarySensorEntity +from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_CONNECTIVITY, + BinarySensorEntity, +) from homeassistant.helpers.dispatcher import async_dispatcher_connect from .const import DISPATCHER_REMOTE_UPDATE, DOMAIN @@ -44,7 +47,7 @@ class CloudRemoteBinary(BinarySensorEntity): @property def device_class(self) -> str: """Return the class of this device, from component DEVICE_CLASSES.""" - return "connectivity" + return DEVICE_CLASS_CONNECTIVITY @property def available(self) -> bool: diff --git a/homeassistant/components/guardian/binary_sensor.py b/homeassistant/components/guardian/binary_sensor.py index c63d80163bc..4d8c429a9d1 100644 --- a/homeassistant/components/guardian/binary_sensor.py +++ b/homeassistant/components/guardian/binary_sensor.py @@ -3,7 +3,10 @@ from typing import Callable, Dict from aioguardian import Client -from homeassistant.components.binary_sensor import BinarySensorEntity +from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_CONNECTIVITY, + BinarySensorEntity, +) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.update_coordinator import DataUpdateCoordinator @@ -22,7 +25,7 @@ ATTR_CONNECTED_CLIENTS = "connected_clients" SENSOR_KIND_AP_INFO = "ap_enabled" SENSOR_KIND_LEAK_DETECTED = "leak_detected" SENSORS = [ - (SENSOR_KIND_AP_INFO, "Onboard AP Enabled", "connectivity"), + (SENSOR_KIND_AP_INFO, "Onboard AP Enabled", DEVICE_CLASS_CONNECTIVITY), (SENSOR_KIND_LEAK_DETECTED, "Leak Detected", "moisture"), ] diff --git a/homeassistant/components/hikvision/binary_sensor.py b/homeassistant/components/hikvision/binary_sensor.py index 779afa10cca..f10a11b317b 100644 --- a/homeassistant/components/hikvision/binary_sensor.py +++ b/homeassistant/components/hikvision/binary_sensor.py @@ -5,7 +5,11 @@ import logging from pyhik.hikvision import HikCamera import voluptuous as vol -from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorEntity +from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_CONNECTIVITY, + PLATFORM_SCHEMA, + BinarySensorEntity, +) from homeassistant.const import ( ATTR_LAST_TRIP_TIME, CONF_CUSTOMIZE, @@ -42,8 +46,8 @@ DEVICE_CLASS_MAP = { "Shelter Alarm": None, "Disk Full": None, "Disk Error": None, - "Net Interface Broken": "connectivity", - "IP Conflict": "connectivity", + "Net Interface Broken": DEVICE_CLASS_CONNECTIVITY, + "IP Conflict": DEVICE_CLASS_CONNECTIVITY, "Illegal Access": None, "Video Mismatch": None, "Bad Video": None, diff --git a/homeassistant/components/nest/binary_sensor.py b/homeassistant/components/nest/binary_sensor.py index 35acab6f504..31603f37cc2 100644 --- a/homeassistant/components/nest/binary_sensor.py +++ b/homeassistant/components/nest/binary_sensor.py @@ -3,6 +3,7 @@ from itertools import chain import logging from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_CONNECTIVITY, DEVICE_CLASS_OCCUPANCY, DEVICE_CLASS_SOUND, BinarySensorEntity, @@ -13,7 +14,7 @@ from . import CONF_BINARY_SENSORS, DATA_NEST, DATA_NEST_CONFIG, NestSensorDevice _LOGGER = logging.getLogger(__name__) -BINARY_TYPES = {"online": "connectivity"} +BINARY_TYPES = {"online": DEVICE_CLASS_CONNECTIVITY} CLIMATE_BINARY_TYPES = { "fan": None, diff --git a/homeassistant/components/notion/binary_sensor.py b/homeassistant/components/notion/binary_sensor.py index 3d02e364021..5bae2592b6c 100644 --- a/homeassistant/components/notion/binary_sensor.py +++ b/homeassistant/components/notion/binary_sensor.py @@ -3,6 +3,7 @@ import logging from typing import Callable from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_CONNECTIVITY, DEVICE_CLASS_DOOR, DEVICE_CLASS_SMOKE, DEVICE_CLASS_WINDOW, @@ -34,7 +35,7 @@ BINARY_SENSOR_TYPES = { SENSOR_DOOR: ("Door", DEVICE_CLASS_DOOR), SENSOR_GARAGE_DOOR: ("Garage Door", "garage_door"), SENSOR_LEAK: ("Leak Detector", "moisture"), - SENSOR_MISSING: ("Missing", "connectivity"), + SENSOR_MISSING: ("Missing", DEVICE_CLASS_CONNECTIVITY), SENSOR_SAFE: ("Safe", DEVICE_CLASS_DOOR), SENSOR_SLIDING: ("Sliding Door/Window", DEVICE_CLASS_DOOR), SENSOR_SMOKE_CO: ("Smoke/Carbon Monoxide Detector", DEVICE_CLASS_SMOKE), diff --git a/homeassistant/components/ping/binary_sensor.py b/homeassistant/components/ping/binary_sensor.py index ac73da0a13f..df93aaaf5f1 100644 --- a/homeassistant/components/ping/binary_sensor.py +++ b/homeassistant/components/ping/binary_sensor.py @@ -10,7 +10,11 @@ from typing import Any, Dict from icmplib import SocketPermissionError, ping as icmp_ping import voluptuous as vol -from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorEntity +from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_CONNECTIVITY, + PLATFORM_SCHEMA, + BinarySensorEntity, +) from homeassistant.const import CONF_HOST, CONF_NAME import homeassistant.helpers.config_validation as cv from homeassistant.helpers.reload import setup_reload_service @@ -30,7 +34,6 @@ CONF_PING_COUNT = "count" DEFAULT_NAME = "Ping" DEFAULT_PING_COUNT = 5 -DEFAULT_DEVICE_CLASS = "connectivity" SCAN_INTERVAL = timedelta(minutes=5) @@ -94,7 +97,7 @@ class PingBinarySensor(BinarySensorEntity): @property def device_class(self) -> str: """Return the class of this sensor.""" - return DEFAULT_DEVICE_CLASS + return DEVICE_CLASS_CONNECTIVITY @property def is_on(self) -> bool: diff --git a/homeassistant/components/point/binary_sensor.py b/homeassistant/components/point/binary_sensor.py index 5a780c2e57a..d82ecd096ee 100644 --- a/homeassistant/components/point/binary_sensor.py +++ b/homeassistant/components/point/binary_sensor.py @@ -1,7 +1,11 @@ """Support for Minut Point binary sensors.""" import logging -from homeassistant.components.binary_sensor import DOMAIN, BinarySensorEntity +from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_CONNECTIVITY, + DOMAIN, + BinarySensorEntity, +) from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -116,7 +120,7 @@ class MinutPointBinarySensor(MinutPointEntity, BinarySensorEntity): @property def is_on(self): """Return the state of the binary sensor.""" - if self.device_class == "connectivity": + if self.device_class == DEVICE_CLASS_CONNECTIVITY: # connectivity is the other way around. return not self._is_on return self._is_on diff --git a/homeassistant/components/uptimerobot/binary_sensor.py b/homeassistant/components/uptimerobot/binary_sensor.py index 231dce9a402..e31d8b44b10 100644 --- a/homeassistant/components/uptimerobot/binary_sensor.py +++ b/homeassistant/components/uptimerobot/binary_sensor.py @@ -4,7 +4,11 @@ import logging from pyuptimerobot import UptimeRobot import voluptuous as vol -from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorEntity +from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_CONNECTIVITY, + PLATFORM_SCHEMA, + BinarySensorEntity, +) from homeassistant.const import ATTR_ATTRIBUTION, CONF_API_KEY import homeassistant.helpers.config_validation as cv @@ -68,7 +72,7 @@ class UptimeRobotBinarySensor(BinarySensorEntity): @property def device_class(self): """Return the class of this device, from component DEVICE_CLASSES.""" - return "connectivity" + return DEVICE_CLASS_CONNECTIVITY @property def device_state_attributes(self): diff --git a/homeassistant/components/zoneminder/binary_sensor.py b/homeassistant/components/zoneminder/binary_sensor.py index 739864fdea8..73d6877ef2d 100644 --- a/homeassistant/components/zoneminder/binary_sensor.py +++ b/homeassistant/components/zoneminder/binary_sensor.py @@ -1,5 +1,8 @@ """Support for ZoneMinder binary sensors.""" -from homeassistant.components.binary_sensor import BinarySensorEntity +from homeassistant.components.binary_sensor import ( + DEVICE_CLASS_CONNECTIVITY, + BinarySensorEntity, +) from . import DOMAIN as ZONEMINDER_DOMAIN @@ -35,7 +38,7 @@ class ZMAvailabilitySensor(BinarySensorEntity): @property def device_class(self): """Return the class of this device, from component DEVICE_CLASSES.""" - return "connectivity" + return DEVICE_CLASS_CONNECTIVITY def update(self): """Update the state of this sensor (availability of ZoneMinder)."""