mirror of
https://github.com/esphome/esphome.git
synced 2026-10-14 10:12:52 +00:00
[tmp102] Add number entities for runtime thermostat thresholds (#20596)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: J. Nick Koston <nick@home-assistant.io>
This commit is contained in:
co-authored by
pre-commit-ci-lite[bot]
J. Nick Koston
parent
74e96b7da6
commit
f829447b2e
@@ -0,0 +1,25 @@
|
||||
---
|
||||
esphome:
|
||||
name: tmp102-test
|
||||
|
||||
esp32:
|
||||
board: esp32dev
|
||||
|
||||
i2c:
|
||||
sda: GPIO21
|
||||
scl: GPIO22
|
||||
|
||||
sensor:
|
||||
- platform: tmp102
|
||||
id: chip
|
||||
name: Temperature
|
||||
|
||||
number:
|
||||
- platform: tmp102
|
||||
tmp102_id: chip
|
||||
temperature_high:
|
||||
name: High One
|
||||
- platform: tmp102
|
||||
tmp102_id: chip
|
||||
temperature_low:
|
||||
name: Low Two
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
esphome:
|
||||
name: tmp102-test
|
||||
|
||||
esp32:
|
||||
board: esp32dev
|
||||
|
||||
i2c:
|
||||
sda: GPIO21
|
||||
scl: GPIO22
|
||||
|
||||
sensor:
|
||||
- platform: tmp102
|
||||
id: chip
|
||||
name: Temperature
|
||||
|
||||
number:
|
||||
- platform: tmp102
|
||||
tmp102_id: chip
|
||||
temperature_high:
|
||||
name: High
|
||||
temperature_low:
|
||||
name: Low
|
||||
restore_value: false
|
||||
@@ -0,0 +1,25 @@
|
||||
---
|
||||
esphome:
|
||||
name: tmp102-test
|
||||
|
||||
esp32:
|
||||
board: esp32dev
|
||||
|
||||
i2c:
|
||||
sda: GPIO21
|
||||
scl: GPIO22
|
||||
|
||||
sensor:
|
||||
- platform: tmp102
|
||||
id: chip
|
||||
name: Temperature
|
||||
extended_mode: true
|
||||
temperature_high: 140
|
||||
temperature_low: 120
|
||||
|
||||
number:
|
||||
- platform: tmp102
|
||||
temperature_high:
|
||||
name: High
|
||||
temperature_low:
|
||||
name: Low
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
esphome:
|
||||
name: tmp102-test
|
||||
|
||||
esp32:
|
||||
board: esp32dev
|
||||
|
||||
i2c:
|
||||
sda: GPIO21
|
||||
scl: GPIO22
|
||||
|
||||
sensor:
|
||||
- platform: tmp102
|
||||
id: chip
|
||||
name: Temperature
|
||||
|
||||
number:
|
||||
- platform: tmp102
|
||||
tmp102_id: chip
|
||||
temperature_high:
|
||||
name: High
|
||||
initial_value: 30
|
||||
@@ -58,6 +58,54 @@ def test_duplicate_alert_entities_are_rejected(
|
||||
)
|
||||
|
||||
|
||||
def test_threshold_numbers_enable_configuration_once(
|
||||
generate_main: Callable[[Path], str],
|
||||
component_config_path: Callable[[str], Path],
|
||||
) -> None:
|
||||
source = generate_main(component_config_path("numbers.yaml"))
|
||||
assert source.count("set_configuration(") == 1
|
||||
assert "set_configuration(128, 20480, 19200)" in source
|
||||
assert source.count("set_limit_control(") == 2
|
||||
assert "tmp102::TMP102_LIMIT_HIGH" in source
|
||||
assert "tmp102::TMP102_LIMIT_LOW" in source
|
||||
assert "set_restore_value(false)" in source
|
||||
assert "set_max_value(127.9375f)" in source
|
||||
defines = " ".join(define.name for define in CORE.defines)
|
||||
assert "USE_TMP102_NUMBER" in defines
|
||||
assert "USE_TMP102_CONFIGURE" in defines
|
||||
|
||||
|
||||
def test_threshold_numbers_use_sensor_thresholds(
|
||||
generate_main: Callable[[Path], str],
|
||||
component_config_path: Callable[[str], Path],
|
||||
) -> None:
|
||||
source = generate_main(component_config_path("numbers_inherit.yaml"))
|
||||
assert source.count("set_configuration(") == 1
|
||||
assert "set_configuration(144, 17920, 15360)" in source
|
||||
assert "set_max_value(150.0f)" in source
|
||||
|
||||
|
||||
def test_threshold_number_initial_value_is_rejected(
|
||||
component_config_path: Callable[[str], Path],
|
||||
capsys: pytest.CaptureFixture[str],
|
||||
) -> None:
|
||||
CORE.config_path = component_config_path("numbers_initial_value.yaml")
|
||||
assert read_config({}) is None
|
||||
assert "[initial_value] is an invalid option" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_duplicate_numbers_are_rejected(
|
||||
component_config_path: Callable[[str], Path],
|
||||
capsys: pytest.CaptureFixture[str],
|
||||
) -> None:
|
||||
CORE.config_path = component_config_path("duplicate_numbers.yaml")
|
||||
assert read_config({}) is None
|
||||
assert (
|
||||
"Only one TMP102 number may reference each temperature sensor"
|
||||
in capsys.readouterr().out
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("extended", "high", "low"),
|
||||
[
|
||||
@@ -117,5 +165,12 @@ def test_precomputed_register_values() -> None:
|
||||
assert component.encode_temperature(config["temperature_low"], True) == 0xF9E0
|
||||
|
||||
|
||||
def test_threshold_encoding_rounds_half_steps_away_from_zero() -> None:
|
||||
assert component.encode_temperature(30.03125, False) == 481 << 4
|
||||
assert component.encode_temperature(-30.03125, False) == (-481 << 4) & 0xFFFF
|
||||
assert component.encode_temperature(30.03125, True) == 481 << 3
|
||||
assert component.encode_temperature(-30.03125, True) == (-481 << 3) & 0xFFFF
|
||||
|
||||
|
||||
def test_defaults_match_chip_reset() -> None:
|
||||
assert component.build_configuration({}) == 0x0080
|
||||
|
||||
Reference in New Issue
Block a user