From e0cd7072d6480ff314e4cf1935decc9a22d46a9e Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 22 Mar 2021 12:37:16 +0100 Subject: [PATCH] Migrate integrations a-c to extend SensorEntity (#48210) --- homeassistant/components/abode/sensor.py | 3 ++- homeassistant/components/accuweather/sensor.py | 3 ++- homeassistant/components/acmeda/sensor.py | 3 ++- homeassistant/components/adguard/sensor.py | 3 ++- homeassistant/components/ads/sensor.py | 4 ++-- homeassistant/components/advantage_air/sensor.py | 7 ++++--- homeassistant/components/aemet/sensor.py | 6 ++++-- homeassistant/components/aftership/sensor.py | 5 ++--- homeassistant/components/airly/sensor.py | 3 ++- homeassistant/components/airnow/sensor.py | 3 ++- homeassistant/components/airvisual/sensor.py | 5 +++-- homeassistant/components/alarmdecoder/sensor.py | 4 ++-- homeassistant/components/alpha_vantage/sensor.py | 7 +++---- homeassistant/components/ambient_station/sensor.py | 3 ++- homeassistant/components/amcrest/sensor.py | 4 ++-- homeassistant/components/android_ip_webcam/sensor.py | 3 ++- homeassistant/components/apcupsd/sensor.py | 5 ++--- homeassistant/components/aqualogic/sensor.py | 5 ++--- homeassistant/components/arduino/sensor.py | 5 ++--- homeassistant/components/arest/sensor.py | 5 ++--- homeassistant/components/arlo/sensor.py | 5 ++--- homeassistant/components/arwn/sensor.py | 4 ++-- homeassistant/components/asuswrt/sensor.py | 3 ++- homeassistant/components/atag/sensor.py | 3 ++- homeassistant/components/atome/sensor.py | 5 ++--- homeassistant/components/august/sensor.py | 7 +++---- homeassistant/components/aurora/sensor.py | 3 ++- homeassistant/components/aurora_abb_powerone/sensor.py | 5 ++--- homeassistant/components/awair/sensor.py | 4 ++-- homeassistant/components/azure_devops/sensor.py | 3 ++- homeassistant/components/bbox/sensor.py | 7 +++---- homeassistant/components/beewi_smartclim/sensor.py | 5 ++--- homeassistant/components/bh1750/sensor.py | 5 ++--- homeassistant/components/bitcoin/sensor.py | 5 ++--- homeassistant/components/bizkaibus/sensor.py | 5 ++--- homeassistant/components/blebox/sensor.py | 4 ++-- homeassistant/components/blink/sensor.py | 4 ++-- homeassistant/components/blockchain/sensor.py | 5 ++--- homeassistant/components/bloomsky/sensor.py | 5 ++--- homeassistant/components/bme280/sensor.py | 5 ++--- homeassistant/components/bme680/sensor.py | 5 ++--- homeassistant/components/bmp280/sensor.py | 4 ++-- homeassistant/components/bmw_connected_drive/sensor.py | 4 ++-- homeassistant/components/broadlink/sensor.py | 4 ++-- homeassistant/components/brother/sensor.py | 3 ++- homeassistant/components/brottsplatskartan/sensor.py | 5 ++--- homeassistant/components/buienradar/sensor.py | 5 ++--- homeassistant/components/canary/sensor.py | 3 ++- homeassistant/components/cert_expiry/sensor.py | 4 ++-- homeassistant/components/citybikes/sensor.py | 10 +++++++--- homeassistant/components/co2signal/sensor.py | 5 ++--- homeassistant/components/coinbase/sensor.py | 6 +++--- .../components/comed_hourly_pricing/sensor.py | 5 ++--- homeassistant/components/comfoconnect/sensor.py | 5 ++--- homeassistant/components/command_line/sensor.py | 5 ++--- homeassistant/components/coronavirus/sensor.py | 3 ++- homeassistant/components/cpuspeed/sensor.py | 5 ++--- homeassistant/components/cups/sensor.py | 9 ++++----- homeassistant/components/currencylayer/sensor.py | 5 ++--- homeassistant/components/sensor/__init__.py | 5 +++++ 60 files changed, 139 insertions(+), 139 deletions(-) diff --git a/homeassistant/components/abode/sensor.py b/homeassistant/components/abode/sensor.py index 6ecc5c871cd..993228c36ac 100644 --- a/homeassistant/components/abode/sensor.py +++ b/homeassistant/components/abode/sensor.py @@ -1,6 +1,7 @@ """Support for Abode Security System sensors.""" import abodepy.helpers.constants as CONST +from homeassistant.components.sensor import SensorEntity from homeassistant.const import ( DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE, @@ -33,7 +34,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities(entities) -class AbodeSensor(AbodeDevice): +class AbodeSensor(SensorEntity, AbodeDevice): """A sensor implementation for Abode devices.""" def __init__(self, data, device, sensor_type): diff --git a/homeassistant/components/accuweather/sensor.py b/homeassistant/components/accuweather/sensor.py index aa7f604e27f..89147cc7104 100644 --- a/homeassistant/components/accuweather/sensor.py +++ b/homeassistant/components/accuweather/sensor.py @@ -1,4 +1,5 @@ """Support for the AccuWeather service.""" +from homeassistant.components.sensor import SensorEntity from homeassistant.const import ( ATTR_ATTRIBUTION, ATTR_DEVICE_CLASS, @@ -48,7 +49,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities(sensors, False) -class AccuWeatherSensor(CoordinatorEntity): +class AccuWeatherSensor(SensorEntity, CoordinatorEntity): """Define an AccuWeather entity.""" def __init__(self, name, kind, coordinator, forecast_day=None): diff --git a/homeassistant/components/acmeda/sensor.py b/homeassistant/components/acmeda/sensor.py index f427548ab94..f1961b85589 100644 --- a/homeassistant/components/acmeda/sensor.py +++ b/homeassistant/components/acmeda/sensor.py @@ -1,4 +1,5 @@ """Support for Acmeda Roller Blind Batteries.""" +from homeassistant.components.sensor import SensorEntity from homeassistant.const import DEVICE_CLASS_BATTERY, PERCENTAGE from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -29,7 +30,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): ) -class AcmedaBattery(AcmedaBase): +class AcmedaBattery(SensorEntity, AcmedaBase): """Representation of a Acmeda cover device.""" device_class = DEVICE_CLASS_BATTERY diff --git a/homeassistant/components/adguard/sensor.py b/homeassistant/components/adguard/sensor.py index 3a93d9fbb35..6f2f0f54beb 100644 --- a/homeassistant/components/adguard/sensor.py +++ b/homeassistant/components/adguard/sensor.py @@ -6,6 +6,7 @@ from typing import Callable from adguardhome import AdGuardHome, AdGuardHomeConnectionError +from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.const import PERCENTAGE, TIME_MILLISECONDS from homeassistant.core import HomeAssistant @@ -48,7 +49,7 @@ async def async_setup_entry( async_add_entities(sensors, True) -class AdGuardHomeSensor(AdGuardHomeDeviceEntity): +class AdGuardHomeSensor(SensorEntity, AdGuardHomeDeviceEntity): """Defines a AdGuard Home sensor.""" def __init__( diff --git a/homeassistant/components/ads/sensor.py b/homeassistant/components/ads/sensor.py index 2f411b27723..6e7c69d3c2d 100644 --- a/homeassistant/components/ads/sensor.py +++ b/homeassistant/components/ads/sensor.py @@ -2,7 +2,7 @@ import voluptuous as vol from homeassistant.components import ads -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import CONF_NAME, CONF_UNIT_OF_MEASUREMENT import homeassistant.helpers.config_validation as cv @@ -43,7 +43,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities([entity]) -class AdsSensor(AdsEntity): +class AdsSensor(SensorEntity, AdsEntity): """Representation of an ADS sensor entity.""" def __init__(self, ads_hub, ads_var, ads_type, name, unit_of_measurement, factor): diff --git a/homeassistant/components/advantage_air/sensor.py b/homeassistant/components/advantage_air/sensor.py index d25ce4888fc..cef70ebb245 100644 --- a/homeassistant/components/advantage_air/sensor.py +++ b/homeassistant/components/advantage_air/sensor.py @@ -1,6 +1,7 @@ """Sensor platform for Advantage Air integration.""" import voluptuous as vol +from homeassistant.components.sensor import SensorEntity from homeassistant.const import PERCENTAGE from homeassistant.helpers import config_validation as cv, entity_platform @@ -40,7 +41,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): ) -class AdvantageAirTimeTo(AdvantageAirEntity): +class AdvantageAirTimeTo(SensorEntity, AdvantageAirEntity): """Representation of Advantage Air timer control.""" def __init__(self, instance, ac_key, action): @@ -82,7 +83,7 @@ class AdvantageAirTimeTo(AdvantageAirEntity): await self.async_change({self.ac_key: {"info": {self._time_key: value}}}) -class AdvantageAirZoneVent(AdvantageAirEntity): +class AdvantageAirZoneVent(SensorEntity, AdvantageAirEntity): """Representation of Advantage Air Zone Vent Sensor.""" @property @@ -115,7 +116,7 @@ class AdvantageAirZoneVent(AdvantageAirEntity): return "mdi:fan-off" -class AdvantageAirZoneSignal(AdvantageAirEntity): +class AdvantageAirZoneSignal(SensorEntity, AdvantageAirEntity): """Representation of Advantage Air Zone wireless signal sensor.""" @property diff --git a/homeassistant/components/aemet/sensor.py b/homeassistant/components/aemet/sensor.py index b57de1ce890..400952830cc 100644 --- a/homeassistant/components/aemet/sensor.py +++ b/homeassistant/components/aemet/sensor.py @@ -1,4 +1,6 @@ """Support for the AEMET OpenData service.""" +from homeassistant.components.sensor import SensorEntity + from .abstract_aemet_sensor import AbstractAemetSensor from .const import ( DOMAIN, @@ -56,7 +58,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities(entities) -class AemetSensor(AbstractAemetSensor): +class AemetSensor(SensorEntity, AbstractAemetSensor): """Implementation of an AEMET OpenData sensor.""" def __init__( @@ -79,7 +81,7 @@ class AemetSensor(AbstractAemetSensor): return self._weather_coordinator.data.get(self._sensor_type) -class AemetForecastSensor(AbstractAemetSensor): +class AemetForecastSensor(SensorEntity, AbstractAemetSensor): """Implementation of an AEMET OpenData forecast sensor.""" def __init__( diff --git a/homeassistant/components/aftership/sensor.py b/homeassistant/components/aftership/sensor.py index 754b3ce72eb..a5ffc511a26 100644 --- a/homeassistant/components/aftership/sensor.py +++ b/homeassistant/components/aftership/sensor.py @@ -5,12 +5,11 @@ import logging from pyaftership.tracker import Tracking import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ATTR_ATTRIBUTION, CONF_API_KEY, CONF_NAME, HTTP_OK from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_send -from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle from .const import DOMAIN @@ -108,7 +107,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= ) -class AfterShipSensor(Entity): +class AfterShipSensor(SensorEntity): """Representation of a AfterShip sensor.""" def __init__(self, aftership, name): diff --git a/homeassistant/components/airly/sensor.py b/homeassistant/components/airly/sensor.py index dae167559e0..efadeac94e1 100644 --- a/homeassistant/components/airly/sensor.py +++ b/homeassistant/components/airly/sensor.py @@ -1,4 +1,5 @@ """Support for the Airly sensor service.""" +from homeassistant.components.sensor import SensorEntity from homeassistant.const import ( ATTR_ATTRIBUTION, ATTR_DEVICE_CLASS, @@ -72,7 +73,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities(sensors, False) -class AirlySensor(CoordinatorEntity): +class AirlySensor(SensorEntity, CoordinatorEntity): """Define an Airly sensor.""" def __init__(self, coordinator, name, kind): diff --git a/homeassistant/components/airnow/sensor.py b/homeassistant/components/airnow/sensor.py index ea2ff9856fb..f8f5eff6cc7 100644 --- a/homeassistant/components/airnow/sensor.py +++ b/homeassistant/components/airnow/sensor.py @@ -1,4 +1,5 @@ """Support for the AirNow sensor service.""" +from homeassistant.components.sensor import SensorEntity from homeassistant.const import ( ATTR_ATTRIBUTION, ATTR_DEVICE_CLASS, @@ -59,7 +60,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities(sensors, False) -class AirNowSensor(CoordinatorEntity): +class AirNowSensor(SensorEntity, CoordinatorEntity): """Define an AirNow sensor.""" def __init__(self, coordinator, kind): diff --git a/homeassistant/components/airvisual/sensor.py b/homeassistant/components/airvisual/sensor.py index 3c1aef128ab..c4cbf3af22e 100644 --- a/homeassistant/components/airvisual/sensor.py +++ b/homeassistant/components/airvisual/sensor.py @@ -1,4 +1,5 @@ """Support for AirVisual air quality sensors.""" +from homeassistant.components.sensor import SensorEntity from homeassistant.const import ( ATTR_LATITUDE, ATTR_LONGITUDE, @@ -138,7 +139,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities(sensors, True) -class AirVisualGeographySensor(AirVisualEntity): +class AirVisualGeographySensor(SensorEntity, AirVisualEntity): """Define an AirVisual sensor related to geography data via the Cloud API.""" def __init__(self, coordinator, config_entry, kind, name, icon, unit, locale): @@ -236,7 +237,7 @@ class AirVisualGeographySensor(AirVisualEntity): self._attrs.pop(ATTR_LONGITUDE, None) -class AirVisualNodeProSensor(AirVisualEntity): +class AirVisualNodeProSensor(SensorEntity, AirVisualEntity): """Define an AirVisual sensor related to a Node/Pro unit.""" def __init__(self, coordinator, kind, name, device_class, unit): diff --git a/homeassistant/components/alarmdecoder/sensor.py b/homeassistant/components/alarmdecoder/sensor.py index a8aed8dac73..80b9c1261a3 100644 --- a/homeassistant/components/alarmdecoder/sensor.py +++ b/homeassistant/components/alarmdecoder/sensor.py @@ -1,6 +1,6 @@ """Support for AlarmDecoder sensors (Shows Panel Display).""" +from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry -from homeassistant.helpers.entity import Entity from homeassistant.helpers.typing import HomeAssistantType from .const import SIGNAL_PANEL_MESSAGE @@ -16,7 +16,7 @@ async def async_setup_entry( return True -class AlarmDecoderSensor(Entity): +class AlarmDecoderSensor(SensorEntity): """Representation of an AlarmDecoder keypad.""" def __init__(self): diff --git a/homeassistant/components/alpha_vantage/sensor.py b/homeassistant/components/alpha_vantage/sensor.py index cd161b1870c..0788772a45b 100644 --- a/homeassistant/components/alpha_vantage/sensor.py +++ b/homeassistant/components/alpha_vantage/sensor.py @@ -6,10 +6,9 @@ from alpha_vantage.foreignexchange import ForeignExchange from alpha_vantage.timeseries import TimeSeries import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ATTR_ATTRIBUTION, CONF_API_KEY, CONF_CURRENCY, CONF_NAME import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity _LOGGER = logging.getLogger(__name__) @@ -105,7 +104,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): _LOGGER.debug("Setup completed") -class AlphaVantageSensor(Entity): +class AlphaVantageSensor(SensorEntity): """Representation of a Alpha Vantage sensor.""" def __init__(self, timeseries, symbol): @@ -156,7 +155,7 @@ class AlphaVantageSensor(Entity): _LOGGER.debug("Received new values for symbol %s", self._symbol) -class AlphaVantageForeignExchange(Entity): +class AlphaVantageForeignExchange(SensorEntity): """Sensor for foreign exchange rates.""" def __init__(self, foreign_exchange, config): diff --git a/homeassistant/components/ambient_station/sensor.py b/homeassistant/components/ambient_station/sensor.py index 184927a1ef5..7e8f3d26ec6 100644 --- a/homeassistant/components/ambient_station/sensor.py +++ b/homeassistant/components/ambient_station/sensor.py @@ -1,5 +1,6 @@ """Support for Ambient Weather Station sensors.""" from homeassistant.components.binary_sensor import DOMAIN as SENSOR +from homeassistant.components.sensor import SensorEntity from homeassistant.const import ATTR_NAME from homeassistant.core import callback @@ -36,7 +37,7 @@ async def async_setup_entry(hass, entry, async_add_entities): async_add_entities(sensor_list, True) -class AmbientWeatherSensor(AmbientWeatherEntity): +class AmbientWeatherSensor(SensorEntity, AmbientWeatherEntity): """Define an Ambient sensor.""" def __init__( diff --git a/homeassistant/components/amcrest/sensor.py b/homeassistant/components/amcrest/sensor.py index 15a610b23b4..a30de62494e 100644 --- a/homeassistant/components/amcrest/sensor.py +++ b/homeassistant/components/amcrest/sensor.py @@ -4,9 +4,9 @@ import logging from amcrest import AmcrestError +from homeassistant.components.sensor import SensorEntity from homeassistant.const import CONF_NAME, CONF_SENSORS, PERCENTAGE from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.helpers.entity import Entity from .const import DATA_AMCREST, DEVICES, SENSOR_SCAN_INTERVAL_SECS, SERVICE_UPDATE from .helpers import log_update_error, service_signal @@ -40,7 +40,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= ) -class AmcrestSensor(Entity): +class AmcrestSensor(SensorEntity): """A sensor implementation for Amcrest IP camera.""" def __init__(self, name, device, sensor_type): diff --git a/homeassistant/components/android_ip_webcam/sensor.py b/homeassistant/components/android_ip_webcam/sensor.py index 05c1fe16c61..de029c39aba 100644 --- a/homeassistant/components/android_ip_webcam/sensor.py +++ b/homeassistant/components/android_ip_webcam/sensor.py @@ -1,4 +1,5 @@ """Support for Android IP Webcam sensors.""" +from homeassistant.components.sensor import SensorEntity from homeassistant.helpers.icon import icon_for_battery_level from . import ( @@ -30,7 +31,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= async_add_entities(all_sensors, True) -class IPWebcamSensor(AndroidIPCamEntity): +class IPWebcamSensor(SensorEntity, AndroidIPCamEntity): """Representation of a IP Webcam sensor.""" def __init__(self, name, host, ipcam, sensor): diff --git a/homeassistant/components/apcupsd/sensor.py b/homeassistant/components/apcupsd/sensor.py index 55e6d8c7a56..36dc1155b7f 100644 --- a/homeassistant/components/apcupsd/sensor.py +++ b/homeassistant/components/apcupsd/sensor.py @@ -4,7 +4,7 @@ import logging from apcaccess.status import ALL_UNITS import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ( CONF_RESOURCES, ELECTRICAL_CURRENT_AMPERE, @@ -18,7 +18,6 @@ from homeassistant.const import ( VOLT, ) import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity from . import DOMAIN @@ -156,7 +155,7 @@ def infer_unit(value): return value, None -class APCUPSdSensor(Entity): +class APCUPSdSensor(SensorEntity): """Representation of a sensor entity for APCUPSd status values.""" def __init__(self, data, sensor_type): diff --git a/homeassistant/components/aqualogic/sensor.py b/homeassistant/components/aqualogic/sensor.py index f92cd11c011..315b039f778 100644 --- a/homeassistant/components/aqualogic/sensor.py +++ b/homeassistant/components/aqualogic/sensor.py @@ -2,7 +2,7 @@ import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ( CONF_MONITORED_CONDITIONS, PERCENTAGE, @@ -12,7 +12,6 @@ from homeassistant.const import ( ) from homeassistant.core import callback import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity from . import DOMAIN, UPDATE_TOPIC @@ -56,7 +55,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= async_add_entities(sensors) -class AquaLogicSensor(Entity): +class AquaLogicSensor(SensorEntity): """Sensor implementation for the AquaLogic component.""" def __init__(self, processor, sensor_type): diff --git a/homeassistant/components/arduino/sensor.py b/homeassistant/components/arduino/sensor.py index f31272b3a20..588a652660a 100644 --- a/homeassistant/components/arduino/sensor.py +++ b/homeassistant/components/arduino/sensor.py @@ -1,10 +1,9 @@ """Support for getting information from Arduino pins.""" import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import CONF_NAME import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity from . import DOMAIN @@ -30,7 +29,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities(sensors) -class ArduinoSensor(Entity): +class ArduinoSensor(SensorEntity): """Representation of an Arduino Sensor.""" def __init__(self, name, pin, pin_type, board): diff --git a/homeassistant/components/arest/sensor.py b/homeassistant/components/arest/sensor.py index d213a3d2903..061c15eafb0 100644 --- a/homeassistant/components/arest/sensor.py +++ b/homeassistant/components/arest/sensor.py @@ -5,7 +5,7 @@ import logging import requests import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ( CONF_MONITORED_VARIABLES, CONF_NAME, @@ -16,7 +16,6 @@ from homeassistant.const import ( ) from homeassistant.exceptions import TemplateError import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle _LOGGER = logging.getLogger(__name__) @@ -124,7 +123,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities(dev, True) -class ArestSensor(Entity): +class ArestSensor(SensorEntity): """Implementation of an aREST sensor for exposed variables.""" def __init__( diff --git a/homeassistant/components/arlo/sensor.py b/homeassistant/components/arlo/sensor.py index 1e0c55c5d31..c794bf1ef5e 100644 --- a/homeassistant/components/arlo/sensor.py +++ b/homeassistant/components/arlo/sensor.py @@ -3,7 +3,7 @@ import logging import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ( ATTR_ATTRIBUTION, CONCENTRATION_PARTS_PER_MILLION, @@ -16,7 +16,6 @@ from homeassistant.const import ( from homeassistant.core import callback import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.helpers.entity import Entity from homeassistant.helpers.icon import icon_for_battery_level from . import ATTRIBUTION, DATA_ARLO, DEFAULT_BRAND, SIGNAL_UPDATE_ARLO @@ -73,7 +72,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities(sensors, True) -class ArloSensor(Entity): +class ArloSensor(SensorEntity): """An implementation of a Netgear Arlo IP sensor.""" def __init__(self, name, device, sensor_type): diff --git a/homeassistant/components/arwn/sensor.py b/homeassistant/components/arwn/sensor.py index d68549ea95c..ba9166d1af5 100644 --- a/homeassistant/components/arwn/sensor.py +++ b/homeassistant/components/arwn/sensor.py @@ -3,9 +3,9 @@ import json import logging from homeassistant.components import mqtt +from homeassistant.components.sensor import SensorEntity from homeassistant.const import DEGREE, TEMP_CELSIUS, TEMP_FAHRENHEIT from homeassistant.core import callback -from homeassistant.helpers.entity import Entity from homeassistant.util import slugify _LOGGER = logging.getLogger(__name__) @@ -114,7 +114,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= return True -class ArwnSensor(Entity): +class ArwnSensor(SensorEntity): """Representation of an ARWN sensor.""" def __init__(self, topic, name, state_key, units, icon=None): diff --git a/homeassistant/components/asuswrt/sensor.py b/homeassistant/components/asuswrt/sensor.py index 7dc8208ee67..30f4163d01b 100644 --- a/homeassistant/components/asuswrt/sensor.py +++ b/homeassistant/components/asuswrt/sensor.py @@ -4,6 +4,7 @@ from __future__ import annotations import logging from numbers import Number +from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.const import DATA_GIGABYTES, DATA_RATE_MEGABITS_PER_SECOND from homeassistant.helpers.typing import HomeAssistantType @@ -97,7 +98,7 @@ async def async_setup_entry( async_add_entities(entities, True) -class AsusWrtSensor(CoordinatorEntity): +class AsusWrtSensor(SensorEntity, CoordinatorEntity): """Representation of a AsusWrt sensor.""" def __init__( diff --git a/homeassistant/components/atag/sensor.py b/homeassistant/components/atag/sensor.py index 3123e245711..163ed669be4 100644 --- a/homeassistant/components/atag/sensor.py +++ b/homeassistant/components/atag/sensor.py @@ -1,4 +1,5 @@ """Initialization of ATAG One sensor platform.""" +from homeassistant.components.sensor import SensorEntity from homeassistant.const import ( DEVICE_CLASS_PRESSURE, DEVICE_CLASS_TEMPERATURE, @@ -29,7 +30,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities([AtagSensor(coordinator, sensor) for sensor in SENSORS]) -class AtagSensor(AtagEntity): +class AtagSensor(SensorEntity, AtagEntity): """Representation of a AtagOne Sensor.""" def __init__(self, coordinator, sensor): diff --git a/homeassistant/components/atome/sensor.py b/homeassistant/components/atome/sensor.py index e50f7cd5de6..d10024f64c2 100644 --- a/homeassistant/components/atome/sensor.py +++ b/homeassistant/components/atome/sensor.py @@ -5,7 +5,7 @@ import logging from pyatome.client import AtomeClient, PyAtomeError import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ( CONF_NAME, CONF_PASSWORD, @@ -15,7 +15,6 @@ from homeassistant.const import ( POWER_WATT, ) import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle _LOGGER = logging.getLogger(__name__) @@ -215,7 +214,7 @@ class AtomeData: _LOGGER.error("Missing last value in values: %s: %s", values, error) -class AtomeSensor(Entity): +class AtomeSensor(SensorEntity): """Representation of a sensor entity for Atome.""" def __init__(self, data, name, sensor_type): diff --git a/homeassistant/components/august/sensor.py b/homeassistant/components/august/sensor.py index 1841b2cef56..9b8352a0b96 100644 --- a/homeassistant/components/august/sensor.py +++ b/homeassistant/components/august/sensor.py @@ -3,10 +3,9 @@ import logging from yalexs.activity import ActivityType -from homeassistant.components.sensor import DEVICE_CLASS_BATTERY +from homeassistant.components.sensor import DEVICE_CLASS_BATTERY, SensorEntity from homeassistant.const import ATTR_ENTITY_PICTURE, PERCENTAGE, STATE_UNAVAILABLE from homeassistant.core import callback -from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity_registry import async_get_registry from homeassistant.helpers.restore_state import RestoreEntity @@ -118,7 +117,7 @@ async def _async_migrate_old_unique_ids(hass, devices): registry.async_update_entity(old_entity_id, new_unique_id=device.unique_id) -class AugustOperatorSensor(AugustEntityMixin, RestoreEntity, Entity): +class AugustOperatorSensor(SensorEntity, AugustEntityMixin, RestoreEntity): """Representation of an August lock operation sensor.""" def __init__(self, data, device): @@ -217,7 +216,7 @@ class AugustOperatorSensor(AugustEntityMixin, RestoreEntity, Entity): return f"{self._device_id}_lock_operator" -class AugustBatterySensor(AugustEntityMixin, Entity): +class AugustBatterySensor(SensorEntity, AugustEntityMixin): """Representation of an August sensor.""" def __init__(self, data, sensor_type, device, old_device): diff --git a/homeassistant/components/aurora/sensor.py b/homeassistant/components/aurora/sensor.py index 731c6d08afd..1a34bb604da 100644 --- a/homeassistant/components/aurora/sensor.py +++ b/homeassistant/components/aurora/sensor.py @@ -1,4 +1,5 @@ """Support for Aurora Forecast sensor.""" +from homeassistant.components.sensor import SensorEntity from homeassistant.const import PERCENTAGE from . import AuroraEntity @@ -18,7 +19,7 @@ async def async_setup_entry(hass, entry, async_add_entries): async_add_entries([entity]) -class AuroraSensor(AuroraEntity): +class AuroraSensor(SensorEntity, AuroraEntity): """Implementation of an aurora sensor.""" @property diff --git a/homeassistant/components/aurora_abb_powerone/sensor.py b/homeassistant/components/aurora_abb_powerone/sensor.py index 69a513dd8fb..f4640e7c014 100644 --- a/homeassistant/components/aurora_abb_powerone/sensor.py +++ b/homeassistant/components/aurora_abb_powerone/sensor.py @@ -5,7 +5,7 @@ import logging from aurorapy.client import AuroraError, AuroraSerialClient import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ( CONF_ADDRESS, CONF_DEVICE, @@ -14,7 +14,6 @@ from homeassistant.const import ( POWER_WATT, ) import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity _LOGGER = logging.getLogger(__name__) @@ -44,7 +43,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities(devices, True) -class AuroraABBSolarPVMonitorSensor(Entity): +class AuroraABBSolarPVMonitorSensor(SensorEntity): """Representation of a Sensor.""" def __init__(self, client, name, typename): diff --git a/homeassistant/components/awair/sensor.py b/homeassistant/components/awair/sensor.py index 33ecaf46660..de39c20eb60 100644 --- a/homeassistant/components/awair/sensor.py +++ b/homeassistant/components/awair/sensor.py @@ -7,7 +7,7 @@ from python_awair.devices import AwairDevice import voluptuous as vol from homeassistant.components.awair import AwairDataUpdateCoordinator, AwairResult -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.config_entries import SOURCE_IMPORT from homeassistant.const import ATTR_ATTRIBUTION, ATTR_DEVICE_CLASS, CONF_ACCESS_TOKEN from homeassistant.helpers import device_registry as dr @@ -84,7 +84,7 @@ async def async_setup_entry( async_add_entities(sensors) -class AwairSensor(CoordinatorEntity): +class AwairSensor(SensorEntity, CoordinatorEntity): """Defines an Awair sensor entity.""" def __init__( diff --git a/homeassistant/components/azure_devops/sensor.py b/homeassistant/components/azure_devops/sensor.py index 1d30bfcb9f9..a0701ac9839 100644 --- a/homeassistant/components/azure_devops/sensor.py +++ b/homeassistant/components/azure_devops/sensor.py @@ -17,6 +17,7 @@ from homeassistant.components.azure_devops.const import ( DATA_PROJECT, DOMAIN, ) +from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.exceptions import PlatformNotReady from homeassistant.helpers.typing import HomeAssistantType @@ -55,7 +56,7 @@ async def async_setup_entry( async_add_entities(sensors, True) -class AzureDevOpsSensor(AzureDevOpsDeviceEntity): +class AzureDevOpsSensor(SensorEntity, AzureDevOpsDeviceEntity): """Defines a Azure DevOps sensor.""" def __init__( diff --git a/homeassistant/components/bbox/sensor.py b/homeassistant/components/bbox/sensor.py index 8d6708c6342..5256c2a61a0 100644 --- a/homeassistant/components/bbox/sensor.py +++ b/homeassistant/components/bbox/sensor.py @@ -6,7 +6,7 @@ import pybbox import requests import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ( ATTR_ATTRIBUTION, CONF_MONITORED_VARIABLES, @@ -15,7 +15,6 @@ from homeassistant.const import ( DEVICE_CLASS_TIMESTAMP, ) import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle from homeassistant.util.dt import utcnow @@ -86,7 +85,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities(sensors, True) -class BboxUptimeSensor(Entity): +class BboxUptimeSensor(SensorEntity): """Bbox uptime sensor.""" def __init__(self, bbox_data, sensor_type, name): @@ -133,7 +132,7 @@ class BboxUptimeSensor(Entity): self._state = uptime.replace(microsecond=0).isoformat() -class BboxSensor(Entity): +class BboxSensor(SensorEntity): """Implementation of a Bbox sensor.""" def __init__(self, bbox_data, sensor_type, name): diff --git a/homeassistant/components/beewi_smartclim/sensor.py b/homeassistant/components/beewi_smartclim/sensor.py index e8a37d51be4..9bf935f3c4f 100644 --- a/homeassistant/components/beewi_smartclim/sensor.py +++ b/homeassistant/components/beewi_smartclim/sensor.py @@ -2,7 +2,7 @@ from beewi_smartclim import BeewiSmartClimPoller # pylint: disable=import-error import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ( CONF_MAC, CONF_NAME, @@ -13,7 +13,6 @@ from homeassistant.const import ( TEMP_CELSIUS, ) import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity # Default values DEFAULT_NAME = "BeeWi SmartClim" @@ -56,7 +55,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities(sensors) -class BeewiSmartclimSensor(Entity): +class BeewiSmartclimSensor(SensorEntity): """Representation of a Sensor.""" def __init__(self, poller, name, mac, device, unit): diff --git a/homeassistant/components/bh1750/sensor.py b/homeassistant/components/bh1750/sensor.py index eb9bbc2dccc..5b708ae2630 100644 --- a/homeassistant/components/bh1750/sensor.py +++ b/homeassistant/components/bh1750/sensor.py @@ -6,10 +6,9 @@ from i2csense.bh1750 import BH1750 # pylint: disable=import-error import smbus import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import CONF_NAME, DEVICE_CLASS_ILLUMINANCE, LIGHT_LUX import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity _LOGGER = logging.getLogger(__name__) @@ -94,7 +93,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= async_add_entities(dev, True) -class BH1750Sensor(Entity): +class BH1750Sensor(SensorEntity): """Implementation of the BH1750 sensor.""" def __init__(self, bh1750_sensor, name, unit, multiplier=1.0): diff --git a/homeassistant/components/bitcoin/sensor.py b/homeassistant/components/bitcoin/sensor.py index f6f5a24d22f..4acce03d6fa 100644 --- a/homeassistant/components/bitcoin/sensor.py +++ b/homeassistant/components/bitcoin/sensor.py @@ -5,7 +5,7 @@ import logging from blockchain import exchangerates, statistics import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ( ATTR_ATTRIBUTION, CONF_CURRENCY, @@ -14,7 +14,6 @@ from homeassistant.const import ( TIME_SECONDS, ) import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity _LOGGER = logging.getLogger(__name__) @@ -77,7 +76,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities(dev, True) -class BitcoinSensor(Entity): +class BitcoinSensor(SensorEntity): """Representation of a Bitcoin sensor.""" def __init__(self, data, option_type, currency): diff --git a/homeassistant/components/bizkaibus/sensor.py b/homeassistant/components/bizkaibus/sensor.py index c1cee98208c..a905498328b 100644 --- a/homeassistant/components/bizkaibus/sensor.py +++ b/homeassistant/components/bizkaibus/sensor.py @@ -2,10 +2,9 @@ from bizkaibus.bizkaibus import BizkaibusData import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import CONF_NAME, TIME_MINUTES import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity ATTR_DUE_IN = "Due in" @@ -33,7 +32,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities([BizkaibusSensor(data, stop, route, name)], True) -class BizkaibusSensor(Entity): +class BizkaibusSensor(SensorEntity): """The class for handling the data.""" def __init__(self, data, stop, route, name): diff --git a/homeassistant/components/blebox/sensor.py b/homeassistant/components/blebox/sensor.py index 84f4c19371d..688d2931461 100644 --- a/homeassistant/components/blebox/sensor.py +++ b/homeassistant/components/blebox/sensor.py @@ -1,6 +1,6 @@ """BleBox sensor entities.""" -from homeassistant.helpers.entity import Entity +from homeassistant.components.sensor import SensorEntity from . import BleBoxEntity, create_blebox_entities from .const import BLEBOX_TO_HASS_DEVICE_CLASSES, BLEBOX_TO_UNIT_MAP @@ -14,7 +14,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): ) -class BleBoxSensorEntity(BleBoxEntity, Entity): +class BleBoxSensorEntity(SensorEntity, BleBoxEntity): """Representation of a BleBox sensor feature.""" @property diff --git a/homeassistant/components/blink/sensor.py b/homeassistant/components/blink/sensor.py index 3c3adf6d990..1ec61900091 100644 --- a/homeassistant/components/blink/sensor.py +++ b/homeassistant/components/blink/sensor.py @@ -1,13 +1,13 @@ """Support for Blink system camera sensors.""" import logging +from homeassistant.components.sensor import SensorEntity from homeassistant.const import ( DEVICE_CLASS_SIGNAL_STRENGTH, DEVICE_CLASS_TEMPERATURE, SIGNAL_STRENGTH_DECIBELS_MILLIWATT, TEMP_FAHRENHEIT, ) -from homeassistant.helpers.entity import Entity from .const import DOMAIN, TYPE_TEMPERATURE, TYPE_WIFI_STRENGTH @@ -34,7 +34,7 @@ async def async_setup_entry(hass, config, async_add_entities): async_add_entities(entities) -class BlinkSensor(Entity): +class BlinkSensor(SensorEntity): """A Blink camera sensor.""" def __init__(self, data, camera, sensor_type): diff --git a/homeassistant/components/blockchain/sensor.py b/homeassistant/components/blockchain/sensor.py index 790051dad96..3ecf4bee319 100644 --- a/homeassistant/components/blockchain/sensor.py +++ b/homeassistant/components/blockchain/sensor.py @@ -5,10 +5,9 @@ import logging from pyblockchain import get_balance, validate_address import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity _LOGGER = logging.getLogger(__name__) @@ -44,7 +43,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities([BlockchainSensor(name, addresses)], True) -class BlockchainSensor(Entity): +class BlockchainSensor(SensorEntity): """Representation of a Blockchain.com sensor.""" def __init__(self, name, addresses): diff --git a/homeassistant/components/bloomsky/sensor.py b/homeassistant/components/bloomsky/sensor.py index df06e39db7e..4dc52e1a85c 100644 --- a/homeassistant/components/bloomsky/sensor.py +++ b/homeassistant/components/bloomsky/sensor.py @@ -1,7 +1,7 @@ """Support the sensor of a BloomSky weather station.""" import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ( AREA_SQUARE_METERS, CONF_MONITORED_CONDITIONS, @@ -12,7 +12,6 @@ from homeassistant.const import ( TEMP_FAHRENHEIT, ) import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity from . import DOMAIN @@ -70,7 +69,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities([BloomSkySensor(bloomsky, device, variable)], True) -class BloomSkySensor(Entity): +class BloomSkySensor(SensorEntity): """Representation of a single sensor in a BloomSky device.""" def __init__(self, bs, device, sensor_name): diff --git a/homeassistant/components/bme280/sensor.py b/homeassistant/components/bme280/sensor.py index d3d97881035..ffe68479341 100644 --- a/homeassistant/components/bme280/sensor.py +++ b/homeassistant/components/bme280/sensor.py @@ -7,7 +7,7 @@ from i2csense.bme280 import BME280 # pylint: disable=import-error import smbus import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ( CONF_MONITORED_CONDITIONS, CONF_NAME, @@ -15,7 +15,6 @@ from homeassistant.const import ( TEMP_FAHRENHEIT, ) import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle from homeassistant.util.temperature import celsius_to_fahrenheit @@ -136,7 +135,7 @@ class BME280Handler: self.sensor.update(first_reading) -class BME280Sensor(Entity): +class BME280Sensor(SensorEntity): """Implementation of the BME280 sensor.""" def __init__(self, bme280_client, sensor_type, temp_unit, name): diff --git a/homeassistant/components/bme680/sensor.py b/homeassistant/components/bme680/sensor.py index 6af9d46c0bc..f3d6b9428ea 100644 --- a/homeassistant/components/bme680/sensor.py +++ b/homeassistant/components/bme680/sensor.py @@ -7,7 +7,7 @@ import bme680 # pylint: disable=import-error from smbus import SMBus import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ( CONF_MONITORED_CONDITIONS, CONF_NAME, @@ -15,7 +15,6 @@ from homeassistant.const import ( TEMP_FAHRENHEIT, ) import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity from homeassistant.util.temperature import celsius_to_fahrenheit _LOGGER = logging.getLogger(__name__) @@ -316,7 +315,7 @@ class BME680Handler: return hum_score + gas_score -class BME680Sensor(Entity): +class BME680Sensor(SensorEntity): """Implementation of the BME680 sensor.""" def __init__(self, bme680_client, sensor_type, temp_unit, name): diff --git a/homeassistant/components/bmp280/sensor.py b/homeassistant/components/bmp280/sensor.py index 3c34408cb62..60cbdb75d41 100644 --- a/homeassistant/components/bmp280/sensor.py +++ b/homeassistant/components/bmp280/sensor.py @@ -11,11 +11,11 @@ from homeassistant.components.sensor import ( DEVICE_CLASS_PRESSURE, DEVICE_CLASS_TEMPERATURE, PLATFORM_SCHEMA, + SensorEntity, ) from homeassistant.const import CONF_NAME, PRESSURE_HPA, TEMP_CELSIUS from homeassistant.exceptions import PlatformNotReady import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle _LOGGER = logging.getLogger(__name__) @@ -65,7 +65,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): ) -class Bmp280Sensor(Entity): +class Bmp280Sensor(SensorEntity): """Base class for BMP280 entities.""" def __init__( diff --git a/homeassistant/components/bmw_connected_drive/sensor.py b/homeassistant/components/bmw_connected_drive/sensor.py index 480aac34eb3..5c85312d959 100644 --- a/homeassistant/components/bmw_connected_drive/sensor.py +++ b/homeassistant/components/bmw_connected_drive/sensor.py @@ -3,6 +3,7 @@ import logging from bimmer_connected.state import ChargingState +from homeassistant.components.sensor import SensorEntity from homeassistant.const import ( CONF_UNIT_SYSTEM_IMPERIAL, LENGTH_KILOMETERS, @@ -12,7 +13,6 @@ from homeassistant.const import ( VOLUME_GALLONS, VOLUME_LITERS, ) -from homeassistant.helpers.entity import Entity from homeassistant.helpers.icon import icon_for_battery_level from . import DOMAIN as BMW_DOMAIN, BMWConnectedDriveBaseEntity @@ -67,7 +67,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities(entities, True) -class BMWConnectedDriveSensor(BMWConnectedDriveBaseEntity, Entity): +class BMWConnectedDriveSensor(SensorEntity, BMWConnectedDriveBaseEntity): """Representation of a BMW vehicle sensor.""" def __init__(self, account, vehicle, attribute: str, attribute_info): diff --git a/homeassistant/components/broadlink/sensor.py b/homeassistant/components/broadlink/sensor.py index af350329e8c..0e42d8c438f 100644 --- a/homeassistant/components/broadlink/sensor.py +++ b/homeassistant/components/broadlink/sensor.py @@ -8,11 +8,11 @@ from homeassistant.components.sensor import ( DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_TEMPERATURE, PLATFORM_SCHEMA, + SensorEntity, ) from homeassistant.const import CONF_HOST, PERCENTAGE, TEMP_CELSIUS from homeassistant.core import callback from homeassistant.helpers import config_validation as cv -from homeassistant.helpers.entity import Entity from .const import DOMAIN from .helpers import import_device @@ -56,7 +56,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities(sensors) -class BroadlinkSensor(Entity): +class BroadlinkSensor(SensorEntity): """Representation of a Broadlink sensor.""" def __init__(self, device, monitored_condition): diff --git a/homeassistant/components/brother/sensor.py b/homeassistant/components/brother/sensor.py index dcbf92fba7d..10cc3979207 100644 --- a/homeassistant/components/brother/sensor.py +++ b/homeassistant/components/brother/sensor.py @@ -1,4 +1,5 @@ """Support for the Brother service.""" +from homeassistant.components.sensor import SensorEntity from homeassistant.const import DEVICE_CLASS_TIMESTAMP from homeassistant.helpers.update_coordinator import CoordinatorEntity @@ -56,7 +57,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities(sensors, False) -class BrotherPrinterSensor(CoordinatorEntity): +class BrotherPrinterSensor(SensorEntity, CoordinatorEntity): """Define an Brother Printer sensor.""" def __init__(self, coordinator, kind, device_info): diff --git a/homeassistant/components/brottsplatskartan/sensor.py b/homeassistant/components/brottsplatskartan/sensor.py index b75edcc7f4a..32af96dfe60 100644 --- a/homeassistant/components/brottsplatskartan/sensor.py +++ b/homeassistant/components/brottsplatskartan/sensor.py @@ -7,7 +7,7 @@ import uuid import brottsplatskartan import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ( ATTR_ATTRIBUTION, CONF_LATITUDE, @@ -15,7 +15,6 @@ from homeassistant.const import ( CONF_NAME, ) import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity _LOGGER = logging.getLogger(__name__) @@ -78,7 +77,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities([BrottsplatskartanSensor(bpk, name)], True) -class BrottsplatskartanSensor(Entity): +class BrottsplatskartanSensor(SensorEntity): """Representation of a Brottsplatskartan Sensor.""" def __init__(self, bpk, name): diff --git a/homeassistant/components/buienradar/sensor.py b/homeassistant/components/buienradar/sensor.py index fbfa23f1e74..170493969f8 100644 --- a/homeassistant/components/buienradar/sensor.py +++ b/homeassistant/components/buienradar/sensor.py @@ -20,7 +20,7 @@ from buienradar.constants import ( ) import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ( ATTR_ATTRIBUTION, CONF_LATITUDE, @@ -39,7 +39,6 @@ from homeassistant.const import ( ) from homeassistant.core import callback import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity from homeassistant.util import dt as dt_util from .const import DEFAULT_TIMEFRAME @@ -236,7 +235,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= await data.schedule_update(1) -class BrSensor(Entity): +class BrSensor(SensorEntity): """Representation of an Buienradar sensor.""" def __init__(self, sensor_type, client_name, coordinates): diff --git a/homeassistant/components/canary/sensor.py b/homeassistant/components/canary/sensor.py index 87e40d268bd..e4c6190ff99 100644 --- a/homeassistant/components/canary/sensor.py +++ b/homeassistant/components/canary/sensor.py @@ -5,6 +5,7 @@ from typing import Callable from canary.api import SensorType +from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( DEVICE_CLASS_BATTERY, @@ -77,7 +78,7 @@ async def async_setup_entry( async_add_entities(sensors, True) -class CanarySensor(CoordinatorEntity, Entity): +class CanarySensor(SensorEntity, CoordinatorEntity): """Representation of a Canary sensor.""" def __init__(self, coordinator, sensor_type, location, device): diff --git a/homeassistant/components/cert_expiry/sensor.py b/homeassistant/components/cert_expiry/sensor.py index 582205f9c0d..bf80f8b8fb5 100644 --- a/homeassistant/components/cert_expiry/sensor.py +++ b/homeassistant/components/cert_expiry/sensor.py @@ -3,7 +3,7 @@ from datetime import timedelta import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.config_entries import SOURCE_IMPORT from homeassistant.const import ( CONF_HOST, @@ -76,7 +76,7 @@ class CertExpiryEntity(CoordinatorEntity): } -class SSLCertificateTimestamp(CertExpiryEntity): +class SSLCertificateTimestamp(SensorEntity, CertExpiryEntity): """Implementation of the Cert Expiry timestamp sensor.""" @property diff --git a/homeassistant/components/citybikes/sensor.py b/homeassistant/components/citybikes/sensor.py index 2dd60078bd5..bc323a51151 100644 --- a/homeassistant/components/citybikes/sensor.py +++ b/homeassistant/components/citybikes/sensor.py @@ -7,7 +7,11 @@ import aiohttp import async_timeout import voluptuous as vol -from homeassistant.components.sensor import ENTITY_ID_FORMAT, PLATFORM_SCHEMA +from homeassistant.components.sensor import ( + ENTITY_ID_FORMAT, + PLATFORM_SCHEMA, + SensorEntity, +) from homeassistant.const import ( ATTR_ATTRIBUTION, ATTR_ID, @@ -25,7 +29,7 @@ from homeassistant.const import ( from homeassistant.exceptions import PlatformNotReady from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity, async_generate_entity_id +from homeassistant.helpers.entity import async_generate_entity_id from homeassistant.helpers.event import async_track_time_interval from homeassistant.util import distance, location @@ -258,7 +262,7 @@ class CityBikesNetwork: raise PlatformNotReady from err -class CityBikesStation(Entity): +class CityBikesStation(SensorEntity): """CityBikes API Sensor.""" def __init__(self, network, station_id, entity_id): diff --git a/homeassistant/components/co2signal/sensor.py b/homeassistant/components/co2signal/sensor.py index 2153a8a7af5..c7d2a64d6b0 100644 --- a/homeassistant/components/co2signal/sensor.py +++ b/homeassistant/components/co2signal/sensor.py @@ -4,7 +4,7 @@ import logging import CO2Signal import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ( ATTR_ATTRIBUTION, CONF_LATITUDE, @@ -13,7 +13,6 @@ from homeassistant.const import ( ENERGY_KILO_WATT_HOUR, ) import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity CONF_COUNTRY_CODE = "country_code" @@ -52,7 +51,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities(devs, True) -class CO2Sensor(Entity): +class CO2Sensor(SensorEntity): """Implementation of the CO2Signal sensor.""" def __init__(self, token, country_code, lat, lon): diff --git a/homeassistant/components/coinbase/sensor.py b/homeassistant/components/coinbase/sensor.py index 1d239ba457e..e4e4e719c9e 100644 --- a/homeassistant/components/coinbase/sensor.py +++ b/homeassistant/components/coinbase/sensor.py @@ -1,6 +1,6 @@ """Support for Coinbase sensors.""" +from homeassistant.components.sensor import SensorEntity from homeassistant.const import ATTR_ATTRIBUTION -from homeassistant.helpers.entity import Entity ATTR_NATIVE_BALANCE = "Balance in native currency" @@ -38,7 +38,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities([sensor], True) -class AccountSensor(Entity): +class AccountSensor(SensorEntity): """Representation of a Coinbase.com sensor.""" def __init__(self, coinbase_data, name, currency): @@ -88,7 +88,7 @@ class AccountSensor(Entity): self._native_currency = account["native_balance"]["currency"] -class ExchangeRateSensor(Entity): +class ExchangeRateSensor(SensorEntity): """Representation of a Coinbase.com sensor.""" def __init__(self, coinbase_data, exchange_currency, native_currency): diff --git a/homeassistant/components/comed_hourly_pricing/sensor.py b/homeassistant/components/comed_hourly_pricing/sensor.py index c1a784f619c..5d4ec6eec13 100644 --- a/homeassistant/components/comed_hourly_pricing/sensor.py +++ b/homeassistant/components/comed_hourly_pricing/sensor.py @@ -8,11 +8,10 @@ import aiohttp import async_timeout import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME, CONF_OFFSET from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity _LOGGER = logging.getLogger(__name__) _RESOURCE = "https://hourlypricing.comed.com/api" @@ -65,7 +64,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= async_add_entities(dev, True) -class ComedHourlyPricingSensor(Entity): +class ComedHourlyPricingSensor(SensorEntity): """Implementation of a ComEd Hourly Pricing sensor.""" def __init__(self, loop, websession, sensor_type, offset, name): diff --git a/homeassistant/components/comfoconnect/sensor.py b/homeassistant/components/comfoconnect/sensor.py index 87fa8f4a1a6..728bc13b76b 100644 --- a/homeassistant/components/comfoconnect/sensor.py +++ b/homeassistant/components/comfoconnect/sensor.py @@ -26,7 +26,7 @@ from pycomfoconnect import ( ) import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ( ATTR_DEVICE_CLASS, ATTR_ICON, @@ -45,7 +45,6 @@ from homeassistant.const import ( ) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.helpers.entity import Entity from . import DOMAIN, SIGNAL_COMFOCONNECT_UPDATE_RECEIVED, ComfoConnectBridge @@ -258,7 +257,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities(sensors, True) -class ComfoConnectSensor(Entity): +class ComfoConnectSensor(SensorEntity): """Representation of a ComfoConnect sensor.""" def __init__(self, name, ccb: ComfoConnectBridge, sensor_type) -> None: diff --git a/homeassistant/components/command_line/sensor.py b/homeassistant/components/command_line/sensor.py index fc99befb821..10c5a16f60b 100644 --- a/homeassistant/components/command_line/sensor.py +++ b/homeassistant/components/command_line/sensor.py @@ -6,7 +6,7 @@ import logging import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ( CONF_COMMAND, CONF_NAME, @@ -17,7 +17,6 @@ from homeassistant.const import ( from homeassistant.exceptions import TemplateError from homeassistant.helpers import template import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity from homeassistant.helpers.reload import setup_reload_service from . import check_output_or_log @@ -63,7 +62,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): ) -class CommandSensor(Entity): +class CommandSensor(SensorEntity): """Representation of a sensor that is using shell commands.""" def __init__( diff --git a/homeassistant/components/coronavirus/sensor.py b/homeassistant/components/coronavirus/sensor.py index acfc5569f34..58e6760a85d 100644 --- a/homeassistant/components/coronavirus/sensor.py +++ b/homeassistant/components/coronavirus/sensor.py @@ -1,4 +1,5 @@ """Sensor platform for the Corona virus.""" +from homeassistant.components.sensor import SensorEntity from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.helpers.update_coordinator import CoordinatorEntity @@ -23,7 +24,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): ) -class CoronavirusSensor(CoordinatorEntity): +class CoronavirusSensor(SensorEntity, CoordinatorEntity): """Sensor representing corona virus data.""" name = None diff --git a/homeassistant/components/cpuspeed/sensor.py b/homeassistant/components/cpuspeed/sensor.py index f21513f616e..01938344694 100644 --- a/homeassistant/components/cpuspeed/sensor.py +++ b/homeassistant/components/cpuspeed/sensor.py @@ -2,10 +2,9 @@ from cpuinfo import cpuinfo import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import CONF_NAME, FREQUENCY_GIGAHERTZ import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity ATTR_BRAND = "brand" ATTR_HZ = "ghz_advertised" @@ -29,7 +28,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities([CpuSpeedSensor(name)], True) -class CpuSpeedSensor(Entity): +class CpuSpeedSensor(SensorEntity): """Representation of a CPU sensor.""" def __init__(self, name): diff --git a/homeassistant/components/cups/sensor.py b/homeassistant/components/cups/sensor.py index 54e674b1811..6a3fc7b4215 100644 --- a/homeassistant/components/cups/sensor.py +++ b/homeassistant/components/cups/sensor.py @@ -5,11 +5,10 @@ import logging import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import CONF_HOST, CONF_PORT, PERCENTAGE from homeassistant.exceptions import PlatformNotReady import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity _LOGGER = logging.getLogger(__name__) @@ -96,7 +95,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities(dev, True) -class CupsSensor(Entity): +class CupsSensor(SensorEntity): """Representation of a CUPS sensor.""" def __init__(self, data, printer): @@ -155,7 +154,7 @@ class CupsSensor(Entity): self._available = self.data.available -class IPPSensor(Entity): +class IPPSensor(SensorEntity): """Implementation of the IPPSensor. This sensor represents the status of the printer. @@ -232,7 +231,7 @@ class IPPSensor(Entity): self._available = self.data.available -class MarkerSensor(Entity): +class MarkerSensor(SensorEntity): """Implementation of the MarkerSensor. This sensor represents the percentage of ink or toner. diff --git a/homeassistant/components/currencylayer/sensor.py b/homeassistant/components/currencylayer/sensor.py index 66b26eb0692..f42534f509b 100644 --- a/homeassistant/components/currencylayer/sensor.py +++ b/homeassistant/components/currencylayer/sensor.py @@ -5,7 +5,7 @@ import logging import requests import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ( ATTR_ATTRIBUTION, CONF_API_KEY, @@ -14,7 +14,6 @@ from homeassistant.const import ( CONF_QUOTE, ) import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity _LOGGER = logging.getLogger(__name__) _RESOURCE = "http://apilayer.net/api/live" @@ -55,7 +54,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities(sensors, True) -class CurrencylayerSensor(Entity): +class CurrencylayerSensor(SensorEntity): """Implementing the Currencylayer sensor.""" def __init__(self, rest, base, quote): diff --git a/homeassistant/components/sensor/__init__.py b/homeassistant/components/sensor/__init__.py index 187cb0c410d..0012b1a3aa2 100644 --- a/homeassistant/components/sensor/__init__.py +++ b/homeassistant/components/sensor/__init__.py @@ -25,6 +25,7 @@ from homeassistant.helpers.config_validation import ( # noqa: F401 PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE, ) +from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity_component import EntityComponent # mypy: allow-untyped-defs, no-check-untyped-defs @@ -74,3 +75,7 @@ async def async_setup_entry(hass, entry): async def async_unload_entry(hass, entry): """Unload a config entry.""" return await hass.data[DOMAIN].async_unload_entry(entry) + + +class SensorEntity(Entity): + """Base class for sensor entities."""