[adc] Deprecate pin: TEMPERATURE in favour of internal_temperature (#18304)

This commit is contained in:
Jesse Hills
2026-08-12 14:20:41 +12:00
committed by GitHub
parent bab62b345b
commit 9605b34c69
5 changed files with 64 additions and 0 deletions
+1
View File
@@ -231,6 +231,7 @@ def validate_adc_pin(value):
return pins.internal_gpio_input_pin_schema(29)
return cv.only_on([PLATFORM_ESP8266])("VCC")
# Deprecated in favour of the `internal_temperature` platform, remove before 2027.2.0
if str(value).upper() == "TEMPERATURE":
return cv.only_on_rp2("TEMPERATURE")
+8
View File
@@ -67,6 +67,13 @@ def validate_config(config):
# Alter value here so `config` command prints the recommended change
config[CONF_ATTENUATION] = _attenuation("12db")
# Remove before 2027.2.0
if config[CONF_PIN] == "TEMPERATURE":
_LOGGER.warning(
"[adc] `pin: TEMPERATURE` is deprecated, use the `internal_temperature` "
"sensor platform instead. Will be removed in 2027.2.0"
)
return config
@@ -133,6 +140,7 @@ async def to_code(config):
if config[CONF_PIN] == "VCC":
cg.add_define("USE_ADC_SENSOR_VCC")
elif config[CONF_PIN] == "TEMPERATURE":
# Remove before 2027.2.0
cg.add(var.set_is_temperature())
elif not CORE.is_nrf52 or config[CONF_PIN][CONF_NUMBER] not in EXTRA_ADC:
pin = await cg.gpio_pin_expression(config[CONF_PIN])
@@ -0,0 +1,32 @@
"""Tests for the ADC sensor component."""
from __future__ import annotations
from collections.abc import Callable
from pathlib import Path
import pytest
def test_adc_temperature_pin_is_deprecated(
generate_main: Callable[[str | Path], str],
caplog: pytest.LogCaptureFixture,
) -> None:
"""`pin: TEMPERATURE` still works, but warns and points at internal_temperature."""
main_cpp = generate_main("tests/component_tests/adc/test_adc_sensor.yaml")
assert "adc_temperature->set_is_temperature();" in main_cpp
assert "`pin: TEMPERATURE` is deprecated" in caplog.text
assert "internal_temperature" in caplog.text
assert "2027.2.0" in caplog.text
def test_adc_regular_pin_is_not_deprecated(
generate_main: Callable[[str | Path], str],
caplog: pytest.LogCaptureFixture,
) -> None:
"""A normal ADC pin does not emit the temperature deprecation warning."""
main_cpp = generate_main("tests/component_tests/adc/test_adc_sensor.yaml")
assert "adc_voltage->set_is_temperature();" not in main_cpp
assert caplog.text.count("`pin: TEMPERATURE` is deprecated") == 1
@@ -0,0 +1,16 @@
esphome:
name: test
rp2:
board: rpipicow
sensor:
- platform: adc
pin: TEMPERATURE
name: Deprecated ADC Temperature
id: adc_temperature
- platform: adc
pin: 26
name: ADC Voltage
id: adc_voltage
@@ -0,0 +1,7 @@
# Deprecated `pin: TEMPERATURE`, superseded by the `internal_temperature` platform.
# Remove before 2027.2.0
sensor:
- id: adc_temperature_sensor
platform: adc
pin: TEMPERATURE
name: ADC Test temperature