Migrate integrations w-z to extend SensorEntity (#48217)

This commit is contained in:
Erik Montnemery 2021-03-22 19:50:29 +01:00 committed by GitHub
parent 783b453bbe
commit 0c086b5067
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 72 additions and 79 deletions

View file

@ -7,6 +7,7 @@ import aiohttp
import voluptuous as vol import voluptuous as vol
from waqiasync import WaqiClient from waqiasync import WaqiClient
from homeassistant.components.sensor import SensorEntity
from homeassistant.const import ( from homeassistant.const import (
ATTR_ATTRIBUTION, ATTR_ATTRIBUTION,
ATTR_TEMPERATURE, ATTR_TEMPERATURE,
@ -17,7 +18,6 @@ from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA from homeassistant.helpers.config_validation import PLATFORM_SCHEMA
from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -93,7 +93,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
async_add_entities(dev, True) async_add_entities(dev, True)
class WaqiSensor(Entity): class WaqiSensor(SensorEntity):
"""Implementation of a WAQI sensor.""" """Implementation of a WAQI sensor."""
def __init__(self, client, station): def __init__(self, client, station):

View file

@ -1,9 +1,8 @@
"""Support for Waterfurnace.""" """Support for Waterfurnace."""
from homeassistant.components.sensor import ENTITY_ID_FORMAT from homeassistant.components.sensor import ENTITY_ID_FORMAT, SensorEntity
from homeassistant.const import PERCENTAGE, POWER_WATT, TEMP_FAHRENHEIT from homeassistant.const import PERCENTAGE, POWER_WATT, TEMP_FAHRENHEIT
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers.entity import Entity
from homeassistant.util import slugify from homeassistant.util import slugify
from . import DOMAIN as WF_DOMAIN, UPDATE_TOPIC from . import DOMAIN as WF_DOMAIN, UPDATE_TOPIC
@ -61,7 +60,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities(sensors) add_entities(sensors)
class WaterFurnaceSensor(Entity): class WaterFurnaceSensor(SensorEntity):
"""Implementing the Waterfurnace sensor.""" """Implementing the Waterfurnace sensor."""
def __init__(self, client, config): def __init__(self, client, config):

View file

@ -6,7 +6,7 @@ import re
import WazeRouteCalculator import WazeRouteCalculator
import voluptuous as vol import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import ( from homeassistant.const import (
ATTR_ATTRIBUTION, ATTR_ATTRIBUTION,
ATTR_LATITUDE, ATTR_LATITUDE,
@ -20,7 +20,6 @@ from homeassistant.const import (
) )
from homeassistant.helpers import location from homeassistant.helpers import location
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -126,7 +125,7 @@ def _get_location_from_attributes(state):
return "{},{}".format(attr.get(ATTR_LATITUDE), attr.get(ATTR_LONGITUDE)) return "{},{}".format(attr.get(ATTR_LATITUDE), attr.get(ATTR_LONGITUDE))
class WazeTravelTime(Entity): class WazeTravelTime(SensorEntity):
"""Representation of a Waze travel time sensor.""" """Representation of a Waze travel time sensor."""
def __init__(self, name, origin, destination, waze_data): def __init__(self, name, origin, destination, waze_data):

View file

@ -1,7 +1,7 @@
"""Entity to track connections to websocket API.""" """Entity to track connections to websocket API."""
from homeassistant.components.sensor import SensorEntity
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers.entity import Entity
from .const import ( from .const import (
DATA_CONNECTIONS, DATA_CONNECTIONS,
@ -19,7 +19,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
async_add_entities([entity]) async_add_entities([entity])
class APICount(Entity): class APICount(SensorEntity):
"""Entity to represent how many people are connected to the stream API.""" """Entity to represent how many people are connected to the stream API."""
def __init__(self): def __init__(self):

View file

@ -5,10 +5,9 @@ import logging
import voluptuous as vol import voluptuous as vol
import whois import whois
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import CONF_DOMAIN, CONF_NAME, TIME_DAYS from homeassistant.const import CONF_DOMAIN, CONF_NAME, TIME_DAYS
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -47,7 +46,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
return return
class WhoisSensor(Entity): class WhoisSensor(SensorEntity):
"""Implementation of a WHOIS sensor.""" """Implementation of a WHOIS sensor."""
def __init__(self, name, domain): def __init__(self, name, domain):

View file

@ -5,6 +5,7 @@ from homeassistant.components.sensor import (
DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_PRESSURE, DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
SensorEntity,
) )
from homeassistant.const import DEGREE, PRESSURE_MBAR, TEMP_CELSIUS from homeassistant.const import DEGREE, PRESSURE_MBAR, TEMP_CELSIUS
from homeassistant.core import callback from homeassistant.core import callback
@ -58,7 +59,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async_dispatcher_connect(hass, CREATE_ENTITY_SIGNAL, _create_entity) async_dispatcher_connect(hass, CREATE_ENTITY_SIGNAL, _create_entity)
class NumberEntity(WiffiEntity): class NumberEntity(WiffiEntity, SensorEntity):
"""Entity for wiffi metrics which have a number value.""" """Entity for wiffi metrics which have a number value."""
def __init__(self, device, metric, options): def __init__(self, device, metric, options):
@ -100,7 +101,7 @@ class NumberEntity(WiffiEntity):
self.async_write_ha_state() self.async_write_ha_state()
class StringEntity(WiffiEntity): class StringEntity(WiffiEntity, SensorEntity):
"""Entity for wiffi metrics which have a string value.""" """Entity for wiffi metrics which have a string value."""
def __init__(self, device, metric, options): def __init__(self, device, metric, options):

View file

@ -3,6 +3,7 @@ import logging
import pywink import pywink
from homeassistant.components.sensor import SensorEntity
from homeassistant.const import DEGREE, TEMP_CELSIUS from homeassistant.const import DEGREE, TEMP_CELSIUS
from . import DOMAIN, WinkDevice from . import DOMAIN, WinkDevice
@ -19,29 +20,29 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
_id = sensor.object_id() + sensor.name() _id = sensor.object_id() + sensor.name()
if _id not in hass.data[DOMAIN]["unique_ids"]: if _id not in hass.data[DOMAIN]["unique_ids"]:
if sensor.capability() in SENSOR_TYPES: if sensor.capability() in SENSOR_TYPES:
add_entities([WinkSensorDevice(sensor, hass)]) add_entities([WinkSensorEntity(sensor, hass)])
for eggtray in pywink.get_eggtrays(): for eggtray in pywink.get_eggtrays():
_id = eggtray.object_id() + eggtray.name() _id = eggtray.object_id() + eggtray.name()
if _id not in hass.data[DOMAIN]["unique_ids"]: if _id not in hass.data[DOMAIN]["unique_ids"]:
add_entities([WinkSensorDevice(eggtray, hass)]) add_entities([WinkSensorEntity(eggtray, hass)])
for tank in pywink.get_propane_tanks(): for tank in pywink.get_propane_tanks():
_id = tank.object_id() + tank.name() _id = tank.object_id() + tank.name()
if _id not in hass.data[DOMAIN]["unique_ids"]: if _id not in hass.data[DOMAIN]["unique_ids"]:
add_entities([WinkSensorDevice(tank, hass)]) add_entities([WinkSensorEntity(tank, hass)])
for piggy_bank in pywink.get_piggy_banks(): for piggy_bank in pywink.get_piggy_banks():
_id = piggy_bank.object_id() + piggy_bank.name() _id = piggy_bank.object_id() + piggy_bank.name()
if _id not in hass.data[DOMAIN]["unique_ids"]: if _id not in hass.data[DOMAIN]["unique_ids"]:
try: try:
if piggy_bank.capability() in SENSOR_TYPES: if piggy_bank.capability() in SENSOR_TYPES:
add_entities([WinkSensorDevice(piggy_bank, hass)]) add_entities([WinkSensorEntity(piggy_bank, hass)])
except AttributeError: except AttributeError:
_LOGGER.info("Device is not a sensor") _LOGGER.info("Device is not a sensor")
class WinkSensorDevice(WinkDevice): class WinkSensorEntity(WinkDevice, SensorEntity):
"""Representation of a Wink sensor.""" """Representation of a Wink sensor."""
def __init__(self, wink, hass): def __init__(self, wink, hass):

View file

@ -3,7 +3,7 @@ import logging
import voluptuous as vol 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 from homeassistant.const import CONF_MONITORED_CONDITIONS
from homeassistant.core import callback from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
@ -44,7 +44,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities(sensors, True) add_entities(sensors, True)
class WirelessTagSensor(WirelessTagBaseSensor): class WirelessTagSensor(WirelessTagBaseSensor, SensorEntity):
"""Representation of a Sensor.""" """Representation of a Sensor."""
def __init__(self, api, tag, sensor_type, config): def __init__(self, api, tag, sensor_type, config):

View file

@ -3,7 +3,7 @@ from __future__ import annotations
from typing import Callable from typing import Callable
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN, SensorEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
@ -28,7 +28,7 @@ async def async_setup_entry(
async_add_entities(entities, True) async_add_entities(entities, True)
class WithingsHealthSensor(BaseWithingsSensor): class WithingsHealthSensor(BaseWithingsSensor, SensorEntity):
"""Implementation of a Withings sensor.""" """Implementation of a Withings sensor."""
@property @property

View file

@ -4,7 +4,7 @@ from __future__ import annotations
from datetime import timedelta from datetime import timedelta
from typing import Any, Callable from typing import Any, Callable
from homeassistant.components.sensor import DEVICE_CLASS_CURRENT from homeassistant.components.sensor import DEVICE_CLASS_CURRENT, SensorEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
DATA_BYTES, DATA_BYTES,
@ -42,7 +42,7 @@ async def async_setup_entry(
async_add_entities(sensors, True) async_add_entities(sensors, True)
class WLEDSensor(WLEDDeviceEntity): class WLEDSensor(WLEDDeviceEntity, SensorEntity):
"""Defines a WLED sensor.""" """Defines a WLED sensor."""
def __init__( def __init__(

View file

@ -9,6 +9,7 @@ from wolf_smartset.models import (
Temperature, Temperature,
) )
from homeassistant.components.sensor import SensorEntity
from homeassistant.const import ( from homeassistant.const import (
DEVICE_CLASS_PRESSURE, DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
@ -46,7 +47,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async_add_entities(entities, True) async_add_entities(entities, True)
class WolfLinkSensor(CoordinatorEntity): class WolfLinkSensor(CoordinatorEntity, SensorEntity):
"""Base class for all Wolf entities.""" """Base class for all Wolf entities."""
def __init__(self, coordinator, wolf_object: Parameter, device_id): def __init__(self, coordinator, wolf_object: Parameter, device_id):

View file

@ -1,10 +1,9 @@
"""Support for showing the time in a different time zone.""" """Support for showing the time in a different time zone."""
import voluptuous as vol 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_TIME_ZONE from homeassistant.const import CONF_NAME, CONF_TIME_ZONE
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
CONF_TIME_FORMAT = "time_format" CONF_TIME_FORMAT = "time_format"
@ -39,7 +38,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
) )
class WorldClockSensor(Entity): class WorldClockSensor(SensorEntity):
"""Representation of a World clock sensor.""" """Representation of a World clock sensor."""
def __init__(self, time_zone, name, time_format): def __init__(self, time_zone, name, time_format):

View file

@ -6,7 +6,7 @@ import time
import requests import requests
import voluptuous as vol import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import ( from homeassistant.const import (
ATTR_ATTRIBUTION, ATTR_ATTRIBUTION,
CONF_API_KEY, CONF_API_KEY,
@ -15,7 +15,6 @@ from homeassistant.const import (
CONF_NAME, CONF_NAME,
) )
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -55,7 +54,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities([tides]) add_entities([tides])
class WorldTidesInfoSensor(Entity): class WorldTidesInfoSensor(SensorEntity):
"""Representation of a WorldTidesInfo sensor.""" """Representation of a WorldTidesInfo sensor."""
def __init__(self, name, lat, lon, key): def __init__(self, name, lat, lon, key):

View file

@ -6,11 +6,10 @@ import aiohttp
import async_timeout import async_timeout
import voluptuous as vol 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_PIN, CONF_TIMEOUT, PERCENTAGE from homeassistant.const import CONF_HOST, CONF_PIN, CONF_TIMEOUT, PERCENTAGE
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -50,7 +49,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
async_add_entities([WorxLandroidSensor(typ, config)]) async_add_entities([WorxLandroidSensor(typ, config)])
class WorxLandroidSensor(Entity): class WorxLandroidSensor(SensorEntity):
"""Implementation of a Worx Landroid sensor.""" """Implementation of a Worx Landroid sensor."""
def __init__(self, sensor, config): def __init__(self, sensor, config):

View file

@ -6,7 +6,7 @@ import re
import requests import requests
import voluptuous as vol import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import ( from homeassistant.const import (
ATTR_ATTRIBUTION, ATTR_ATTRIBUTION,
ATTR_NAME, ATTR_NAME,
@ -17,7 +17,6 @@ from homeassistant.const import (
TIME_MINUTES, TIME_MINUTES,
) )
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -65,7 +64,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities(sensors, True) add_entities(sensors, True)
class WashingtonStateTransportSensor(Entity): class WashingtonStateTransportSensor(SensorEntity):
""" """
Sensor that reads the WSDOT web API. Sensor that reads the WSDOT web API.

View file

@ -12,7 +12,7 @@ import async_timeout
import voluptuous as vol import voluptuous as vol
from homeassistant.components import sensor from homeassistant.components import sensor
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import ( from homeassistant.const import (
ATTR_ATTRIBUTION, ATTR_ATTRIBUTION,
CONF_API_KEY, CONF_API_KEY,
@ -36,7 +36,6 @@ from homeassistant.const import (
from homeassistant.exceptions import PlatformNotReady from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.typing import ConfigType, HomeAssistantType from homeassistant.helpers.typing import ConfigType, HomeAssistantType
from homeassistant.util import Throttle from homeassistant.util import Throttle
@ -1117,7 +1116,7 @@ async def async_setup_platform(
async_add_entities(sensors, True) async_add_entities(sensors, True)
class WUndergroundSensor(Entity): class WUndergroundSensor(SensorEntity):
"""Implementing the WUnderground sensor.""" """Implementing the WUnderground sensor."""
def __init__(self, hass: HomeAssistantType, rest, condition, unique_id_base: str): def __init__(self, hass: HomeAssistantType, rest, condition, unique_id_base: str):

View file

@ -5,8 +5,8 @@ import logging
import voluptuous as vol import voluptuous as vol
from xbee_helper.exceptions import ZigBeeException, ZigBeeTxFailure from xbee_helper.exceptions import ZigBeeException, ZigBeeTxFailure
from homeassistant.components.sensor import SensorEntity
from homeassistant.const import CONF_TYPE, TEMP_CELSIUS from homeassistant.const import CONF_TYPE, TEMP_CELSIUS
from homeassistant.helpers.entity import Entity
from . import DOMAIN, PLATFORM_SCHEMA, XBeeAnalogIn, XBeeAnalogInConfig, XBeeConfig from . import DOMAIN, PLATFORM_SCHEMA, XBeeAnalogIn, XBeeAnalogInConfig, XBeeConfig
@ -43,7 +43,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities([sensor_class(config_class(config), zigbee_device)], True) add_entities([sensor_class(config_class(config), zigbee_device)], True)
class XBeeTemperatureSensor(Entity): class XBeeTemperatureSensor(SensorEntity):
"""Representation of XBee Pro temperature sensor.""" """Representation of XBee Pro temperature sensor."""
def __init__(self, config, device): def __init__(self, config, device):

View file

@ -3,6 +3,7 @@ from __future__ import annotations
from functools import partial from functools import partial
from homeassistant.components.sensor import SensorEntity
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers.entity_registry import ( from homeassistant.helpers.entity_registry import (
async_get_registry as async_get_entity_registry, async_get_registry as async_get_entity_registry,
@ -29,7 +30,7 @@ async def async_setup_entry(hass: HomeAssistantType, config_entry, async_add_ent
update_friends() update_friends()
class XboxSensorEntity(XboxBaseSensorEntity): class XboxSensorEntity(XboxBaseSensorEntity, SensorEntity):
"""Representation of a Xbox presence state.""" """Representation of a Xbox presence state."""
@property @property

View file

@ -5,11 +5,10 @@ import logging
import voluptuous as vol import voluptuous as vol
from xboxapi import Client from xboxapi import Client
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import CONF_API_KEY, CONF_SCAN_INTERVAL from homeassistant.const import CONF_API_KEY, CONF_SCAN_INTERVAL
from homeassistant.core import callback from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.event import async_track_time_interval
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -73,7 +72,7 @@ def get_user_gamercard(api, xuid):
return None return None
class XboxSensor(Entity): class XboxSensor(SensorEntity):
"""A class for the Xbox account.""" """A class for the Xbox account."""
def __init__(self, api, xuid, gamercard, interval): def __init__(self, api, xuid, gamercard, interval):

View file

@ -1,6 +1,7 @@
"""Support for Xiaomi Aqara sensors.""" """Support for Xiaomi Aqara sensors."""
import logging import logging
from homeassistant.components.sensor import SensorEntity
from homeassistant.const import ( from homeassistant.const import (
ATTR_BATTERY_LEVEL, ATTR_BATTERY_LEVEL,
DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY,
@ -107,7 +108,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async_add_entities(entities) async_add_entities(entities)
class XiaomiSensor(XiaomiDevice): class XiaomiSensor(XiaomiDevice, SensorEntity):
"""Representation of a XiaomiSensor.""" """Representation of a XiaomiSensor."""
def __init__(self, device, name, data_key, xiaomi_hub, config_entry): def __init__(self, device, name, data_key, xiaomi_hub, config_entry):
@ -171,7 +172,7 @@ class XiaomiSensor(XiaomiDevice):
return True return True
class XiaomiBatterySensor(XiaomiDevice): class XiaomiBatterySensor(XiaomiDevice, SensorEntity):
"""Representation of a XiaomiSensor.""" """Representation of a XiaomiSensor."""
@property @property

View file

@ -12,7 +12,7 @@ from miio.gateway.gateway import (
) )
import voluptuous as vol 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.config_entries import SOURCE_IMPORT
from homeassistant.const import ( from homeassistant.const import (
ATTR_BATTERY_LEVEL, ATTR_BATTERY_LEVEL,
@ -30,7 +30,6 @@ from homeassistant.const import (
TEMP_CELSIUS, TEMP_CELSIUS,
) )
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
from .const import CONF_DEVICE, CONF_FLOW_TYPE, CONF_GATEWAY, DOMAIN, KEY_COORDINATOR from .const import CONF_DEVICE, CONF_FLOW_TYPE, CONF_GATEWAY, DOMAIN, KEY_COORDINATOR
from .device import XiaomiMiioEntity from .device import XiaomiMiioEntity
@ -147,7 +146,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async_add_entities(entities, update_before_add=True) async_add_entities(entities, update_before_add=True)
class XiaomiAirQualityMonitor(XiaomiMiioEntity): class XiaomiAirQualityMonitor(XiaomiMiioEntity, SensorEntity):
"""Representation of a Xiaomi Air Quality Monitor.""" """Representation of a Xiaomi Air Quality Monitor."""
def __init__(self, name, device, entry, unique_id): def __init__(self, name, device, entry, unique_id):
@ -221,7 +220,7 @@ class XiaomiAirQualityMonitor(XiaomiMiioEntity):
_LOGGER.error("Got exception while fetching the state: %s", ex) _LOGGER.error("Got exception while fetching the state: %s", ex)
class XiaomiGatewaySensor(XiaomiGatewayDevice): class XiaomiGatewaySensor(XiaomiGatewayDevice, SensorEntity):
"""Representation of a XiaomiGatewaySensor.""" """Representation of a XiaomiGatewaySensor."""
def __init__(self, coordinator, sub_device, entry, data_key): def __init__(self, coordinator, sub_device, entry, data_key):
@ -252,7 +251,7 @@ class XiaomiGatewaySensor(XiaomiGatewayDevice):
return self._sub_device.status[self._data_key] return self._sub_device.status[self._data_key]
class XiaomiGatewayIlluminanceSensor(Entity): class XiaomiGatewayIlluminanceSensor(SensorEntity):
"""Representation of the gateway device's illuminance sensor.""" """Representation of the gateway device's illuminance sensor."""
def __init__(self, gateway_device, gateway_name, gateway_device_id): def __init__(self, gateway_device, gateway_name, gateway_device_id):

View file

@ -1,7 +1,7 @@
"""Support for XS1 sensors.""" """Support for XS1 sensors."""
from xs1_api_client.api_constants import ActuatorType from xs1_api_client.api_constants import ActuatorType
from homeassistant.helpers.entity import Entity from homeassistant.components.sensor import SensorEntity
from . import ACTUATORS, DOMAIN as COMPONENT_DOMAIN, SENSORS, XS1DeviceEntity from . import ACTUATORS, DOMAIN as COMPONENT_DOMAIN, SENSORS, XS1DeviceEntity
@ -28,7 +28,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities(sensor_entities) add_entities(sensor_entities)
class XS1Sensor(XS1DeviceEntity, Entity): class XS1Sensor(XS1DeviceEntity, SensorEntity):
"""Representation of a Sensor.""" """Representation of a Sensor."""
@property @property

View file

@ -6,11 +6,10 @@ import logging
from aioymaps import YandexMapsRequester from aioymaps import YandexMapsRequester
import voluptuous as vol 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, DEVICE_CLASS_TIMESTAMP from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME, DEVICE_CLASS_TIMESTAMP
from homeassistant.helpers.aiohttp_client import async_create_clientsession from homeassistant.helpers.aiohttp_client import async_create_clientsession
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -47,7 +46,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
async_add_entities([DiscoverYandexTransport(data, stop_id, routes, name)], True) async_add_entities([DiscoverYandexTransport(data, stop_id, routes, name)], True)
class DiscoverYandexTransport(Entity): class DiscoverYandexTransport(SensorEntity):
"""Implementation of yandex_transport sensor.""" """Implementation of yandex_transport sensor."""
def __init__(self, requester: YandexMapsRequester, stop_id, routes, name): def __init__(self, requester: YandexMapsRequester, stop_id, routes, name):

View file

@ -4,10 +4,9 @@ import logging
import voluptuous as vol import voluptuous as vol
from homeassistant.components import zabbix from homeassistant.components import zabbix
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import CONF_NAME from homeassistant.const import CONF_NAME
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -79,7 +78,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities(sensors) add_entities(sensors)
class ZabbixTriggerCountSensor(Entity): class ZabbixTriggerCountSensor(SensorEntity):
"""Get the active trigger count for all Zabbix monitored hosts.""" """Get the active trigger count for all Zabbix monitored hosts."""
def __init__(self, zApi, name="Zabbix"): def __init__(self, zApi, name="Zabbix"):

View file

@ -11,6 +11,7 @@ import pytz
import requests import requests
import voluptuous as vol import voluptuous as vol
from homeassistant.components.sensor import SensorEntity
from homeassistant.const import ( from homeassistant.const import (
AREA_SQUARE_METERS, AREA_SQUARE_METERS,
ATTR_ATTRIBUTION, ATTR_ATTRIBUTION,
@ -27,7 +28,6 @@ from homeassistant.const import (
__version__, __version__,
) )
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle from homeassistant.util import Throttle
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -132,7 +132,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
) )
class ZamgSensor(Entity): class ZamgSensor(SensorEntity):
"""Implementation of a ZAMG sensor.""" """Implementation of a ZAMG sensor."""
def __init__(self, probe, variable, name): def __init__(self, probe, variable, name):

View file

@ -6,10 +6,9 @@ import requests
import voluptuous as vol import voluptuous as vol
import xmltodict import xmltodict
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 from homeassistant.const import ATTR_ATTRIBUTION, CONF_API_KEY, CONF_NAME
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
_RESOURCE = "http://www.zillow.com/webservice/GetZestimate.htm" _RESOURCE = "http://www.zillow.com/webservice/GetZestimate.htm"
@ -56,7 +55,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities(sensors, True) add_entities(sensors, True)
class ZestimateDataSensor(Entity): class ZestimateDataSensor(SensorEntity):
"""Implementation of a Zestimate sensor.""" """Implementation of a Zestimate sensor."""
def __init__(self, name, params): def __init__(self, name, params):

View file

@ -15,6 +15,7 @@ from homeassistant.components.sensor import (
DEVICE_CLASS_PRESSURE, DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
DOMAIN, DOMAIN,
SensorEntity,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
@ -89,7 +90,7 @@ async def async_setup_entry(
hass.data[DATA_ZHA][DATA_ZHA_DISPATCHERS].append(unsub) hass.data[DATA_ZHA][DATA_ZHA_DISPATCHERS].append(unsub)
class Sensor(ZhaEntity): class Sensor(ZhaEntity, SensorEntity):
"""Base ZHA sensor.""" """Base ZHA sensor."""
SENSOR_ATTR: int | str | None = None SENSOR_ATTR: int | str | None = None

View file

@ -1,5 +1,5 @@
"""Support for tracking the zodiac sign.""" """Support for tracking the zodiac sign."""
from homeassistant.helpers.entity import Entity from homeassistant.components.sensor import SensorEntity
from homeassistant.util.dt import as_local, utcnow from homeassistant.util.dt import as_local, utcnow
from .const import ( from .const import (
@ -162,7 +162,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
async_add_entities([ZodiacSensor()], True) async_add_entities([ZodiacSensor()], True)
class ZodiacSensor(Entity): class ZodiacSensor(SensorEntity):
"""Representation of a Zodiac sensor.""" """Representation of a Zodiac sensor."""
def __init__(self): def __init__(self):

View file

@ -4,10 +4,9 @@ import logging
import voluptuous as vol import voluptuous as vol
from zoneminder.monitor import TimePeriod from zoneminder.monitor import TimePeriod
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import CONF_MONITORED_CONDITIONS from homeassistant.const import CONF_MONITORED_CONDITIONS
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
from . import DOMAIN as ZONEMINDER_DOMAIN from . import DOMAIN as ZONEMINDER_DOMAIN
@ -57,7 +56,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities(sensors) add_entities(sensors)
class ZMSensorMonitors(Entity): class ZMSensorMonitors(SensorEntity):
"""Get the status of each ZoneMinder monitor.""" """Get the status of each ZoneMinder monitor."""
def __init__(self, monitor): def __init__(self, monitor):
@ -91,7 +90,7 @@ class ZMSensorMonitors(Entity):
self._is_available = self._monitor.is_available self._is_available = self._monitor.is_available
class ZMSensorEvents(Entity): class ZMSensorEvents(SensorEntity):
"""Get the number of events for each monitor.""" """Get the number of events for each monitor."""
def __init__(self, monitor, include_archived, sensor_type): def __init__(self, monitor, include_archived, sensor_type):
@ -122,7 +121,7 @@ class ZMSensorEvents(Entity):
self._state = self._monitor.get_events(self.time_period, self._include_archived) self._state = self._monitor.get_events(self.time_period, self._include_archived)
class ZMSensorRunState(Entity): class ZMSensorRunState(SensorEntity):
"""Get the ZoneMinder run state.""" """Get the ZoneMinder run state."""
def __init__(self, client): def __init__(self, client):

View file

@ -1,5 +1,5 @@
"""Support for Z-Wave sensors.""" """Support for Z-Wave sensors."""
from homeassistant.components.sensor import DEVICE_CLASS_BATTERY, DOMAIN from homeassistant.components.sensor import DEVICE_CLASS_BATTERY, DOMAIN, SensorEntity
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT
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
@ -37,7 +37,7 @@ def get_device(node, values, **kwargs):
return None return None
class ZWaveSensor(ZWaveDeviceEntity): class ZWaveSensor(ZWaveDeviceEntity, SensorEntity):
"""Representation of a Z-Wave sensor.""" """Representation of a Z-Wave sensor."""
def __init__(self, values): def __init__(self, values):

View file

@ -13,6 +13,7 @@ from homeassistant.components.sensor import (
DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_POWER, DEVICE_CLASS_POWER,
DOMAIN as SENSOR_DOMAIN, DOMAIN as SENSOR_DOMAIN,
SensorEntity,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
@ -67,7 +68,7 @@ async def async_setup_entry(
) )
class ZwaveSensorBase(ZWaveBaseEntity): class ZwaveSensorBase(ZWaveBaseEntity, SensorEntity):
"""Basic Representation of a Z-Wave sensor.""" """Basic Representation of a Z-Wave sensor."""
def __init__( def __init__(