Add device classes new in HA 2021.9 (#2248)

This commit is contained in:
Oxan van Leeuwen 2021-09-07 00:12:26 +02:00 committed by GitHub
parent 2d91e6b977
commit d9cb64b893
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 97 additions and 17 deletions

View file

@ -4,6 +4,8 @@ from esphome.components import i2c, sensor
from esphome.const import ( from esphome.const import (
CONF_ID, CONF_ID,
ICON_RADIATOR, ICON_RADIATOR,
DEVICE_CLASS_CARBON_DIOXIDE,
DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_PARTS_PER_MILLION, UNIT_PARTS_PER_MILLION,
UNIT_PARTS_PER_BILLION, UNIT_PARTS_PER_BILLION,
@ -30,12 +32,14 @@ CONFIG_SCHEMA = (
unit_of_measurement=UNIT_PARTS_PER_MILLION, unit_of_measurement=UNIT_PARTS_PER_MILLION,
icon=ICON_MOLECULE_CO2, icon=ICON_MOLECULE_CO2,
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_CARBON_DIOXIDE,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
cv.Required(CONF_TVOC): sensor.sensor_schema( cv.Required(CONF_TVOC): sensor.sensor_schema(
unit_of_measurement=UNIT_PARTS_PER_BILLION, unit_of_measurement=UNIT_PARTS_PER_BILLION,
icon=ICON_RADIATOR, icon=ICON_RADIATOR,
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_BASELINE): cv.hex_uint16_t, cv.Optional(CONF_BASELINE): cv.hex_uint16_t,

View file

@ -6,6 +6,10 @@ from esphome.const import (
CONF_PM_2_5, CONF_PM_2_5,
CONF_PM_10_0, CONF_PM_10_0,
CONF_PM_1_0, CONF_PM_1_0,
DEVICE_CLASS_AQI,
DEVICE_CLASS_PM1,
DEVICE_CLASS_PM10,
DEVICE_CLASS_PM25,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
@ -45,24 +49,28 @@ CONFIG_SCHEMA = cv.All(
unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER, unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER,
icon=ICON_CHEMICAL_WEAPON, icon=ICON_CHEMICAL_WEAPON,
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_PM1,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PM_2_5): sensor.sensor_schema( cv.Optional(CONF_PM_2_5): sensor.sensor_schema(
unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER, unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER,
icon=ICON_CHEMICAL_WEAPON, icon=ICON_CHEMICAL_WEAPON,
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_PM25,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PM_10_0): sensor.sensor_schema( cv.Optional(CONF_PM_10_0): sensor.sensor_schema(
unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER, unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER,
icon=ICON_CHEMICAL_WEAPON, icon=ICON_CHEMICAL_WEAPON,
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_PM10,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_AQI): sensor.sensor_schema( cv.Optional(CONF_AQI): sensor.sensor_schema(
unit_of_measurement=UNIT_INDEX, unit_of_measurement=UNIT_INDEX,
icon=ICON_CHEMICAL_WEAPON, icon=ICON_CHEMICAL_WEAPON,
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_AQI,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
).extend( ).extend(
{ {

View file

@ -8,6 +8,7 @@ from esphome.const import (
CONF_ID, CONF_ID,
CONF_TEMPERATURE, CONF_TEMPERATURE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_CARBON_DIOXIDE,
ICON_MOLECULE_CO2, ICON_MOLECULE_CO2,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_PARTS_PER_MILLION, UNIT_PARTS_PER_MILLION,
@ -34,6 +35,7 @@ CONFIG_SCHEMA = (
unit_of_measurement=UNIT_PARTS_PER_MILLION, unit_of_measurement=UNIT_PARTS_PER_MILLION,
icon=ICON_MOLECULE_CO2, icon=ICON_MOLECULE_CO2,
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_CARBON_DIOXIDE,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(

View file

@ -4,6 +4,7 @@ from esphome.components import sensor, uart
from esphome.const import ( from esphome.const import (
CONF_ID, CONF_ID,
CONF_PM_2_5, CONF_PM_2_5,
DEVICE_CLASS_PM25,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_BLUR, ICON_BLUR,
@ -23,6 +24,7 @@ CONFIG_SCHEMA = cv.All(
unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER, unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER,
icon=ICON_BLUR, icon=ICON_BLUR,
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_PM25,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
} }

View file

@ -13,6 +13,9 @@ from esphome.const import (
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
ICON_COUNTER, ICON_COUNTER,
DEVICE_CLASS_PM1,
DEVICE_CLASS_PM10,
DEVICE_CLASS_PM25,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
) )
@ -39,19 +42,19 @@ CONFIG_SCHEMA = (
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
2, 2,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_PM1,
), ),
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_PM25,
), ),
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_PM10,
), ),
cv.Optional(CONF_PMC_0_3): sensor.sensor_schema( cv.Optional(CONF_PMC_0_3): sensor.sensor_schema(
UNIT_COUNTS_PER_100ML, ICON_COUNTER, 0, DEVICE_CLASS_EMPTY UNIT_COUNTS_PER_100ML, ICON_COUNTER, 0, DEVICE_CLASS_EMPTY

View file

@ -19,6 +19,9 @@ from esphome.const import (
CONF_PM_10_0UM, CONF_PM_10_0UM,
CONF_TEMPERATURE, CONF_TEMPERATURE,
CONF_TYPE, CONF_TYPE,
DEVICE_CLASS_PM1,
DEVICE_CLASS_PM10,
DEVICE_CLASS_PM25,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
@ -75,19 +78,19 @@ CONFIG_SCHEMA = (
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
0, 0,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_PM1,
), ),
cv.Optional(CONF_PM_2_5_STD): sensor.sensor_schema( cv.Optional(CONF_PM_2_5_STD): 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_PM25,
), ),
cv.Optional(CONF_PM_10_0_STD): sensor.sensor_schema( cv.Optional(CONF_PM_10_0_STD): 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_PM10,
), ),
cv.Optional(CONF_PM_1_0): sensor.sensor_schema( cv.Optional(CONF_PM_1_0): sensor.sensor_schema(
unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER, unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER,

View file

@ -7,6 +7,8 @@ from esphome.const import (
CONF_PM_2_5, CONF_PM_2_5,
CONF_RX_ONLY, CONF_RX_ONLY,
CONF_UPDATE_INTERVAL, CONF_UPDATE_INTERVAL,
DEVICE_CLASS_PM25,
DEVICE_CLASS_PM10,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
ICON_CHEMICAL_WEAPON, ICON_CHEMICAL_WEAPON,
@ -41,12 +43,14 @@ CONFIG_SCHEMA = cv.All(
unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER, unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER,
icon=ICON_CHEMICAL_WEAPON, icon=ICON_CHEMICAL_WEAPON,
accuracy_decimals=1, accuracy_decimals=1,
device_class=DEVICE_CLASS_PM25,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PM_10_0): sensor.sensor_schema( cv.Optional(CONF_PM_10_0): sensor.sensor_schema(
unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER, unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER,
icon=ICON_CHEMICAL_WEAPON, icon=ICON_CHEMICAL_WEAPON,
accuracy_decimals=1, accuracy_decimals=1,
device_class=DEVICE_CLASS_PM10,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_RX_ONLY, default=False): cv.boolean, cv.Optional(CONF_RX_ONLY, default=False): cv.boolean,

View file

@ -7,6 +7,7 @@ from esphome.const import (
CONF_CO2, CONF_CO2,
CONF_ID, CONF_ID,
ICON_MOLECULE_CO2, ICON_MOLECULE_CO2,
DEVICE_CLASS_CARBON_DIOXIDE,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_PARTS_PER_MILLION, UNIT_PARTS_PER_MILLION,
) )
@ -41,6 +42,7 @@ CONFIG_SCHEMA = (
unit_of_measurement=UNIT_PARTS_PER_MILLION, unit_of_measurement=UNIT_PARTS_PER_MILLION,
icon=ICON_MOLECULE_CO2, icon=ICON_MOLECULE_CO2,
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_CARBON_DIOXIDE,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
} }

View file

@ -31,21 +31,31 @@ from esphome.const import (
CONF_MQTT_ID, CONF_MQTT_ID,
CONF_FORCE_UPDATE, CONF_FORCE_UPDATE,
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
DEVICE_CLASS_AQI,
DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY,
DEVICE_CLASS_CARBON_MONOXIDE,
DEVICE_CLASS_CARBON_DIOXIDE, DEVICE_CLASS_CARBON_DIOXIDE,
DEVICE_CLASS_CARBON_MONOXIDE,
DEVICE_CLASS_CURRENT, DEVICE_CLASS_CURRENT,
DEVICE_CLASS_ENERGY, DEVICE_CLASS_ENERGY,
DEVICE_CLASS_GAS, DEVICE_CLASS_GAS,
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_MONETARY, DEVICE_CLASS_MONETARY,
DEVICE_CLASS_SIGNAL_STRENGTH, DEVICE_CLASS_NITROGEN_DIOXIDE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_NITROGEN_MONOXIDE,
DEVICE_CLASS_NITROUS_OXIDE,
DEVICE_CLASS_OZONE,
DEVICE_CLASS_PM1,
DEVICE_CLASS_PM10,
DEVICE_CLASS_PM25,
DEVICE_CLASS_POWER, DEVICE_CLASS_POWER,
DEVICE_CLASS_POWER_FACTOR, DEVICE_CLASS_POWER_FACTOR,
DEVICE_CLASS_PRESSURE, DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_SIGNAL_STRENGTH,
DEVICE_CLASS_SULPHUR_DIOXIDE,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_TIMESTAMP, DEVICE_CLASS_TIMESTAMP,
DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
) )
from esphome.core import CORE, coroutine_with_priority from esphome.core import CORE, coroutine_with_priority
@ -54,21 +64,31 @@ from esphome.util import Registry
CODEOWNERS = ["@esphome/core"] CODEOWNERS = ["@esphome/core"]
DEVICE_CLASSES = [ DEVICE_CLASSES = [
DEVICE_CLASS_EMPTY, DEVICE_CLASS_EMPTY,
DEVICE_CLASS_AQI,
DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY,
DEVICE_CLASS_CARBON_MONOXIDE,
DEVICE_CLASS_CARBON_DIOXIDE, DEVICE_CLASS_CARBON_DIOXIDE,
DEVICE_CLASS_CARBON_MONOXIDE,
DEVICE_CLASS_CURRENT, DEVICE_CLASS_CURRENT,
DEVICE_CLASS_ENERGY, DEVICE_CLASS_ENERGY,
DEVICE_CLASS_GAS, DEVICE_CLASS_GAS,
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_MONETARY, DEVICE_CLASS_MONETARY,
DEVICE_CLASS_SIGNAL_STRENGTH, DEVICE_CLASS_NITROGEN_DIOXIDE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_NITROGEN_MONOXIDE,
DEVICE_CLASS_TIMESTAMP, DEVICE_CLASS_NITROUS_OXIDE,
DEVICE_CLASS_OZONE,
DEVICE_CLASS_PM1,
DEVICE_CLASS_PM10,
DEVICE_CLASS_PM25,
DEVICE_CLASS_POWER, DEVICE_CLASS_POWER,
DEVICE_CLASS_POWER_FACTOR, DEVICE_CLASS_POWER_FACTOR,
DEVICE_CLASS_PRESSURE, DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_SIGNAL_STRENGTH,
DEVICE_CLASS_SULPHUR_DIOXIDE,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_TIMESTAMP,
DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
] ]

View file

@ -7,6 +7,8 @@ from esphome.const import (
CONF_ECO2, CONF_ECO2,
CONF_TVOC, CONF_TVOC,
ICON_RADIATOR, ICON_RADIATOR,
DEVICE_CLASS_CARBON_DIOXIDE,
DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_PARTS_PER_MILLION, UNIT_PARTS_PER_MILLION,
UNIT_PARTS_PER_BILLION, UNIT_PARTS_PER_BILLION,
@ -34,12 +36,14 @@ CONFIG_SCHEMA = (
unit_of_measurement=UNIT_PARTS_PER_MILLION, unit_of_measurement=UNIT_PARTS_PER_MILLION,
icon=ICON_MOLECULE_CO2, icon=ICON_MOLECULE_CO2,
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_CARBON_DIOXIDE,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
cv.Required(CONF_TVOC): sensor.sensor_schema( cv.Required(CONF_TVOC): sensor.sensor_schema(
unit_of_measurement=UNIT_PARTS_PER_BILLION, unit_of_measurement=UNIT_PARTS_PER_BILLION,
icon=ICON_RADIATOR, icon=ICON_RADIATOR,
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_ECO2_BASELINE): sensor.sensor_schema( cv.Optional(CONF_ECO2_BASELINE): sensor.sensor_schema(

View file

@ -4,6 +4,7 @@ from esphome.components import i2c, sensor
from esphome.const import ( from esphome.const import (
CONF_ID, CONF_ID,
ICON_RADIATOR, ICON_RADIATOR,
DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
) )
@ -26,6 +27,7 @@ CONFIG_SCHEMA = (
sensor.sensor_schema( sensor.sensor_schema(
icon=ICON_RADIATOR, icon=ICON_RADIATOR,
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
) )
.extend( .extend(

View file

@ -10,6 +10,10 @@ from esphome.const import (
CONF_PM_10_0, CONF_PM_10_0,
CONF_TEMPERATURE, CONF_TEMPERATURE,
CONF_HUMIDITY, CONF_HUMIDITY,
DEVICE_CLASS_CARBON_DIOXIDE,
DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS,
DEVICE_CLASS_PM25,
DEVICE_CLASS_PM10,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
@ -36,6 +40,7 @@ CONFIG_SCHEMA = cv.All(
unit_of_measurement=UNIT_PARTS_PER_MILLION, unit_of_measurement=UNIT_PARTS_PER_MILLION,
icon=ICON_MOLECULE_CO2, icon=ICON_MOLECULE_CO2,
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_CARBON_DIOXIDE,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_FORMALDEHYDE): sensor.sensor_schema( cv.Optional(CONF_FORMALDEHYDE): sensor.sensor_schema(
@ -48,18 +53,21 @@ CONFIG_SCHEMA = cv.All(
unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER, unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER,
icon=ICON_CHEMICAL_WEAPON, icon=ICON_CHEMICAL_WEAPON,
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PM_2_5): sensor.sensor_schema( cv.Optional(CONF_PM_2_5): sensor.sensor_schema(
unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER, unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER,
icon=ICON_GRAIN, icon=ICON_GRAIN,
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_PM25,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PM_10_0): sensor.sensor_schema( cv.Optional(CONF_PM_10_0): sensor.sensor_schema(
unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER, unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER,
icon=ICON_GRAIN, icon=ICON_GRAIN,
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_PM10,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(

View file

@ -13,6 +13,9 @@ from esphome.const import (
CONF_PMC_4_0, CONF_PMC_4_0,
CONF_PMC_10_0, CONF_PMC_10_0,
CONF_PM_SIZE, CONF_PM_SIZE,
DEVICE_CLASS_PM1,
DEVICE_CLASS_PM10,
DEVICE_CLASS_PM25,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_MICROGRAMS_PER_CUBIC_METER, UNIT_MICROGRAMS_PER_CUBIC_METER,
UNIT_COUNTS_PER_CUBIC_METER, UNIT_COUNTS_PER_CUBIC_METER,
@ -35,12 +38,14 @@ CONFIG_SCHEMA = (
unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER, unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER,
icon=ICON_CHEMICAL_WEAPON, icon=ICON_CHEMICAL_WEAPON,
accuracy_decimals=2, accuracy_decimals=2,
device_class=DEVICE_CLASS_PM1,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PM_2_5): sensor.sensor_schema( cv.Optional(CONF_PM_2_5): sensor.sensor_schema(
unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER, unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER,
icon=ICON_CHEMICAL_WEAPON, icon=ICON_CHEMICAL_WEAPON,
accuracy_decimals=2, accuracy_decimals=2,
device_class=DEVICE_CLASS_PM25,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PM_4_0): sensor.sensor_schema( cv.Optional(CONF_PM_4_0): sensor.sensor_schema(
@ -53,6 +58,7 @@ CONFIG_SCHEMA = (
unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER, unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER,
icon=ICON_CHEMICAL_WEAPON, icon=ICON_CHEMICAL_WEAPON,
accuracy_decimals=2, accuracy_decimals=2,
device_class=DEVICE_CLASS_PM10,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_PMC_0_5): sensor.sensor_schema( cv.Optional(CONF_PMC_0_5): sensor.sensor_schema(

View file

@ -9,6 +9,7 @@ from esphome.const import (
CONF_CO2, CONF_CO2,
CONF_TEMPERATURE, CONF_TEMPERATURE,
CONF_HUMIDITY, CONF_HUMIDITY,
DEVICE_CLASS_CARBON_DIOXIDE,
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
@ -35,6 +36,7 @@ CONFIG_SCHEMA = cv.Schema(
unit_of_measurement=UNIT_PARTS_PER_MILLION, unit_of_measurement=UNIT_PARTS_PER_MILLION,
icon=ICON_MOLECULE_CO2, icon=ICON_MOLECULE_CO2,
accuracy_decimals=0, accuracy_decimals=0,
device_class=DEVICE_CLASS_CARBON_DIOXIDE,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(

View file

@ -811,7 +811,6 @@ DEVICE_CLASS_COLD = "cold"
DEVICE_CLASS_CONNECTIVITY = "connectivity" DEVICE_CLASS_CONNECTIVITY = "connectivity"
DEVICE_CLASS_DOOR = "door" DEVICE_CLASS_DOOR = "door"
DEVICE_CLASS_GARAGE_DOOR = "garage_door" DEVICE_CLASS_GARAGE_DOOR = "garage_door"
DEVICE_CLASS_GAS = "gas"
DEVICE_CLASS_HEAT = "heat" DEVICE_CLASS_HEAT = "heat"
DEVICE_CLASS_LIGHT = "light" DEVICE_CLASS_LIGHT = "light"
DEVICE_CLASS_LOCK = "lock" DEVICE_CLASS_LOCK = "lock"
@ -832,20 +831,31 @@ DEVICE_CLASS_WINDOW = "window"
# device classes of both binary_sensor and sensor component # device classes of both binary_sensor and sensor component
DEVICE_CLASS_EMPTY = "" DEVICE_CLASS_EMPTY = ""
DEVICE_CLASS_BATTERY = "battery" DEVICE_CLASS_BATTERY = "battery"
DEVICE_CLASS_GAS = "gas"
DEVICE_CLASS_POWER = "power" DEVICE_CLASS_POWER = "power"
# device classes of sensor component # device classes of sensor component
DEVICE_CLASS_CARBON_MONOXIDE = "carbon_monoxide" DEVICE_CLASS_AQI = "aqi"
DEVICE_CLASS_CARBON_DIOXIDE = "carbon_dioxide" DEVICE_CLASS_CARBON_DIOXIDE = "carbon_dioxide"
DEVICE_CLASS_CARBON_MONOXIDE = "carbon_monoxide"
DEVICE_CLASS_CURRENT = "current" DEVICE_CLASS_CURRENT = "current"
DEVICE_CLASS_ENERGY = "energy" DEVICE_CLASS_ENERGY = "energy"
DEVICE_CLASS_HUMIDITY = "humidity" DEVICE_CLASS_HUMIDITY = "humidity"
DEVICE_CLASS_ILLUMINANCE = "illuminance" DEVICE_CLASS_ILLUMINANCE = "illuminance"
DEVICE_CLASS_MONETARY = "monetary" DEVICE_CLASS_MONETARY = "monetary"
DEVICE_CLASS_SIGNAL_STRENGTH = "signal_strength" DEVICE_CLASS_NITROGEN_DIOXIDE = "nitrogen_dioxide"
DEVICE_CLASS_TEMPERATURE = "temperature" DEVICE_CLASS_NITROGEN_MONOXIDE = "nitrogen_monoxide"
DEVICE_CLASS_NITROUS_OXIDE = "nitrous_oxide"
DEVICE_CLASS_OZONE = "ozone"
DEVICE_CLASS_PM1 = "pm1"
DEVICE_CLASS_PM10 = "pm10"
DEVICE_CLASS_PM25 = "pm25"
DEVICE_CLASS_POWER_FACTOR = "power_factor" DEVICE_CLASS_POWER_FACTOR = "power_factor"
DEVICE_CLASS_PRESSURE = "pressure" DEVICE_CLASS_PRESSURE = "pressure"
DEVICE_CLASS_SIGNAL_STRENGTH = "signal_strength"
DEVICE_CLASS_SULPHUR_DIOXIDE = "sulphur_dioxide"
DEVICE_CLASS_TEMPERATURE = "temperature"
DEVICE_CLASS_TIMESTAMP = "timestamp" DEVICE_CLASS_TIMESTAMP = "timestamp"
DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS = "volatile_organic_compounds"
DEVICE_CLASS_VOLTAGE = "voltage" DEVICE_CLASS_VOLTAGE = "voltage"
# state classes # state classes