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:
14
tests/component_tests/sensor/test_sensor.py
Normal file
14
tests/component_tests/sensor/test_sensor.py
Normal 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
|
12
tests/component_tests/sensor/test_sensor.yaml
Normal file
12
tests/component_tests/sensor/test_sensor.yaml
Normal 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"
|
Reference in New Issue
Block a user