Add support for Sensor state class (#1835)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Franck Nijhof 2021-06-03 03:49:56 +02:00 committed by GitHub
parent 913ac8b7e8
commit 11fb54c74e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
112 changed files with 1237 additions and 269 deletions

View file

@ -8,6 +8,7 @@ from esphome.const import (
CONF_PIN, CONF_PIN,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_VOLT, UNIT_VOLT,
) )
@ -35,7 +36,9 @@ ADCSensor = adc_ns.class_(
) )
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_VOLT, ICON_EMPTY, 2, DEVICE_CLASS_VOLTAGE) sensor.sensor_schema(
UNIT_VOLT, ICON_EMPTY, 2, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(ADCSensor), cv.GenerateID(): cv.declare_id(ADCSensor),

View file

@ -9,6 +9,7 @@ from esphome.const import (
DEVICE_CLASS_POWER, DEVICE_CLASS_POWER,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_VOLT, UNIT_VOLT,
UNIT_AMPERE, UNIT_AMPERE,
UNIT_WATT, UNIT_WATT,
@ -31,19 +32,27 @@ CONFIG_SCHEMA = (
cv.GenerateID(): cv.declare_id(ADE7953), cv.GenerateID(): cv.declare_id(ADE7953),
cv.Optional(CONF_IRQ_PIN): pins.input_pin, cv.Optional(CONF_IRQ_PIN): pins.input_pin,
cv.Optional(CONF_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_VOLTAGE): sensor.sensor_schema(
UNIT_VOLT, ICON_EMPTY, 1, DEVICE_CLASS_VOLTAGE UNIT_VOLT, ICON_EMPTY, 1, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_CURRENT_A): sensor.sensor_schema( cv.Optional(CONF_CURRENT_A): sensor.sensor_schema(
UNIT_AMPERE, ICON_EMPTY, 2, DEVICE_CLASS_CURRENT UNIT_AMPERE,
ICON_EMPTY,
2,
DEVICE_CLASS_CURRENT,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_CURRENT_B): sensor.sensor_schema( cv.Optional(CONF_CURRENT_B): sensor.sensor_schema(
UNIT_AMPERE, ICON_EMPTY, 2, DEVICE_CLASS_CURRENT UNIT_AMPERE,
ICON_EMPTY,
2,
DEVICE_CLASS_CURRENT,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_ACTIVE_POWER_A): sensor.sensor_schema( cv.Optional(CONF_ACTIVE_POWER_A): sensor.sensor_schema(
UNIT_WATT, ICON_EMPTY, 1, DEVICE_CLASS_POWER UNIT_WATT, ICON_EMPTY, 1, DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_ACTIVE_POWER_B): sensor.sensor_schema( cv.Optional(CONF_ACTIVE_POWER_B): sensor.sensor_schema(
UNIT_WATT, ICON_EMPTY, 1, DEVICE_CLASS_POWER UNIT_WATT, ICON_EMPTY, 1, DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT
), ),
} }
) )

View file

@ -6,6 +6,7 @@ from esphome.const import (
CONF_MULTIPLEXER, CONF_MULTIPLEXER,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_VOLT, UNIT_VOLT,
CONF_ID, CONF_ID,
) )
@ -51,7 +52,9 @@ ADS1115Sensor = ads1115_ns.class_(
CONF_ADS1115_ID = "ads1115_id" CONF_ADS1115_ID = "ads1115_id"
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_VOLT, ICON_EMPTY, 3, DEVICE_CLASS_VOLTAGE) sensor.sensor_schema(
UNIT_VOLT, ICON_EMPTY, 3, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(ADS1115Sensor), cv.GenerateID(): cv.declare_id(ADS1115Sensor),

View file

@ -8,6 +8,7 @@ from esphome.const import (
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
) )
@ -22,10 +23,18 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(AHT10Component), cv.GenerateID(): cv.declare_id(AHT10Component),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 2, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
2,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 2, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
2,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -7,6 +7,7 @@ from esphome.const import (
CONF_TEMPERATURE, CONF_TEMPERATURE,
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
ICON_EMPTY, ICON_EMPTY,
UNIT_PERCENT, UNIT_PERCENT,
@ -24,10 +25,18 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(AM2320Component), cv.GenerateID(): cv.declare_id(AM2320Component),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 1, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
1,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -1,7 +1,13 @@
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.components import sensor from esphome.components import sensor
from esphome.const import CONF_TYPE, DEVICE_CLASS_EMPTY, UNIT_PERCENT, ICON_LIGHTBULB from esphome.const import (
CONF_TYPE,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_PERCENT,
ICON_LIGHTBULB,
)
from . import APDS9960, CONF_APDS9960_ID from . import APDS9960, CONF_APDS9960_ID
DEPENDENCIES = ["apds9960"] DEPENDENCIES = ["apds9960"]
@ -15,7 +21,7 @@ TYPES = {
} }
CONFIG_SCHEMA = sensor.sensor_schema( CONFIG_SCHEMA = sensor.sensor_schema(
UNIT_PERCENT, ICON_LIGHTBULB, 1, DEVICE_CLASS_EMPTY UNIT_PERCENT, ICON_LIGHTBULB, 1, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT
).extend( ).extend(
{ {
cv.Required(CONF_TYPE): cv.one_of(*TYPES, upper=True), cv.Required(CONF_TYPE): cv.one_of(*TYPES, upper=True),

View file

@ -409,6 +409,11 @@ message LightCommandRequest {
} }
// ==================== SENSOR ==================== // ==================== SENSOR ====================
enum SensorStateClass {
STATE_CLASS_NONE = 0;
STATE_CLASS_MEASUREMENT = 1;
}
message ListEntitiesSensorResponse { message ListEntitiesSensorResponse {
option (id) = 16; option (id) = 16;
option (source) = SOURCE_SERVER; option (source) = SOURCE_SERVER;
@ -424,6 +429,7 @@ message ListEntitiesSensorResponse {
int32 accuracy_decimals = 7; int32 accuracy_decimals = 7;
bool force_update = 8; bool force_update = 8;
string device_class = 9; string device_class = 9;
SensorStateClass state_class = 10;
} }
message SensorStateResponse { message SensorStateResponse {
option (id) = 25; option (id) = 25;

View file

@ -395,6 +395,8 @@ bool APIConnection::send_sensor_info(sensor::Sensor *sensor) {
msg.accuracy_decimals = sensor->get_accuracy_decimals(); msg.accuracy_decimals = sensor->get_accuracy_decimals();
msg.force_update = sensor->get_force_update(); msg.force_update = sensor->get_force_update();
msg.device_class = sensor->get_device_class(); msg.device_class = sensor->get_device_class();
msg.state_class = static_cast<enums::SensorStateClass>(sensor->state_class);
return this->send_list_entities_sensor_response(msg); return this->send_list_entities_sensor_response(msg);
} }
#endif #endif

View file

@ -62,6 +62,16 @@ template<> const char *proto_enum_to_string<enums::FanDirection>(enums::FanDirec
return "UNKNOWN"; return "UNKNOWN";
} }
} }
template<> const char *proto_enum_to_string<enums::SensorStateClass>(enums::SensorStateClass value) {
switch (value) {
case enums::STATE_CLASS_NONE:
return "STATE_CLASS_NONE";
case enums::STATE_CLASS_MEASUREMENT:
return "STATE_CLASS_MEASUREMENT";
default:
return "UNKNOWN";
}
}
template<> const char *proto_enum_to_string<enums::LogLevel>(enums::LogLevel value) { template<> const char *proto_enum_to_string<enums::LogLevel>(enums::LogLevel value) {
switch (value) { switch (value) {
case enums::LOG_LEVEL_NONE: case enums::LOG_LEVEL_NONE:
@ -1507,6 +1517,10 @@ bool ListEntitiesSensorResponse::decode_varint(uint32_t field_id, ProtoVarInt va
this->force_update = value.as_bool(); this->force_update = value.as_bool();
return true; return true;
} }
case 10: {
this->state_class = value.as_enum<enums::SensorStateClass>();
return true;
}
default: default:
return false; return false;
} }
@ -1561,6 +1575,7 @@ void ListEntitiesSensorResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_int32(7, this->accuracy_decimals); buffer.encode_int32(7, this->accuracy_decimals);
buffer.encode_bool(8, this->force_update); buffer.encode_bool(8, this->force_update);
buffer.encode_string(9, this->device_class); buffer.encode_string(9, this->device_class);
buffer.encode_enum<enums::SensorStateClass>(10, this->state_class);
} }
void ListEntitiesSensorResponse::dump_to(std::string &out) const { void ListEntitiesSensorResponse::dump_to(std::string &out) const {
char buffer[64]; char buffer[64];
@ -1602,6 +1617,10 @@ void ListEntitiesSensorResponse::dump_to(std::string &out) const {
out.append(" device_class: "); out.append(" device_class: ");
out.append("'").append(this->device_class).append("'"); out.append("'").append(this->device_class).append("'");
out.append("\n"); out.append("\n");
out.append(" state_class: ");
out.append(proto_enum_to_string<enums::SensorStateClass>(this->state_class));
out.append("\n");
out.append("}"); out.append("}");
} }
bool SensorStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { bool SensorStateResponse::decode_varint(uint32_t field_id, ProtoVarInt value) {

View file

@ -32,6 +32,10 @@ enum FanDirection : uint32_t {
FAN_DIRECTION_FORWARD = 0, FAN_DIRECTION_FORWARD = 0,
FAN_DIRECTION_REVERSE = 1, FAN_DIRECTION_REVERSE = 1,
}; };
enum SensorStateClass : uint32_t {
STATE_CLASS_NONE = 0,
STATE_CLASS_MEASUREMENT = 1,
};
enum LogLevel : uint32_t { enum LogLevel : uint32_t {
LOG_LEVEL_NONE = 0, LOG_LEVEL_NONE = 0,
LOG_LEVEL_ERROR = 1, LOG_LEVEL_ERROR = 1,
@ -408,6 +412,7 @@ class ListEntitiesSensorResponse : public ProtoMessage {
int32_t accuracy_decimals{0}; int32_t accuracy_decimals{0};
bool force_update{false}; bool force_update{false};
std::string device_class{}; std::string device_class{};
enums::SensorStateClass state_class{};
void encode(ProtoWriteBuffer buffer) const override; void encode(ProtoWriteBuffer buffer) const override;
void dump_to(std::string &out) const override; void dump_to(std::string &out) const override;

View file

@ -5,6 +5,7 @@ from esphome.const import (
CONF_DISTANCE, CONF_DISTANCE,
CONF_LIGHTNING_ENERGY, CONF_LIGHTNING_ENERGY,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_NONE,
UNIT_KILOMETER, UNIT_KILOMETER,
UNIT_EMPTY, UNIT_EMPTY,
ICON_SIGNAL_DISTANCE_VARIANT, ICON_SIGNAL_DISTANCE_VARIANT,
@ -18,10 +19,14 @@ CONFIG_SCHEMA = cv.Schema(
{ {
cv.GenerateID(CONF_AS3935_ID): cv.use_id(AS3935), cv.GenerateID(CONF_AS3935_ID): cv.use_id(AS3935),
cv.Optional(CONF_DISTANCE): sensor.sensor_schema( cv.Optional(CONF_DISTANCE): sensor.sensor_schema(
UNIT_KILOMETER, ICON_SIGNAL_DISTANCE_VARIANT, 1, DEVICE_CLASS_EMPTY UNIT_KILOMETER,
ICON_SIGNAL_DISTANCE_VARIANT,
1,
DEVICE_CLASS_EMPTY,
STATE_CLASS_NONE,
), ),
cv.Optional(CONF_LIGHTNING_ENERGY): sensor.sensor_schema( cv.Optional(CONF_LIGHTNING_ENERGY): sensor.sensor_schema(
UNIT_EMPTY, ICON_FLASH, 1, DEVICE_CLASS_EMPTY UNIT_EMPTY, ICON_FLASH, 1, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
), ),
} }
).extend(cv.COMPONENT_SCHEMA) ).extend(cv.COMPONENT_SCHEMA)

View file

@ -13,6 +13,7 @@ from esphome.const import (
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
UNIT_VOLT, UNIT_VOLT,
@ -33,16 +34,28 @@ CONFIG_SCHEMA = (
cv.GenerateID(): cv.declare_id(ATCMiThermometer), cv.GenerateID(): cv.declare_id(ATCMiThermometer),
cv.Required(CONF_MAC_ADDRESS): cv.mac_address, cv.Required(CONF_MAC_ADDRESS): cv.mac_address,
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 0, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
0,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema( cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 0, DEVICE_CLASS_BATTERY UNIT_PERCENT,
ICON_EMPTY,
0,
DEVICE_CLASS_BATTERY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_BATTERY_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_BATTERY_VOLTAGE): sensor.sensor_schema(
UNIT_VOLT, ICON_EMPTY, 3, DEVICE_CLASS_VOLTAGE UNIT_VOLT, ICON_EMPTY, 3, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT
), ),
} }
) )

View file

@ -21,6 +21,7 @@ from esphome.const import (
ICON_EMPTY, ICON_EMPTY,
ICON_LIGHTBULB, ICON_LIGHTBULB,
ICON_CURRENT_AC, ICON_CURRENT_AC,
STATE_CLASS_MEASUREMENT,
UNIT_HERTZ, UNIT_HERTZ,
UNIT_VOLT, UNIT_VOLT,
UNIT_AMPERE, UNIT_AMPERE,
@ -63,25 +64,37 @@ ATM90E32Component = atm90e32_ns.class_(
ATM90E32_PHASE_SCHEMA = cv.Schema( ATM90E32_PHASE_SCHEMA = cv.Schema(
{ {
cv.Optional(CONF_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_VOLTAGE): sensor.sensor_schema(
UNIT_VOLT, ICON_EMPTY, 2, DEVICE_CLASS_VOLTAGE UNIT_VOLT,
ICON_EMPTY,
2,
DEVICE_CLASS_VOLTAGE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_CURRENT): sensor.sensor_schema( cv.Optional(CONF_CURRENT): sensor.sensor_schema(
UNIT_AMPERE, ICON_EMPTY, 2, DEVICE_CLASS_CURRENT UNIT_AMPERE, ICON_EMPTY, 2, DEVICE_CLASS_CURRENT, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_POWER): sensor.sensor_schema( cv.Optional(CONF_POWER): sensor.sensor_schema(
UNIT_WATT, ICON_EMPTY, 2, DEVICE_CLASS_POWER UNIT_WATT, ICON_EMPTY, 2, DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_REACTIVE_POWER): sensor.sensor_schema( cv.Optional(CONF_REACTIVE_POWER): sensor.sensor_schema(
UNIT_VOLT_AMPS_REACTIVE, ICON_LIGHTBULB, 2, DEVICE_CLASS_EMPTY UNIT_VOLT_AMPS_REACTIVE,
ICON_LIGHTBULB,
2,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_POWER_FACTOR): sensor.sensor_schema( cv.Optional(CONF_POWER_FACTOR): sensor.sensor_schema(
UNIT_EMPTY, ICON_EMPTY, 2, DEVICE_CLASS_POWER_FACTOR UNIT_EMPTY,
ICON_EMPTY,
2,
DEVICE_CLASS_POWER_FACTOR,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_FORWARD_ACTIVE_ENERGY): sensor.sensor_schema( cv.Optional(CONF_FORWARD_ACTIVE_ENERGY): sensor.sensor_schema(
UNIT_WATT_HOURS, ICON_EMPTY, 2, DEVICE_CLASS_ENERGY UNIT_WATT_HOURS, ICON_EMPTY, 2, DEVICE_CLASS_ENERGY, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_REVERSE_ACTIVE_ENERGY): sensor.sensor_schema( cv.Optional(CONF_REVERSE_ACTIVE_ENERGY): sensor.sensor_schema(
UNIT_WATT_HOURS, ICON_EMPTY, 2, DEVICE_CLASS_ENERGY UNIT_WATT_HOURS, ICON_EMPTY, 2, DEVICE_CLASS_ENERGY, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_GAIN_VOLTAGE, default=7305): cv.uint16_t, cv.Optional(CONF_GAIN_VOLTAGE, default=7305): cv.uint16_t,
cv.Optional(CONF_GAIN_CT, default=27961): cv.uint16_t, cv.Optional(CONF_GAIN_CT, default=27961): cv.uint16_t,
@ -96,10 +109,18 @@ CONFIG_SCHEMA = (
cv.Optional(CONF_PHASE_B): ATM90E32_PHASE_SCHEMA, cv.Optional(CONF_PHASE_B): ATM90E32_PHASE_SCHEMA,
cv.Optional(CONF_PHASE_C): ATM90E32_PHASE_SCHEMA, cv.Optional(CONF_PHASE_C): ATM90E32_PHASE_SCHEMA,
cv.Optional(CONF_FREQUENCY): sensor.sensor_schema( cv.Optional(CONF_FREQUENCY): sensor.sensor_schema(
UNIT_HERTZ, ICON_CURRENT_AC, 1, DEVICE_CLASS_EMPTY UNIT_HERTZ,
ICON_CURRENT_AC,
1,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_CHIP_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_CHIP_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Required(CONF_LINE_FREQUENCY): cv.enum(LINE_FREQS, upper=True), cv.Required(CONF_LINE_FREQUENCY): cv.enum(LINE_FREQS, upper=True),
cv.Optional(CONF_CURRENT_PHASES, default="3"): cv.enum( cv.Optional(CONF_CURRENT_PHASES, default="3"): cv.enum(

View file

@ -12,6 +12,7 @@ from esphome.const import (
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
UNIT_VOLT, UNIT_VOLT,
@ -32,16 +33,28 @@ CONFIG_SCHEMA = (
cv.GenerateID(): cv.declare_id(BParasite), cv.GenerateID(): cv.declare_id(BParasite),
cv.Required(CONF_MAC_ADDRESS): cv.mac_address, cv.Required(CONF_MAC_ADDRESS): cv.mac_address,
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 1, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
1,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_BATTERY_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_BATTERY_VOLTAGE): sensor.sensor_schema(
UNIT_VOLT, ICON_EMPTY, 3, DEVICE_CLASS_VOLTAGE UNIT_VOLT, ICON_EMPTY, 3, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_MOISTURE): sensor.sensor_schema( cv.Optional(CONF_MOISTURE): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 1, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
1,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -6,6 +6,7 @@ from esphome.const import (
CONF_RESOLUTION, CONF_RESOLUTION,
DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_ILLUMINANCE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_LUX, UNIT_LUX,
CONF_MEASUREMENT_DURATION, CONF_MEASUREMENT_DURATION,
) )
@ -26,7 +27,9 @@ BH1750Sensor = bh1750_ns.class_(
CONF_MEASUREMENT_TIME = "measurement_time" CONF_MEASUREMENT_TIME = "measurement_time"
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_LUX, ICON_EMPTY, 1, DEVICE_CLASS_ILLUMINANCE) sensor.sensor_schema(
UNIT_LUX, ICON_EMPTY, 1, DEVICE_CLASS_ILLUMINANCE, STATE_CLASS_MEASUREMENT
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(BH1750Sensor), cv.GenerateID(): cv.declare_id(BH1750Sensor),

View file

@ -12,6 +12,7 @@ from esphome.const import (
ICON_CHECK_CIRCLE_OUTLINE, ICON_CHECK_CIRCLE_OUTLINE,
CONF_BINARY_SENSOR, CONF_BINARY_SENSOR,
CONF_GROUP, CONF_GROUP,
STATE_CLASS_NONE,
) )
DEPENDENCIES = ["binary_sensor"] DEPENDENCIES = ["binary_sensor"]
@ -34,7 +35,11 @@ entry = {
CONFIG_SCHEMA = cv.typed_schema( CONFIG_SCHEMA = cv.typed_schema(
{ {
CONF_GROUP: sensor.sensor_schema( CONF_GROUP: sensor.sensor_schema(
UNIT_EMPTY, ICON_CHECK_CIRCLE_OUTLINE, 0, DEVICE_CLASS_EMPTY UNIT_EMPTY,
ICON_CHECK_CIRCLE_OUTLINE,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_NONE,
).extend( ).extend(
{ {
cv.GenerateID(): cv.declare_id(BinarySensorMap), cv.GenerateID(): cv.declare_id(BinarySensorMap),

View file

@ -5,6 +5,7 @@ from esphome.const import (
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
CONF_ID, CONF_ID,
CONF_LAMBDA, CONF_LAMBDA,
STATE_CLASS_NONE,
UNIT_EMPTY, UNIT_EMPTY,
ICON_EMPTY, ICON_EMPTY,
CONF_TRIGGER_ID, CONF_TRIGGER_ID,
@ -32,7 +33,9 @@ BLESensorNotifyTrigger = ble_client_ns.class_(
) )
CONFIG_SCHEMA = cv.All( CONFIG_SCHEMA = cv.All(
sensor.sensor_schema(UNIT_EMPTY, ICON_EMPTY, 0, DEVICE_CLASS_EMPTY) sensor.sensor_schema(
UNIT_EMPTY, ICON_EMPTY, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(BLESensor), cv.GenerateID(): cv.declare_id(BLESensor),

View file

@ -6,6 +6,7 @@ from esphome.const import (
CONF_MAC_ADDRESS, CONF_MAC_ADDRESS,
CONF_ID, CONF_ID,
DEVICE_CLASS_SIGNAL_STRENGTH, DEVICE_CLASS_SIGNAL_STRENGTH,
STATE_CLASS_MEASUREMENT,
UNIT_DECIBEL, UNIT_DECIBEL,
ICON_EMPTY, ICON_EMPTY,
) )
@ -18,7 +19,13 @@ BLERSSISensor = ble_rssi_ns.class_(
) )
CONFIG_SCHEMA = cv.All( CONFIG_SCHEMA = cv.All(
sensor.sensor_schema(UNIT_DECIBEL, ICON_EMPTY, 0, DEVICE_CLASS_SIGNAL_STRENGTH) sensor.sensor_schema(
UNIT_DECIBEL,
ICON_EMPTY,
0,
DEVICE_CLASS_SIGNAL_STRENGTH,
STATE_CLASS_MEASUREMENT,
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(BLERSSISensor), cv.GenerateID(): cv.declare_id(BLERSSISensor),

View file

@ -12,6 +12,7 @@ from esphome.const import (
DEVICE_CLASS_PRESSURE, DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_HECTOPASCAL, UNIT_HECTOPASCAL,
UNIT_PERCENT, UNIT_PERCENT,
@ -48,7 +49,11 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(BME280Component), cv.GenerateID(): cv.declare_id(BME280Component),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
).extend( ).extend(
{ {
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum( cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(
@ -57,7 +62,11 @@ CONFIG_SCHEMA = (
} }
), ),
cv.Optional(CONF_PRESSURE): sensor.sensor_schema( cv.Optional(CONF_PRESSURE): sensor.sensor_schema(
UNIT_HECTOPASCAL, ICON_EMPTY, 1, DEVICE_CLASS_PRESSURE UNIT_HECTOPASCAL,
ICON_EMPTY,
1,
DEVICE_CLASS_PRESSURE,
STATE_CLASS_MEASUREMENT,
).extend( ).extend(
{ {
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum( cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(
@ -66,7 +75,11 @@ CONFIG_SCHEMA = (
} }
), ),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 1, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
1,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
).extend( ).extend(
{ {
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum( cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(

View file

@ -16,6 +16,7 @@ from esphome.const import (
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_PRESSURE, DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
UNIT_OHM, UNIT_OHM,
ICON_GAS_CYLINDER, ICON_GAS_CYLINDER,
UNIT_CELSIUS, UNIT_CELSIUS,
@ -58,7 +59,11 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(BME680Component), cv.GenerateID(): cv.declare_id(BME680Component),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
).extend( ).extend(
{ {
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum( cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(
@ -67,7 +72,11 @@ CONFIG_SCHEMA = (
} }
), ),
cv.Optional(CONF_PRESSURE): sensor.sensor_schema( cv.Optional(CONF_PRESSURE): sensor.sensor_schema(
UNIT_HECTOPASCAL, ICON_EMPTY, 1, DEVICE_CLASS_PRESSURE UNIT_HECTOPASCAL,
ICON_EMPTY,
1,
DEVICE_CLASS_PRESSURE,
STATE_CLASS_MEASUREMENT,
).extend( ).extend(
{ {
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum( cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(
@ -76,7 +85,11 @@ CONFIG_SCHEMA = (
} }
), ),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 1, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
1,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
).extend( ).extend(
{ {
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum( cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(
@ -85,7 +98,11 @@ CONFIG_SCHEMA = (
} }
), ),
cv.Optional(CONF_GAS_RESISTANCE): sensor.sensor_schema( cv.Optional(CONF_GAS_RESISTANCE): sensor.sensor_schema(
UNIT_OHM, ICON_GAS_CYLINDER, 1, DEVICE_CLASS_EMPTY UNIT_OHM,
ICON_GAS_CYLINDER,
1,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_IIR_FILTER, default="OFF"): cv.enum( cv.Optional(CONF_IIR_FILTER, default="OFF"): cv.enum(
IIR_FILTER_OPTIONS, upper=True IIR_FILTER_OPTIONS, upper=True

View file

@ -10,6 +10,7 @@ from esphome.const import (
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_PRESSURE, DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_EMPTY, UNIT_EMPTY,
UNIT_HECTOPASCAL, UNIT_HECTOPASCAL,
@ -53,34 +54,54 @@ CONFIG_SCHEMA = cv.Schema(
{ {
cv.GenerateID(CONF_BME680_BSEC_ID): cv.use_id(BME680BSECComponent), cv.GenerateID(CONF_BME680_BSEC_ID): cv.use_id(BME680BSECComponent),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_THERMOMETER, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_THERMOMETER,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
).extend( ).extend(
{cv.Optional(CONF_SAMPLE_RATE): cv.enum(SAMPLE_RATE_OPTIONS, upper=True)} {cv.Optional(CONF_SAMPLE_RATE): cv.enum(SAMPLE_RATE_OPTIONS, upper=True)}
), ),
cv.Optional(CONF_PRESSURE): sensor.sensor_schema( cv.Optional(CONF_PRESSURE): sensor.sensor_schema(
UNIT_HECTOPASCAL, ICON_GAUGE, 1, DEVICE_CLASS_PRESSURE UNIT_HECTOPASCAL,
ICON_GAUGE,
1,
DEVICE_CLASS_PRESSURE,
STATE_CLASS_MEASUREMENT,
).extend( ).extend(
{cv.Optional(CONF_SAMPLE_RATE): cv.enum(SAMPLE_RATE_OPTIONS, upper=True)} {cv.Optional(CONF_SAMPLE_RATE): cv.enum(SAMPLE_RATE_OPTIONS, upper=True)}
), ),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_WATER_PERCENT, 1, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_WATER_PERCENT,
1,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
).extend( ).extend(
{cv.Optional(CONF_SAMPLE_RATE): cv.enum(SAMPLE_RATE_OPTIONS, upper=True)} {cv.Optional(CONF_SAMPLE_RATE): cv.enum(SAMPLE_RATE_OPTIONS, upper=True)}
), ),
cv.Optional(CONF_GAS_RESISTANCE): sensor.sensor_schema( cv.Optional(CONF_GAS_RESISTANCE): sensor.sensor_schema(
UNIT_OHM, ICON_GAS_CYLINDER, 0, DEVICE_CLASS_EMPTY UNIT_OHM, ICON_GAS_CYLINDER, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_IAQ): sensor.sensor_schema( cv.Optional(CONF_IAQ): sensor.sensor_schema(
UNIT_IAQ, ICON_GAUGE, 0, DEVICE_CLASS_EMPTY UNIT_IAQ, ICON_GAUGE, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_IAQ_ACCURACY): sensor.sensor_schema( cv.Optional(CONF_IAQ_ACCURACY): sensor.sensor_schema(
UNIT_EMPTY, ICON_ACCURACY, 0, DEVICE_CLASS_EMPTY UNIT_EMPTY, ICON_ACCURACY, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_CO2_EQUIVALENT): sensor.sensor_schema( cv.Optional(CONF_CO2_EQUIVALENT): sensor.sensor_schema(
UNIT_PARTS_PER_MILLION, ICON_TEST_TUBE, 1, DEVICE_CLASS_EMPTY UNIT_PARTS_PER_MILLION,
ICON_TEST_TUBE,
1,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_BREATH_VOC_EQUIVALENT): sensor.sensor_schema( cv.Optional(CONF_BREATH_VOC_EQUIVALENT): sensor.sensor_schema(
UNIT_PARTS_PER_MILLION, ICON_TEST_TUBE, 1, DEVICE_CLASS_EMPTY UNIT_PARTS_PER_MILLION,
ICON_TEST_TUBE,
1,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -7,6 +7,7 @@ from esphome.const import (
CONF_TEMPERATURE, CONF_TEMPERATURE,
DEVICE_CLASS_PRESSURE, DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
ICON_EMPTY, ICON_EMPTY,
UNIT_HECTOPASCAL, UNIT_HECTOPASCAL,
@ -24,10 +25,18 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(BMP085Component), cv.GenerateID(): cv.declare_id(BMP085Component),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PRESSURE): sensor.sensor_schema( cv.Optional(CONF_PRESSURE): sensor.sensor_schema(
UNIT_HECTOPASCAL, ICON_EMPTY, 1, DEVICE_CLASS_PRESSURE UNIT_HECTOPASCAL,
ICON_EMPTY,
1,
DEVICE_CLASS_PRESSURE,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -7,6 +7,7 @@ from esphome.const import (
CONF_TEMPERATURE, CONF_TEMPERATURE,
DEVICE_CLASS_PRESSURE, DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
ICON_EMPTY, ICON_EMPTY,
UNIT_HECTOPASCAL, UNIT_HECTOPASCAL,
@ -45,7 +46,11 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(BMP280Component), cv.GenerateID(): cv.declare_id(BMP280Component),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
).extend( ).extend(
{ {
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum( cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(
@ -54,7 +59,11 @@ CONFIG_SCHEMA = (
} }
), ),
cv.Optional(CONF_PRESSURE): sensor.sensor_schema( cv.Optional(CONF_PRESSURE): sensor.sensor_schema(
UNIT_HECTOPASCAL, ICON_EMPTY, 1, DEVICE_CLASS_PRESSURE UNIT_HECTOPASCAL,
ICON_EMPTY,
1,
DEVICE_CLASS_PRESSURE,
STATE_CLASS_MEASUREMENT,
).extend( ).extend(
{ {
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum( cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(

View file

@ -5,6 +5,7 @@ from esphome.const import (
CONF_ID, CONF_ID,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
ICON_RADIATOR, ICON_RADIATOR,
STATE_CLASS_MEASUREMENT,
UNIT_PARTS_PER_MILLION, UNIT_PARTS_PER_MILLION,
UNIT_PARTS_PER_BILLION, UNIT_PARTS_PER_BILLION,
CONF_TEMPERATURE, CONF_TEMPERATURE,
@ -28,10 +29,18 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(CCS811Component), cv.GenerateID(): cv.declare_id(CCS811Component),
cv.Required(CONF_ECO2): sensor.sensor_schema( cv.Required(CONF_ECO2): sensor.sensor_schema(
UNIT_PARTS_PER_MILLION, ICON_MOLECULE_CO2, 0, DEVICE_CLASS_EMPTY UNIT_PARTS_PER_MILLION,
ICON_MOLECULE_CO2,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Required(CONF_TVOC): sensor.sensor_schema( cv.Required(CONF_TVOC): sensor.sensor_schema(
UNIT_PARTS_PER_BILLION, ICON_RADIATOR, 0, DEVICE_CLASS_EMPTY UNIT_PARTS_PER_BILLION,
ICON_RADIATOR,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_BASELINE): cv.hex_uint16_t, cv.Optional(CONF_BASELINE): cv.hex_uint16_t,
cv.Optional(CONF_TEMPERATURE): cv.use_id(sensor.Sensor), cv.Optional(CONF_TEMPERATURE): cv.use_id(sensor.Sensor),

View file

@ -10,6 +10,7 @@ from esphome.const import (
DEVICE_CLASS_POWER, DEVICE_CLASS_POWER,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_VOLT, UNIT_VOLT,
UNIT_AMPERE, UNIT_AMPERE,
UNIT_WATT, UNIT_WATT,
@ -27,13 +28,17 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(CSE7766Component), cv.GenerateID(): cv.declare_id(CSE7766Component),
cv.Optional(CONF_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_VOLTAGE): sensor.sensor_schema(
UNIT_VOLT, ICON_EMPTY, 1, DEVICE_CLASS_VOLTAGE UNIT_VOLT, ICON_EMPTY, 1, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_CURRENT): sensor.sensor_schema( cv.Optional(CONF_CURRENT): sensor.sensor_schema(
UNIT_AMPERE, ICON_EMPTY, 2, DEVICE_CLASS_CURRENT UNIT_AMPERE,
ICON_EMPTY,
2,
DEVICE_CLASS_CURRENT,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_POWER): sensor.sensor_schema( cv.Optional(CONF_POWER): sensor.sensor_schema(
UNIT_WATT, ICON_EMPTY, 1, DEVICE_CLASS_POWER UNIT_WATT, ICON_EMPTY, 1, DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT
), ),
} }
) )

View file

@ -6,6 +6,7 @@ from esphome.const import (
CONF_ID, CONF_ID,
DEVICE_CLASS_CURRENT, DEVICE_CLASS_CURRENT,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_AMPERE, UNIT_AMPERE,
) )
@ -18,7 +19,9 @@ ct_clamp_ns = cg.esphome_ns.namespace("ct_clamp")
CTClampSensor = ct_clamp_ns.class_("CTClampSensor", sensor.Sensor, cg.PollingComponent) CTClampSensor = ct_clamp_ns.class_("CTClampSensor", sensor.Sensor, cg.PollingComponent)
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_AMPERE, ICON_EMPTY, 2, DEVICE_CLASS_CURRENT) sensor.sensor_schema(
UNIT_AMPERE, ICON_EMPTY, 2, DEVICE_CLASS_CURRENT, STATE_CLASS_MEASUREMENT
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(CTClampSensor), cv.GenerateID(): cv.declare_id(CTClampSensor),

View file

@ -8,6 +8,7 @@ from esphome.const import (
CONF_RESOLUTION, CONF_RESOLUTION,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
CONF_ID, CONF_ID,
) )
@ -16,7 +17,9 @@ from . import DallasComponent, dallas_ns
DallasTemperatureSensor = dallas_ns.class_("DallasTemperatureSensor", sensor.Sensor) DallasTemperatureSensor = dallas_ns.class_("DallasTemperatureSensor", sensor.Sensor)
CONFIG_SCHEMA = cv.All( CONFIG_SCHEMA = cv.All(
sensor.sensor_schema(UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE).extend( sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT
).extend(
{ {
cv.GenerateID(): cv.declare_id(DallasTemperatureSensor), cv.GenerateID(): cv.declare_id(DallasTemperatureSensor),
cv.GenerateID(CONF_DALLAS_ID): cv.use_id(DallasComponent), cv.GenerateID(CONF_DALLAS_ID): cv.use_id(DallasComponent),

View file

@ -9,6 +9,7 @@ from esphome.const import (
CONF_PIN, CONF_PIN,
CONF_TEMPERATURE, CONF_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
@ -35,10 +36,14 @@ CONFIG_SCHEMA = cv.Schema(
cv.GenerateID(): cv.declare_id(DHT), cv.GenerateID(): cv.declare_id(DHT),
cv.Required(CONF_PIN): pins.gpio_input_pin_schema, cv.Required(CONF_PIN): pins.gpio_input_pin_schema,
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 0, DEVICE_CLASS_HUMIDITY UNIT_PERCENT, ICON_EMPTY, 0, DEVICE_CLASS_HUMIDITY, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_MODEL, default="auto detect"): cv.enum( cv.Optional(CONF_MODEL, default="auto detect"): cv.enum(
DHT_MODELS, upper=True, space="_" DHT_MODELS, upper=True, space="_"

View file

@ -5,6 +5,7 @@ from esphome.const import (
CONF_HUMIDITY, CONF_HUMIDITY,
CONF_ID, CONF_ID,
CONF_TEMPERATURE, CONF_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
ICON_EMPTY, ICON_EMPTY,
UNIT_PERCENT, UNIT_PERCENT,
@ -22,10 +23,18 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(DHT12Component), cv.GenerateID(): cv.declare_id(DHT12Component),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 1, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
1,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -6,6 +6,7 @@ from esphome.const import (
CONF_ID, CONF_ID,
CONF_PIN, CONF_PIN,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_PERCENT, UNIT_PERCENT,
ICON_PERCENT, ICON_PERCENT,
) )
@ -16,7 +17,9 @@ DutyCycleSensor = duty_cycle_ns.class_(
) )
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_PERCENT, ICON_PERCENT, 1, DEVICE_CLASS_EMPTY) sensor.sensor_schema(
UNIT_PERCENT, ICON_PERCENT, 1, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(DutyCycleSensor), cv.GenerateID(): cv.declare_id(DutyCycleSensor),

View file

@ -5,6 +5,7 @@ from esphome.const import (
CONF_ID, CONF_ID,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
ESP_PLATFORM_ESP32, ESP_PLATFORM_ESP32,
STATE_CLASS_MEASUREMENT,
UNIT_MICROTESLA, UNIT_MICROTESLA,
ICON_MAGNET, ICON_MAGNET,
) )
@ -17,7 +18,9 @@ ESP32HallSensor = esp32_hall_ns.class_(
) )
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_MICROTESLA, ICON_MAGNET, 1, DEVICE_CLASS_EMPTY) sensor.sensor_schema(
UNIT_MICROTESLA, ICON_MAGNET, 1, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(ESP32HallSensor), cv.GenerateID(): cv.declare_id(ESP32HallSensor),

View file

@ -15,6 +15,7 @@ from esphome.const import (
ICON_EMPTY, ICON_EMPTY,
ICON_FINGERPRINT, ICON_FINGERPRINT,
ICON_SECURITY, ICON_SECURITY,
STATE_CLASS_NONE,
UNIT_EMPTY, UNIT_EMPTY,
) )
from . import CONF_FINGERPRINT_GROW_ID, FingerprintGrowComponent from . import CONF_FINGERPRINT_GROW_ID, FingerprintGrowComponent
@ -25,22 +26,22 @@ CONFIG_SCHEMA = cv.Schema(
{ {
cv.GenerateID(CONF_FINGERPRINT_GROW_ID): cv.use_id(FingerprintGrowComponent), cv.GenerateID(CONF_FINGERPRINT_GROW_ID): cv.use_id(FingerprintGrowComponent),
cv.Optional(CONF_FINGERPRINT_COUNT): sensor.sensor_schema( cv.Optional(CONF_FINGERPRINT_COUNT): sensor.sensor_schema(
UNIT_EMPTY, ICON_FINGERPRINT, 0, DEVICE_CLASS_EMPTY UNIT_EMPTY, ICON_FINGERPRINT, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
), ),
cv.Optional(CONF_STATUS): sensor.sensor_schema( cv.Optional(CONF_STATUS): sensor.sensor_schema(
UNIT_EMPTY, ICON_EMPTY, 0, DEVICE_CLASS_EMPTY UNIT_EMPTY, ICON_EMPTY, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
), ),
cv.Optional(CONF_CAPACITY): sensor.sensor_schema( cv.Optional(CONF_CAPACITY): sensor.sensor_schema(
UNIT_EMPTY, ICON_DATABASE, 0, DEVICE_CLASS_EMPTY UNIT_EMPTY, ICON_DATABASE, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
), ),
cv.Optional(CONF_SECURITY_LEVEL): sensor.sensor_schema( cv.Optional(CONF_SECURITY_LEVEL): sensor.sensor_schema(
UNIT_EMPTY, ICON_SECURITY, 0, DEVICE_CLASS_EMPTY UNIT_EMPTY, ICON_SECURITY, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
), ),
cv.Optional(CONF_LAST_FINGER_ID): sensor.sensor_schema( cv.Optional(CONF_LAST_FINGER_ID): sensor.sensor_schema(
UNIT_EMPTY, ICON_ACCOUNT, 0, DEVICE_CLASS_EMPTY UNIT_EMPTY, ICON_ACCOUNT, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
), ),
cv.Optional(CONF_LAST_CONFIDENCE): sensor.sensor_schema( cv.Optional(CONF_LAST_CONFIDENCE): sensor.sensor_schema(
UNIT_EMPTY, ICON_ACCOUNT_CHECK, 0, DEVICE_CLASS_EMPTY UNIT_EMPTY, ICON_ACCOUNT_CHECK, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
), ),
} }
) )

View file

@ -10,6 +10,8 @@ from esphome.const import (
CONF_COURSE, CONF_COURSE,
CONF_ALTITUDE, CONF_ALTITUDE,
CONF_SATELLITES, CONF_SATELLITES,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_NONE,
UNIT_DEGREES, UNIT_DEGREES,
UNIT_KILOMETER_PER_HOUR, UNIT_KILOMETER_PER_HOUR,
UNIT_METER, UNIT_METER,
@ -34,22 +36,26 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(GPS), cv.GenerateID(): cv.declare_id(GPS),
cv.Optional(CONF_LATITUDE): sensor.sensor_schema( cv.Optional(CONF_LATITUDE): sensor.sensor_schema(
UNIT_DEGREES, ICON_EMPTY, 6, DEVICE_CLASS_EMPTY UNIT_DEGREES, ICON_EMPTY, 6, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
), ),
cv.Optional(CONF_LONGITUDE): sensor.sensor_schema( cv.Optional(CONF_LONGITUDE): sensor.sensor_schema(
UNIT_DEGREES, ICON_EMPTY, 6, DEVICE_CLASS_EMPTY UNIT_DEGREES, ICON_EMPTY, 6, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
), ),
cv.Optional(CONF_SPEED): sensor.sensor_schema( cv.Optional(CONF_SPEED): sensor.sensor_schema(
UNIT_KILOMETER_PER_HOUR, ICON_EMPTY, 6, DEVICE_CLASS_EMPTY UNIT_KILOMETER_PER_HOUR,
ICON_EMPTY,
6,
DEVICE_CLASS_EMPTY,
STATE_CLASS_NONE,
), ),
cv.Optional(CONF_COURSE): sensor.sensor_schema( cv.Optional(CONF_COURSE): sensor.sensor_schema(
UNIT_DEGREES, ICON_EMPTY, 2, DEVICE_CLASS_EMPTY UNIT_DEGREES, ICON_EMPTY, 2, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
), ),
cv.Optional(CONF_ALTITUDE): sensor.sensor_schema( cv.Optional(CONF_ALTITUDE): sensor.sensor_schema(
UNIT_METER, ICON_EMPTY, 1, DEVICE_CLASS_EMPTY UNIT_METER, ICON_EMPTY, 1, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
), ),
cv.Optional(CONF_SATELLITES): sensor.sensor_schema( cv.Optional(CONF_SATELLITES): sensor.sensor_schema(
UNIT_EMPTY, ICON_EMPTY, 0, DEVICE_CLASS_EMPTY UNIT_EMPTY, ICON_EMPTY, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT
), ),
} }
) )

View file

@ -8,6 +8,7 @@ from esphome.const import (
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
) )
@ -24,10 +25,18 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(HDC1080Component), cv.GenerateID(): cv.declare_id(HDC1080Component),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 0, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
0,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -18,6 +18,8 @@ from esphome.const import (
DEVICE_CLASS_POWER, DEVICE_CLASS_POWER,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_NONE,
UNIT_VOLT, UNIT_VOLT,
UNIT_AMPERE, UNIT_AMPERE,
UNIT_WATT, UNIT_WATT,
@ -47,16 +49,16 @@ CONFIG_SCHEMA = cv.Schema(
pins.internal_gpio_input_pullup_pin_schema, pins.validate_has_interrupt pins.internal_gpio_input_pullup_pin_schema, pins.validate_has_interrupt
), ),
cv.Optional(CONF_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_VOLTAGE): sensor.sensor_schema(
UNIT_VOLT, ICON_EMPTY, 1, DEVICE_CLASS_VOLTAGE UNIT_VOLT, ICON_EMPTY, 1, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_CURRENT): sensor.sensor_schema( cv.Optional(CONF_CURRENT): sensor.sensor_schema(
UNIT_AMPERE, ICON_EMPTY, 2, DEVICE_CLASS_CURRENT UNIT_AMPERE, ICON_EMPTY, 2, DEVICE_CLASS_CURRENT, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_POWER): sensor.sensor_schema( cv.Optional(CONF_POWER): sensor.sensor_schema(
UNIT_WATT, ICON_EMPTY, 1, DEVICE_CLASS_POWER UNIT_WATT, ICON_EMPTY, 1, DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_ENERGY): sensor.sensor_schema( cv.Optional(CONF_ENERGY): sensor.sensor_schema(
UNIT_WATT_HOURS, ICON_EMPTY, 1, DEVICE_CLASS_ENERGY UNIT_WATT_HOURS, ICON_EMPTY, 1, DEVICE_CLASS_ENERGY, STATE_CLASS_NONE
), ),
cv.Optional(CONF_CURRENT_RESISTOR, default=0.001): cv.resistance, cv.Optional(CONF_CURRENT_RESISTOR, default=0.001): cv.resistance,
cv.Optional(CONF_VOLTAGE_DIVIDER, default=2351): cv.positive_float, cv.Optional(CONF_VOLTAGE_DIVIDER, default=2351): cv.positive_float,

View file

@ -7,6 +7,7 @@ from esphome.const import (
CONF_PM_10_0, CONF_PM_10_0,
CONF_PM_1_0, CONF_PM_1_0,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
) )
@ -46,21 +47,28 @@ CONFIG_SCHEMA = cv.All(
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
0, 0,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PM_2_5): sensor.sensor_schema( cv.Optional(CONF_PM_2_5): sensor.sensor_schema(
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
0, 0,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PM_10_0): sensor.sensor_schema( cv.Optional(CONF_PM_10_0): sensor.sensor_schema(
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
0, 0,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_AQI): sensor.sensor_schema( cv.Optional(CONF_AQI): sensor.sensor_schema(
UNIT_INDEX, ICON_CHEMICAL_WEAPON, 0, DEVICE_CLASS_EMPTY UNIT_INDEX,
ICON_CHEMICAL_WEAPON,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
).extend( ).extend(
{ {
cv.Required(CONF_CALCULATION_TYPE): cv.enum( cv.Required(CONF_CALCULATION_TYPE): cv.enum(

View file

@ -8,6 +8,8 @@ from esphome.const import (
CONF_RANGE, CONF_RANGE,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
ICON_MAGNET, ICON_MAGNET,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_NONE,
UNIT_MICROTESLA, UNIT_MICROTESLA,
UNIT_DEGREES, UNIT_DEGREES,
ICON_SCREEN_ROTATION, ICON_SCREEN_ROTATION,
@ -78,10 +80,10 @@ def validate_enum(enum_values, units=None, int=True):
field_strength_schema = sensor.sensor_schema( field_strength_schema = sensor.sensor_schema(
UNIT_MICROTESLA, ICON_MAGNET, 1, DEVICE_CLASS_EMPTY UNIT_MICROTESLA, ICON_MAGNET, 1, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT
) )
heading_schema = sensor.sensor_schema( heading_schema = sensor.sensor_schema(
UNIT_DEGREES, ICON_SCREEN_ROTATION, 1, DEVICE_CLASS_EMPTY UNIT_DEGREES, ICON_SCREEN_ROTATION, 1, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
) )
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (

View file

@ -6,6 +6,7 @@ from esphome.const import (
CONF_ENTITY_ID, CONF_ENTITY_ID,
CONF_ID, CONF_ID,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_NONE,
UNIT_EMPTY, UNIT_EMPTY,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
) )
@ -18,7 +19,7 @@ HomeassistantSensor = homeassistant_ns.class_(
) )
CONFIG_SCHEMA = sensor.sensor_schema( CONFIG_SCHEMA = sensor.sensor_schema(
UNIT_EMPTY, ICON_EMPTY, 1, DEVICE_CLASS_EMPTY UNIT_EMPTY, ICON_EMPTY, 1, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
).extend( ).extend(
{ {
cv.GenerateID(): cv.declare_id(HomeassistantSensor), cv.GenerateID(): cv.declare_id(HomeassistantSensor),

View file

@ -8,6 +8,7 @@ from esphome.const import (
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
) )
@ -24,10 +25,18 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(HTU21DComponent), cv.GenerateID(): cv.declare_id(HTU21DComponent),
cv.Required(CONF_TEMPERATURE): sensor.sensor_schema( cv.Required(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Required(CONF_HUMIDITY): sensor.sensor_schema( cv.Required(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 1, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
1,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -8,6 +8,7 @@ from esphome.const import (
CONF_ID, CONF_ID,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
ICON_SCALE, ICON_SCALE,
STATE_CLASS_MEASUREMENT,
UNIT_EMPTY, UNIT_EMPTY,
) )
@ -24,7 +25,9 @@ GAINS = {
} }
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_EMPTY, ICON_SCALE, 0, DEVICE_CLASS_EMPTY) sensor.sensor_schema(
UNIT_EMPTY, ICON_SCALE, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(HX711Sensor), cv.GenerateID(): cv.declare_id(HX711Sensor),

View file

@ -14,6 +14,7 @@ from esphome.const import (
DEVICE_CLASS_POWER, DEVICE_CLASS_POWER,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_VOLT, UNIT_VOLT,
UNIT_AMPERE, UNIT_AMPERE,
UNIT_WATT, UNIT_WATT,
@ -31,16 +32,20 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(INA219Component), cv.GenerateID(): cv.declare_id(INA219Component),
cv.Optional(CONF_BUS_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_BUS_VOLTAGE): sensor.sensor_schema(
UNIT_VOLT, ICON_EMPTY, 2, DEVICE_CLASS_VOLTAGE UNIT_VOLT, ICON_EMPTY, 2, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_SHUNT_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_SHUNT_VOLTAGE): sensor.sensor_schema(
UNIT_VOLT, ICON_EMPTY, 2, DEVICE_CLASS_VOLTAGE UNIT_VOLT, ICON_EMPTY, 2, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_CURRENT): sensor.sensor_schema( cv.Optional(CONF_CURRENT): sensor.sensor_schema(
UNIT_AMPERE, ICON_EMPTY, 3, DEVICE_CLASS_CURRENT UNIT_AMPERE,
ICON_EMPTY,
3,
DEVICE_CLASS_CURRENT,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_POWER): sensor.sensor_schema( cv.Optional(CONF_POWER): sensor.sensor_schema(
UNIT_WATT, ICON_EMPTY, 2, DEVICE_CLASS_POWER UNIT_WATT, ICON_EMPTY, 2, DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_SHUNT_RESISTANCE, default=0.1): cv.All( cv.Optional(CONF_SHUNT_RESISTANCE, default=0.1): cv.All(
cv.resistance, cv.Range(min=0.0, max=32.0) cv.resistance, cv.Range(min=0.0, max=32.0)

View file

@ -13,6 +13,7 @@ from esphome.const import (
DEVICE_CLASS_CURRENT, DEVICE_CLASS_CURRENT,
DEVICE_CLASS_POWER, DEVICE_CLASS_POWER,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_VOLT, UNIT_VOLT,
UNIT_AMPERE, UNIT_AMPERE,
UNIT_WATT, UNIT_WATT,
@ -30,16 +31,20 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(INA226Component), cv.GenerateID(): cv.declare_id(INA226Component),
cv.Optional(CONF_BUS_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_BUS_VOLTAGE): sensor.sensor_schema(
UNIT_VOLT, ICON_EMPTY, 2, DEVICE_CLASS_VOLTAGE UNIT_VOLT, ICON_EMPTY, 2, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_SHUNT_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_SHUNT_VOLTAGE): sensor.sensor_schema(
UNIT_VOLT, ICON_EMPTY, 2, DEVICE_CLASS_VOLTAGE UNIT_VOLT, ICON_EMPTY, 2, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_CURRENT): sensor.sensor_schema( cv.Optional(CONF_CURRENT): sensor.sensor_schema(
UNIT_AMPERE, ICON_EMPTY, 3, DEVICE_CLASS_CURRENT UNIT_AMPERE,
ICON_EMPTY,
3,
DEVICE_CLASS_CURRENT,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_POWER): sensor.sensor_schema( cv.Optional(CONF_POWER): sensor.sensor_schema(
UNIT_WATT, ICON_EMPTY, 2, DEVICE_CLASS_POWER UNIT_WATT, ICON_EMPTY, 2, DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_SHUNT_RESISTANCE, default=0.1): cv.All( cv.Optional(CONF_SHUNT_RESISTANCE, default=0.1): cv.All(
cv.resistance, cv.Range(min=0.0) cv.resistance, cv.Range(min=0.0)

View file

@ -12,6 +12,7 @@ from esphome.const import (
DEVICE_CLASS_CURRENT, DEVICE_CLASS_CURRENT,
DEVICE_CLASS_POWER, DEVICE_CLASS_POWER,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_VOLT, UNIT_VOLT,
UNIT_AMPERE, UNIT_AMPERE,
UNIT_WATT, UNIT_WATT,
@ -31,16 +32,16 @@ INA3221Component = ina3221_ns.class_(
INA3221_CHANNEL_SCHEMA = cv.Schema( INA3221_CHANNEL_SCHEMA = cv.Schema(
{ {
cv.Optional(CONF_BUS_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_BUS_VOLTAGE): sensor.sensor_schema(
UNIT_VOLT, ICON_EMPTY, 2, DEVICE_CLASS_VOLTAGE UNIT_VOLT, ICON_EMPTY, 2, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_SHUNT_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_SHUNT_VOLTAGE): sensor.sensor_schema(
UNIT_VOLT, ICON_EMPTY, 2, DEVICE_CLASS_VOLTAGE UNIT_VOLT, ICON_EMPTY, 2, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_CURRENT): sensor.sensor_schema( cv.Optional(CONF_CURRENT): sensor.sensor_schema(
UNIT_AMPERE, ICON_EMPTY, 2, DEVICE_CLASS_CURRENT UNIT_AMPERE, ICON_EMPTY, 2, DEVICE_CLASS_CURRENT, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_POWER): sensor.sensor_schema( cv.Optional(CONF_POWER): sensor.sensor_schema(
UNIT_WATT, ICON_EMPTY, 2, DEVICE_CLASS_POWER UNIT_WATT, ICON_EMPTY, 2, DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_SHUNT_RESISTANCE, default=0.1): cv.All( cv.Optional(CONF_SHUNT_RESISTANCE, default=0.1): cv.All(
cv.resistance, cv.Range(min=0.0, max=32.0) cv.resistance, cv.Range(min=0.0, max=32.0)

View file

@ -10,6 +10,7 @@ from esphome.const import (
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
CONF_ID, CONF_ID,
@ -29,13 +30,25 @@ CONFIG_SCHEMA = (
cv.GenerateID(): cv.declare_id(InkbirdUBSTH1_MINI), cv.GenerateID(): cv.declare_id(InkbirdUBSTH1_MINI),
cv.Required(CONF_MAC_ADDRESS): cv.mac_address, cv.Required(CONF_MAC_ADDRESS): cv.mac_address,
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 1, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
1,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema( cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 0, DEVICE_CLASS_BATTERY UNIT_PERCENT,
ICON_EMPTY,
0,
DEVICE_CLASS_BATTERY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -6,6 +6,7 @@ from esphome.const import (
CONF_REFERENCE_TEMPERATURE, CONF_REFERENCE_TEMPERATURE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
) )
@ -20,7 +21,11 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(MAX31855Sensor), cv.GenerateID(): cv.declare_id(MAX31855Sensor),
cv.Optional(CONF_REFERENCE_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_REFERENCE_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 2, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
2,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -6,6 +6,7 @@ from esphome.const import (
CONF_MAINS_FILTER, CONF_MAINS_FILTER,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
) )
@ -21,7 +22,13 @@ FILTER = {
} }
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE) sensor.sensor_schema(
UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(MAX31856Sensor), cv.GenerateID(): cv.declare_id(MAX31856Sensor),

View file

@ -9,6 +9,7 @@ from esphome.const import (
CONF_RTD_WIRES, CONF_RTD_WIRES,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
) )
@ -24,7 +25,9 @@ FILTER = {
} }
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_CELSIUS, ICON_EMPTY, 2, DEVICE_CLASS_TEMPERATURE) sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 2, DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(MAX31865Sensor), cv.GenerateID(): cv.declare_id(MAX31865Sensor),

View file

@ -1,7 +1,13 @@
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.components import sensor, spi from esphome.components import sensor, spi
from esphome.const import CONF_ID, DEVICE_CLASS_TEMPERATURE, ICON_EMPTY, UNIT_CELSIUS from esphome.const import (
CONF_ID,
DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS,
)
max6675_ns = cg.esphome_ns.namespace("max6675") max6675_ns = cg.esphome_ns.namespace("max6675")
MAX6675Sensor = max6675_ns.class_( MAX6675Sensor = max6675_ns.class_(
@ -9,7 +15,9 @@ MAX6675Sensor = max6675_ns.class_(
) )
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE) sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(MAX6675Sensor), cv.GenerateID(): cv.declare_id(MAX6675Sensor),

View file

@ -1,7 +1,13 @@
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.components import i2c, sensor from esphome.components import i2c, sensor
from esphome.const import CONF_ID, DEVICE_CLASS_TEMPERATURE, ICON_EMPTY, UNIT_CELSIUS from esphome.const import (
CONF_ID,
DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS,
)
CODEOWNERS = ["@k7hpn"] CODEOWNERS = ["@k7hpn"]
DEPENDENCIES = ["i2c"] DEPENDENCIES = ["i2c"]
@ -12,7 +18,9 @@ MCP9808Sensor = mcp9808_ns.class_(
) )
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE) sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(MCP9808Sensor), cv.GenerateID(): cv.declare_id(MCP9808Sensor),

View file

@ -10,6 +10,7 @@ from esphome.const import (
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_MOLECULE_CO2, ICON_MOLECULE_CO2,
STATE_CLASS_MEASUREMENT,
UNIT_PARTS_PER_MILLION, UNIT_PARTS_PER_MILLION,
UNIT_CELSIUS, UNIT_CELSIUS,
ICON_EMPTY, ICON_EMPTY,
@ -32,10 +33,18 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(MHZ19Component), cv.GenerateID(): cv.declare_id(MHZ19Component),
cv.Required(CONF_CO2): sensor.sensor_schema( cv.Required(CONF_CO2): sensor.sensor_schema(
UNIT_PARTS_PER_MILLION, ICON_MOLECULE_CO2, 0, DEVICE_CLASS_EMPTY UNIT_PARTS_PER_MILLION,
ICON_MOLECULE_CO2,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 0, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
0,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_AUTOMATIC_BASELINE_CALIBRATION): cv.boolean, cv.Optional(CONF_AUTOMATIC_BASELINE_CALIBRATION): cv.boolean,
} }

View file

@ -3,6 +3,7 @@ import esphome.config_validation as cv
import esphome.codegen as cg import esphome.codegen as cg
from esphome.const import ( from esphome.const import (
CONF_ID, CONF_ID,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
UNIT_WATT, UNIT_WATT,
@ -36,13 +37,21 @@ CONFIG_SCHEMA = cv.All(
cv.Optional(CONF_SWING_HORIZONTAL, default=False): cv.boolean, cv.Optional(CONF_SWING_HORIZONTAL, default=False): cv.boolean,
cv.Optional(CONF_SWING_BOTH, default=False): cv.boolean, cv.Optional(CONF_SWING_BOTH, default=False): cv.boolean,
cv.Optional(CONF_OUTDOOR_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_OUTDOOR_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_THERMOMETER, 0, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_THERMOMETER,
0,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_POWER_USAGE): sensor.sensor_schema( cv.Optional(CONF_POWER_USAGE): sensor.sensor_schema(
UNIT_WATT, ICON_POWER, 0, DEVICE_CLASS_POWER UNIT_WATT, ICON_POWER, 0, DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_HUMIDITY_SETPOINT): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY_SETPOINT): sensor.sensor_schema(
UNIT_PERCENT, ICON_WATER_PERCENT, 0, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_WATER_PERCENT,
0,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
} }
).extend(cv.COMPONENT_SCHEMA) ).extend(cv.COMPONENT_SCHEMA)

View file

@ -8,6 +8,7 @@ from esphome.const import (
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_BRIEFCASE_DOWNLOAD, ICON_BRIEFCASE_DOWNLOAD,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_METER_PER_SECOND_SQUARED, UNIT_METER_PER_SECOND_SQUARED,
ICON_SCREEN_ROTATION, ICON_SCREEN_ROTATION,
UNIT_DEGREE_PER_SECOND, UNIT_DEGREE_PER_SECOND,
@ -29,13 +30,21 @@ MPU6050Component = mpu6050_ns.class_(
) )
accel_schema = sensor.sensor_schema( accel_schema = sensor.sensor_schema(
UNIT_METER_PER_SECOND_SQUARED, ICON_BRIEFCASE_DOWNLOAD, 2, DEVICE_CLASS_EMPTY UNIT_METER_PER_SECOND_SQUARED,
ICON_BRIEFCASE_DOWNLOAD,
2,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
) )
gyro_schema = sensor.sensor_schema( gyro_schema = sensor.sensor_schema(
UNIT_DEGREE_PER_SECOND, ICON_SCREEN_ROTATION, 2, DEVICE_CLASS_EMPTY UNIT_DEGREE_PER_SECOND,
ICON_SCREEN_ROTATION,
2,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
) )
temperature_schema = sensor.sensor_schema( temperature_schema = sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT
) )
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (

View file

@ -5,6 +5,7 @@ from esphome.const import (
CONF_ID, CONF_ID,
CONF_QOS, CONF_QOS,
CONF_TOPIC, CONF_TOPIC,
STATE_CLASS_NONE,
UNIT_EMPTY, UNIT_EMPTY,
ICON_EMPTY, ICON_EMPTY,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
@ -19,7 +20,9 @@ MQTTSubscribeSensor = mqtt_subscribe_ns.class_(
) )
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_EMPTY, ICON_EMPTY, 1, DEVICE_CLASS_EMPTY) sensor.sensor_schema(
UNIT_EMPTY, ICON_EMPTY, 1, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(MQTTSubscribeSensor), cv.GenerateID(): cv.declare_id(MQTTSubscribeSensor),

View file

@ -8,6 +8,7 @@ from esphome.const import (
DEVICE_CLASS_PRESSURE, DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
ICON_GAUGE, ICON_GAUGE,
UNIT_HECTOPASCAL, UNIT_HECTOPASCAL,
@ -25,10 +26,18 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(MS5611Component), cv.GenerateID(): cv.declare_id(MS5611Component),
cv.Required(CONF_TEMPERATURE): sensor.sensor_schema( cv.Required(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Required(CONF_PRESSURE): sensor.sensor_schema( cv.Required(CONF_PRESSURE): sensor.sensor_schema(
UNIT_HECTOPASCAL, ICON_GAUGE, 1, DEVICE_CLASS_PRESSURE UNIT_HECTOPASCAL,
ICON_GAUGE,
1,
DEVICE_CLASS_PRESSURE,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -13,6 +13,7 @@ from esphome.const import (
CONF_VALUE, CONF_VALUE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
) )
@ -118,7 +119,9 @@ def process_calibration(value):
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE) sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(NTC), cv.GenerateID(): cv.declare_id(NTC),

View file

@ -4,6 +4,7 @@ from esphome.components import sensor
from esphome.const import ( from esphome.const import (
CONF_ID, CONF_ID,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_PERCENT, UNIT_PERCENT,
ICON_GAUGE, ICON_GAUGE,
CONF_TYPE, CONF_TYPE,
@ -28,7 +29,9 @@ PID_CLIMATE_SENSOR_TYPES = {
CONF_CLIMATE_ID = "climate_id" CONF_CLIMATE_ID = "climate_id"
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_PERCENT, ICON_GAUGE, 1, DEVICE_CLASS_EMPTY) sensor.sensor_schema(
UNIT_PERCENT, ICON_GAUGE, 1, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(PIDClimateSensor), cv.GenerateID(): cv.declare_id(PIDClimateSensor),

View file

@ -15,6 +15,7 @@ from esphome.const import (
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
@ -66,30 +67,42 @@ CONFIG_SCHEMA = (
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
0, 0,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PM_2_5): sensor.sensor_schema( cv.Optional(CONF_PM_2_5): sensor.sensor_schema(
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
0, 0,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PM_10_0): sensor.sensor_schema( cv.Optional(CONF_PM_10_0): sensor.sensor_schema(
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
0, 0,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 1, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
1,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_FORMALDEHYDE): sensor.sensor_schema( cv.Optional(CONF_FORMALDEHYDE): sensor.sensor_schema(
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
0, 0,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -13,6 +13,8 @@ from esphome.const import (
CONF_TOTAL, CONF_TOTAL,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
ICON_PULSE, ICON_PULSE,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_NONE,
UNIT_PULSES_PER_MINUTE, UNIT_PULSES_PER_MINUTE,
UNIT_PULSES, UNIT_PULSES,
) )
@ -64,7 +66,13 @@ def validate_count_mode(value):
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_PULSES_PER_MINUTE, ICON_PULSE, 2, DEVICE_CLASS_EMPTY) sensor.sensor_schema(
UNIT_PULSES_PER_MINUTE,
ICON_PULSE,
2,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(PulseCounterSensor), cv.GenerateID(): cv.declare_id(PulseCounterSensor),
@ -86,7 +94,7 @@ CONFIG_SCHEMA = (
), ),
cv.Optional(CONF_INTERNAL_FILTER, default="13us"): validate_internal_filter, cv.Optional(CONF_INTERNAL_FILTER, default="13us"): validate_internal_filter,
cv.Optional(CONF_TOTAL): sensor.sensor_schema( cv.Optional(CONF_TOTAL): sensor.sensor_schema(
UNIT_PULSES, ICON_PULSE, 0, DEVICE_CLASS_EMPTY UNIT_PULSES, ICON_PULSE, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
), ),
} }
) )

View file

@ -11,6 +11,8 @@ from esphome.const import (
CONF_TOTAL, CONF_TOTAL,
CONF_VALUE, CONF_VALUE,
ICON_PULSE, ICON_PULSE,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_NONE,
UNIT_PULSES, UNIT_PULSES,
UNIT_PULSES_PER_MINUTE, UNIT_PULSES_PER_MINUTE,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
@ -49,7 +51,7 @@ def validate_pulse_meter_pin(value):
CONFIG_SCHEMA = sensor.sensor_schema( CONFIG_SCHEMA = sensor.sensor_schema(
UNIT_PULSES_PER_MINUTE, ICON_PULSE, 2, DEVICE_CLASS_EMPTY UNIT_PULSES_PER_MINUTE, ICON_PULSE, 2, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT
).extend( ).extend(
{ {
cv.GenerateID(): cv.declare_id(PulseMeterSensor), cv.GenerateID(): cv.declare_id(PulseMeterSensor),
@ -57,7 +59,7 @@ CONFIG_SCHEMA = sensor.sensor_schema(
cv.Optional(CONF_INTERNAL_FILTER, default="13us"): validate_internal_filter, cv.Optional(CONF_INTERNAL_FILTER, default="13us"): validate_internal_filter,
cv.Optional(CONF_TIMEOUT, default="5min"): validate_timeout, cv.Optional(CONF_TIMEOUT, default="5min"): validate_timeout,
cv.Optional(CONF_TOTAL): sensor.sensor_schema( cv.Optional(CONF_TOTAL): sensor.sensor_schema(
UNIT_PULSES, ICON_PULSE, 0, DEVICE_CLASS_EMPTY UNIT_PULSES, ICON_PULSE, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
), ),
} }
) )

View file

@ -2,7 +2,14 @@ import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome import pins from esphome import pins
from esphome.components import sensor from esphome.components import sensor
from esphome.const import CONF_ID, CONF_PIN, DEVICE_CLASS_EMPTY, UNIT_SECOND, ICON_TIMER from esphome.const import (
CONF_ID,
CONF_PIN,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_SECOND,
ICON_TIMER,
)
pulse_width_ns = cg.esphome_ns.namespace("pulse_width") pulse_width_ns = cg.esphome_ns.namespace("pulse_width")
@ -11,7 +18,9 @@ PulseWidthSensor = pulse_width_ns.class_(
) )
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_SECOND, ICON_TIMER, 3, DEVICE_CLASS_EMPTY) sensor.sensor_schema(
UNIT_SECOND, ICON_TIMER, 3, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(PulseWidthSensor), cv.GenerateID(): cv.declare_id(PulseWidthSensor),

View file

@ -12,6 +12,8 @@ from esphome.const import (
DEVICE_CLASS_POWER, DEVICE_CLASS_POWER,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_NONE,
UNIT_VOLT, UNIT_VOLT,
UNIT_AMPERE, UNIT_AMPERE,
UNIT_WATT, UNIT_WATT,
@ -28,16 +30,24 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(PZEM004T), cv.GenerateID(): cv.declare_id(PZEM004T),
cv.Optional(CONF_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_VOLTAGE): sensor.sensor_schema(
UNIT_VOLT, ICON_EMPTY, 1, DEVICE_CLASS_VOLTAGE UNIT_VOLT, ICON_EMPTY, 1, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_CURRENT): sensor.sensor_schema( cv.Optional(CONF_CURRENT): sensor.sensor_schema(
UNIT_AMPERE, ICON_EMPTY, 2, DEVICE_CLASS_CURRENT UNIT_AMPERE,
ICON_EMPTY,
2,
DEVICE_CLASS_CURRENT,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_POWER): sensor.sensor_schema( cv.Optional(CONF_POWER): sensor.sensor_schema(
UNIT_WATT, ICON_EMPTY, 0, DEVICE_CLASS_POWER UNIT_WATT, ICON_EMPTY, 0, DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_ENERGY): sensor.sensor_schema( cv.Optional(CONF_ENERGY): sensor.sensor_schema(
UNIT_WATT_HOURS, ICON_EMPTY, 0, DEVICE_CLASS_ENERGY UNIT_WATT_HOURS,
ICON_EMPTY,
0,
DEVICE_CLASS_ENERGY,
STATE_CLASS_NONE,
), ),
} }
) )

View file

@ -17,6 +17,8 @@ from esphome.const import (
DEVICE_CLASS_ENERGY, DEVICE_CLASS_ENERGY,
ICON_EMPTY, ICON_EMPTY,
ICON_CURRENT_AC, ICON_CURRENT_AC,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_NONE,
UNIT_HERTZ, UNIT_HERTZ,
UNIT_VOLT, UNIT_VOLT,
UNIT_AMPERE, UNIT_AMPERE,
@ -35,22 +37,38 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(PZEMAC), cv.GenerateID(): cv.declare_id(PZEMAC),
cv.Optional(CONF_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_VOLTAGE): sensor.sensor_schema(
UNIT_VOLT, ICON_EMPTY, 1, DEVICE_CLASS_VOLTAGE UNIT_VOLT, ICON_EMPTY, 1, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_CURRENT): sensor.sensor_schema( cv.Optional(CONF_CURRENT): sensor.sensor_schema(
UNIT_AMPERE, ICON_EMPTY, 3, DEVICE_CLASS_CURRENT UNIT_AMPERE,
ICON_EMPTY,
3,
DEVICE_CLASS_CURRENT,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_POWER): sensor.sensor_schema( cv.Optional(CONF_POWER): sensor.sensor_schema(
UNIT_WATT, ICON_EMPTY, 2, DEVICE_CLASS_POWER UNIT_WATT, ICON_EMPTY, 2, DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_ENERGY): sensor.sensor_schema( cv.Optional(CONF_ENERGY): sensor.sensor_schema(
UNIT_WATT_HOURS, ICON_EMPTY, 0, DEVICE_CLASS_ENERGY UNIT_WATT_HOURS,
ICON_EMPTY,
0,
DEVICE_CLASS_ENERGY,
STATE_CLASS_NONE,
), ),
cv.Optional(CONF_FREQUENCY): sensor.sensor_schema( cv.Optional(CONF_FREQUENCY): sensor.sensor_schema(
UNIT_HERTZ, ICON_CURRENT_AC, 1, DEVICE_CLASS_EMPTY UNIT_HERTZ,
ICON_CURRENT_AC,
1,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_POWER_FACTOR): sensor.sensor_schema( cv.Optional(CONF_POWER_FACTOR): sensor.sensor_schema(
UNIT_EMPTY, ICON_EMPTY, 2, DEVICE_CLASS_POWER_FACTOR UNIT_EMPTY,
ICON_EMPTY,
2,
DEVICE_CLASS_POWER_FACTOR,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -10,6 +10,7 @@ from esphome.const import (
DEVICE_CLASS_POWER, DEVICE_CLASS_POWER,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_VOLT, UNIT_VOLT,
UNIT_AMPERE, UNIT_AMPERE,
UNIT_WATT, UNIT_WATT,
@ -25,13 +26,17 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(PZEMDC), cv.GenerateID(): cv.declare_id(PZEMDC),
cv.Optional(CONF_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_VOLTAGE): sensor.sensor_schema(
UNIT_VOLT, ICON_EMPTY, 1, DEVICE_CLASS_VOLTAGE UNIT_VOLT, ICON_EMPTY, 1, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_CURRENT): sensor.sensor_schema( cv.Optional(CONF_CURRENT): sensor.sensor_schema(
UNIT_AMPERE, ICON_EMPTY, 3, DEVICE_CLASS_CURRENT UNIT_AMPERE,
ICON_EMPTY,
3,
DEVICE_CLASS_CURRENT,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_POWER): sensor.sensor_schema( cv.Optional(CONF_POWER): sensor.sensor_schema(
UNIT_WATT, ICON_EMPTY, 1, DEVICE_CLASS_POWER UNIT_WATT, ICON_EMPTY, 1, DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT
), ),
} }
) )

View file

@ -8,6 +8,8 @@ from esphome.const import (
CONF_RANGE, CONF_RANGE,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
ICON_MAGNET, ICON_MAGNET,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_NONE,
UNIT_MICROTESLA, UNIT_MICROTESLA,
UNIT_DEGREES, UNIT_DEGREES,
ICON_SCREEN_ROTATION, ICON_SCREEN_ROTATION,
@ -69,10 +71,10 @@ def validate_enum(enum_values, units=None, int=True):
field_strength_schema = sensor.sensor_schema( field_strength_schema = sensor.sensor_schema(
UNIT_MICROTESLA, ICON_MAGNET, 1, DEVICE_CLASS_EMPTY UNIT_MICROTESLA, ICON_MAGNET, 1, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT
) )
heading_schema = sensor.sensor_schema( heading_schema = sensor.sensor_schema(
UNIT_DEGREES, ICON_SCREEN_ROTATION, 1, DEVICE_CLASS_EMPTY UNIT_DEGREES, ICON_SCREEN_ROTATION, 1, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
) )
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (

View file

@ -1,7 +1,14 @@
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.components import sensor from esphome.components import sensor
from esphome.const import CONF_SENSOR, DEVICE_CLASS_EMPTY, UNIT_OHM, ICON_FLASH, CONF_ID from esphome.const import (
CONF_SENSOR,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_OHM,
ICON_FLASH,
CONF_ID,
)
resistance_ns = cg.esphome_ns.namespace("resistance") resistance_ns = cg.esphome_ns.namespace("resistance")
ResistanceSensor = resistance_ns.class_("ResistanceSensor", cg.Component, sensor.Sensor) ResistanceSensor = resistance_ns.class_("ResistanceSensor", cg.Component, sensor.Sensor)
@ -17,7 +24,9 @@ CONFIGURATIONS = {
} }
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_OHM, ICON_FLASH, 1, DEVICE_CLASS_EMPTY) sensor.sensor_schema(
UNIT_OHM, ICON_FLASH, 1, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(ResistanceSensor), cv.GenerateID(): cv.declare_id(ResistanceSensor),

View file

@ -8,6 +8,7 @@ from esphome.const import (
CONF_MIN_VALUE, CONF_MIN_VALUE,
CONF_MAX_VALUE, CONF_MAX_VALUE,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_NONE,
UNIT_STEPS, UNIT_STEPS,
ICON_ROTATE_RIGHT, ICON_ROTATE_RIGHT,
CONF_VALUE, CONF_VALUE,
@ -56,7 +57,9 @@ def validate_min_max_value(config):
CONFIG_SCHEMA = cv.All( CONFIG_SCHEMA = cv.All(
sensor.sensor_schema(UNIT_STEPS, ICON_ROTATE_RIGHT, 0, DEVICE_CLASS_EMPTY) sensor.sensor_schema(
UNIT_STEPS, ICON_ROTATE_RIGHT, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(RotaryEncoderSensor), cv.GenerateID(): cv.declare_id(RotaryEncoderSensor),

View file

@ -21,6 +21,8 @@ from esphome.const import (
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_NONE,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
UNIT_VOLT, UNIT_VOLT,
@ -50,37 +52,69 @@ CONFIG_SCHEMA = (
cv.GenerateID(): cv.declare_id(RuuviTag), cv.GenerateID(): cv.declare_id(RuuviTag),
cv.Required(CONF_MAC_ADDRESS): cv.mac_address, cv.Required(CONF_MAC_ADDRESS): cv.mac_address,
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 2, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
2,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 2, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
2,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PRESSURE): sensor.sensor_schema( cv.Optional(CONF_PRESSURE): sensor.sensor_schema(
UNIT_HECTOPASCAL, ICON_EMPTY, 2, DEVICE_CLASS_PRESSURE UNIT_HECTOPASCAL,
ICON_EMPTY,
2,
DEVICE_CLASS_PRESSURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_ACCELERATION): sensor.sensor_schema( cv.Optional(CONF_ACCELERATION): sensor.sensor_schema(
UNIT_G, ICON_ACCELERATION, 3, DEVICE_CLASS_EMPTY UNIT_G,
ICON_ACCELERATION,
3,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_ACCELERATION_X): sensor.sensor_schema( cv.Optional(CONF_ACCELERATION_X): sensor.sensor_schema(
UNIT_G, ICON_ACCELERATION_X, 3, DEVICE_CLASS_EMPTY UNIT_G,
ICON_ACCELERATION_X,
3,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_ACCELERATION_Y): sensor.sensor_schema( cv.Optional(CONF_ACCELERATION_Y): sensor.sensor_schema(
UNIT_G, ICON_ACCELERATION_Y, 3, DEVICE_CLASS_EMPTY UNIT_G,
ICON_ACCELERATION_Y,
3,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_ACCELERATION_Z): sensor.sensor_schema( cv.Optional(CONF_ACCELERATION_Z): sensor.sensor_schema(
UNIT_G, ICON_ACCELERATION_Z, 3, DEVICE_CLASS_EMPTY UNIT_G,
ICON_ACCELERATION_Z,
3,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_BATTERY_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_BATTERY_VOLTAGE): sensor.sensor_schema(
UNIT_VOLT, ICON_EMPTY, 3, DEVICE_CLASS_VOLTAGE UNIT_VOLT, ICON_EMPTY, 3, DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT
), ),
cv.Optional(CONF_TX_POWER): sensor.sensor_schema( cv.Optional(CONF_TX_POWER): sensor.sensor_schema(
UNIT_DECIBEL_MILLIWATT, ICON_EMPTY, 0, DEVICE_CLASS_SIGNAL_STRENGTH UNIT_DECIBEL_MILLIWATT,
ICON_EMPTY,
0,
DEVICE_CLASS_SIGNAL_STRENGTH,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_MOVEMENT_COUNTER): sensor.sensor_schema( cv.Optional(CONF_MOVEMENT_COUNTER): sensor.sensor_schema(
UNIT_EMPTY, ICON_GAUGE, 0, DEVICE_CLASS_EMPTY UNIT_EMPTY, ICON_GAUGE, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
), ),
cv.Optional(CONF_MEASUREMENT_SEQUENCE_NUMBER): sensor.sensor_schema( cv.Optional(CONF_MEASUREMENT_SEQUENCE_NUMBER): sensor.sensor_schema(
UNIT_EMPTY, ICON_GAUGE, 0, DEVICE_CLASS_EMPTY UNIT_EMPTY, ICON_GAUGE, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
), ),
} }
) )

View file

@ -10,6 +10,7 @@ from esphome.const import (
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_PARTS_PER_MILLION, UNIT_PARTS_PER_MILLION,
ICON_MOLECULE_CO2, ICON_MOLECULE_CO2,
UNIT_CELSIUS, UNIT_CELSIUS,
@ -32,13 +33,25 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(SCD30Component), cv.GenerateID(): cv.declare_id(SCD30Component),
cv.Optional(CONF_CO2): sensor.sensor_schema( cv.Optional(CONF_CO2): sensor.sensor_schema(
UNIT_PARTS_PER_MILLION, ICON_MOLECULE_CO2, 0, DEVICE_CLASS_EMPTY UNIT_PARTS_PER_MILLION,
ICON_MOLECULE_CO2,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 1, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
1,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_AUTOMATIC_SELF_CALIBRATION, default=True): cv.boolean, cv.Optional(CONF_AUTOMATIC_SELF_CALIBRATION, default=True): cv.boolean,
cv.Optional(CONF_ALTITUDE_COMPENSATION): cv.All( cv.Optional(CONF_ALTITUDE_COMPENSATION): cv.All(

View file

@ -17,6 +17,7 @@ from esphome.const import (
CONF_REACTIVE_POWER, CONF_REACTIVE_POWER,
CONF_VOLTAGE, CONF_VOLTAGE,
DEVICE_CLASS_CURRENT, DEVICE_CLASS_CURRENT,
DEVICE_CLASS_EMPTY,
DEVICE_CLASS_ENERGY, DEVICE_CLASS_ENERGY,
DEVICE_CLASS_POWER, DEVICE_CLASS_POWER,
DEVICE_CLASS_POWER_FACTOR, DEVICE_CLASS_POWER_FACTOR,
@ -24,6 +25,8 @@ from esphome.const import (
ICON_CURRENT_AC, ICON_CURRENT_AC,
ICON_EMPTY, ICON_EMPTY,
ICON_FLASH, ICON_FLASH,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_NONE,
UNIT_AMPERE, UNIT_AMPERE,
UNIT_DEGREES, UNIT_DEGREES,
UNIT_EMPTY, UNIT_EMPTY,
@ -45,19 +48,23 @@ SDMMeter = sdm_meter_ns.class_("SDMMeter", cg.PollingComponent, modbus.ModbusDev
PHASE_SENSORS = { PHASE_SENSORS = {
CONF_VOLTAGE: sensor.sensor_schema(UNIT_VOLT, ICON_EMPTY, 2, DEVICE_CLASS_VOLTAGE), CONF_VOLTAGE: sensor.sensor_schema(UNIT_VOLT, ICON_EMPTY, 2, DEVICE_CLASS_VOLTAGE),
CONF_CURRENT: sensor.sensor_schema( CONF_CURRENT: sensor.sensor_schema(
UNIT_AMPERE, ICON_EMPTY, 3, DEVICE_CLASS_CURRENT UNIT_AMPERE, ICON_EMPTY, 3, DEVICE_CLASS_CURRENT, STATE_CLASS_MEASUREMENT
), ),
CONF_ACTIVE_POWER: sensor.sensor_schema( CONF_ACTIVE_POWER: sensor.sensor_schema(
UNIT_WATT, ICON_EMPTY, 2, DEVICE_CLASS_POWER UNIT_WATT, ICON_EMPTY, 2, DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT
), ),
CONF_APPARENT_POWER: sensor.sensor_schema( CONF_APPARENT_POWER: sensor.sensor_schema(
UNIT_VOLT_AMPS, ICON_EMPTY, 2, DEVICE_CLASS_POWER UNIT_VOLT_AMPS, ICON_EMPTY, 2, DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT
), ),
CONF_REACTIVE_POWER: sensor.sensor_schema( CONF_REACTIVE_POWER: sensor.sensor_schema(
UNIT_VOLT_AMPS_REACTIVE, ICON_EMPTY, 2, DEVICE_CLASS_POWER UNIT_VOLT_AMPS_REACTIVE,
ICON_EMPTY,
2,
DEVICE_CLASS_POWER,
STATE_CLASS_MEASUREMENT,
), ),
CONF_POWER_FACTOR: sensor.sensor_schema( CONF_POWER_FACTOR: sensor.sensor_schema(
UNIT_EMPTY, ICON_EMPTY, 3, DEVICE_CLASS_POWER_FACTOR UNIT_EMPTY, ICON_EMPTY, 3, DEVICE_CLASS_POWER_FACTOR, STATE_CLASS_MEASUREMENT
), ),
CONF_PHASE_ANGLE: sensor.sensor_schema(UNIT_DEGREES, ICON_FLASH, 3), CONF_PHASE_ANGLE: sensor.sensor_schema(UNIT_DEGREES, ICON_FLASH, 3),
} }
@ -74,19 +81,31 @@ CONFIG_SCHEMA = (
cv.Optional(CONF_PHASE_B): PHASE_SCHEMA, cv.Optional(CONF_PHASE_B): PHASE_SCHEMA,
cv.Optional(CONF_PHASE_C): PHASE_SCHEMA, cv.Optional(CONF_PHASE_C): PHASE_SCHEMA,
cv.Optional(CONF_FREQUENCY): sensor.sensor_schema( cv.Optional(CONF_FREQUENCY): sensor.sensor_schema(
UNIT_HERTZ, ICON_CURRENT_AC, 3 UNIT_HERTZ,
ICON_CURRENT_AC,
3,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_IMPORT_ACTIVE_ENERGY): sensor.sensor_schema( cv.Optional(CONF_IMPORT_ACTIVE_ENERGY): sensor.sensor_schema(
UNIT_WATT_HOURS, ICON_EMPTY, 2, DEVICE_CLASS_ENERGY UNIT_WATT_HOURS, ICON_EMPTY, 2, DEVICE_CLASS_ENERGY, STATE_CLASS_NONE
), ),
cv.Optional(CONF_EXPORT_ACTIVE_ENERGY): sensor.sensor_schema( cv.Optional(CONF_EXPORT_ACTIVE_ENERGY): sensor.sensor_schema(
UNIT_WATT_HOURS, ICON_EMPTY, 2, DEVICE_CLASS_ENERGY UNIT_WATT_HOURS, ICON_EMPTY, 2, DEVICE_CLASS_ENERGY, STATE_CLASS_NONE
), ),
cv.Optional(CONF_IMPORT_REACTIVE_ENERGY): sensor.sensor_schema( cv.Optional(CONF_IMPORT_REACTIVE_ENERGY): sensor.sensor_schema(
UNIT_VOLT_AMPS_REACTIVE_HOURS, ICON_EMPTY, 2, DEVICE_CLASS_ENERGY UNIT_VOLT_AMPS_REACTIVE_HOURS,
ICON_EMPTY,
2,
DEVICE_CLASS_ENERGY,
STATE_CLASS_NONE,
), ),
cv.Optional(CONF_EXPORT_REACTIVE_ENERGY): sensor.sensor_schema( cv.Optional(CONF_EXPORT_REACTIVE_ENERGY): sensor.sensor_schema(
UNIT_VOLT_AMPS_REACTIVE_HOURS, ICON_EMPTY, 2, DEVICE_CLASS_ENERGY UNIT_VOLT_AMPS_REACTIVE_HOURS,
ICON_EMPTY,
2,
DEVICE_CLASS_ENERGY,
STATE_CLASS_NONE,
), ),
} }
) )

View file

@ -8,6 +8,7 @@ from esphome.const import (
CONF_RX_ONLY, CONF_RX_ONLY,
CONF_UPDATE_INTERVAL, CONF_UPDATE_INTERVAL,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
) )
@ -42,12 +43,14 @@ CONFIG_SCHEMA = cv.All(
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
1, 1,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PM_10_0): sensor.sensor_schema( cv.Optional(CONF_PM_10_0): sensor.sensor_schema(
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
1, 1,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_RX_ONLY, default=False): cv.boolean, cv.Optional(CONF_RX_ONLY, default=False): cv.boolean,
cv.Optional(CONF_UPDATE_INTERVAL): cv.positive_time_period_minutes, cv.Optional(CONF_UPDATE_INTERVAL): cv.positive_time_period_minutes,

View file

@ -8,6 +8,7 @@ from esphome.const import (
CONF_ID, CONF_ID,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
ICON_MOLECULE_CO2, ICON_MOLECULE_CO2,
STATE_CLASS_MEASUREMENT,
UNIT_PARTS_PER_MILLION, UNIT_PARTS_PER_MILLION,
) )
@ -38,7 +39,11 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(SenseAirComponent), cv.GenerateID(): cv.declare_id(SenseAirComponent),
cv.Required(CONF_CO2): sensor.sensor_schema( cv.Required(CONF_CO2): sensor.sensor_schema(
UNIT_PARTS_PER_MILLION, ICON_MOLECULE_CO2, 0, DEVICE_CLASS_EMPTY UNIT_PARTS_PER_MILLION,
ICON_MOLECULE_CO2,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -22,6 +22,7 @@ from esphome.const import (
CONF_ON_VALUE_RANGE, CONF_ON_VALUE_RANGE,
CONF_SEND_EVERY, CONF_SEND_EVERY,
CONF_SEND_FIRST_AT, CONF_SEND_FIRST_AT,
CONF_STATE_CLASS,
CONF_TO, CONF_TO,
CONF_TRIGGER_ID, CONF_TRIGGER_ID,
CONF_UNIT_OF_MEASUREMENT, CONF_UNIT_OF_MEASUREMENT,
@ -46,6 +47,7 @@ from esphome.const import (
DEVICE_CLASS_PRESSURE, DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TIMESTAMP, DEVICE_CLASS_TIMESTAMP,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
STATE_CLASS_NONE,
) )
from esphome.core import CORE, coroutine_with_priority from esphome.core import CORE, coroutine_with_priority
from esphome.util import Registry from esphome.util import Registry
@ -69,6 +71,14 @@ DEVICE_CLASSES = [
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
] ]
sensor_ns = cg.esphome_ns.namespace("sensor")
StateClasses = sensor_ns.enum("StateClass")
STATE_CLASSES = {
"": StateClasses.STATE_CLASS_NONE,
"measurement": StateClasses.STATE_CLASS_MEASUREMENT,
}
validate_state_class = cv.enum(STATE_CLASSES, lower=True, space="_")
IS_PLATFORM_COMPONENT = True IS_PLATFORM_COMPONENT = True
@ -157,6 +167,7 @@ SENSOR_SCHEMA = cv.MQTT_COMPONENT_SCHEMA.extend(
cv.Optional(CONF_ICON): icon, cv.Optional(CONF_ICON): icon,
cv.Optional(CONF_ACCURACY_DECIMALS): accuracy_decimals, cv.Optional(CONF_ACCURACY_DECIMALS): accuracy_decimals,
cv.Optional(CONF_DEVICE_CLASS): device_class, cv.Optional(CONF_DEVICE_CLASS): device_class,
cv.Optional(CONF_STATE_CLASS): validate_state_class,
cv.Optional(CONF_FORCE_UPDATE, default=False): cv.boolean, cv.Optional(CONF_FORCE_UPDATE, default=False): cv.boolean,
cv.Optional(CONF_EXPIRE_AFTER): cv.All( cv.Optional(CONF_EXPIRE_AFTER): cv.All(
cv.requires_component("mqtt"), cv.requires_component("mqtt"),
@ -190,6 +201,7 @@ def sensor_schema(
icon_: str, icon_: str,
accuracy_decimals_: int, accuracy_decimals_: int,
device_class_: Optional[str] = DEVICE_CLASS_EMPTY, device_class_: Optional[str] = DEVICE_CLASS_EMPTY,
state_class_: Optional[str] = STATE_CLASS_NONE,
) -> cv.Schema: ) -> cv.Schema:
schema = SENSOR_SCHEMA schema = SENSOR_SCHEMA
if unit_of_measurement_ != UNIT_EMPTY: if unit_of_measurement_ != UNIT_EMPTY:
@ -214,6 +226,10 @@ def sensor_schema(
schema = schema.extend( schema = schema.extend(
{cv.Optional(CONF_DEVICE_CLASS, default=device_class_): device_class} {cv.Optional(CONF_DEVICE_CLASS, default=device_class_): device_class}
) )
if state_class_ != STATE_CLASS_NONE:
schema = schema.extend(
{cv.Optional(CONF_STATE_CLASS, default=state_class_): validate_state_class}
)
return schema return schema
@ -455,6 +471,8 @@ async def setup_sensor_core_(var, config):
cg.add(var.set_internal(config[CONF_INTERNAL])) cg.add(var.set_internal(config[CONF_INTERNAL]))
if CONF_DEVICE_CLASS in config: if CONF_DEVICE_CLASS in config:
cg.add(var.set_device_class(config[CONF_DEVICE_CLASS])) cg.add(var.set_device_class(config[CONF_DEVICE_CLASS]))
if CONF_STATE_CLASS in config:
cg.add(var.set_state_class(config[CONF_STATE_CLASS]))
if CONF_UNIT_OF_MEASUREMENT in config: if CONF_UNIT_OF_MEASUREMENT in config:
cg.add(var.set_unit_of_measurement(config[CONF_UNIT_OF_MEASUREMENT])) cg.add(var.set_unit_of_measurement(config[CONF_UNIT_OF_MEASUREMENT]))
if CONF_ICON in config: if CONF_ICON in config:

View file

@ -6,6 +6,16 @@ namespace sensor {
static const char *TAG = "sensor"; static const char *TAG = "sensor";
const char *state_class_to_string(StateClass state_class) {
switch (state_class) {
case STATE_CLASS_MEASUREMENT:
return "measurement";
case STATE_CLASS_NONE:
default:
return "";
}
}
void Sensor::publish_state(float state) { void Sensor::publish_state(float state) {
this->raw_state = state; this->raw_state = state;
this->raw_callback_.call(state); this->raw_callback_.call(state);
@ -47,6 +57,14 @@ std::string Sensor::get_device_class() {
return this->device_class(); return this->device_class();
} }
std::string Sensor::device_class() { return ""; } std::string Sensor::device_class() { return ""; }
void Sensor::set_state_class(StateClass state_class) { this->state_class = state_class; }
void Sensor::set_state_class(const std::string &state_class) {
if (str_equals_case_insensitive(state_class, "measurement")) {
this->state_class = STATE_CLASS_MEASUREMENT;
} else {
ESP_LOGW(TAG, "'%s' - Unrecognized state class %s", this->get_name().c_str(), state_class.c_str());
}
}
std::string Sensor::get_unit_of_measurement() { std::string Sensor::get_unit_of_measurement() {
if (this->unit_of_measurement_.has_value()) if (this->unit_of_measurement_.has_value())
return *this->unit_of_measurement_; return *this->unit_of_measurement_;

View file

@ -13,6 +13,7 @@ namespace sensor {
if (!obj->get_device_class().empty()) { \ if (!obj->get_device_class().empty()) { \
ESP_LOGCONFIG(TAG, "%s Device Class: '%s'", prefix, obj->get_device_class().c_str()); \ ESP_LOGCONFIG(TAG, "%s Device Class: '%s'", prefix, obj->get_device_class().c_str()); \
} \ } \
ESP_LOGCONFIG(TAG, "%s State Class: '%s'", prefix, state_class_to_string(obj->state_class)); \
ESP_LOGCONFIG(TAG, "%s Unit of Measurement: '%s'", prefix, obj->get_unit_of_measurement().c_str()); \ ESP_LOGCONFIG(TAG, "%s Unit of Measurement: '%s'", prefix, obj->get_unit_of_measurement().c_str()); \
ESP_LOGCONFIG(TAG, "%s Accuracy Decimals: %d", prefix, obj->get_accuracy_decimals()); \ ESP_LOGCONFIG(TAG, "%s Accuracy Decimals: %d", prefix, obj->get_accuracy_decimals()); \
if (!obj->get_icon().empty()) { \ if (!obj->get_icon().empty()) { \
@ -26,6 +27,16 @@ namespace sensor {
} \ } \
} }
/**
* Sensor state classes
*/
enum StateClass : uint8_t {
STATE_CLASS_NONE = 0,
STATE_CLASS_MEASUREMENT = 1,
};
const char *state_class_to_string(StateClass state_class);
/** Base-class for all sensors. /** Base-class for all sensors.
* *
* A sensor has unit of measurement and can use publish_state to send out a new value with the specified accuracy. * A sensor has unit of measurement and can use publish_state to send out a new value with the specified accuracy.
@ -139,6 +150,13 @@ class Sensor : public Nameable {
/// Return whether this sensor has gotten a full state (that passed through all filters) yet. /// Return whether this sensor has gotten a full state (that passed through all filters) yet.
bool has_state() const; bool has_state() const;
// The state class of this sensor state
StateClass state_class{STATE_CLASS_NONE};
/// Manually set the Home Assistant state class (see sensor::state_class)
void set_state_class(StateClass state_class);
void set_state_class(const std::string &state_class);
/** Override this to set the Home Assistant device class for this sensor. /** Override this to set the Home Assistant device class for this sensor.
* *
* Return "" to disable this feature. * Return "" to disable this feature.

View file

@ -5,6 +5,7 @@ from esphome.const import (
CONF_ID, CONF_ID,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
ICON_RADIATOR, ICON_RADIATOR,
STATE_CLASS_MEASUREMENT,
UNIT_PARTS_PER_MILLION, UNIT_PARTS_PER_MILLION,
UNIT_PARTS_PER_BILLION, UNIT_PARTS_PER_BILLION,
ICON_MOLECULE_CO2, ICON_MOLECULE_CO2,
@ -30,10 +31,18 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(SGP30Component), cv.GenerateID(): cv.declare_id(SGP30Component),
cv.Required(CONF_ECO2): sensor.sensor_schema( cv.Required(CONF_ECO2): sensor.sensor_schema(
UNIT_PARTS_PER_MILLION, ICON_MOLECULE_CO2, 0, DEVICE_CLASS_EMPTY UNIT_PARTS_PER_MILLION,
ICON_MOLECULE_CO2,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Required(CONF_TVOC): sensor.sensor_schema( cv.Required(CONF_TVOC): sensor.sensor_schema(
UNIT_PARTS_PER_BILLION, ICON_RADIATOR, 0, DEVICE_CLASS_EMPTY UNIT_PARTS_PER_BILLION,
ICON_RADIATOR,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_BASELINE): cv.Schema( cv.Optional(CONF_BASELINE): cv.Schema(
{ {

View file

@ -1,7 +1,13 @@
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.components import i2c, sensor from esphome.components import i2c, sensor
from esphome.const import CONF_ID, DEVICE_CLASS_EMPTY, ICON_RADIATOR, UNIT_EMPTY from esphome.const import (
CONF_ID,
DEVICE_CLASS_EMPTY,
ICON_RADIATOR,
STATE_CLASS_MEASUREMENT,
UNIT_EMPTY,
)
DEPENDENCIES = ["i2c"] DEPENDENCIES = ["i2c"]
@ -19,7 +25,9 @@ CONF_STORE_BASELINE = "store_baseline"
CONF_VOC_BASELINE = "voc_baseline" CONF_VOC_BASELINE = "voc_baseline"
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_EMPTY, ICON_RADIATOR, 0, DEVICE_CLASS_EMPTY) sensor.sensor_schema(
UNIT_EMPTY, ICON_RADIATOR, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(SGP40Component), cv.GenerateID(): cv.declare_id(SGP40Component),

View file

@ -8,6 +8,7 @@ from esphome.const import (
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
) )
@ -24,10 +25,18 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(SHT3XDComponent), cv.GenerateID(): cv.declare_id(SHT3XDComponent),
cv.Required(CONF_TEMPERATURE): sensor.sensor_schema( cv.Required(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Required(CONF_HUMIDITY): sensor.sensor_schema( cv.Required(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 1, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
1,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -5,6 +5,7 @@ from esphome.const import (
CONF_ID, CONF_ID,
CONF_TEMPERATURE, CONF_TEMPERATURE,
CONF_HUMIDITY, CONF_HUMIDITY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
ICON_THERMOMETER, ICON_THERMOMETER,
@ -50,10 +51,18 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(SHT4XComponent), cv.GenerateID(): cv.declare_id(SHT4XComponent),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_THERMOMETER, 2, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_THERMOMETER,
2,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_WATER_PERCENT, 2, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_WATER_PERCENT,
2,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PRECISION, default="High"): cv.enum(PRECISION_OPTIONS), cv.Optional(CONF_PRECISION, default="High"): cv.enum(PRECISION_OPTIONS),
cv.Optional(CONF_HEATER_POWER, default="High"): cv.enum( cv.Optional(CONF_HEATER_POWER, default="High"): cv.enum(

View file

@ -8,6 +8,7 @@ from esphome.const import (
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
) )
@ -24,10 +25,18 @@ CONFIG_SCHEMA = (
{ {
cv.GenerateID(): cv.declare_id(SHTCXComponent), cv.GenerateID(): cv.declare_id(SHTCXComponent),
cv.Required(CONF_TEMPERATURE): sensor.sensor_schema( cv.Required(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Required(CONF_HUMIDITY): sensor.sensor_schema( cv.Required(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 1, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
1,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -13,6 +13,7 @@ from esphome.const import (
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
UNIT_PARTS_PER_MILLION, UNIT_PARTS_PER_MILLION,
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
UNIT_CELSIUS, UNIT_CELSIUS,
@ -34,28 +35,53 @@ CONFIG_SCHEMA = cv.All(
{ {
cv.GenerateID(): cv.declare_id(SM300D2Sensor), cv.GenerateID(): cv.declare_id(SM300D2Sensor),
cv.Optional(CONF_CO2): sensor.sensor_schema( cv.Optional(CONF_CO2): sensor.sensor_schema(
UNIT_PARTS_PER_MILLION, ICON_MOLECULE_CO2, 0, DEVICE_CLASS_EMPTY UNIT_PARTS_PER_MILLION,
ICON_MOLECULE_CO2,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_FORMALDEHYDE): sensor.sensor_schema( cv.Optional(CONF_FORMALDEHYDE): sensor.sensor_schema(
UNIT_MICROGRAMS_PER_CUBIC_METER, ICON_FLASK, 0, DEVICE_CLASS_EMPTY UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_FLASK,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_TVOC): sensor.sensor_schema( cv.Optional(CONF_TVOC): sensor.sensor_schema(
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
0, 0,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PM_2_5): sensor.sensor_schema( cv.Optional(CONF_PM_2_5): sensor.sensor_schema(
UNIT_MICROGRAMS_PER_CUBIC_METER, ICON_GRAIN, 0, DEVICE_CLASS_EMPTY UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_GRAIN,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PM_10_0): sensor.sensor_schema( cv.Optional(CONF_PM_10_0): sensor.sensor_schema(
UNIT_MICROGRAMS_PER_CUBIC_METER, ICON_GRAIN, 0, DEVICE_CLASS_EMPTY UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_GRAIN,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 0, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
0,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 0, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
0,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -14,6 +14,7 @@ from esphome.const import (
CONF_PMC_10_0, CONF_PMC_10_0,
CONF_PM_SIZE, CONF_PM_SIZE,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
UNIT_COUNTS_PER_CUBIC_METER, UNIT_COUNTS_PER_CUBIC_METER,
UNIT_MICROMETER, UNIT_MICROMETER,
@ -36,42 +37,70 @@ CONFIG_SCHEMA = (
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
2, 2,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PM_2_5): sensor.sensor_schema( cv.Optional(CONF_PM_2_5): sensor.sensor_schema(
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
2, 2,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PM_4_0): sensor.sensor_schema( cv.Optional(CONF_PM_4_0): sensor.sensor_schema(
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
2, 2,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PM_10_0): sensor.sensor_schema( cv.Optional(CONF_PM_10_0): sensor.sensor_schema(
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
2, 2,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PMC_0_5): sensor.sensor_schema( cv.Optional(CONF_PMC_0_5): sensor.sensor_schema(
UNIT_COUNTS_PER_CUBIC_METER, ICON_COUNTER, 2, DEVICE_CLASS_EMPTY UNIT_COUNTS_PER_CUBIC_METER,
ICON_COUNTER,
2,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PMC_1_0): sensor.sensor_schema( cv.Optional(CONF_PMC_1_0): sensor.sensor_schema(
UNIT_COUNTS_PER_CUBIC_METER, ICON_COUNTER, 2, DEVICE_CLASS_EMPTY UNIT_COUNTS_PER_CUBIC_METER,
ICON_COUNTER,
2,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PMC_2_5): sensor.sensor_schema( cv.Optional(CONF_PMC_2_5): sensor.sensor_schema(
UNIT_COUNTS_PER_CUBIC_METER, ICON_COUNTER, 2, DEVICE_CLASS_EMPTY UNIT_COUNTS_PER_CUBIC_METER,
ICON_COUNTER,
2,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PMC_4_0): sensor.sensor_schema( cv.Optional(CONF_PMC_4_0): sensor.sensor_schema(
UNIT_COUNTS_PER_CUBIC_METER, ICON_COUNTER, 2, DEVICE_CLASS_EMPTY UNIT_COUNTS_PER_CUBIC_METER,
ICON_COUNTER,
2,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PMC_10_0): sensor.sensor_schema( cv.Optional(CONF_PMC_10_0): sensor.sensor_schema(
UNIT_COUNTS_PER_CUBIC_METER, ICON_COUNTER, 2, DEVICE_CLASS_EMPTY UNIT_COUNTS_PER_CUBIC_METER,
ICON_COUNTER,
2,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PM_SIZE): sensor.sensor_schema( cv.Optional(CONF_PM_SIZE): sensor.sensor_schema(
UNIT_MICROMETER, ICON_RULER, 0, DEVICE_CLASS_EMPTY UNIT_MICROMETER,
ICON_RULER,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -1,7 +1,13 @@
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.components import i2c, sensor from esphome.components import i2c, sensor
from esphome.const import CONF_ID, DEVICE_CLASS_TEMPERATURE, ICON_EMPTY, UNIT_CELSIUS from esphome.const import (
CONF_ID,
DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS,
)
DEPENDENCIES = ["i2c"] DEPENDENCIES = ["i2c"]
@ -12,7 +18,9 @@ STS3XComponent = sts3x_ns.class_(
) )
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE) sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(STS3XComponent), cv.GenerateID(): cv.declare_id(STS3XComponent),

View file

@ -3,6 +3,7 @@ import esphome.config_validation as cv
from esphome.components import sensor from esphome.components import sensor
from esphome.const import ( from esphome.const import (
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_NONE,
UNIT_DEGREES, UNIT_DEGREES,
ICON_WEATHER_SUNSET, ICON_WEATHER_SUNSET,
CONF_ID, CONF_ID,
@ -20,7 +21,9 @@ TYPES = {
} }
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_DEGREES, ICON_WEATHER_SUNSET, 1, DEVICE_CLASS_EMPTY) sensor.sensor_schema(
UNIT_DEGREES, ICON_WEATHER_SUNSET, 1, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(SunSensor), cv.GenerateID(): cv.declare_id(SunSensor),

View file

@ -11,6 +11,7 @@ from esphome.const import (
DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_ILLUMINANCE,
ICON_EMPTY, ICON_EMPTY,
ICON_LIGHTBULB, ICON_LIGHTBULB,
STATE_CLASS_MEASUREMENT,
UNIT_PERCENT, UNIT_PERCENT,
ICON_THERMOMETER, ICON_THERMOMETER,
UNIT_KELVIN, UNIT_KELVIN,
@ -48,13 +49,13 @@ TCS34725_GAINS = {
} }
color_channel_schema = sensor.sensor_schema( color_channel_schema = sensor.sensor_schema(
UNIT_PERCENT, ICON_LIGHTBULB, 1, DEVICE_CLASS_EMPTY UNIT_PERCENT, ICON_LIGHTBULB, 1, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT
) )
color_temperature_schema = sensor.sensor_schema( color_temperature_schema = sensor.sensor_schema(
UNIT_KELVIN, ICON_THERMOMETER, 1, DEVICE_CLASS_EMPTY UNIT_KELVIN, ICON_THERMOMETER, 1, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT
) )
illuminance_schema = sensor.sensor_schema( illuminance_schema = sensor.sensor_schema(
UNIT_LUX, ICON_EMPTY, 1, DEVICE_CLASS_ILLUMINANCE UNIT_LUX, ICON_EMPTY, 1, DEVICE_CLASS_ILLUMINANCE, STATE_CLASS_MEASUREMENT
) )
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (

View file

@ -7,8 +7,9 @@ from esphome.const import (
CONF_LAMBDA, CONF_LAMBDA,
CONF_STATE, CONF_STATE,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
UNIT_EMPTY,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_NONE,
UNIT_EMPTY,
) )
from .. import template_ns from .. import template_ns
@ -17,7 +18,13 @@ TemplateSensor = template_ns.class_(
) )
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_EMPTY, ICON_EMPTY, 1, DEVICE_CLASS_EMPTY) sensor.sensor_schema(
UNIT_EMPTY,
ICON_EMPTY,
1,
DEVICE_CLASS_EMPTY,
STATE_CLASS_NONE,
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(TemplateSensor), cv.GenerateID(): cv.declare_id(TemplateSensor),

View file

@ -10,7 +10,13 @@ https://www.sparkfun.com/datasheets/Sensors/Temperature/tmp102.pdf
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.components import i2c, sensor from esphome.components import i2c, sensor
from esphome.const import CONF_ID, DEVICE_CLASS_TEMPERATURE, ICON_EMPTY, UNIT_CELSIUS from esphome.const import (
CONF_ID,
DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS,
)
CODEOWNERS = ["@timsavage"] CODEOWNERS = ["@timsavage"]
DEPENDENCIES = ["i2c"] DEPENDENCIES = ["i2c"]
@ -21,7 +27,9 @@ TMP102Component = tmp102_ns.class_(
) )
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE) sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(TMP102Component), cv.GenerateID(): cv.declare_id(TMP102Component),

View file

@ -6,6 +6,7 @@ from esphome.const import (
CONF_UPDATE_INTERVAL, CONF_UPDATE_INTERVAL,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
) )
@ -17,7 +18,9 @@ TMP117Component = tmp117_ns.class_(
) )
CONFIG_SCHEMA = cv.All( CONFIG_SCHEMA = cv.All(
sensor.sensor_schema(UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE) sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(TMP117Component), cv.GenerateID(): cv.declare_id(TMP117Component),

View file

@ -1,7 +1,13 @@
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.components import i2c, sensor from esphome.components import i2c, sensor
from esphome.const import CONF_ID, UNIT_METER, ICON_ARROW_EXPAND_VERTICAL from esphome.const import (
CONF_ID,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_METER,
ICON_ARROW_EXPAND_VERTICAL,
)
CODEOWNERS = ["@wstrzalka"] CODEOWNERS = ["@wstrzalka"]
DEPENDENCIES = ["i2c"] DEPENDENCIES = ["i2c"]
@ -12,7 +18,13 @@ TOF10120Sensor = tof10120_ns.class_(
) )
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_METER, ICON_ARROW_EXPAND_VERTICAL, 3) sensor.sensor_schema(
UNIT_METER,
ICON_ARROW_EXPAND_VERTICAL,
3,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
)
.extend({cv.GenerateID(): cv.declare_id(TOF10120Sensor)}) .extend({cv.GenerateID(): cv.declare_id(TOF10120Sensor)})
.extend(cv.polling_component_schema("60s")) .extend(cv.polling_component_schema("60s"))
.extend(i2c.i2c_device_schema(0x52)) .extend(i2c.i2c_device_schema(0x52))

View file

@ -7,6 +7,7 @@ from esphome.const import (
CONF_INTEGRATION_TIME, CONF_INTEGRATION_TIME,
DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_ILLUMINANCE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_LUX, UNIT_LUX,
) )
@ -39,7 +40,9 @@ TSL2561Sensor = tsl2561_ns.class_(
) )
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_LUX, ICON_EMPTY, 1, DEVICE_CLASS_ILLUMINANCE) sensor.sensor_schema(
UNIT_LUX, ICON_EMPTY, 1, DEVICE_CLASS_ILLUMINANCE, STATE_CLASS_MEASUREMENT
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(TSL2561Sensor), cv.GenerateID(): cv.declare_id(TSL2561Sensor),

View file

@ -8,6 +8,8 @@ from esphome.const import (
CONF_PIN, CONF_PIN,
CONF_WIND_DIRECTION_DEGREES, CONF_WIND_DIRECTION_DEGREES,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_NONE,
UNIT_KILOMETER_PER_HOUR, UNIT_KILOMETER_PER_HOUR,
ICON_WEATHER_WINDY, ICON_WEATHER_WINDY,
ICON_SIGN_DIRECTION, ICON_SIGN_DIRECTION,
@ -21,10 +23,14 @@ CONFIG_SCHEMA = cv.Schema(
{ {
cv.GenerateID(): cv.declare_id(Tx20Component), cv.GenerateID(): cv.declare_id(Tx20Component),
cv.Optional(CONF_WIND_SPEED): sensor.sensor_schema( cv.Optional(CONF_WIND_SPEED): sensor.sensor_schema(
UNIT_KILOMETER_PER_HOUR, ICON_WEATHER_WINDY, 1, DEVICE_CLASS_EMPTY UNIT_KILOMETER_PER_HOUR,
ICON_WEATHER_WINDY,
1,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_WIND_DIRECTION_DEGREES): sensor.sensor_schema( cv.Optional(CONF_WIND_DIRECTION_DEGREES): sensor.sensor_schema(
UNIT_DEGREES, ICON_SIGN_DIRECTION, 1, DEVICE_CLASS_EMPTY UNIT_DEGREES, ICON_SIGN_DIRECTION, 1, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
), ),
cv.Required(CONF_PIN): cv.All( cv.Required(CONF_PIN): cv.All(
pins.internal_gpio_input_pin_schema, pins.validate_has_interrupt pins.internal_gpio_input_pin_schema, pins.validate_has_interrupt

View file

@ -8,6 +8,7 @@ from esphome.const import (
CONF_TRIGGER_PIN, CONF_TRIGGER_PIN,
CONF_TIMEOUT, CONF_TIMEOUT,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_METER, UNIT_METER,
ICON_ARROW_EXPAND_VERTICAL, ICON_ARROW_EXPAND_VERTICAL,
) )
@ -20,7 +21,13 @@ UltrasonicSensorComponent = ultrasonic_ns.class_(
) )
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_METER, ICON_ARROW_EXPAND_VERTICAL, 2, DEVICE_CLASS_EMPTY) sensor.sensor_schema(
UNIT_METER,
ICON_ARROW_EXPAND_VERTICAL,
2,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(UltrasonicSensorComponent), cv.GenerateID(): cv.declare_id(UltrasonicSensorComponent),

View file

@ -1,13 +1,21 @@
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.components import sensor from esphome.components import sensor
from esphome.const import CONF_ID, DEVICE_CLASS_EMPTY, UNIT_SECOND, ICON_TIMER from esphome.const import (
CONF_ID,
DEVICE_CLASS_EMPTY,
STATE_CLASS_NONE,
UNIT_SECOND,
ICON_TIMER,
)
uptime_ns = cg.esphome_ns.namespace("uptime") uptime_ns = cg.esphome_ns.namespace("uptime")
UptimeSensor = uptime_ns.class_("UptimeSensor", sensor.Sensor, cg.PollingComponent) UptimeSensor = uptime_ns.class_("UptimeSensor", sensor.Sensor, cg.PollingComponent)
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema(UNIT_SECOND, ICON_TIMER, 0, DEVICE_CLASS_EMPTY) sensor.sensor_schema(
UNIT_SECOND, ICON_TIMER, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(UptimeSensor), cv.GenerateID(): cv.declare_id(UptimeSensor),

View file

@ -4,6 +4,7 @@ from esphome.components import i2c, sensor
from esphome.const import ( from esphome.const import (
CONF_ID, CONF_ID,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_METER, UNIT_METER,
ICON_ARROW_EXPAND_VERTICAL, ICON_ARROW_EXPAND_VERTICAL,
CONF_ADDRESS, CONF_ADDRESS,
@ -40,7 +41,13 @@ def check_timeout(value):
CONFIG_SCHEMA = cv.All( CONFIG_SCHEMA = cv.All(
sensor.sensor_schema(UNIT_METER, ICON_ARROW_EXPAND_VERTICAL, 2, DEVICE_CLASS_EMPTY) sensor.sensor_schema(
UNIT_METER,
ICON_ARROW_EXPAND_VERTICAL,
2,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
)
.extend( .extend(
{ {
cv.GenerateID(): cv.declare_id(VL53L0XSensor), cv.GenerateID(): cv.declare_id(VL53L0XSensor),

View file

@ -5,6 +5,7 @@ from esphome.const import (
CONF_ID, CONF_ID,
DEVICE_CLASS_SIGNAL_STRENGTH, DEVICE_CLASS_SIGNAL_STRENGTH,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_DECIBEL_MILLIWATT, UNIT_DECIBEL_MILLIWATT,
) )
@ -16,7 +17,11 @@ WiFiSignalSensor = wifi_signal_ns.class_(
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
sensor.sensor_schema( sensor.sensor_schema(
UNIT_DECIBEL_MILLIWATT, ICON_EMPTY, 0, DEVICE_CLASS_SIGNAL_STRENGTH UNIT_DECIBEL_MILLIWATT,
ICON_EMPTY,
0,
DEVICE_CLASS_SIGNAL_STRENGTH,
STATE_CLASS_MEASUREMENT,
) )
.extend( .extend(
{ {

View file

@ -11,6 +11,7 @@ from esphome.const import (
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
CONF_BINDKEY, CONF_BINDKEY,
@ -31,13 +32,25 @@ CONFIG_SCHEMA = (
cv.Required(CONF_BINDKEY): cv.bind_key, cv.Required(CONF_BINDKEY): cv.bind_key,
cv.Required(CONF_MAC_ADDRESS): cv.mac_address, cv.Required(CONF_MAC_ADDRESS): cv.mac_address,
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 1, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
1,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema( cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 0, DEVICE_CLASS_BATTERY UNIT_PERCENT,
ICON_EMPTY,
0,
DEVICE_CLASS_BATTERY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -10,6 +10,7 @@ from esphome.const import (
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
CONF_ID, CONF_ID,
@ -31,13 +32,25 @@ CONFIG_SCHEMA = (
cv.Required(CONF_BINDKEY): cv.bind_key, cv.Required(CONF_BINDKEY): cv.bind_key,
cv.Required(CONF_MAC_ADDRESS): cv.mac_address, cv.Required(CONF_MAC_ADDRESS): cv.mac_address,
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 1, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
1,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema( cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 0, DEVICE_CLASS_BATTERY UNIT_PERCENT,
ICON_EMPTY,
0,
DEVICE_CLASS_BATTERY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -12,6 +12,7 @@ from esphome.const import (
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
) )
@ -31,13 +32,25 @@ CONFIG_SCHEMA = (
cv.Optional(CONF_BINDKEY): cv.bind_key, cv.Optional(CONF_BINDKEY): cv.bind_key,
cv.Required(CONF_MAC_ADDRESS): cv.mac_address, cv.Required(CONF_MAC_ADDRESS): cv.mac_address,
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 1, DEVICE_CLASS_HUMIDITY UNIT_PERCENT,
ICON_EMPTY,
1,
DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema( cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 0, DEVICE_CLASS_BATTERY UNIT_PERCENT,
ICON_EMPTY,
0,
DEVICE_CLASS_BATTERY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -9,6 +9,7 @@ from esphome.const import (
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
ICON_WATER_PERCENT, ICON_WATER_PERCENT,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
CONF_ID, CONF_ID,
@ -34,16 +35,32 @@ CONFIG_SCHEMA = (
cv.GenerateID(): cv.declare_id(XiaomiGCLS002), cv.GenerateID(): cv.declare_id(XiaomiGCLS002),
cv.Required(CONF_MAC_ADDRESS): cv.mac_address, cv.Required(CONF_MAC_ADDRESS): cv.mac_address,
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_MOISTURE): sensor.sensor_schema( cv.Optional(CONF_MOISTURE): sensor.sensor_schema(
UNIT_PERCENT, ICON_WATER_PERCENT, 0, DEVICE_CLASS_EMPTY UNIT_PERCENT,
ICON_WATER_PERCENT,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_ILLUMINANCE): sensor.sensor_schema( cv.Optional(CONF_ILLUMINANCE): sensor.sensor_schema(
UNIT_LUX, ICON_EMPTY, 0, DEVICE_CLASS_ILLUMINANCE UNIT_LUX,
ICON_EMPTY,
0,
DEVICE_CLASS_ILLUMINANCE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_CONDUCTIVITY): sensor.sensor_schema( cv.Optional(CONF_CONDUCTIVITY): sensor.sensor_schema(
UNIT_MICROSIEMENS_PER_CENTIMETER, ICON_FLOWER, 0, DEVICE_CLASS_EMPTY UNIT_MICROSIEMENS_PER_CENTIMETER,
ICON_FLOWER,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -9,6 +9,7 @@ from esphome.const import (
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
ICON_EMPTY, ICON_EMPTY,
ICON_WATER_PERCENT, ICON_WATER_PERCENT,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS, UNIT_CELSIUS,
UNIT_PERCENT, UNIT_PERCENT,
CONF_ID, CONF_ID,
@ -36,19 +37,39 @@ CONFIG_SCHEMA = (
cv.GenerateID(): cv.declare_id(XiaomiHHCCJCY01), cv.GenerateID(): cv.declare_id(XiaomiHHCCJCY01),
cv.Required(CONF_MAC_ADDRESS): cv.mac_address, cv.Required(CONF_MAC_ADDRESS): cv.mac_address,
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE UNIT_CELSIUS,
ICON_EMPTY,
1,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_MOISTURE): sensor.sensor_schema( cv.Optional(CONF_MOISTURE): sensor.sensor_schema(
UNIT_PERCENT, ICON_WATER_PERCENT, 0, DEVICE_CLASS_EMPTY UNIT_PERCENT,
ICON_WATER_PERCENT,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_ILLUMINANCE): sensor.sensor_schema( cv.Optional(CONF_ILLUMINANCE): sensor.sensor_schema(
UNIT_LUX, ICON_EMPTY, 0, DEVICE_CLASS_ILLUMINANCE UNIT_LUX,
ICON_EMPTY,
0,
DEVICE_CLASS_ILLUMINANCE,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_CONDUCTIVITY): sensor.sensor_schema( cv.Optional(CONF_CONDUCTIVITY): sensor.sensor_schema(
UNIT_MICROSIEMENS_PER_CENTIMETER, ICON_FLOWER, 0, DEVICE_CLASS_EMPTY UNIT_MICROSIEMENS_PER_CENTIMETER,
ICON_FLOWER,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema( cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(
UNIT_PERCENT, ICON_EMPTY, 0, DEVICE_CLASS_BATTERY UNIT_PERCENT,
ICON_EMPTY,
0,
DEVICE_CLASS_BATTERY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

View file

@ -4,6 +4,7 @@ from esphome.components import sensor, esp32_ble_tracker
from esphome.const import ( from esphome.const import (
CONF_MAC_ADDRESS, CONF_MAC_ADDRESS,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
UNIT_PERCENT, UNIT_PERCENT,
ICON_WATER_PERCENT, ICON_WATER_PERCENT,
CONF_ID, CONF_ID,
@ -27,10 +28,18 @@ CONFIG_SCHEMA = (
cv.GenerateID(): cv.declare_id(XiaomiHHCCPOT002), cv.GenerateID(): cv.declare_id(XiaomiHHCCPOT002),
cv.Required(CONF_MAC_ADDRESS): cv.mac_address, cv.Required(CONF_MAC_ADDRESS): cv.mac_address,
cv.Optional(CONF_MOISTURE): sensor.sensor_schema( cv.Optional(CONF_MOISTURE): sensor.sensor_schema(
UNIT_PERCENT, ICON_WATER_PERCENT, 0, DEVICE_CLASS_EMPTY UNIT_PERCENT,
ICON_WATER_PERCENT,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_CONDUCTIVITY): sensor.sensor_schema( cv.Optional(CONF_CONDUCTIVITY): sensor.sensor_schema(
UNIT_MICROSIEMENS_PER_CENTIMETER, ICON_FLOWER, 0, DEVICE_CLASS_EMPTY UNIT_MICROSIEMENS_PER_CENTIMETER,
ICON_FLOWER,
0,
DEVICE_CLASS_EMPTY,
STATE_CLASS_MEASUREMENT,
), ),
} }
) )

Some files were not shown because too many files have changed in this diff Show more