Add CONF_STATE_CLASS to `sensor/__init__.py` ()

* 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
pull/55318/head
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
tests/components/modbus

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.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 (
CONF_DEVICE_CLASS,
CONF_ENTITY_ID,
@ -730,7 +730,6 @@ class SensorSchema(KNXPlatformSchema):
CONF_ALWAYS_CALLBACK = "always_callback"
CONF_STATE_ADDRESS = CONF_STATE_ADDRESS
CONF_STATE_CLASS = "state_class"
CONF_SYNC_STATE = CONF_SYNC_STATE
DEFAULT_NAME = "KNX Sensor"

View File

@ -6,7 +6,11 @@ from typing import Any
from xknx import XKNX
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.core import HomeAssistant
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_unique_id = str(self._device.sensor_value.group_address_state)
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
def native_value(self) -> StateType:

View File

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

View File

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

View File

@ -4,7 +4,7 @@ from __future__ import annotations
import logging
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.core import HomeAssistant
from homeassistant.helpers.restore_state import RestoreEntity
@ -12,7 +12,6 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import get_hub
from .base_platform import BaseStructPlatform
from .const import CONF_STATE_CLASS
from .modbus import ModbusHub
PARALLEL_UPDATES = 1

View File

@ -9,6 +9,7 @@ import voluptuous as vol
from homeassistant.components import sensor
from homeassistant.components.sensor import (
CONF_STATE_CLASS,
DEVICE_CLASSES_SCHEMA,
STATE_CLASSES_SCHEMA,
SensorEntity,
@ -42,7 +43,6 @@ _LOGGER = logging.getLogger(__name__)
CONF_EXPIRE_AFTER = "expire_after"
CONF_LAST_RESET_TOPIC = "last_reset_topic"
CONF_LAST_RESET_VALUE_TEMPLATE = "last_reset_value_template"
CONF_STATE_CLASS = "state_class"
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.typing import ConfigType, StateType
from .const import CONF_STATE_CLASS # noqa: F401
_LOGGER: Final = logging.getLogger(__name__)
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_PICTURE = "picture"
CONF_OBJECT_ID = "object_id"
CONF_STATE_CLASS = "state_class"

View File

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

View File

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