Revert "Swap order of int template helper kwargs (#57729)" (#58015)

This reverts commit f8dbcb953c.
pull/58264/head
Erik Montnemery 2021-10-21 15:03:33 +02:00 committed by GitHub
parent 2ff356393c
commit df1154395e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 14 deletions

View File

@ -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:

View File

@ -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