This reverts commit f8dbcb953c
.
pull/58264/head
parent
2ff356393c
commit
df1154395e
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue