Add CONF_STATE_CLASS to sensor/__init__.py (#54106)

* add CONF_STATE_CLASS to const.py

* move to `sensor/__init__.py`

* move to sensor/const.py

* Revert "move to sensor/const.py"

This reverts commit 604d0d066b.

* move it to `sensor/const.py` but import it from `sensor/__init__.py`

* add Modbus
This commit is contained in:
Matthias Alphart 2021-08-27 05:54:50 +02:00 committed by GitHub
parent 65d14909ee
commit cd0ae66d58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 18 additions and 12 deletions

View file

@ -18,7 +18,7 @@ from homeassistant.components.binary_sensor import (
) )
from homeassistant.components.climate.const import HVAC_MODE_HEAT, HVAC_MODES from homeassistant.components.climate.const import HVAC_MODE_HEAT, HVAC_MODES
from homeassistant.components.cover import DEVICE_CLASSES as COVER_DEVICE_CLASSES from homeassistant.components.cover import DEVICE_CLASSES as COVER_DEVICE_CLASSES
from homeassistant.components.sensor import STATE_CLASSES_SCHEMA from homeassistant.components.sensor import CONF_STATE_CLASS, STATE_CLASSES_SCHEMA
from homeassistant.const import ( from homeassistant.const import (
CONF_DEVICE_CLASS, CONF_DEVICE_CLASS,
CONF_ENTITY_ID, CONF_ENTITY_ID,
@ -730,7 +730,6 @@ class SensorSchema(KNXPlatformSchema):
CONF_ALWAYS_CALLBACK = "always_callback" CONF_ALWAYS_CALLBACK = "always_callback"
CONF_STATE_ADDRESS = CONF_STATE_ADDRESS CONF_STATE_ADDRESS = CONF_STATE_ADDRESS
CONF_STATE_CLASS = "state_class"
CONF_SYNC_STATE = CONF_SYNC_STATE CONF_SYNC_STATE = CONF_SYNC_STATE
DEFAULT_NAME = "KNX Sensor" DEFAULT_NAME = "KNX Sensor"

View file

@ -6,7 +6,11 @@ from typing import Any
from xknx import XKNX from xknx import XKNX
from xknx.devices import Sensor as XknxSensor from xknx.devices import Sensor as XknxSensor
from homeassistant.components.sensor import DEVICE_CLASSES, SensorEntity from homeassistant.components.sensor import (
CONF_STATE_CLASS,
DEVICE_CLASSES,
SensorEntity,
)
from homeassistant.const import CONF_NAME, CONF_TYPE from homeassistant.const import CONF_NAME, CONF_TYPE
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -63,7 +67,7 @@ class KNXSensor(KnxEntity, SensorEntity):
self._attr_force_update = self._device.always_callback self._attr_force_update = self._device.always_callback
self._attr_unique_id = str(self._device.sensor_value.group_address_state) self._attr_unique_id = str(self._device.sensor_value.group_address_state)
self._attr_native_unit_of_measurement = self._device.unit_of_measurement() self._attr_native_unit_of_measurement = self._device.unit_of_measurement()
self._attr_state_class = config.get(SensorSchema.CONF_STATE_CLASS) self._attr_state_class = config.get(CONF_STATE_CLASS)
@property @property
def native_value(self) -> StateType: def native_value(self) -> StateType:

View file

@ -12,6 +12,7 @@ from homeassistant.components.cover import (
DEVICE_CLASSES_SCHEMA as COVER_DEVICE_CLASSES_SCHEMA, DEVICE_CLASSES_SCHEMA as COVER_DEVICE_CLASSES_SCHEMA,
) )
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
CONF_STATE_CLASS,
DEVICE_CLASSES_SCHEMA as SENSOR_DEVICE_CLASSES_SCHEMA, DEVICE_CLASSES_SCHEMA as SENSOR_DEVICE_CLASSES_SCHEMA,
STATE_CLASSES_SCHEMA as SENSOR_STATE_CLASSES_SCHEMA, STATE_CLASSES_SCHEMA as SENSOR_STATE_CLASSES_SCHEMA,
) )
@ -76,7 +77,6 @@ from .const import (
CONF_RETRY_ON_EMPTY, CONF_RETRY_ON_EMPTY,
CONF_REVERSE_ORDER, CONF_REVERSE_ORDER,
CONF_SCALE, CONF_SCALE,
CONF_STATE_CLASS,
CONF_STATE_CLOSED, CONF_STATE_CLOSED,
CONF_STATE_CLOSING, CONF_STATE_CLOSING,
CONF_STATE_OFF, CONF_STATE_OFF,

View file

@ -41,7 +41,6 @@ CONF_RETRY_ON_EMPTY = "retry_on_empty"
CONF_REVERSE_ORDER = "reverse_order" CONF_REVERSE_ORDER = "reverse_order"
CONF_PRECISION = "precision" CONF_PRECISION = "precision"
CONF_SCALE = "scale" CONF_SCALE = "scale"
CONF_STATE_CLASS = "state_class"
CONF_STATE_CLOSED = "state_closed" CONF_STATE_CLOSED = "state_closed"
CONF_STATE_CLOSING = "state_closing" CONF_STATE_CLOSING = "state_closing"
CONF_STATE_OFF = "state_off" CONF_STATE_OFF = "state_off"

View file

@ -4,7 +4,7 @@ from __future__ import annotations
import logging import logging
from typing import Any from typing import Any
from homeassistant.components.sensor import SensorEntity from homeassistant.components.sensor import CONF_STATE_CLASS, SensorEntity
from homeassistant.const import CONF_NAME, CONF_SENSORS, CONF_UNIT_OF_MEASUREMENT from homeassistant.const import CONF_NAME, CONF_SENSORS, CONF_UNIT_OF_MEASUREMENT
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.restore_state import RestoreEntity
@ -12,7 +12,6 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import get_hub from . import get_hub
from .base_platform import BaseStructPlatform from .base_platform import BaseStructPlatform
from .const import CONF_STATE_CLASS
from .modbus import ModbusHub from .modbus import ModbusHub
PARALLEL_UPDATES = 1 PARALLEL_UPDATES = 1

View file

@ -9,6 +9,7 @@ import voluptuous as vol
from homeassistant.components import sensor from homeassistant.components import sensor
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
CONF_STATE_CLASS,
DEVICE_CLASSES_SCHEMA, DEVICE_CLASSES_SCHEMA,
STATE_CLASSES_SCHEMA, STATE_CLASSES_SCHEMA,
SensorEntity, SensorEntity,
@ -42,7 +43,6 @@ _LOGGER = logging.getLogger(__name__)
CONF_EXPIRE_AFTER = "expire_after" CONF_EXPIRE_AFTER = "expire_after"
CONF_LAST_RESET_TOPIC = "last_reset_topic" CONF_LAST_RESET_TOPIC = "last_reset_topic"
CONF_LAST_RESET_VALUE_TEMPLATE = "last_reset_value_template" CONF_LAST_RESET_VALUE_TEMPLATE = "last_reset_value_template"
CONF_STATE_CLASS = "state_class"
MQTT_SENSOR_ATTRIBUTES_BLOCKED = frozenset( MQTT_SENSOR_ATTRIBUTES_BLOCKED = frozenset(
{ {

View file

@ -51,6 +51,8 @@ from homeassistant.helpers.entity import Entity, EntityDescription
from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.typing import ConfigType, StateType from homeassistant.helpers.typing import ConfigType, StateType
from .const import CONF_STATE_CLASS # noqa: F401
_LOGGER: Final = logging.getLogger(__name__) _LOGGER: Final = logging.getLogger(__name__)
ATTR_LAST_RESET: Final = "last_reset" # Deprecated, to be removed in 2021.11 ATTR_LAST_RESET: Final = "last_reset" # Deprecated, to be removed in 2021.11

View file

@ -0,0 +1,4 @@
"""Constants for sensor."""
from typing import Final
CONF_STATE_CLASS: Final = "state_class"

View file

@ -27,4 +27,3 @@ CONF_AVAILABILITY = "availability"
CONF_ATTRIBUTES = "attributes" CONF_ATTRIBUTES = "attributes"
CONF_PICTURE = "picture" CONF_PICTURE = "picture"
CONF_OBJECT_ID = "object_id" CONF_OBJECT_ID = "object_id"
CONF_STATE_CLASS = "state_class"

View file

@ -4,6 +4,7 @@ from __future__ import annotations
import voluptuous as vol import voluptuous as vol
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
CONF_STATE_CLASS,
DEVICE_CLASSES_SCHEMA, DEVICE_CLASSES_SCHEMA,
DOMAIN as SENSOR_DOMAIN, DOMAIN as SENSOR_DOMAIN,
ENTITY_ID_FORMAT, ENTITY_ID_FORMAT,
@ -38,7 +39,6 @@ from .const import (
CONF_AVAILABILITY_TEMPLATE, CONF_AVAILABILITY_TEMPLATE,
CONF_OBJECT_ID, CONF_OBJECT_ID,
CONF_PICTURE, CONF_PICTURE,
CONF_STATE_CLASS,
CONF_TRIGGER, CONF_TRIGGER,
) )
from .template_entity import TemplateEntity from .template_entity import TemplateEntity

View file

@ -9,7 +9,6 @@ from homeassistant.components.modbus.const import (
CONF_LAZY_ERROR, CONF_LAZY_ERROR,
CONF_PRECISION, CONF_PRECISION,
CONF_SCALE, CONF_SCALE,
CONF_STATE_CLASS,
CONF_SWAP, CONF_SWAP,
CONF_SWAP_BYTE, CONF_SWAP_BYTE,
CONF_SWAP_NONE, CONF_SWAP_NONE,
@ -22,6 +21,7 @@ from homeassistant.components.modbus.const import (
DATA_TYPE_UINT, DATA_TYPE_UINT,
) )
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
CONF_STATE_CLASS,
DOMAIN as SENSOR_DOMAIN, DOMAIN as SENSOR_DOMAIN,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
) )