mirror of
https://github.com/esphome/esphome.git
synced 2026-10-03 09:46:03 +00:00
[number] Fix the default mode check so mode auto is no longer emitted (#19231)
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
---
|
||||
esphome:
|
||||
name: test
|
||||
|
||||
esp32:
|
||||
board: esp32dev
|
||||
|
||||
number:
|
||||
- platform: template
|
||||
id: auto_number
|
||||
min_value: 0
|
||||
max_value: 10
|
||||
step: 1
|
||||
optimistic: true
|
||||
- platform: template
|
||||
id: box_number
|
||||
min_value: 0
|
||||
max_value: 10
|
||||
step: 1
|
||||
mode: box
|
||||
optimistic: true
|
||||
- platform: template
|
||||
id: explicit_auto_number
|
||||
min_value: 0
|
||||
max_value: 10
|
||||
step: 1
|
||||
mode: auto
|
||||
optimistic: true
|
||||
@@ -0,0 +1,16 @@
|
||||
"""Tests for the number component codegen."""
|
||||
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def test_default_mode_is_not_emitted(
|
||||
generate_main: Callable[[str | Path], str],
|
||||
component_config_path: Callable[[str], Path],
|
||||
) -> None:
|
||||
"""Mode auto is the C++ initializer, so only a non default mode is set."""
|
||||
main_cpp = generate_main(component_config_path("mode.yaml"))
|
||||
|
||||
assert "auto_number->traits.set_mode(" not in main_cpp
|
||||
assert "explicit_auto_number->traits.set_mode(" not in main_cpp
|
||||
assert "box_number->traits.set_mode(number::NUMBER_MODE_BOX);" in main_cpp
|
||||
Reference in New Issue
Block a user