From df1154395e0f5101e74e66927b037131ad0938b1 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Thu, 21 Oct 2021 15:03:33 +0200 Subject: [PATCH] Revert "Swap order of int template helper kwargs (#57729)" (#58015) This reverts commit f8dbcb953c8abec020da44bc1b581832405a17ba. --- homeassistant/helpers/template.py | 4 ++-- tests/helpers/test_template.py | 14 ++------------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index 8a72f7bdda4..1c6fcce9e5e 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -1460,7 +1460,7 @@ def forgiving_float_filter(value, default=_SENTINEL): return default -def forgiving_int(value, base=10, default=_SENTINEL): +def forgiving_int(value, default=_SENTINEL, base=10): """Try to convert value to an int, and warn if it fails.""" result = jinja2.filters.do_int(value, default=default, base=base) if result is _SENTINEL: @@ -1469,7 +1469,7 @@ def forgiving_int(value, base=10, default=_SENTINEL): return result -def forgiving_int_filter(value, base=10, default=_SENTINEL): +def forgiving_int_filter(value, default=_SENTINEL, base=10): """Try to convert value to an int, and warn if it fails.""" result = jinja2.filters.do_int(value, default=default, base=base) if result is _SENTINEL: diff --git a/tests/helpers/test_template.py b/tests/helpers/test_template.py index d6a25496bbf..4be9d527d31 100644 --- a/tests/helpers/test_template.py +++ b/tests/helpers/test_template.py @@ -248,14 +248,9 @@ def test_int_filter(hass): hass.states.async_set("sensor.temperature", "0x10") assert render(hass, "{{ states.sensor.temperature.state | int(base=16) }}") == 16 - assert render(hass, "{{ states.sensor.temperature.state | int(16) }}") == 16 - - hass.states.async_set("sensor.temperature", "1111") - assert render(hass, "{{ states.sensor.temperature.state | int(base=2) }}") == 15 - assert render(hass, "{{ states.sensor.temperature.state | int(2) }}") == 15 assert render(hass, "{{ 'bad' | int }}") == 0 - assert render(hass, "{{ 'bad' | int(10, 1) }}") == 1 + assert render(hass, "{{ 'bad' | int(1) }}") == 1 assert render(hass, "{{ 'bad' | int(default=1) }}") == 1 @@ -267,14 +262,9 @@ def test_int_function(hass): hass.states.async_set("sensor.temperature", "0x10") assert render(hass, "{{ int(states.sensor.temperature.state, base=16) }}") == 16 - assert render(hass, "{{ int(states.sensor.temperature.state, 16) }}") == 16 - - hass.states.async_set("sensor.temperature", "1111") - assert render(hass, "{{ int(states.sensor.temperature.state, base=2) }}") == 15 - assert render(hass, "{{ int(states.sensor.temperature.state, 2) }}") == 15 assert render(hass, "{{ int('bad') }}") == "bad" - assert render(hass, "{{ int('bad', 10, 1) }}") == 1 + assert render(hass, "{{ int('bad', 1) }}") == 1 assert render(hass, "{{ int('bad', default=1) }}") == 1