Implement thermostat support for Alexa (#13340)

* Implement thermostat support for Alexa

* util.temperature: Support interval conversions

* Use climate.ATTR_OPERATION_MODE for Alexa thermostat mode

* Switch coroutines to async/await

* Log all Alexa error events
This commit is contained in:
Albert Lee 2018-03-30 01:49:08 -05:00 committed by Paulus Schoutsen
parent 184f2be83e
commit 5801d78017
3 changed files with 374 additions and 17 deletions

View file

@ -3,17 +3,22 @@ from homeassistant.const import (
TEMP_CELSIUS, TEMP_FAHRENHEIT, UNIT_NOT_RECOGNIZED_TEMPLATE, TEMPERATURE)
def fahrenheit_to_celsius(fahrenheit: float) -> float:
def fahrenheit_to_celsius(fahrenheit: float, interval: bool = False) -> float:
"""Convert a temperature in Fahrenheit to Celsius."""
if interval:
return fahrenheit / 1.8
return (fahrenheit - 32.0) / 1.8
def celsius_to_fahrenheit(celsius: float) -> float:
def celsius_to_fahrenheit(celsius: float, interval: bool = False) -> float:
"""Convert a temperature in Celsius to Fahrenheit."""
if interval:
return celsius * 1.8
return celsius * 1.8 + 32.0
def convert(temperature: float, from_unit: str, to_unit: str) -> float:
def convert(temperature: float, from_unit: str, to_unit: str,
interval: bool = False) -> float:
"""Convert a temperature from one unit to another."""
if from_unit not in (TEMP_CELSIUS, TEMP_FAHRENHEIT):
raise ValueError(UNIT_NOT_RECOGNIZED_TEMPLATE.format(
@ -25,5 +30,5 @@ def convert(temperature: float, from_unit: str, to_unit: str) -> float:
if from_unit == to_unit:
return temperature
elif from_unit == TEMP_CELSIUS:
return celsius_to_fahrenheit(temperature)
return fahrenheit_to_celsius(temperature)
return celsius_to_fahrenheit(temperature, interval)
return fahrenheit_to_celsius(temperature, interval)