mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Use new unit enums in alexa (#83409)
* Use new unit enums in alexa * Adjust for mypy
This commit is contained in:
parent
d715aa6867
commit
91d6d620c2
@ -2,7 +2,7 @@
|
||||
from collections import OrderedDict
|
||||
|
||||
from homeassistant.components import climate
|
||||
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||
from homeassistant.const import UnitOfTemperature
|
||||
|
||||
DOMAIN = "alexa"
|
||||
EVENT_ALEXA_SMART_HOME = "alexa_smart_home"
|
||||
@ -61,7 +61,10 @@ CONF_SUPPORTED_LOCALES = (
|
||||
"pt-BR",
|
||||
)
|
||||
|
||||
API_TEMP_UNITS = {TEMP_FAHRENHEIT: "FAHRENHEIT", TEMP_CELSIUS: "CELSIUS"}
|
||||
API_TEMP_UNITS = {
|
||||
UnitOfTemperature.FAHRENHEIT: "FAHRENHEIT",
|
||||
UnitOfTemperature.CELSIUS: "CELSIUS",
|
||||
}
|
||||
|
||||
# Needs to be ordered dict for `async_api_set_thermostat_mode` which does a
|
||||
# reverse mapping of this dict and we want to map the first occurrence of OFF
|
||||
|
@ -37,8 +37,7 @@ from homeassistant.const import (
|
||||
CLOUD_NEVER_EXPOSED_ENTITIES,
|
||||
CONF_DESCRIPTION,
|
||||
CONF_NAME,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
UnitOfTemperature,
|
||||
__version__,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, State, callback
|
||||
@ -745,7 +744,10 @@ class SensorCapabilities(AlexaEntity):
|
||||
def interfaces(self):
|
||||
"""Yield the supported interfaces."""
|
||||
attrs = self.entity.attributes
|
||||
if attrs.get(ATTR_UNIT_OF_MEASUREMENT) in (TEMP_FAHRENHEIT, TEMP_CELSIUS):
|
||||
if attrs.get(ATTR_UNIT_OF_MEASUREMENT) in {
|
||||
UnitOfTemperature.FAHRENHEIT,
|
||||
UnitOfTemperature.CELSIUS,
|
||||
}:
|
||||
yield AlexaTemperatureSensor(self.hass, self.entity)
|
||||
yield AlexaEndpointHealth(self.hass, self.entity)
|
||||
yield Alexa(self.hass)
|
||||
|
@ -47,8 +47,7 @@ from homeassistant.const import (
|
||||
SERVICE_VOLUME_SET,
|
||||
SERVICE_VOLUME_UP,
|
||||
STATE_ALARM_DISARMED,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.helpers import network
|
||||
from homeassistant.util import color as color_util, dt as dt_util
|
||||
@ -758,11 +757,11 @@ async def async_api_previous(
|
||||
def temperature_from_object(hass, temp_obj, interval=False):
|
||||
"""Get temperature from Temperature object in requested unit."""
|
||||
to_unit = hass.config.units.temperature_unit
|
||||
from_unit = TEMP_CELSIUS
|
||||
from_unit = UnitOfTemperature.CELSIUS
|
||||
temp = float(temp_obj["value"])
|
||||
|
||||
if temp_obj["scale"] == "FAHRENHEIT":
|
||||
from_unit = TEMP_FAHRENHEIT
|
||||
from_unit = UnitOfTemperature.FAHRENHEIT
|
||||
elif temp_obj["scale"] == "KELVIN" and not interval:
|
||||
# convert to Celsius if absolute temperature
|
||||
temp -= 273.15
|
||||
|
@ -179,7 +179,7 @@ async def async_get_trigger_capabilities(
|
||||
}
|
||||
|
||||
if trigger_type == "current_temperature_changed":
|
||||
unit_of_measurement = hass.config.units.temperature_unit
|
||||
unit_of_measurement: str = hass.config.units.temperature_unit
|
||||
else:
|
||||
unit_of_measurement = PERCENTAGE
|
||||
|
||||
|
@ -84,14 +84,14 @@ class UnitSystem:
|
||||
self,
|
||||
name: str,
|
||||
*,
|
||||
accumulated_precipitation: str,
|
||||
accumulated_precipitation: UnitOfPrecipitationDepth,
|
||||
conversions: dict[tuple[SensorDeviceClass | str | None, str | None], str],
|
||||
length: str,
|
||||
mass: str,
|
||||
pressure: str,
|
||||
temperature: str,
|
||||
volume: str,
|
||||
wind_speed: str,
|
||||
length: UnitOfLength,
|
||||
mass: UnitOfMass,
|
||||
pressure: UnitOfPressure,
|
||||
temperature: UnitOfTemperature,
|
||||
volume: UnitOfVolume,
|
||||
wind_speed: UnitOfSpeed,
|
||||
) -> None:
|
||||
"""Initialize the unit system object."""
|
||||
errors: str = ", ".join(
|
||||
|
Loading…
x
Reference in New Issue
Block a user