Merge branch 'dev' into climate-control-action-bitmask

This commit is contained in:
J. Nick Koston
2026-04-29 05:42:01 -05:00
committed by GitHub
161 changed files with 5061 additions and 1232 deletions
@@ -0,0 +1,60 @@
esphome:
name: light-dim-relative-action-test
host:
api:
logger:
level: DEBUG
output:
- platform: template
id: test_out
type: float
write_action:
- lambda: ""
light:
- platform: monochromatic
name: "Test Light"
id: test_light
output: test_out
default_transition_length: 0s
button:
# Set up: turn on at 50% brightness
- platform: template
id: btn_setup
name: "Setup"
on_press:
- light.turn_on:
id: test_light
brightness: 50%
# Test 1: dim_relative without transition_length (HasTransitionLength=false)
- platform: template
id: btn_dim_up
name: "Dim Up"
on_press:
- light.dim_relative:
id: test_light
relative_brightness: 25%
# Test 2: dim_relative with transition_length (HasTransitionLength=true)
- platform: template
id: btn_dim_down
name: "Dim Down"
on_press:
- light.dim_relative:
id: test_light
relative_brightness: -10%
transition_length: 0s
# Test 3: dim_relative with brightness limits
- platform: template
id: btn_dim_clamp
name: "Dim Clamp"
on_press:
- light.dim_relative:
id: test_light
relative_brightness: 50%
brightness_limits:
max_brightness: 80%
@@ -0,0 +1,37 @@
esphome:
name: light-toggle-action-test
host:
api:
logger:
level: DEBUG
output:
- platform: template
id: test_out
type: float
write_action:
- lambda: ""
light:
- platform: monochromatic
name: "Test Light"
id: test_light
output: test_out
default_transition_length: 0s
button:
# Test 1: light.toggle without transition_length (HasTransitionLength=false)
- platform: template
id: btn_toggle
name: "Toggle"
on_press:
- light.toggle: test_light
# Test 2: light.toggle with transition_length (HasTransitionLength=true)
- platform: template
id: btn_toggle_with_trans
name: "Toggle With Trans"
on_press:
- light.toggle:
id: test_light
transition_length: 0s
@@ -86,9 +86,9 @@ modbus:
uart_id: virtual_uart_dev
role: server
modbus_controller:
modbus_server:
- address: 1
server_registers:
registers:
- address: 0x03
value_type: U_WORD
read_lambda: |-
@@ -33,7 +33,7 @@ uart_mock:
data: !lambda return data;
- id: virtual_uart_controller
baud_rate: 9600
auto_start: true # See comment on virtual_uart_server above
auto_start: true # See comment on virtual_uart_server above
debug:
on_tx:
- then:
@@ -56,10 +56,11 @@ modbus_controller:
update_interval: 1s
id: modbus_controller_1
modbus_server:
- address: 1
modbus_id: virtual_modbus_server
id: modbus_server_1
server_registers:
registers:
- address: 0x01
value_type: U_WORD
read_lambda: return 99;
@@ -36,7 +36,7 @@ uart_mock:
data: !lambda return data;
- id: virtual_uart_server_2
baud_rate: 9600
auto_start: true # See comment on virtual_uart_server above
auto_start: true # See comment on virtual_uart_server above
debug:
on_tx:
- then:
@@ -48,7 +48,7 @@ uart_mock:
data: !lambda return data;
- id: virtual_uart_controller
baud_rate: 9600
auto_start: true # See comment on virtual_uart_server above
auto_start: true # See comment on virtual_uart_server above
debug:
on_tx:
- then:
@@ -81,15 +81,16 @@ modbus_controller:
update_interval: 1s
id: modbus_controller_2
modbus_server:
- address: 1
modbus_id: virtual_modbus_server
server_registers:
registers:
- address: 0x01
value_type: U_WORD
read_lambda: return 919;
- address: 2
modbus_id: virtual_modbus_server_2
server_registers:
registers:
- address: 0x01
value_type: U_WORD
read_lambda: return 929;
@@ -33,7 +33,7 @@ uart_mock:
data: !lambda return data;
- id: virtual_uart_controller
baud_rate: 9600
auto_start: true # See comment on virtual_uart_server above
auto_start: true # See comment on virtual_uart_server above
debug:
on_tx:
- then:
@@ -94,10 +94,11 @@ modbus_controller:
update_interval: 2s
id: modbus_controller_1
modbus_server:
- address: 1
modbus_id: virtual_modbus_server
id: modbus_server_1
server_registers:
registers:
- address: 0x01
value_type: U_WORD
read_lambda: return id(stored_u_word);
@@ -0,0 +1,72 @@
"""Integration test for light::DimRelativeAction.
Tests both DimRelativeAction<HasTransitionLength=false> and
DimRelativeAction<HasTransitionLength=true> instantiations.
"""
from __future__ import annotations
import asyncio
from aioesphomeapi import ButtonInfo, EntityState, LightInfo, LightState
import pytest
from .state_utils import InitialStateHelper, require_entity
from .types import APIClientConnectedFactory, RunCompiledFunction
@pytest.mark.asyncio
async def test_light_dim_relative_action(
yaml_config: str,
run_compiled: RunCompiledFunction,
api_client_connected: APIClientConnectedFactory,
) -> None:
"""Test light.dim_relative with and without transition_length."""
loop = asyncio.get_running_loop()
async with run_compiled(yaml_config), api_client_connected() as client:
light_state_future: asyncio.Future[LightState] | None = None
def on_state(state: EntityState) -> None:
if (
isinstance(state, LightState)
and light_state_future is not None
and not light_state_future.done()
):
light_state_future.set_result(state)
async def wait_for_light_state(timeout: float = 5.0) -> LightState:
nonlocal light_state_future
light_state_future = loop.create_future()
try:
return await asyncio.wait_for(light_state_future, timeout)
finally:
light_state_future = None
entities, _ = await client.list_entities_services()
initial_state_helper = InitialStateHelper(entities)
client.subscribe_states(initial_state_helper.on_state_wrapper(on_state))
await initial_state_helper.wait_for_initial_states()
require_entity(entities, "test_light", LightInfo)
async def press_and_wait(name: str) -> LightState:
btn = require_entity(entities, name.lower().replace(" ", "_"), ButtonInfo)
client.button_command(btn.key)
return await wait_for_light_state()
# Setup: turn on at 50%
state = await press_and_wait("Setup")
assert state.state is True
assert state.brightness == pytest.approx(0.5, abs=0.05)
# Test 1: dim_relative without transition_length: 50% + 25% = 75%
state = await press_and_wait("Dim Up")
assert state.brightness == pytest.approx(0.75, abs=0.05)
# Test 2: dim_relative with transition_length: 75% - 10% = 65%
state = await press_and_wait("Dim Down")
assert state.brightness == pytest.approx(0.65, abs=0.05)
# Test 3: dim_relative with max_brightness limit: 65% + 50% clamped to 80%
state = await press_and_wait("Dim Clamp")
assert state.brightness == pytest.approx(0.80, abs=0.05)
@@ -0,0 +1,67 @@
"""Integration test for light::ToggleAction.
Tests both ToggleAction<HasTransitionLength=false> and
ToggleAction<HasTransitionLength=true> instantiations.
"""
from __future__ import annotations
import asyncio
from aioesphomeapi import ButtonInfo, EntityState, LightInfo, LightState
import pytest
from .state_utils import InitialStateHelper, require_entity
from .types import APIClientConnectedFactory, RunCompiledFunction
@pytest.mark.asyncio
async def test_light_toggle_action(
yaml_config: str,
run_compiled: RunCompiledFunction,
api_client_connected: APIClientConnectedFactory,
) -> None:
"""Test light.toggle with and without transition_length."""
loop = asyncio.get_running_loop()
async with run_compiled(yaml_config), api_client_connected() as client:
light_state_future: asyncio.Future[LightState] | None = None
def on_state(state: EntityState) -> None:
if (
isinstance(state, LightState)
and light_state_future is not None
and not light_state_future.done()
):
light_state_future.set_result(state)
async def wait_for_light_state(timeout: float = 5.0) -> LightState:
nonlocal light_state_future
light_state_future = loop.create_future()
try:
return await asyncio.wait_for(light_state_future, timeout)
finally:
light_state_future = None
entities, _ = await client.list_entities_services()
initial_state_helper = InitialStateHelper(entities)
client.subscribe_states(initial_state_helper.on_state_wrapper(on_state))
await initial_state_helper.wait_for_initial_states()
require_entity(entities, "test_light", LightInfo)
async def press_and_wait(name: str) -> LightState:
btn = require_entity(entities, name.lower().replace(" ", "_"), ButtonInfo)
client.button_command(btn.key)
return await wait_for_light_state()
# Test 1: toggle without transition_length flips off->on
state = await press_and_wait("Toggle")
assert state.state is True
# Test 2: toggle with transition_length flips on->off
state = await press_and_wait("Toggle With Trans")
assert state.state is False
# Test 3: toggle without transition_length flips off->on again
state = await press_and_wait("Toggle")
assert state.state is True