1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-01 19:02:18 +01:00

Device class attribute for sensor component (#1525)

* Add constants for sensor device_class

* Add device_class attribute to sensor component

* Add device_class attribute to sensor class

* Add device_class to mhz19 temperature sensor

* Add device_class to sensor in api component

* Add test for device_class of sensor

* Rename DEVICE_CLASS_NONE to DEVICE_CLASS_EMPTY for consistency

* Make optional attributes of sensor component truly optional
This commit is contained in:
marecabo
2021-02-15 16:49:02 +01:00
committed by GitHub
parent a342302114
commit f95be6a0df
11 changed files with 117 additions and 12 deletions

View File

@@ -0,0 +1,14 @@
""" Tests for the sensor component """
def test_sensor_device_class_set(generate_main):
"""
When the device_class of sensor is set in the yaml file, it should be registered in main
"""
# Given
# When
main_cpp = generate_main("tests/component_tests/sensor/test_sensor.yaml")
# Then
assert "s_1->set_device_class(\"voltage\");" in main_cpp

View File

@@ -0,0 +1,12 @@
esphome:
name: test
platform: ESP8266
board: d1_mini_lite
sensor:
- platform: adc
pin: A0
id: s_1
name: "test s1"
update_interval: 60s
device_class: "voltage"