forked from esphome/esphome
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add device class support to text sensor (esphome#6202)
Co-authored-by: Jesse Hills <[email protected]>
- Loading branch information
1 parent
a8ab745
commit 323849c
Showing
10 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"""Tests for the text sensor component.""" | ||
|
||
|
||
def test_text_sensor_is_setup(generate_main): | ||
""" | ||
When the text is set in the yaml file, it should be registered in main | ||
""" | ||
# Given | ||
|
||
# When | ||
main_cpp = generate_main("tests/component_tests/text_sensor/test_text_sensor.yaml") | ||
|
||
# Then | ||
assert "new template_::TemplateTextSensor();" in main_cpp | ||
assert "App.register_text_sensor" in main_cpp | ||
|
||
|
||
def test_text_sensor_sets_mandatory_fields(generate_main): | ||
""" | ||
When the mandatory fields are set in the yaml, they should be set in main | ||
""" | ||
# Given | ||
|
||
# When | ||
main_cpp = generate_main("tests/component_tests/text_sensor/test_text_sensor.yaml") | ||
|
||
# Then | ||
assert 'ts_1->set_name("Template Text Sensor 1");' in main_cpp | ||
assert 'ts_2->set_name("Template Text Sensor 2");' in main_cpp | ||
assert 'ts_3->set_name("Template Text Sensor 3");' in main_cpp | ||
|
||
|
||
def test_text_sensor_config_value_internal_set(generate_main): | ||
""" | ||
Test that the "internal" config value is correctly set | ||
""" | ||
# Given | ||
|
||
# When | ||
main_cpp = generate_main("tests/component_tests/text_sensor/test_text_sensor.yaml") | ||
|
||
# Then | ||
assert "ts_2->set_internal(true);" in main_cpp | ||
assert "ts_3->set_internal(false);" in main_cpp | ||
|
||
|
||
def test_text_sensor_device_class_set(generate_main): | ||
""" | ||
When the device_class of text_sensor is set in the yaml file, it should be registered in main | ||
""" | ||
# Given | ||
|
||
# When | ||
main_cpp = generate_main("tests/component_tests/text_sensor/test_text_sensor.yaml") | ||
|
||
# Then | ||
assert 'ts_2->set_device_class("timestamp");' in main_cpp | ||
assert 'ts_3->set_device_class("date");' in main_cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
esphome: | ||
name: test | ||
platform: ESP8266 | ||
board: d1_mini_lite | ||
|
||
text_sensor: | ||
- platform: template | ||
id: ts_1 | ||
name: "Template Text Sensor 1" | ||
lambda: |- | ||
return {"Hello World"}; | ||
- platform: template | ||
id: ts_2 | ||
name: "Template Text Sensor 2" | ||
lambda: |- | ||
return {"2023-06-22T18:43:52+00:00"}; | ||
device_class: timestamp | ||
internal: true | ||
- platform: template | ||
id: ts_3 | ||
name: "Template Text Sensor 3" | ||
lambda: |- | ||
return {"2023-06-22T18:43:52+00:00"}; | ||
device_class: date | ||
internal: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters