mirror of
https://github.com/esphome/esphome.git
synced 2026-10-05 02:21:30 +00:00
[uptime] Skip the timestamp sensor source unless a timestamp sensor is configured (#18746)
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
esphome:
|
||||
name: test
|
||||
|
||||
esp32:
|
||||
board: esp32dev
|
||||
framework:
|
||||
type: esp-idf
|
||||
|
||||
wifi:
|
||||
ssid: "test_ssid"
|
||||
password: "test_password"
|
||||
|
||||
time:
|
||||
- platform: sntp
|
||||
id: sntp_time
|
||||
|
||||
sensor:
|
||||
- platform: uptime
|
||||
name: Uptime Seconds
|
||||
type: seconds
|
||||
@@ -0,0 +1,20 @@
|
||||
esphome:
|
||||
name: test
|
||||
|
||||
esp32:
|
||||
board: esp32dev
|
||||
framework:
|
||||
type: esp-idf
|
||||
|
||||
wifi:
|
||||
ssid: "test_ssid"
|
||||
password: "test_password"
|
||||
|
||||
time:
|
||||
- platform: sntp
|
||||
id: sntp_time
|
||||
|
||||
sensor:
|
||||
- platform: uptime
|
||||
name: Uptime Timestamp
|
||||
type: timestamp
|
||||
@@ -0,0 +1,27 @@
|
||||
"""The timestamp uptime sensor source is only compiled when that type is used,
|
||||
so the define must follow the configured sensor type rather than time: alone."""
|
||||
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from esphome.core import CORE
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("fixture", "emits"),
|
||||
[
|
||||
("seconds.yaml", False),
|
||||
("timestamp.yaml", True),
|
||||
],
|
||||
)
|
||||
def test_timestamp_define_follows_sensor_type(
|
||||
fixture: str,
|
||||
emits: bool,
|
||||
generate_main: Callable[[str | Path], str],
|
||||
component_config_path: Callable[[str], Path],
|
||||
) -> None:
|
||||
generate_main(component_config_path(fixture))
|
||||
defines = {define.name for define in CORE.defines}
|
||||
assert ("USE_UPTIME_TIMESTAMP" in defines) is emits
|
||||
Reference in New Issue
Block a user