Set state() template round param default to True

This commit is contained in:
abmantis 2025-07-03 17:15:54 +01:00
parent 3c4ecffa1b
commit be1ba31ff2
2 changed files with 3 additions and 5 deletions

View File

@ -938,17 +938,15 @@ class AllStates:
def __call__(
self,
entity_id: str,
rounded: bool | object = _SENTINEL,
rounded: bool = True,
with_unit: bool = False,
) -> str:
"""Return the states."""
state = _get_state(self._hass, entity_id)
if state is None:
return STATE_UNKNOWN
if rounded is _SENTINEL:
rounded = with_unit
if rounded or with_unit:
return state.format_state(rounded, with_unit) # type: ignore[arg-type]
return state.format_state(rounded, with_unit)
return state.state
def __repr__(self) -> str:

View File

@ -5183,7 +5183,7 @@ def test_state_with_unit_and_rounding(
assert tpl.async_render() == "23.02 beers"
assert tpl2.async_render() == "23.015 beers"
assert tpl3.async_render() == 23.015
assert tpl3.async_render() == 23.02
assert tpl4.async_render() == 23.015
assert tpl5.async_render() == "23.02 beers"
assert tpl6.async_render() == "23.015 beers"