From 9638dc2450791d8196c22a4c1db2f2886ba60391 Mon Sep 17 00:00:00 2001 From: Bram Date: Wed, 5 Oct 2022 09:28:44 +0200 Subject: [PATCH] Add test for template tracking --- tests/sensors/test_power.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/sensors/test_power.py b/tests/sensors/test_power.py index df75e5a62..1108727c0 100644 --- a/tests/sensors/test_power.py +++ b/tests/sensors/test_power.py @@ -264,3 +264,30 @@ async def test_strategy_enabled_condition(hass: HomeAssistant): await hass.async_block_till_done() assert hass.states.get(power_entity_id).state == "1.50" + + +async def test_template_entity_tracking(hass: HomeAssistant) -> None: + await create_input_number(hass, "test", 0) + await create_input_boolean(hass) + + await run_powercalc_setup_yaml_config( + hass, + { + CONF_ENTITY_ID: "input_boolean.test", + CONF_FIXED: { + CONF_POWER: "{{ states('input_number.test') }}" + }, + }, + ) + + hass.states.async_set("input_boolean.test", STATE_ON) + await hass.async_block_till_done() + + assert hass.states.get("sensor.test_power").state == "0.00" + + hass.states.async_set("input_number.test", 15) + await hass.async_block_till_done() + + assert hass.states.get("sensor.test_power").state == "15.00" + +