Use new unit enums in helpers (#83387)
This commit is contained in:
parent
511fd293b6
commit
9f7fd8956f
2 changed files with 6 additions and 7 deletions
|
@ -82,9 +82,8 @@ from homeassistant.const import (
|
||||||
ENTITY_MATCH_NONE,
|
ENTITY_MATCH_NONE,
|
||||||
SUN_EVENT_SUNRISE,
|
SUN_EVENT_SUNRISE,
|
||||||
SUN_EVENT_SUNSET,
|
SUN_EVENT_SUNSET,
|
||||||
TEMP_CELSIUS,
|
|
||||||
TEMP_FAHRENHEIT,
|
|
||||||
WEEKDAYS,
|
WEEKDAYS,
|
||||||
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import split_entity_id, valid_entity_id
|
from homeassistant.core import split_entity_id, valid_entity_id
|
||||||
from homeassistant.exceptions import TemplateError
|
from homeassistant.exceptions import TemplateError
|
||||||
|
@ -579,13 +578,13 @@ def string_with_no_html(value: Any) -> str:
|
||||||
return str(value)
|
return str(value)
|
||||||
|
|
||||||
|
|
||||||
def temperature_unit(value: Any) -> str:
|
def temperature_unit(value: Any) -> UnitOfTemperature:
|
||||||
"""Validate and transform temperature unit."""
|
"""Validate and transform temperature unit."""
|
||||||
value = str(value).upper()
|
value = str(value).upper()
|
||||||
if value == "C":
|
if value == "C":
|
||||||
return TEMP_CELSIUS
|
return UnitOfTemperature.CELSIUS
|
||||||
if value == "F":
|
if value == "F":
|
||||||
return TEMP_FAHRENHEIT
|
return UnitOfTemperature.FAHRENHEIT
|
||||||
raise vol.Invalid("invalid temperature unit (expected C or F)")
|
raise vol.Invalid("invalid temperature unit (expected C or F)")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,8 @@ from homeassistant.const import (
|
||||||
ATTR_LONGITUDE,
|
ATTR_LONGITUDE,
|
||||||
ATTR_PERSONS,
|
ATTR_PERSONS,
|
||||||
ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
LENGTH_METERS,
|
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
|
UnitOfLength,
|
||||||
)
|
)
|
||||||
from homeassistant.core import (
|
from homeassistant.core import (
|
||||||
Context,
|
Context,
|
||||||
|
@ -1364,7 +1364,7 @@ def distance(hass, *args):
|
||||||
return hass.config.distance(*locations[0])
|
return hass.config.distance(*locations[0])
|
||||||
|
|
||||||
return hass.config.units.length(
|
return hass.config.units.length(
|
||||||
loc_util.distance(*locations[0] + locations[1]), LENGTH_METERS
|
loc_util.distance(*locations[0] + locations[1]), UnitOfLength.METERS
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue