Skip to content

Commit

Permalink
Merge 2733094 into 7e33131
Browse files Browse the repository at this point in the history
  • Loading branch information
bramstroker committed Dec 25, 2022
2 parents 7e33131 + 2733094 commit 8992d5f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion custom_components/powercalc/helpers.py
Expand Up @@ -8,6 +8,6 @@ async def evaluate_power(power: Union[Template, Decimal, float]) -> Decimal:
"""When power is a template render it."""

if isinstance(power, Template):
return power.async_render()
return Decimal(power.async_render())

return Decimal(power)
31 changes: 30 additions & 1 deletion tests/strategy/test_fixed.py
Expand Up @@ -11,6 +11,7 @@
from custom_components.powercalc.common import SourceEntity
from custom_components.powercalc.const import (
CONF_FIXED,
CONF_MULTIPLY_FACTOR,
CONF_POWER,
CONF_POWER_TEMPLATE,
CONF_SENSOR_TYPE,
Expand All @@ -23,7 +24,7 @@
from custom_components.powercalc.strategy.factory import PowerCalculatorStrategyFactory
from custom_components.powercalc.strategy.fixed import FixedStrategy

from ..common import create_input_boolean, create_input_number
from ..common import create_input_boolean, create_input_number, run_powercalc_setup
from .common import create_source_entity


Expand Down Expand Up @@ -188,6 +189,34 @@ async def test_config_entry_with_template_rendered_correctly(hass: HomeAssistant
assert state.state == "40.00"


async def test_template_power_combined_with_multiply_factor(hass: HomeAssistant):
"""
See https://github.com/bramstroker/homeassistant-powercalc/issues/1369
"""

await create_input_boolean(hass, "test")
await create_input_number(hass, "test", 30)

await run_powercalc_setup(
hass,
{
CONF_ENTITY_ID: "input_boolean.test",
CONF_FIXED: {
CONF_POWER: "{{states('input_number.test')}}"
},
CONF_MULTIPLY_FACTOR: 100
},
)

hass.states.async_set("input_boolean.test", STATE_ON)
hass.states.async_set("input_number.test", "20.5")
await hass.async_block_till_done()

state = hass.states.get("sensor.test_power")
assert state
assert state.state == "2050.00"


def _create_strategy(
hass: HomeAssistant, config: ConfigType, source_entity: SourceEntity
) -> FixedStrategy:
Expand Down

0 comments on commit 8992d5f

Please sign in to comment.