2017-09-16 19:35:28 +00:00
|
|
|
"""Test for smart home alexa support."""
|
|
|
|
import pytest
|
|
|
|
|
2018-08-20 12:18:07 +00:00
|
|
|
from homeassistant.core import Context, callback
|
2019-06-13 15:43:57 +00:00
|
|
|
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT
|
2019-07-31 19:25:30 +00:00
|
|
|
from homeassistant.components.alexa import smart_home, messages
|
2017-11-18 05:10:24 +00:00
|
|
|
from homeassistant.helpers import entityfilter
|
2017-09-16 19:35:28 +00:00
|
|
|
|
|
|
|
from tests.common import async_mock_service
|
|
|
|
|
2019-06-13 15:43:57 +00:00
|
|
|
from . import (
|
|
|
|
get_new_request,
|
2019-06-13 18:58:08 +00:00
|
|
|
MockConfig,
|
2019-06-13 15:43:57 +00:00
|
|
|
DEFAULT_CONFIG,
|
|
|
|
assert_request_calls_service,
|
|
|
|
assert_request_fails,
|
|
|
|
ReportedProperties,
|
|
|
|
assert_power_controller_works,
|
|
|
|
assert_scene_controller_works,
|
|
|
|
reported_properties,
|
|
|
|
)
|
2017-11-18 05:10:24 +00:00
|
|
|
|
2017-09-16 19:35:28 +00:00
|
|
|
|
2018-08-20 12:18:07 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def events(hass):
|
|
|
|
"""Fixture that catches alexa events."""
|
|
|
|
events = []
|
|
|
|
hass.bus.async_listen(
|
2019-07-31 19:25:30 +00:00
|
|
|
smart_home.EVENT_ALEXA_SMART_HOME, callback(lambda e: events.append(e))
|
2018-08-20 12:18:07 +00:00
|
|
|
)
|
|
|
|
yield events
|
|
|
|
|
|
|
|
|
Refactor Alexa API, fix thermostats (#17969)
* Refactor Alexa API to use objects for requests
This introduces _AlexaDirective to stand in for the previous model of passing
basic dict and list data structures to and from handlers. This gives a more
expressive platform for functionality common to most or all handlers.
I had two use cases in mind:
1) Most responses should include current properties. In the case of locks and
thermostats, the response must include the properties or Alexa will give the
user a vague error like "Hmm, $device is not responding." Locks currently work,
but thermostats do not. I wanted a way to automatically include properties in
all responses. This is implemented in a subsequent commit.
2) The previous model had a 1:1 mapping between Alexa endpoints and Home
Assistant entities. This works most of the time, but sometimes it's not so
great. For example, my Z-wave thermostat shows as three devices in Alexa: one
for the temperature sensor, one for the heat, and one for the AC. I'd like to
merge these into one device from Alexa's perspective. I believe this will be
facilitated with the `endpoint` attribute on `_AlexaDirective`.
* Include properties in all Alexa responses
The added _AlexaResponse class provides a richer vocabulary for handlers.
Among that vocabulary is .merge_context_properties(), which is invoked
automatically for any request directed at an endpoint. This adds all supported
properties to the response as recommended by the Alexa API docs, and in some
cases (locks, thermostats at least) the user will get an error "Hmm, $device is
not responding" if properties are not provided in the response.
* Fix setting temperature with Alexa thermostats
Fixes https://github.com/home-assistant/home-assistant/issues/16577
2018-10-30 02:16:35 +00:00
|
|
|
def test_create_api_message_defaults(hass):
|
2017-10-07 20:31:57 +00:00
|
|
|
"""Create a API message response of a request with defaults."""
|
2019-07-31 19:25:30 +00:00
|
|
|
request = get_new_request("Alexa.PowerController", "TurnOn", "switch#xy")
|
|
|
|
directive_header = request["directive"]["header"]
|
2019-06-13 15:43:57 +00:00
|
|
|
directive = messages.AlexaDirective(request)
|
2017-10-07 20:31:57 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
msg = directive.response(payload={"test": 3})._response
|
2017-10-07 20:31:57 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert "event" in msg
|
|
|
|
msg = msg["event"]
|
2017-09-16 19:35:28 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert msg["header"]["messageId"] is not None
|
|
|
|
assert msg["header"]["messageId"] != directive_header["messageId"]
|
|
|
|
assert msg["header"]["correlationToken"] == directive_header["correlationToken"]
|
|
|
|
assert msg["header"]["name"] == "Response"
|
|
|
|
assert msg["header"]["namespace"] == "Alexa"
|
|
|
|
assert msg["header"]["payloadVersion"] == "3"
|
2017-10-07 20:31:57 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert "test" in msg["payload"]
|
|
|
|
assert msg["payload"]["test"] == 3
|
2017-10-07 20:31:57 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert msg["endpoint"] == request["directive"]["endpoint"]
|
|
|
|
assert msg["endpoint"] is not request["directive"]["endpoint"]
|
2017-10-07 20:31:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_create_api_message_special():
|
|
|
|
"""Create a API message response of a request with non defaults."""
|
2019-07-31 19:25:30 +00:00
|
|
|
request = get_new_request("Alexa.PowerController", "TurnOn")
|
|
|
|
directive_header = request["directive"]["header"]
|
|
|
|
directive_header.pop("correlationToken")
|
2019-06-13 15:43:57 +00:00
|
|
|
directive = messages.AlexaDirective(request)
|
2017-10-07 20:31:57 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
msg = directive.response("testName", "testNameSpace")._response
|
2017-10-07 20:31:57 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert "event" in msg
|
|
|
|
msg = msg["event"]
|
2017-10-07 20:31:57 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert msg["header"]["messageId"] is not None
|
|
|
|
assert msg["header"]["messageId"] != directive_header["messageId"]
|
|
|
|
assert "correlationToken" not in msg["header"]
|
|
|
|
assert msg["header"]["name"] == "testName"
|
|
|
|
assert msg["header"]["namespace"] == "testNameSpace"
|
|
|
|
assert msg["header"]["payloadVersion"] == "3"
|
2017-10-07 20:31:57 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert msg["payload"] == {}
|
|
|
|
assert "endpoint" not in msg
|
2017-09-16 19:35:28 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_wrong_version(hass):
|
2017-09-16 19:35:28 +00:00
|
|
|
"""Test with wrong version."""
|
2019-07-31 19:25:30 +00:00
|
|
|
msg = get_new_request("Alexa.PowerController", "TurnOn")
|
|
|
|
msg["directive"]["header"]["payloadVersion"] = "2"
|
2017-09-16 19:35:28 +00:00
|
|
|
|
|
|
|
with pytest.raises(AssertionError):
|
2018-10-29 21:57:27 +00:00
|
|
|
await smart_home.async_handle_message(hass, DEFAULT_CONFIG, msg)
|
2017-09-16 19:35:28 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def discovery_test(device, hass, expected_endpoints=1):
|
2017-09-16 19:35:28 +00:00
|
|
|
"""Test alexa discovery request."""
|
2019-07-31 19:25:30 +00:00
|
|
|
request = get_new_request("Alexa.Discovery", "Discover")
|
2017-09-16 19:35:28 +00:00
|
|
|
|
2017-11-17 17:14:22 +00:00
|
|
|
# setup test devices
|
2018-01-30 04:33:39 +00:00
|
|
|
hass.states.async_set(*device)
|
2017-09-16 19:35:28 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
msg = await smart_home.async_handle_message(hass, DEFAULT_CONFIG, request)
|
2017-09-16 19:35:28 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert "event" in msg
|
|
|
|
msg = msg["event"]
|
2017-11-16 05:44:27 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert msg["header"]["name"] == "Discover.Response"
|
|
|
|
assert msg["header"]["namespace"] == "Alexa.Discovery"
|
|
|
|
endpoints = msg["payload"]["endpoints"]
|
2018-01-30 04:33:39 +00:00
|
|
|
assert len(endpoints) == expected_endpoints
|
2017-11-17 17:14:22 +00:00
|
|
|
|
2018-01-30 04:33:39 +00:00
|
|
|
if expected_endpoints == 1:
|
|
|
|
return endpoints[0]
|
2018-07-23 08:16:05 +00:00
|
|
|
if expected_endpoints > 1:
|
2018-01-30 04:33:39 +00:00
|
|
|
return endpoints
|
|
|
|
return None
|
2017-11-17 17:14:22 +00:00
|
|
|
|
|
|
|
|
2019-01-10 23:52:21 +00:00
|
|
|
def get_capability(capabilities, capability_name):
|
|
|
|
"""Search a set of capabilities for a specific one."""
|
|
|
|
for capability in capabilities:
|
2019-07-31 19:25:30 +00:00
|
|
|
if capability["interface"] == capability_name:
|
2019-01-10 23:52:21 +00:00
|
|
|
return capability
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2018-01-30 04:33:39 +00:00
|
|
|
def assert_endpoint_capabilities(endpoint, *interfaces):
|
|
|
|
"""Assert the endpoint supports the given interfaces.
|
2017-11-17 17:14:22 +00:00
|
|
|
|
2018-01-30 04:33:39 +00:00
|
|
|
Returns a set of capabilities, in case you want to assert more things about
|
|
|
|
them.
|
|
|
|
"""
|
2019-07-31 19:25:30 +00:00
|
|
|
capabilities = endpoint["capabilities"]
|
|
|
|
supported = set(feature["interface"] for feature in capabilities)
|
2017-11-17 17:14:22 +00:00
|
|
|
|
2018-01-30 04:33:39 +00:00
|
|
|
assert supported == set(interfaces)
|
|
|
|
return capabilities
|
2017-11-17 17:14:22 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_switch(hass, events):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Test switch discovery."""
|
2019-07-31 19:25:30 +00:00
|
|
|
device = ("switch.test", "on", {"friendly_name": "Test switch"})
|
2018-10-29 21:57:27 +00:00
|
|
|
appliance = await discovery_test(device, hass)
|
2017-11-17 17:14:22 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "switch#test"
|
|
|
|
assert appliance["displayCategories"][0] == "SWITCH"
|
|
|
|
assert appliance["friendlyName"] == "Test switch"
|
2019-01-10 23:52:21 +00:00
|
|
|
assert_endpoint_capabilities(
|
2019-07-31 19:25:30 +00:00
|
|
|
appliance, "Alexa.PowerController", "Alexa.EndpointHealth"
|
2019-01-10 23:52:21 +00:00
|
|
|
)
|
2017-11-17 17:14:22 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
await assert_power_controller_works(
|
2019-07-31 19:25:30 +00:00
|
|
|
"switch#test", "switch.turn_on", "switch.turn_off", hass
|
|
|
|
)
|
2017-11-17 17:14:22 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
properties = await reported_properties(hass, "switch#test")
|
|
|
|
properties.assert_equal("Alexa.PowerController", "powerState", "ON")
|
2018-01-26 18:40:39 +00:00
|
|
|
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_light(hass):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Test light discovery."""
|
2019-07-31 19:25:30 +00:00
|
|
|
device = ("light.test_1", "on", {"friendly_name": "Test light 1"})
|
2018-10-29 21:57:27 +00:00
|
|
|
appliance = await discovery_test(device, hass)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "light#test_1"
|
|
|
|
assert appliance["displayCategories"][0] == "LIGHT"
|
|
|
|
assert appliance["friendlyName"] == "Test light 1"
|
2019-01-10 23:52:21 +00:00
|
|
|
assert_endpoint_capabilities(
|
2019-07-31 19:25:30 +00:00
|
|
|
appliance, "Alexa.PowerController", "Alexa.EndpointHealth"
|
2019-01-10 23:52:21 +00:00
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
await assert_power_controller_works(
|
2019-07-31 19:25:30 +00:00
|
|
|
"light#test_1", "light.turn_on", "light.turn_off", hass
|
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_dimmable_light(hass):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Test dimmable light discovery."""
|
|
|
|
device = (
|
2019-07-31 19:25:30 +00:00
|
|
|
"light.test_2",
|
|
|
|
"on",
|
|
|
|
{"brightness": 128, "friendly_name": "Test light 2", "supported_features": 1},
|
|
|
|
)
|
2018-10-29 21:57:27 +00:00
|
|
|
appliance = await discovery_test(device, hass)
|
2018-01-26 18:40:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "light#test_2"
|
|
|
|
assert appliance["displayCategories"][0] == "LIGHT"
|
|
|
|
assert appliance["friendlyName"] == "Test light 2"
|
2017-10-07 20:31:57 +00:00
|
|
|
|
2018-01-30 04:33:39 +00:00
|
|
|
assert_endpoint_capabilities(
|
|
|
|
appliance,
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.BrightnessController",
|
|
|
|
"Alexa.PowerController",
|
|
|
|
"Alexa.EndpointHealth",
|
2018-01-30 04:33:39 +00:00
|
|
|
)
|
2017-09-16 19:35:28 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
properties = await reported_properties(hass, "light#test_2")
|
|
|
|
properties.assert_equal("Alexa.PowerController", "powerState", "ON")
|
|
|
|
properties.assert_equal("Alexa.BrightnessController", "brightness", 50)
|
2017-09-16 19:35:28 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
call, _ = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.BrightnessController",
|
|
|
|
"SetBrightness",
|
|
|
|
"light#test_2",
|
|
|
|
"light.turn_on",
|
2018-01-30 04:33:39 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"brightness": "50"},
|
|
|
|
)
|
|
|
|
assert call.data["brightness_pct"] == 50
|
2018-01-30 04:33:39 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_color_light(hass):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Test color light discovery."""
|
|
|
|
device = (
|
2019-07-31 19:25:30 +00:00
|
|
|
"light.test_3",
|
|
|
|
"on",
|
2018-01-30 04:33:39 +00:00
|
|
|
{
|
2019-07-31 19:25:30 +00:00
|
|
|
"friendly_name": "Test light 3",
|
|
|
|
"supported_features": 19,
|
|
|
|
"min_mireds": 142,
|
|
|
|
"color_temp": "333",
|
|
|
|
},
|
2018-01-30 04:33:39 +00:00
|
|
|
)
|
2018-10-29 21:57:27 +00:00
|
|
|
appliance = await discovery_test(device, hass)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "light#test_3"
|
|
|
|
assert appliance["displayCategories"][0] == "LIGHT"
|
|
|
|
assert appliance["friendlyName"] == "Test light 3"
|
2018-01-30 04:33:39 +00:00
|
|
|
|
|
|
|
assert_endpoint_capabilities(
|
|
|
|
appliance,
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.BrightnessController",
|
|
|
|
"Alexa.PowerController",
|
|
|
|
"Alexa.ColorController",
|
|
|
|
"Alexa.ColorTemperatureController",
|
|
|
|
"Alexa.EndpointHealth",
|
2018-01-30 04:33:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# IncreaseColorTemperature and DecreaseColorTemperature have their own
|
|
|
|
# tests
|
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_script(hass):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Test script discovery."""
|
2019-07-31 19:25:30 +00:00
|
|
|
device = ("script.test", "off", {"friendly_name": "Test script"})
|
2018-10-29 21:57:27 +00:00
|
|
|
appliance = await discovery_test(device, hass)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "script#test"
|
|
|
|
assert appliance["displayCategories"][0] == "ACTIVITY_TRIGGER"
|
|
|
|
assert appliance["friendlyName"] == "Test script"
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
(capability,) = assert_endpoint_capabilities(appliance, "Alexa.SceneController")
|
|
|
|
assert not capability["supportsDeactivation"]
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
await assert_scene_controller_works("script#test", "script.turn_on", None, hass)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_cancelable_script(hass):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Test cancalable script discovery."""
|
|
|
|
device = (
|
2019-07-31 19:25:30 +00:00
|
|
|
"script.test_2",
|
|
|
|
"off",
|
|
|
|
{"friendly_name": "Test script 2", "can_cancel": True},
|
2018-01-30 04:33:39 +00:00
|
|
|
)
|
2018-10-29 21:57:27 +00:00
|
|
|
appliance = await discovery_test(device, hass)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "script#test_2"
|
|
|
|
(capability,) = assert_endpoint_capabilities(appliance, "Alexa.SceneController")
|
|
|
|
assert capability["supportsDeactivation"]
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
await assert_scene_controller_works(
|
2019-07-31 19:25:30 +00:00
|
|
|
"script#test_2", "script.turn_on", "script.turn_off", hass
|
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_input_boolean(hass):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Test input boolean discovery."""
|
2019-07-31 19:25:30 +00:00
|
|
|
device = ("input_boolean.test", "off", {"friendly_name": "Test input boolean"})
|
2018-10-29 21:57:27 +00:00
|
|
|
appliance = await discovery_test(device, hass)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "input_boolean#test"
|
|
|
|
assert appliance["displayCategories"][0] == "OTHER"
|
|
|
|
assert appliance["friendlyName"] == "Test input boolean"
|
2019-01-10 23:52:21 +00:00
|
|
|
assert_endpoint_capabilities(
|
2019-07-31 19:25:30 +00:00
|
|
|
appliance, "Alexa.PowerController", "Alexa.EndpointHealth"
|
2019-01-10 23:52:21 +00:00
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
await assert_power_controller_works(
|
2019-07-31 19:25:30 +00:00
|
|
|
"input_boolean#test", "input_boolean.turn_on", "input_boolean.turn_off", hass
|
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_scene(hass):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Test scene discovery."""
|
2019-07-31 19:25:30 +00:00
|
|
|
device = ("scene.test", "off", {"friendly_name": "Test scene"})
|
2018-10-29 21:57:27 +00:00
|
|
|
appliance = await discovery_test(device, hass)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "scene#test"
|
|
|
|
assert appliance["displayCategories"][0] == "SCENE_TRIGGER"
|
|
|
|
assert appliance["friendlyName"] == "Test scene"
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
(capability,) = assert_endpoint_capabilities(appliance, "Alexa.SceneController")
|
|
|
|
assert not capability["supportsDeactivation"]
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
await assert_scene_controller_works("scene#test", "scene.turn_on", None, hass)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_fan(hass):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Test fan discovery."""
|
2019-07-31 19:25:30 +00:00
|
|
|
device = ("fan.test_1", "off", {"friendly_name": "Test fan 1"})
|
2018-10-29 21:57:27 +00:00
|
|
|
appliance = await discovery_test(device, hass)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "fan#test_1"
|
|
|
|
assert appliance["displayCategories"][0] == "OTHER"
|
|
|
|
assert appliance["friendlyName"] == "Test fan 1"
|
2019-01-10 23:52:21 +00:00
|
|
|
assert_endpoint_capabilities(
|
2019-07-31 19:25:30 +00:00
|
|
|
appliance, "Alexa.PowerController", "Alexa.EndpointHealth"
|
2019-01-10 23:52:21 +00:00
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_variable_fan(hass):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Test fan discovery.
|
|
|
|
|
|
|
|
This one has variable speed.
|
|
|
|
"""
|
|
|
|
device = (
|
2019-07-31 19:25:30 +00:00
|
|
|
"fan.test_2",
|
|
|
|
"off",
|
|
|
|
{
|
|
|
|
"friendly_name": "Test fan 2",
|
|
|
|
"supported_features": 1,
|
|
|
|
"speed_list": ["low", "medium", "high"],
|
|
|
|
"speed": "high",
|
|
|
|
},
|
2018-01-30 04:33:39 +00:00
|
|
|
)
|
2018-10-29 21:57:27 +00:00
|
|
|
appliance = await discovery_test(device, hass)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "fan#test_2"
|
|
|
|
assert appliance["displayCategories"][0] == "OTHER"
|
|
|
|
assert appliance["friendlyName"] == "Test fan 2"
|
2018-01-30 04:33:39 +00:00
|
|
|
|
|
|
|
assert_endpoint_capabilities(
|
|
|
|
appliance,
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.PercentageController",
|
|
|
|
"Alexa.PowerController",
|
|
|
|
"Alexa.EndpointHealth",
|
2018-01-30 04:33:39 +00:00
|
|
|
)
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
call, _ = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.PercentageController",
|
|
|
|
"SetPercentage",
|
|
|
|
"fan#test_2",
|
|
|
|
"fan.set_speed",
|
2018-01-30 04:33:39 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"percentage": "50"},
|
|
|
|
)
|
|
|
|
assert call.data["speed"] == "medium"
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
await assert_percentage_changes(
|
2018-01-30 04:33:39 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
[("high", "-5"), ("off", "5"), ("low", "-80")],
|
|
|
|
"Alexa.PercentageController",
|
|
|
|
"AdjustPercentage",
|
|
|
|
"fan#test_2",
|
|
|
|
"percentageDelta",
|
|
|
|
"fan.set_speed",
|
|
|
|
"speed",
|
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_lock(hass):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Test lock discovery."""
|
2019-07-31 19:25:30 +00:00
|
|
|
device = ("lock.test", "off", {"friendly_name": "Test lock"})
|
2018-10-29 21:57:27 +00:00
|
|
|
appliance = await discovery_test(device, hass)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "lock#test"
|
|
|
|
assert appliance["displayCategories"][0] == "SMARTLOCK"
|
|
|
|
assert appliance["friendlyName"] == "Test lock"
|
2019-01-10 23:52:21 +00:00
|
|
|
assert_endpoint_capabilities(
|
2019-07-31 19:25:30 +00:00
|
|
|
appliance, "Alexa.LockController", "Alexa.EndpointHealth"
|
2019-01-10 23:52:21 +00:00
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
_, msg = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.LockController", "Lock", "lock#test", "lock.lock", hass
|
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-02-12 07:20:54 +00:00
|
|
|
# always return LOCKED for now
|
2019-07-31 19:25:30 +00:00
|
|
|
properties = msg["context"]["properties"][0]
|
|
|
|
assert properties["name"] == "lockState"
|
|
|
|
assert properties["namespace"] == "Alexa.LockController"
|
|
|
|
assert properties["value"] == "LOCKED"
|
2018-02-12 07:20:54 +00:00
|
|
|
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_media_player(hass):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Test media player discovery."""
|
|
|
|
device = (
|
2019-07-31 19:25:30 +00:00
|
|
|
"media_player.test",
|
|
|
|
"off",
|
|
|
|
{
|
|
|
|
"friendly_name": "Test media player",
|
|
|
|
"supported_features": 0x59BD,
|
|
|
|
"volume_level": 0.75,
|
|
|
|
},
|
2018-01-30 04:33:39 +00:00
|
|
|
)
|
2018-10-29 21:57:27 +00:00
|
|
|
appliance = await discovery_test(device, hass)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "media_player#test"
|
|
|
|
assert appliance["displayCategories"][0] == "TV"
|
|
|
|
assert appliance["friendlyName"] == "Test media player"
|
2018-01-30 04:33:39 +00:00
|
|
|
|
|
|
|
assert_endpoint_capabilities(
|
|
|
|
appliance,
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.InputController",
|
|
|
|
"Alexa.PowerController",
|
|
|
|
"Alexa.Speaker",
|
|
|
|
"Alexa.StepSpeaker",
|
|
|
|
"Alexa.PlaybackController",
|
|
|
|
"Alexa.EndpointHealth",
|
2018-01-30 04:33:39 +00:00
|
|
|
)
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
await assert_power_controller_works(
|
2019-07-31 19:25:30 +00:00
|
|
|
"media_player#test", "media_player.turn_on", "media_player.turn_off", hass
|
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.PlaybackController",
|
|
|
|
"Play",
|
|
|
|
"media_player#test",
|
|
|
|
"media_player.media_play",
|
|
|
|
hass,
|
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.PlaybackController",
|
|
|
|
"Pause",
|
|
|
|
"media_player#test",
|
|
|
|
"media_player.media_pause",
|
|
|
|
hass,
|
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.PlaybackController",
|
|
|
|
"Stop",
|
|
|
|
"media_player#test",
|
|
|
|
"media_player.media_stop",
|
|
|
|
hass,
|
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.PlaybackController",
|
|
|
|
"Next",
|
|
|
|
"media_player#test",
|
|
|
|
"media_player.media_next_track",
|
|
|
|
hass,
|
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.PlaybackController",
|
|
|
|
"Previous",
|
|
|
|
"media_player#test",
|
|
|
|
"media_player.media_previous_track",
|
|
|
|
hass,
|
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
call, _ = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.Speaker",
|
|
|
|
"SetVolume",
|
|
|
|
"media_player#test",
|
|
|
|
"media_player.volume_set",
|
2018-01-30 04:33:39 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"volume": 50},
|
|
|
|
)
|
|
|
|
assert call.data["volume_level"] == 0.5
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
call, _ = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.Speaker",
|
|
|
|
"SetMute",
|
|
|
|
"media_player#test",
|
|
|
|
"media_player.volume_mute",
|
2018-01-30 04:33:39 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"mute": True},
|
|
|
|
)
|
|
|
|
assert call.data["is_volume_muted"]
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
call, _, = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.Speaker",
|
|
|
|
"SetMute",
|
|
|
|
"media_player#test",
|
|
|
|
"media_player.volume_mute",
|
2018-01-30 04:33:39 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"mute": False},
|
|
|
|
)
|
|
|
|
assert not call.data["is_volume_muted"]
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
await assert_percentage_changes(
|
2018-01-30 04:33:39 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
[(0.7, "-5"), (0.8, "5"), (0, "-80")],
|
|
|
|
"Alexa.Speaker",
|
|
|
|
"AdjustVolume",
|
|
|
|
"media_player#test",
|
|
|
|
"volume",
|
|
|
|
"media_player.volume_set",
|
|
|
|
"volume_level",
|
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
call, _ = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.StepSpeaker",
|
|
|
|
"SetMute",
|
|
|
|
"media_player#test",
|
|
|
|
"media_player.volume_mute",
|
2018-02-06 00:02:08 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"mute": True},
|
|
|
|
)
|
|
|
|
assert call.data["is_volume_muted"]
|
2018-02-06 00:02:08 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
call, _, = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.StepSpeaker",
|
|
|
|
"SetMute",
|
|
|
|
"media_player#test",
|
|
|
|
"media_player.volume_mute",
|
2018-02-06 00:02:08 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"mute": False},
|
|
|
|
)
|
|
|
|
assert not call.data["is_volume_muted"]
|
2018-02-06 00:02:08 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
call, _ = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.StepSpeaker",
|
|
|
|
"AdjustVolume",
|
|
|
|
"media_player#test",
|
|
|
|
"media_player.volume_up",
|
2018-02-06 00:02:08 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"volumeSteps": 20},
|
|
|
|
)
|
2018-02-06 00:02:08 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
call, _ = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.StepSpeaker",
|
|
|
|
"AdjustVolume",
|
|
|
|
"media_player#test",
|
|
|
|
"media_player.volume_down",
|
2018-02-06 00:02:08 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"volumeSteps": -20},
|
|
|
|
)
|
2018-02-06 00:02:08 +00:00
|
|
|
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-04-29 20:40:55 +00:00
|
|
|
async def test_media_player_power(hass):
|
|
|
|
"""Test media player discovery with mapped on/off."""
|
|
|
|
device = (
|
2019-07-31 19:25:30 +00:00
|
|
|
"media_player.test",
|
|
|
|
"off",
|
|
|
|
{
|
|
|
|
"friendly_name": "Test media player",
|
|
|
|
"supported_features": 0xFA3F,
|
|
|
|
"volume_level": 0.75,
|
|
|
|
},
|
2019-04-29 20:40:55 +00:00
|
|
|
)
|
|
|
|
appliance = await discovery_test(device, hass)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "media_player#test"
|
|
|
|
assert appliance["displayCategories"][0] == "TV"
|
|
|
|
assert appliance["friendlyName"] == "Test media player"
|
2019-04-29 20:40:55 +00:00
|
|
|
|
|
|
|
assert_endpoint_capabilities(
|
|
|
|
appliance,
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.InputController",
|
|
|
|
"Alexa.PowerController",
|
|
|
|
"Alexa.Speaker",
|
|
|
|
"Alexa.StepSpeaker",
|
|
|
|
"Alexa.PlaybackController",
|
|
|
|
"Alexa.EndpointHealth",
|
2019-04-29 20:40:55 +00:00
|
|
|
)
|
|
|
|
|
2019-07-11 15:35:46 +00:00
|
|
|
await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.PowerController",
|
|
|
|
"TurnOn",
|
|
|
|
"media_player#test",
|
|
|
|
"media_player.media_play",
|
|
|
|
hass,
|
|
|
|
)
|
2019-07-11 15:35:46 +00:00
|
|
|
|
|
|
|
await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.PowerController",
|
|
|
|
"TurnOff",
|
|
|
|
"media_player#test",
|
|
|
|
"media_player.media_stop",
|
|
|
|
hass,
|
|
|
|
)
|
2019-07-11 15:35:46 +00:00
|
|
|
|
2019-04-29 20:40:55 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_alert(hass):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Test alert discovery."""
|
2019-07-31 19:25:30 +00:00
|
|
|
device = ("alert.test", "off", {"friendly_name": "Test alert"})
|
2018-10-29 21:57:27 +00:00
|
|
|
appliance = await discovery_test(device, hass)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "alert#test"
|
|
|
|
assert appliance["displayCategories"][0] == "OTHER"
|
|
|
|
assert appliance["friendlyName"] == "Test alert"
|
2019-01-10 23:52:21 +00:00
|
|
|
assert_endpoint_capabilities(
|
2019-07-31 19:25:30 +00:00
|
|
|
appliance, "Alexa.PowerController", "Alexa.EndpointHealth"
|
2019-01-10 23:52:21 +00:00
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
await assert_power_controller_works(
|
2019-07-31 19:25:30 +00:00
|
|
|
"alert#test", "alert.turn_on", "alert.turn_off", hass
|
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_automation(hass):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Test automation discovery."""
|
2019-07-31 19:25:30 +00:00
|
|
|
device = ("automation.test", "off", {"friendly_name": "Test automation"})
|
2018-10-29 21:57:27 +00:00
|
|
|
appliance = await discovery_test(device, hass)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "automation#test"
|
|
|
|
assert appliance["displayCategories"][0] == "OTHER"
|
|
|
|
assert appliance["friendlyName"] == "Test automation"
|
2019-01-10 23:52:21 +00:00
|
|
|
assert_endpoint_capabilities(
|
2019-07-31 19:25:30 +00:00
|
|
|
appliance, "Alexa.PowerController", "Alexa.EndpointHealth"
|
2019-01-10 23:52:21 +00:00
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
await assert_power_controller_works(
|
2019-07-31 19:25:30 +00:00
|
|
|
"automation#test", "automation.turn_on", "automation.turn_off", hass
|
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_group(hass):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Test group discovery."""
|
2019-07-31 19:25:30 +00:00
|
|
|
device = ("group.test", "off", {"friendly_name": "Test group"})
|
2018-10-29 21:57:27 +00:00
|
|
|
appliance = await discovery_test(device, hass)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "group#test"
|
|
|
|
assert appliance["displayCategories"][0] == "OTHER"
|
|
|
|
assert appliance["friendlyName"] == "Test group"
|
2019-01-10 23:52:21 +00:00
|
|
|
assert_endpoint_capabilities(
|
2019-07-31 19:25:30 +00:00
|
|
|
appliance, "Alexa.PowerController", "Alexa.EndpointHealth"
|
2019-01-10 23:52:21 +00:00
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
await assert_power_controller_works(
|
2019-07-31 19:25:30 +00:00
|
|
|
"group#test", "homeassistant.turn_on", "homeassistant.turn_off", hass
|
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_cover(hass):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Test cover discovery."""
|
|
|
|
device = (
|
2019-07-31 19:25:30 +00:00
|
|
|
"cover.test",
|
|
|
|
"off",
|
|
|
|
{"friendly_name": "Test cover", "supported_features": 255, "position": 30},
|
2018-01-30 04:33:39 +00:00
|
|
|
)
|
2018-10-29 21:57:27 +00:00
|
|
|
appliance = await discovery_test(device, hass)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "cover#test"
|
|
|
|
assert appliance["displayCategories"][0] == "DOOR"
|
|
|
|
assert appliance["friendlyName"] == "Test cover"
|
2018-01-30 04:33:39 +00:00
|
|
|
|
|
|
|
assert_endpoint_capabilities(
|
|
|
|
appliance,
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.PercentageController",
|
|
|
|
"Alexa.PowerController",
|
|
|
|
"Alexa.EndpointHealth",
|
2018-01-30 04:33:39 +00:00
|
|
|
)
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
await assert_power_controller_works(
|
2019-07-31 19:25:30 +00:00
|
|
|
"cover#test", "cover.open_cover", "cover.close_cover", hass
|
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
call, _ = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.PercentageController",
|
|
|
|
"SetPercentage",
|
|
|
|
"cover#test",
|
|
|
|
"cover.set_cover_position",
|
2018-01-30 04:33:39 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"percentage": "50"},
|
|
|
|
)
|
|
|
|
assert call.data["position"] == 50
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
await assert_percentage_changes(
|
2018-01-30 04:33:39 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
[(25, "-5"), (35, "5"), (0, "-80")],
|
|
|
|
"Alexa.PercentageController",
|
|
|
|
"AdjustPercentage",
|
|
|
|
"cover#test",
|
|
|
|
"percentageDelta",
|
|
|
|
"cover.set_cover_position",
|
|
|
|
"position",
|
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def assert_percentage_changes(
|
2019-07-31 19:25:30 +00:00
|
|
|
hass, adjustments, namespace, name, endpoint, parameter, service, changed_parameter
|
|
|
|
):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Assert an API request making percentage changes works.
|
|
|
|
|
|
|
|
AdjustPercentage, AdjustBrightness, etc. are examples of such requests.
|
|
|
|
"""
|
|
|
|
for result_volume, adjustment in adjustments:
|
|
|
|
if parameter:
|
|
|
|
payload = {parameter: adjustment}
|
|
|
|
else:
|
|
|
|
payload = {}
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
call, _ = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
namespace, name, endpoint, service, hass, payload=payload
|
|
|
|
)
|
2018-01-30 04:33:39 +00:00
|
|
|
assert call.data[changed_parameter] == result_volume
|
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_temp_sensor(hass):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Test temperature sensor discovery."""
|
|
|
|
device = (
|
2019-07-31 19:25:30 +00:00
|
|
|
"sensor.test_temp",
|
|
|
|
"42",
|
|
|
|
{"friendly_name": "Test Temp Sensor", "unit_of_measurement": TEMP_FAHRENHEIT},
|
2018-01-30 04:33:39 +00:00
|
|
|
)
|
2018-10-29 21:57:27 +00:00
|
|
|
appliance = await discovery_test(device, hass)
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "sensor#test_temp"
|
|
|
|
assert appliance["displayCategories"][0] == "TEMPERATURE_SENSOR"
|
|
|
|
assert appliance["friendlyName"] == "Test Temp Sensor"
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-01-10 23:52:21 +00:00
|
|
|
capabilities = assert_endpoint_capabilities(
|
2019-07-31 19:25:30 +00:00
|
|
|
appliance, "Alexa.TemperatureSensor", "Alexa.EndpointHealth"
|
2019-01-10 23:52:21 +00:00
|
|
|
)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
temp_sensor_capability = get_capability(capabilities, "Alexa.TemperatureSensor")
|
2019-01-10 23:52:21 +00:00
|
|
|
assert temp_sensor_capability is not None
|
2019-07-31 19:25:30 +00:00
|
|
|
properties = temp_sensor_capability["properties"]
|
|
|
|
assert properties["retrievable"] is True
|
|
|
|
assert {"name": "temperature"} in properties["supported"]
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
properties = await reported_properties(hass, "sensor#test_temp")
|
|
|
|
properties.assert_equal(
|
|
|
|
"Alexa.TemperatureSensor", "temperature", {"value": 42.0, "scale": "FAHRENHEIT"}
|
|
|
|
)
|
2018-01-29 00:43:27 +00:00
|
|
|
|
2018-01-30 04:33:39 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_contact_sensor(hass):
|
2018-10-25 14:46:43 +00:00
|
|
|
"""Test contact sensor discovery."""
|
|
|
|
device = (
|
2019-07-31 19:25:30 +00:00
|
|
|
"binary_sensor.test_contact",
|
|
|
|
"on",
|
|
|
|
{"friendly_name": "Test Contact Sensor", "device_class": "door"},
|
2018-10-25 14:46:43 +00:00
|
|
|
)
|
2018-10-29 21:57:27 +00:00
|
|
|
appliance = await discovery_test(device, hass)
|
2018-10-25 14:46:43 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "binary_sensor#test_contact"
|
|
|
|
assert appliance["displayCategories"][0] == "CONTACT_SENSOR"
|
|
|
|
assert appliance["friendlyName"] == "Test Contact Sensor"
|
2018-10-25 14:46:43 +00:00
|
|
|
|
2019-01-10 23:52:21 +00:00
|
|
|
capabilities = assert_endpoint_capabilities(
|
2019-07-31 19:25:30 +00:00
|
|
|
appliance, "Alexa.ContactSensor", "Alexa.EndpointHealth"
|
2019-01-10 23:52:21 +00:00
|
|
|
)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
contact_sensor_capability = get_capability(capabilities, "Alexa.ContactSensor")
|
2019-01-10 23:52:21 +00:00
|
|
|
assert contact_sensor_capability is not None
|
2019-07-31 19:25:30 +00:00
|
|
|
properties = contact_sensor_capability["properties"]
|
|
|
|
assert properties["retrievable"] is True
|
|
|
|
assert {"name": "detectionState"} in properties["supported"]
|
2018-10-25 14:46:43 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
properties = await reported_properties(hass, "binary_sensor#test_contact")
|
|
|
|
properties.assert_equal("Alexa.ContactSensor", "detectionState", "DETECTED")
|
2018-10-25 14:46:43 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
properties.assert_equal("Alexa.EndpointHealth", "connectivity", {"value": "OK"})
|
2019-01-10 23:52:21 +00:00
|
|
|
|
2018-10-25 14:46:43 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_motion_sensor(hass):
|
2018-10-26 21:43:31 +00:00
|
|
|
"""Test motion sensor discovery."""
|
|
|
|
device = (
|
2019-07-31 19:25:30 +00:00
|
|
|
"binary_sensor.test_motion",
|
|
|
|
"on",
|
|
|
|
{"friendly_name": "Test Motion Sensor", "device_class": "motion"},
|
2018-10-26 21:43:31 +00:00
|
|
|
)
|
2018-10-29 21:57:27 +00:00
|
|
|
appliance = await discovery_test(device, hass)
|
2018-10-26 21:43:31 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "binary_sensor#test_motion"
|
|
|
|
assert appliance["displayCategories"][0] == "MOTION_SENSOR"
|
|
|
|
assert appliance["friendlyName"] == "Test Motion Sensor"
|
2018-10-26 21:43:31 +00:00
|
|
|
|
2019-01-10 23:52:21 +00:00
|
|
|
capabilities = assert_endpoint_capabilities(
|
2019-07-31 19:25:30 +00:00
|
|
|
appliance, "Alexa.MotionSensor", "Alexa.EndpointHealth"
|
2019-01-10 23:52:21 +00:00
|
|
|
)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
motion_sensor_capability = get_capability(capabilities, "Alexa.MotionSensor")
|
2019-01-10 23:52:21 +00:00
|
|
|
assert motion_sensor_capability is not None
|
2019-07-31 19:25:30 +00:00
|
|
|
properties = motion_sensor_capability["properties"]
|
|
|
|
assert properties["retrievable"] is True
|
|
|
|
assert {"name": "detectionState"} in properties["supported"]
|
2018-10-26 21:43:31 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
properties = await reported_properties(hass, "binary_sensor#test_motion")
|
|
|
|
properties.assert_equal("Alexa.MotionSensor", "detectionState", "DETECTED")
|
2018-10-26 21:43:31 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_unknown_sensor(hass):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Test sensors of unknown quantities are not discovered."""
|
|
|
|
device = (
|
2019-07-31 19:25:30 +00:00
|
|
|
"sensor.test_sickness",
|
|
|
|
"0.1",
|
|
|
|
{"friendly_name": "Test Space Sickness Sensor", "unit_of_measurement": "garn"},
|
|
|
|
)
|
2018-10-29 21:57:27 +00:00
|
|
|
await discovery_test(device, hass, expected_endpoints=0)
|
2017-09-16 19:35:28 +00:00
|
|
|
|
|
|
|
|
2018-03-30 06:49:08 +00:00
|
|
|
async def test_thermostat(hass):
|
|
|
|
"""Test thermostat discovery."""
|
2018-08-22 07:17:29 +00:00
|
|
|
hass.config.units.temperature_unit = TEMP_FAHRENHEIT
|
2018-03-30 06:49:08 +00:00
|
|
|
device = (
|
2019-07-31 19:25:30 +00:00
|
|
|
"climate.test_thermostat",
|
|
|
|
"cool",
|
2018-03-30 06:49:08 +00:00
|
|
|
{
|
2019-07-31 19:25:30 +00:00
|
|
|
"temperature": 70.0,
|
|
|
|
"target_temp_high": 80.0,
|
|
|
|
"target_temp_low": 60.0,
|
|
|
|
"current_temperature": 75.0,
|
|
|
|
"friendly_name": "Test Thermostat",
|
|
|
|
"supported_features": 1 | 2 | 4 | 128,
|
|
|
|
"hvac_modes": ["heat", "cool", "auto", "off"],
|
|
|
|
"preset_mode": None,
|
|
|
|
"preset_modes": ["eco"],
|
|
|
|
"min_temp": 50,
|
|
|
|
"max_temp": 90,
|
|
|
|
},
|
2018-03-30 06:49:08 +00:00
|
|
|
)
|
|
|
|
appliance = await discovery_test(device, hass)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert appliance["endpointId"] == "climate#test_thermostat"
|
|
|
|
assert appliance["displayCategories"][0] == "THERMOSTAT"
|
|
|
|
assert appliance["friendlyName"] == "Test Thermostat"
|
2018-03-30 06:49:08 +00:00
|
|
|
|
|
|
|
assert_endpoint_capabilities(
|
|
|
|
appliance,
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.PowerController",
|
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"Alexa.TemperatureSensor",
|
|
|
|
"Alexa.EndpointHealth",
|
2018-03-30 06:49:08 +00:00
|
|
|
)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
properties = await reported_properties(hass, "climate#test_thermostat")
|
|
|
|
properties.assert_equal("Alexa.ThermostatController", "thermostatMode", "COOL")
|
2018-03-30 06:49:08 +00:00
|
|
|
properties.assert_equal(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"targetSetpoint",
|
|
|
|
{"value": 70.0, "scale": "FAHRENHEIT"},
|
|
|
|
)
|
2018-03-30 06:49:08 +00:00
|
|
|
properties.assert_equal(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.TemperatureSensor", "temperature", {"value": 75.0, "scale": "FAHRENHEIT"}
|
|
|
|
)
|
2018-03-30 06:49:08 +00:00
|
|
|
|
Refactor Alexa API, fix thermostats (#17969)
* Refactor Alexa API to use objects for requests
This introduces _AlexaDirective to stand in for the previous model of passing
basic dict and list data structures to and from handlers. This gives a more
expressive platform for functionality common to most or all handlers.
I had two use cases in mind:
1) Most responses should include current properties. In the case of locks and
thermostats, the response must include the properties or Alexa will give the
user a vague error like "Hmm, $device is not responding." Locks currently work,
but thermostats do not. I wanted a way to automatically include properties in
all responses. This is implemented in a subsequent commit.
2) The previous model had a 1:1 mapping between Alexa endpoints and Home
Assistant entities. This works most of the time, but sometimes it's not so
great. For example, my Z-wave thermostat shows as three devices in Alexa: one
for the temperature sensor, one for the heat, and one for the AC. I'd like to
merge these into one device from Alexa's perspective. I believe this will be
facilitated with the `endpoint` attribute on `_AlexaDirective`.
* Include properties in all Alexa responses
The added _AlexaResponse class provides a richer vocabulary for handlers.
Among that vocabulary is .merge_context_properties(), which is invoked
automatically for any request directed at an endpoint. This adds all supported
properties to the response as recommended by the Alexa API docs, and in some
cases (locks, thermostats at least) the user will get an error "Hmm, $device is
not responding" if properties are not provided in the response.
* Fix setting temperature with Alexa thermostats
Fixes https://github.com/home-assistant/home-assistant/issues/16577
2018-10-30 02:16:35 +00:00
|
|
|
call, msg = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"SetTargetTemperature",
|
|
|
|
"climate#test_thermostat",
|
|
|
|
"climate.set_temperature",
|
2018-03-30 06:49:08 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"targetSetpoint": {"value": 69.0, "scale": "FAHRENHEIT"}},
|
2018-03-30 06:49:08 +00:00
|
|
|
)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert call.data["temperature"] == 69.0
|
|
|
|
properties = ReportedProperties(msg["context"]["properties"])
|
Refactor Alexa API, fix thermostats (#17969)
* Refactor Alexa API to use objects for requests
This introduces _AlexaDirective to stand in for the previous model of passing
basic dict and list data structures to and from handlers. This gives a more
expressive platform for functionality common to most or all handlers.
I had two use cases in mind:
1) Most responses should include current properties. In the case of locks and
thermostats, the response must include the properties or Alexa will give the
user a vague error like "Hmm, $device is not responding." Locks currently work,
but thermostats do not. I wanted a way to automatically include properties in
all responses. This is implemented in a subsequent commit.
2) The previous model had a 1:1 mapping between Alexa endpoints and Home
Assistant entities. This works most of the time, but sometimes it's not so
great. For example, my Z-wave thermostat shows as three devices in Alexa: one
for the temperature sensor, one for the heat, and one for the AC. I'd like to
merge these into one device from Alexa's perspective. I believe this will be
facilitated with the `endpoint` attribute on `_AlexaDirective`.
* Include properties in all Alexa responses
The added _AlexaResponse class provides a richer vocabulary for handlers.
Among that vocabulary is .merge_context_properties(), which is invoked
automatically for any request directed at an endpoint. This adds all supported
properties to the response as recommended by the Alexa API docs, and in some
cases (locks, thermostats at least) the user will get an error "Hmm, $device is
not responding" if properties are not provided in the response.
* Fix setting temperature with Alexa thermostats
Fixes https://github.com/home-assistant/home-assistant/issues/16577
2018-10-30 02:16:35 +00:00
|
|
|
properties.assert_equal(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"targetSetpoint",
|
|
|
|
{"value": 69.0, "scale": "FAHRENHEIT"},
|
|
|
|
)
|
2018-03-30 06:49:08 +00:00
|
|
|
|
|
|
|
msg = await assert_request_fails(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"SetTargetTemperature",
|
|
|
|
"climate#test_thermostat",
|
|
|
|
"climate.set_temperature",
|
2018-03-30 06:49:08 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"targetSetpoint": {"value": 0.0, "scale": "CELSIUS"}},
|
2018-03-30 06:49:08 +00:00
|
|
|
)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert msg["event"]["payload"]["type"] == "TEMPERATURE_VALUE_OUT_OF_RANGE"
|
2018-03-30 06:49:08 +00:00
|
|
|
|
Refactor Alexa API, fix thermostats (#17969)
* Refactor Alexa API to use objects for requests
This introduces _AlexaDirective to stand in for the previous model of passing
basic dict and list data structures to and from handlers. This gives a more
expressive platform for functionality common to most or all handlers.
I had two use cases in mind:
1) Most responses should include current properties. In the case of locks and
thermostats, the response must include the properties or Alexa will give the
user a vague error like "Hmm, $device is not responding." Locks currently work,
but thermostats do not. I wanted a way to automatically include properties in
all responses. This is implemented in a subsequent commit.
2) The previous model had a 1:1 mapping between Alexa endpoints and Home
Assistant entities. This works most of the time, but sometimes it's not so
great. For example, my Z-wave thermostat shows as three devices in Alexa: one
for the temperature sensor, one for the heat, and one for the AC. I'd like to
merge these into one device from Alexa's perspective. I believe this will be
facilitated with the `endpoint` attribute on `_AlexaDirective`.
* Include properties in all Alexa responses
The added _AlexaResponse class provides a richer vocabulary for handlers.
Among that vocabulary is .merge_context_properties(), which is invoked
automatically for any request directed at an endpoint. This adds all supported
properties to the response as recommended by the Alexa API docs, and in some
cases (locks, thermostats at least) the user will get an error "Hmm, $device is
not responding" if properties are not provided in the response.
* Fix setting temperature with Alexa thermostats
Fixes https://github.com/home-assistant/home-assistant/issues/16577
2018-10-30 02:16:35 +00:00
|
|
|
call, msg = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"SetTargetTemperature",
|
|
|
|
"climate#test_thermostat",
|
|
|
|
"climate.set_temperature",
|
2018-03-30 06:49:08 +00:00
|
|
|
hass,
|
|
|
|
payload={
|
2019-07-31 19:25:30 +00:00
|
|
|
"targetSetpoint": {"value": 70.0, "scale": "FAHRENHEIT"},
|
|
|
|
"lowerSetpoint": {"value": 293.15, "scale": "KELVIN"},
|
|
|
|
"upperSetpoint": {"value": 30.0, "scale": "CELSIUS"},
|
|
|
|
},
|
2018-03-30 06:49:08 +00:00
|
|
|
)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert call.data["temperature"] == 70.0
|
|
|
|
assert call.data["target_temp_low"] == 68.0
|
|
|
|
assert call.data["target_temp_high"] == 86.0
|
|
|
|
properties = ReportedProperties(msg["context"]["properties"])
|
Refactor Alexa API, fix thermostats (#17969)
* Refactor Alexa API to use objects for requests
This introduces _AlexaDirective to stand in for the previous model of passing
basic dict and list data structures to and from handlers. This gives a more
expressive platform for functionality common to most or all handlers.
I had two use cases in mind:
1) Most responses should include current properties. In the case of locks and
thermostats, the response must include the properties or Alexa will give the
user a vague error like "Hmm, $device is not responding." Locks currently work,
but thermostats do not. I wanted a way to automatically include properties in
all responses. This is implemented in a subsequent commit.
2) The previous model had a 1:1 mapping between Alexa endpoints and Home
Assistant entities. This works most of the time, but sometimes it's not so
great. For example, my Z-wave thermostat shows as three devices in Alexa: one
for the temperature sensor, one for the heat, and one for the AC. I'd like to
merge these into one device from Alexa's perspective. I believe this will be
facilitated with the `endpoint` attribute on `_AlexaDirective`.
* Include properties in all Alexa responses
The added _AlexaResponse class provides a richer vocabulary for handlers.
Among that vocabulary is .merge_context_properties(), which is invoked
automatically for any request directed at an endpoint. This adds all supported
properties to the response as recommended by the Alexa API docs, and in some
cases (locks, thermostats at least) the user will get an error "Hmm, $device is
not responding" if properties are not provided in the response.
* Fix setting temperature with Alexa thermostats
Fixes https://github.com/home-assistant/home-assistant/issues/16577
2018-10-30 02:16:35 +00:00
|
|
|
properties.assert_equal(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"targetSetpoint",
|
|
|
|
{"value": 70.0, "scale": "FAHRENHEIT"},
|
|
|
|
)
|
Refactor Alexa API, fix thermostats (#17969)
* Refactor Alexa API to use objects for requests
This introduces _AlexaDirective to stand in for the previous model of passing
basic dict and list data structures to and from handlers. This gives a more
expressive platform for functionality common to most or all handlers.
I had two use cases in mind:
1) Most responses should include current properties. In the case of locks and
thermostats, the response must include the properties or Alexa will give the
user a vague error like "Hmm, $device is not responding." Locks currently work,
but thermostats do not. I wanted a way to automatically include properties in
all responses. This is implemented in a subsequent commit.
2) The previous model had a 1:1 mapping between Alexa endpoints and Home
Assistant entities. This works most of the time, but sometimes it's not so
great. For example, my Z-wave thermostat shows as three devices in Alexa: one
for the temperature sensor, one for the heat, and one for the AC. I'd like to
merge these into one device from Alexa's perspective. I believe this will be
facilitated with the `endpoint` attribute on `_AlexaDirective`.
* Include properties in all Alexa responses
The added _AlexaResponse class provides a richer vocabulary for handlers.
Among that vocabulary is .merge_context_properties(), which is invoked
automatically for any request directed at an endpoint. This adds all supported
properties to the response as recommended by the Alexa API docs, and in some
cases (locks, thermostats at least) the user will get an error "Hmm, $device is
not responding" if properties are not provided in the response.
* Fix setting temperature with Alexa thermostats
Fixes https://github.com/home-assistant/home-assistant/issues/16577
2018-10-30 02:16:35 +00:00
|
|
|
properties.assert_equal(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"lowerSetpoint",
|
|
|
|
{"value": 68.0, "scale": "FAHRENHEIT"},
|
|
|
|
)
|
Refactor Alexa API, fix thermostats (#17969)
* Refactor Alexa API to use objects for requests
This introduces _AlexaDirective to stand in for the previous model of passing
basic dict and list data structures to and from handlers. This gives a more
expressive platform for functionality common to most or all handlers.
I had two use cases in mind:
1) Most responses should include current properties. In the case of locks and
thermostats, the response must include the properties or Alexa will give the
user a vague error like "Hmm, $device is not responding." Locks currently work,
but thermostats do not. I wanted a way to automatically include properties in
all responses. This is implemented in a subsequent commit.
2) The previous model had a 1:1 mapping between Alexa endpoints and Home
Assistant entities. This works most of the time, but sometimes it's not so
great. For example, my Z-wave thermostat shows as three devices in Alexa: one
for the temperature sensor, one for the heat, and one for the AC. I'd like to
merge these into one device from Alexa's perspective. I believe this will be
facilitated with the `endpoint` attribute on `_AlexaDirective`.
* Include properties in all Alexa responses
The added _AlexaResponse class provides a richer vocabulary for handlers.
Among that vocabulary is .merge_context_properties(), which is invoked
automatically for any request directed at an endpoint. This adds all supported
properties to the response as recommended by the Alexa API docs, and in some
cases (locks, thermostats at least) the user will get an error "Hmm, $device is
not responding" if properties are not provided in the response.
* Fix setting temperature with Alexa thermostats
Fixes https://github.com/home-assistant/home-assistant/issues/16577
2018-10-30 02:16:35 +00:00
|
|
|
properties.assert_equal(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"upperSetpoint",
|
|
|
|
{"value": 86.0, "scale": "FAHRENHEIT"},
|
|
|
|
)
|
2018-03-30 06:49:08 +00:00
|
|
|
|
|
|
|
msg = await assert_request_fails(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"SetTargetTemperature",
|
|
|
|
"climate#test_thermostat",
|
|
|
|
"climate.set_temperature",
|
2018-03-30 06:49:08 +00:00
|
|
|
hass,
|
|
|
|
payload={
|
2019-07-31 19:25:30 +00:00
|
|
|
"lowerSetpoint": {"value": 273.15, "scale": "KELVIN"},
|
|
|
|
"upperSetpoint": {"value": 75.0, "scale": "FAHRENHEIT"},
|
|
|
|
},
|
2018-03-30 06:49:08 +00:00
|
|
|
)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert msg["event"]["payload"]["type"] == "TEMPERATURE_VALUE_OUT_OF_RANGE"
|
2018-03-30 06:49:08 +00:00
|
|
|
|
|
|
|
msg = await assert_request_fails(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"SetTargetTemperature",
|
|
|
|
"climate#test_thermostat",
|
|
|
|
"climate.set_temperature",
|
2018-03-30 06:49:08 +00:00
|
|
|
hass,
|
|
|
|
payload={
|
2019-07-31 19:25:30 +00:00
|
|
|
"lowerSetpoint": {"value": 293.15, "scale": "FAHRENHEIT"},
|
|
|
|
"upperSetpoint": {"value": 75.0, "scale": "CELSIUS"},
|
|
|
|
},
|
2018-03-30 06:49:08 +00:00
|
|
|
)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert msg["event"]["payload"]["type"] == "TEMPERATURE_VALUE_OUT_OF_RANGE"
|
2018-03-30 06:49:08 +00:00
|
|
|
|
Refactor Alexa API, fix thermostats (#17969)
* Refactor Alexa API to use objects for requests
This introduces _AlexaDirective to stand in for the previous model of passing
basic dict and list data structures to and from handlers. This gives a more
expressive platform for functionality common to most or all handlers.
I had two use cases in mind:
1) Most responses should include current properties. In the case of locks and
thermostats, the response must include the properties or Alexa will give the
user a vague error like "Hmm, $device is not responding." Locks currently work,
but thermostats do not. I wanted a way to automatically include properties in
all responses. This is implemented in a subsequent commit.
2) The previous model had a 1:1 mapping between Alexa endpoints and Home
Assistant entities. This works most of the time, but sometimes it's not so
great. For example, my Z-wave thermostat shows as three devices in Alexa: one
for the temperature sensor, one for the heat, and one for the AC. I'd like to
merge these into one device from Alexa's perspective. I believe this will be
facilitated with the `endpoint` attribute on `_AlexaDirective`.
* Include properties in all Alexa responses
The added _AlexaResponse class provides a richer vocabulary for handlers.
Among that vocabulary is .merge_context_properties(), which is invoked
automatically for any request directed at an endpoint. This adds all supported
properties to the response as recommended by the Alexa API docs, and in some
cases (locks, thermostats at least) the user will get an error "Hmm, $device is
not responding" if properties are not provided in the response.
* Fix setting temperature with Alexa thermostats
Fixes https://github.com/home-assistant/home-assistant/issues/16577
2018-10-30 02:16:35 +00:00
|
|
|
call, msg = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"AdjustTargetTemperature",
|
|
|
|
"climate#test_thermostat",
|
|
|
|
"climate.set_temperature",
|
2018-03-30 06:49:08 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"targetSetpointDelta": {"value": -10.0, "scale": "KELVIN"}},
|
2018-03-30 06:49:08 +00:00
|
|
|
)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert call.data["temperature"] == 52.0
|
|
|
|
properties = ReportedProperties(msg["context"]["properties"])
|
Refactor Alexa API, fix thermostats (#17969)
* Refactor Alexa API to use objects for requests
This introduces _AlexaDirective to stand in for the previous model of passing
basic dict and list data structures to and from handlers. This gives a more
expressive platform for functionality common to most or all handlers.
I had two use cases in mind:
1) Most responses should include current properties. In the case of locks and
thermostats, the response must include the properties or Alexa will give the
user a vague error like "Hmm, $device is not responding." Locks currently work,
but thermostats do not. I wanted a way to automatically include properties in
all responses. This is implemented in a subsequent commit.
2) The previous model had a 1:1 mapping between Alexa endpoints and Home
Assistant entities. This works most of the time, but sometimes it's not so
great. For example, my Z-wave thermostat shows as three devices in Alexa: one
for the temperature sensor, one for the heat, and one for the AC. I'd like to
merge these into one device from Alexa's perspective. I believe this will be
facilitated with the `endpoint` attribute on `_AlexaDirective`.
* Include properties in all Alexa responses
The added _AlexaResponse class provides a richer vocabulary for handlers.
Among that vocabulary is .merge_context_properties(), which is invoked
automatically for any request directed at an endpoint. This adds all supported
properties to the response as recommended by the Alexa API docs, and in some
cases (locks, thermostats at least) the user will get an error "Hmm, $device is
not responding" if properties are not provided in the response.
* Fix setting temperature with Alexa thermostats
Fixes https://github.com/home-assistant/home-assistant/issues/16577
2018-10-30 02:16:35 +00:00
|
|
|
properties.assert_equal(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"targetSetpoint",
|
|
|
|
{"value": 52.0, "scale": "FAHRENHEIT"},
|
|
|
|
)
|
2018-03-30 06:49:08 +00:00
|
|
|
|
|
|
|
msg = await assert_request_fails(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"AdjustTargetTemperature",
|
|
|
|
"climate#test_thermostat",
|
|
|
|
"climate.set_temperature",
|
2018-03-30 06:49:08 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"targetSetpointDelta": {"value": 20.0, "scale": "CELSIUS"}},
|
2018-03-30 06:49:08 +00:00
|
|
|
)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert msg["event"]["payload"]["type"] == "TEMPERATURE_VALUE_OUT_OF_RANGE"
|
2018-03-30 06:49:08 +00:00
|
|
|
|
2018-10-31 15:09:13 +00:00
|
|
|
# Setting mode, the payload can be an object with a value attribute...
|
|
|
|
call, msg = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"SetThermostatMode",
|
|
|
|
"climate#test_thermostat",
|
|
|
|
"climate.set_hvac_mode",
|
2018-03-30 06:49:08 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"thermostatMode": {"value": "HEAT"}},
|
2018-03-30 06:49:08 +00:00
|
|
|
)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert call.data["hvac_mode"] == "heat"
|
|
|
|
properties = ReportedProperties(msg["context"]["properties"])
|
|
|
|
properties.assert_equal("Alexa.ThermostatController", "thermostatMode", "HEAT")
|
2018-03-30 06:49:08 +00:00
|
|
|
|
2018-10-31 15:09:13 +00:00
|
|
|
call, msg = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"SetThermostatMode",
|
|
|
|
"climate#test_thermostat",
|
|
|
|
"climate.set_hvac_mode",
|
2018-04-18 18:19:05 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"thermostatMode": {"value": "COOL"}},
|
2018-04-18 18:19:05 +00:00
|
|
|
)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert call.data["hvac_mode"] == "cool"
|
|
|
|
properties = ReportedProperties(msg["context"]["properties"])
|
|
|
|
properties.assert_equal("Alexa.ThermostatController", "thermostatMode", "COOL")
|
2018-04-18 18:19:05 +00:00
|
|
|
|
2018-10-31 15:09:13 +00:00
|
|
|
# ...it can also be just the mode.
|
|
|
|
call, msg = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"SetThermostatMode",
|
|
|
|
"climate#test_thermostat",
|
|
|
|
"climate.set_hvac_mode",
|
2018-10-31 15:09:13 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"thermostatMode": "HEAT"},
|
2018-10-31 15:09:13 +00:00
|
|
|
)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert call.data["hvac_mode"] == "heat"
|
|
|
|
properties = ReportedProperties(msg["context"]["properties"])
|
|
|
|
properties.assert_equal("Alexa.ThermostatController", "thermostatMode", "HEAT")
|
2018-10-31 15:09:13 +00:00
|
|
|
|
2018-03-30 06:49:08 +00:00
|
|
|
msg = await assert_request_fails(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"SetThermostatMode",
|
|
|
|
"climate#test_thermostat",
|
|
|
|
"climate.set_hvac_mode",
|
2018-03-30 06:49:08 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"thermostatMode": {"value": "INVALID"}},
|
2018-03-30 06:49:08 +00:00
|
|
|
)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert msg["event"]["payload"]["type"] == "UNSUPPORTED_THERMOSTAT_MODE"
|
2018-08-22 07:17:29 +00:00
|
|
|
hass.config.units.temperature_unit = TEMP_CELSIUS
|
2018-03-30 06:49:08 +00:00
|
|
|
|
2018-10-29 19:52:34 +00:00
|
|
|
call, _ = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"SetThermostatMode",
|
|
|
|
"climate#test_thermostat",
|
|
|
|
"climate.set_hvac_mode",
|
2018-10-29 19:52:34 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"thermostatMode": "OFF"},
|
2018-10-29 19:52:34 +00:00
|
|
|
)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert call.data["hvac_mode"] == "off"
|
Climate 1.0 (#23899)
* Climate 1.0 / part 1/2/3
* fix flake
* Lint
* Update Google Assistant
* ambiclimate to climate 1.0 (#24911)
* Fix Alexa
* Lint
* Migrate zhong_hong
* Migrate tuya
* Migrate honeywell to new climate schema (#24257)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* Fix PRESET can be None
* apply PR#23913 from dev
* remove EU component, etc.
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* apply PR#23913 from dev
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* delint, move debug code
* away preset now working
* code tidy-up
* code tidy-up 2
* code tidy-up 3
* address issues #18932, #15063
* address issues #18932, #15063 - 2/2
* refactor MODE_AUTO to MODE_HEAT_COOL and use F not C
* add low/high to set_temp
* add low/high to set_temp 2
* add low/high to set_temp - delint
* run HA scripts
* port changes from PR #24402
* manual rebase
* manual rebase 2
* delint
* minor change
* remove SUPPORT_HVAC_ACTION
* Migrate radiotherm
* Convert touchline
* Migrate flexit
* Migrate nuheat
* Migrate maxcube
* Fix names maxcube const
* Migrate proliphix
* Migrate heatmiser
* Migrate fritzbox
* Migrate opentherm_gw
* Migrate venstar
* Migrate daikin
* Migrate modbus
* Fix elif
* Migrate Homematic IP Cloud to climate-1.0 (#24913)
* hmip climate fix
* Update hvac_mode and preset_mode
* fix lint
* Fix lint
* Migrate generic_thermostat
* Migrate incomfort to new climate schema (#24915)
* initial commit
* Update climate.py
* Migrate eq3btsmart
* Lint
* cleanup PRESET_MANUAL
* Migrate ecobee
* No conditional features
* KNX: Migrate climate component to new climate platform (#24931)
* Migrate climate component
* Remove unused code
* Corrected line length
* Lint
* Lint
* fix tests
* Fix value
* Migrate geniushub to new climate schema (#24191)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* delinted
* delinted
* use latest client
* clean up mappings
* clean up mappings
* add duration to set_temperature
* add duration to set_temperature
* manual rebase
* tweak
* fix regression
* small fix
* fix rebase mixup
* address comments
* finish refactor
* fix regression
* tweak type hints
* delint
* manual rebase
* WIP: Fixes for honeywell migration to climate-1.0 (#24938)
* add type hints
* code tidy-up
* Fixes for incomfort migration to climate-1.0 (#24936)
* delint type hints
* no async unless await
* revert: no async unless await
* revert: no async unless await 2
* delint
* fix typo
* Fix homekit_controller on climate-1.0 (#24948)
* Fix tests on climate-1.0 branch
* As part of climate-1.0, make state return the heating-cooling.current characteristic
* Fixes from review
* lint
* Fix imports
* Migrate stibel_eltron
* Fix lint
* Migrate coolmaster to climate 1.0 (#24967)
* Migrate coolmaster to climate 1.0
* fix lint errors
* More lint fixes
* Fix demo to work with UI
* Migrate spider
* Demo update
* Updated frontend to 20190705.0
* Fix boost mode (#24980)
* Prepare Netatmo for climate 1.0 (#24973)
* Migration Netatmo
* Address comments
* Update climate.py
* Migrate ephember
* Migrate Sensibo
* Implemented review comments (#24942)
* Migrate ESPHome
* Migrate MQTT
* Migrate Nest
* Migrate melissa
* Initial/partial migration of ST
* Migrate ST
* Remove Away mode (#24995)
* Migrate evohome, cache access tokens (#24491)
* add water_heater, add storage - initial commit
* add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
* Add Broker, Water Heater & Refactor
add missing code
desiderata
* update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
* bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
* support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
* store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
* update CODEOWNERS
* fix regression
* fix requirements
* migrate to climate-1.0
* tweaking
* de-lint
* TCS working? & delint
* tweaking
* TCS code finalised
* remove available() logic
* refactor _switchpoints()
* tidy up switchpoint code
* tweak
* teaking device_state_attributes
* some refactoring
* move PRESET_CUSTOM back to evohome
* move CONF_ACCESS_TOKEN_EXPIRES CONF_REFRESH_TOKEN back to evohome
* refactor SP code and dt conversion
* delinted
* delinted
* remove water_heater
* fix regression
* Migrate homekit
* Cleanup away mode
* Fix tests
* add helpers
* fix tests melissa
* Fix nehueat
* fix zwave
* add more tests
* fix deconz
* Fix climate test emulate_hue
* fix tests
* fix dyson tests
* fix demo with new layout
* fix honeywell
* Switch homekit_controller to use HVAC_MODE_HEAT_COOL instead of HVAC_MODE_AUTO (#25009)
* Lint
* PyLint
* Pylint
* fix fritzbox tests
* Fix google
* Fix all tests
* Fix lint
* Fix auto for homekit like controler
* Fix lint
* fix lint
2019-07-08 12:00:24 +00:00
|
|
|
|
|
|
|
# Assert we can call presets
|
|
|
|
call, msg = await assert_request_calls_service(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Alexa.ThermostatController",
|
|
|
|
"SetThermostatMode",
|
|
|
|
"climate#test_thermostat",
|
|
|
|
"climate.set_preset_mode",
|
Climate 1.0 (#23899)
* Climate 1.0 / part 1/2/3
* fix flake
* Lint
* Update Google Assistant
* ambiclimate to climate 1.0 (#24911)
* Fix Alexa
* Lint
* Migrate zhong_hong
* Migrate tuya
* Migrate honeywell to new climate schema (#24257)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* Fix PRESET can be None
* apply PR#23913 from dev
* remove EU component, etc.
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* apply PR#23913 from dev
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* delint, move debug code
* away preset now working
* code tidy-up
* code tidy-up 2
* code tidy-up 3
* address issues #18932, #15063
* address issues #18932, #15063 - 2/2
* refactor MODE_AUTO to MODE_HEAT_COOL and use F not C
* add low/high to set_temp
* add low/high to set_temp 2
* add low/high to set_temp - delint
* run HA scripts
* port changes from PR #24402
* manual rebase
* manual rebase 2
* delint
* minor change
* remove SUPPORT_HVAC_ACTION
* Migrate radiotherm
* Convert touchline
* Migrate flexit
* Migrate nuheat
* Migrate maxcube
* Fix names maxcube const
* Migrate proliphix
* Migrate heatmiser
* Migrate fritzbox
* Migrate opentherm_gw
* Migrate venstar
* Migrate daikin
* Migrate modbus
* Fix elif
* Migrate Homematic IP Cloud to climate-1.0 (#24913)
* hmip climate fix
* Update hvac_mode and preset_mode
* fix lint
* Fix lint
* Migrate generic_thermostat
* Migrate incomfort to new climate schema (#24915)
* initial commit
* Update climate.py
* Migrate eq3btsmart
* Lint
* cleanup PRESET_MANUAL
* Migrate ecobee
* No conditional features
* KNX: Migrate climate component to new climate platform (#24931)
* Migrate climate component
* Remove unused code
* Corrected line length
* Lint
* Lint
* fix tests
* Fix value
* Migrate geniushub to new climate schema (#24191)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* delinted
* delinted
* use latest client
* clean up mappings
* clean up mappings
* add duration to set_temperature
* add duration to set_temperature
* manual rebase
* tweak
* fix regression
* small fix
* fix rebase mixup
* address comments
* finish refactor
* fix regression
* tweak type hints
* delint
* manual rebase
* WIP: Fixes for honeywell migration to climate-1.0 (#24938)
* add type hints
* code tidy-up
* Fixes for incomfort migration to climate-1.0 (#24936)
* delint type hints
* no async unless await
* revert: no async unless await
* revert: no async unless await 2
* delint
* fix typo
* Fix homekit_controller on climate-1.0 (#24948)
* Fix tests on climate-1.0 branch
* As part of climate-1.0, make state return the heating-cooling.current characteristic
* Fixes from review
* lint
* Fix imports
* Migrate stibel_eltron
* Fix lint
* Migrate coolmaster to climate 1.0 (#24967)
* Migrate coolmaster to climate 1.0
* fix lint errors
* More lint fixes
* Fix demo to work with UI
* Migrate spider
* Demo update
* Updated frontend to 20190705.0
* Fix boost mode (#24980)
* Prepare Netatmo for climate 1.0 (#24973)
* Migration Netatmo
* Address comments
* Update climate.py
* Migrate ephember
* Migrate Sensibo
* Implemented review comments (#24942)
* Migrate ESPHome
* Migrate MQTT
* Migrate Nest
* Migrate melissa
* Initial/partial migration of ST
* Migrate ST
* Remove Away mode (#24995)
* Migrate evohome, cache access tokens (#24491)
* add water_heater, add storage - initial commit
* add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
* Add Broker, Water Heater & Refactor
add missing code
desiderata
* update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
* bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
* support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
* store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
* update CODEOWNERS
* fix regression
* fix requirements
* migrate to climate-1.0
* tweaking
* de-lint
* TCS working? & delint
* tweaking
* TCS code finalised
* remove available() logic
* refactor _switchpoints()
* tidy up switchpoint code
* tweak
* teaking device_state_attributes
* some refactoring
* move PRESET_CUSTOM back to evohome
* move CONF_ACCESS_TOKEN_EXPIRES CONF_REFRESH_TOKEN back to evohome
* refactor SP code and dt conversion
* delinted
* delinted
* remove water_heater
* fix regression
* Migrate homekit
* Cleanup away mode
* Fix tests
* add helpers
* fix tests melissa
* Fix nehueat
* fix zwave
* add more tests
* fix deconz
* Fix climate test emulate_hue
* fix tests
* fix dyson tests
* fix demo with new layout
* fix honeywell
* Switch homekit_controller to use HVAC_MODE_HEAT_COOL instead of HVAC_MODE_AUTO (#25009)
* Lint
* PyLint
* Pylint
* fix fritzbox tests
* Fix google
* Fix all tests
* Fix lint
* Fix auto for homekit like controler
* Fix lint
* fix lint
2019-07-08 12:00:24 +00:00
|
|
|
hass,
|
2019-07-31 19:25:30 +00:00
|
|
|
payload={"thermostatMode": "ECO"},
|
Climate 1.0 (#23899)
* Climate 1.0 / part 1/2/3
* fix flake
* Lint
* Update Google Assistant
* ambiclimate to climate 1.0 (#24911)
* Fix Alexa
* Lint
* Migrate zhong_hong
* Migrate tuya
* Migrate honeywell to new climate schema (#24257)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* Fix PRESET can be None
* apply PR#23913 from dev
* remove EU component, etc.
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* apply PR#23913 from dev
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* delint, move debug code
* away preset now working
* code tidy-up
* code tidy-up 2
* code tidy-up 3
* address issues #18932, #15063
* address issues #18932, #15063 - 2/2
* refactor MODE_AUTO to MODE_HEAT_COOL and use F not C
* add low/high to set_temp
* add low/high to set_temp 2
* add low/high to set_temp - delint
* run HA scripts
* port changes from PR #24402
* manual rebase
* manual rebase 2
* delint
* minor change
* remove SUPPORT_HVAC_ACTION
* Migrate radiotherm
* Convert touchline
* Migrate flexit
* Migrate nuheat
* Migrate maxcube
* Fix names maxcube const
* Migrate proliphix
* Migrate heatmiser
* Migrate fritzbox
* Migrate opentherm_gw
* Migrate venstar
* Migrate daikin
* Migrate modbus
* Fix elif
* Migrate Homematic IP Cloud to climate-1.0 (#24913)
* hmip climate fix
* Update hvac_mode and preset_mode
* fix lint
* Fix lint
* Migrate generic_thermostat
* Migrate incomfort to new climate schema (#24915)
* initial commit
* Update climate.py
* Migrate eq3btsmart
* Lint
* cleanup PRESET_MANUAL
* Migrate ecobee
* No conditional features
* KNX: Migrate climate component to new climate platform (#24931)
* Migrate climate component
* Remove unused code
* Corrected line length
* Lint
* Lint
* fix tests
* Fix value
* Migrate geniushub to new climate schema (#24191)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* delinted
* delinted
* use latest client
* clean up mappings
* clean up mappings
* add duration to set_temperature
* add duration to set_temperature
* manual rebase
* tweak
* fix regression
* small fix
* fix rebase mixup
* address comments
* finish refactor
* fix regression
* tweak type hints
* delint
* manual rebase
* WIP: Fixes for honeywell migration to climate-1.0 (#24938)
* add type hints
* code tidy-up
* Fixes for incomfort migration to climate-1.0 (#24936)
* delint type hints
* no async unless await
* revert: no async unless await
* revert: no async unless await 2
* delint
* fix typo
* Fix homekit_controller on climate-1.0 (#24948)
* Fix tests on climate-1.0 branch
* As part of climate-1.0, make state return the heating-cooling.current characteristic
* Fixes from review
* lint
* Fix imports
* Migrate stibel_eltron
* Fix lint
* Migrate coolmaster to climate 1.0 (#24967)
* Migrate coolmaster to climate 1.0
* fix lint errors
* More lint fixes
* Fix demo to work with UI
* Migrate spider
* Demo update
* Updated frontend to 20190705.0
* Fix boost mode (#24980)
* Prepare Netatmo for climate 1.0 (#24973)
* Migration Netatmo
* Address comments
* Update climate.py
* Migrate ephember
* Migrate Sensibo
* Implemented review comments (#24942)
* Migrate ESPHome
* Migrate MQTT
* Migrate Nest
* Migrate melissa
* Initial/partial migration of ST
* Migrate ST
* Remove Away mode (#24995)
* Migrate evohome, cache access tokens (#24491)
* add water_heater, add storage - initial commit
* add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
* Add Broker, Water Heater & Refactor
add missing code
desiderata
* update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
* bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
* support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
* store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
* update CODEOWNERS
* fix regression
* fix requirements
* migrate to climate-1.0
* tweaking
* de-lint
* TCS working? & delint
* tweaking
* TCS code finalised
* remove available() logic
* refactor _switchpoints()
* tidy up switchpoint code
* tweak
* teaking device_state_attributes
* some refactoring
* move PRESET_CUSTOM back to evohome
* move CONF_ACCESS_TOKEN_EXPIRES CONF_REFRESH_TOKEN back to evohome
* refactor SP code and dt conversion
* delinted
* delinted
* remove water_heater
* fix regression
* Migrate homekit
* Cleanup away mode
* Fix tests
* add helpers
* fix tests melissa
* Fix nehueat
* fix zwave
* add more tests
* fix deconz
* Fix climate test emulate_hue
* fix tests
* fix dyson tests
* fix demo with new layout
* fix honeywell
* Switch homekit_controller to use HVAC_MODE_HEAT_COOL instead of HVAC_MODE_AUTO (#25009)
* Lint
* PyLint
* Pylint
* fix fritzbox tests
* Fix google
* Fix all tests
* Fix lint
* Fix auto for homekit like controler
* Fix lint
* fix lint
2019-07-08 12:00:24 +00:00
|
|
|
)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert call.data["preset_mode"] == "eco"
|
2018-10-29 19:52:34 +00:00
|
|
|
|
2018-03-30 06:49:08 +00:00
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_exclude_filters(hass):
|
2017-11-18 05:10:24 +00:00
|
|
|
"""Test exclusion filters."""
|
2019-07-31 19:25:30 +00:00
|
|
|
request = get_new_request("Alexa.Discovery", "Discover")
|
2017-11-18 05:10:24 +00:00
|
|
|
|
|
|
|
# setup test devices
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.states.async_set("switch.test", "on", {"friendly_name": "Test switch"})
|
2017-11-18 05:10:24 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.states.async_set("script.deny", "off", {"friendly_name": "Blocked script"})
|
2017-11-18 05:10:24 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.states.async_set("cover.deny", "off", {"friendly_name": "Blocked cover"})
|
2017-11-18 05:10:24 +00:00
|
|
|
|
2019-06-17 20:50:01 +00:00
|
|
|
alexa_config = MockConfig(hass)
|
2019-06-13 18:58:08 +00:00
|
|
|
alexa_config.should_expose = entityfilter.generate_filter(
|
|
|
|
include_domains=[],
|
|
|
|
include_entities=[],
|
2019-07-31 19:25:30 +00:00
|
|
|
exclude_domains=["script"],
|
|
|
|
exclude_entities=["cover.deny"],
|
2019-06-13 18:58:08 +00:00
|
|
|
)
|
2017-11-18 05:10:24 +00:00
|
|
|
|
2019-06-13 15:43:57 +00:00
|
|
|
msg = await smart_home.async_handle_message(hass, alexa_config, request)
|
2018-10-29 21:57:27 +00:00
|
|
|
await hass.async_block_till_done()
|
2017-11-18 05:10:24 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
msg = msg["event"]
|
2017-11-18 05:10:24 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert len(msg["payload"]["endpoints"]) == 1
|
2017-11-18 05:10:24 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_include_filters(hass):
|
2017-11-18 05:10:24 +00:00
|
|
|
"""Test inclusion filters."""
|
2019-07-31 19:25:30 +00:00
|
|
|
request = get_new_request("Alexa.Discovery", "Discover")
|
2017-11-18 05:10:24 +00:00
|
|
|
|
|
|
|
# setup test devices
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.states.async_set("switch.deny", "on", {"friendly_name": "Blocked switch"})
|
2017-11-18 05:10:24 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.states.async_set("script.deny", "off", {"friendly_name": "Blocked script"})
|
2017-11-18 05:10:24 +00:00
|
|
|
|
|
|
|
hass.states.async_set(
|
2019-07-31 19:25:30 +00:00
|
|
|
"automation.allow", "off", {"friendly_name": "Allowed automation"}
|
|
|
|
)
|
2017-11-18 05:10:24 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.states.async_set("group.allow", "off", {"friendly_name": "Allowed group"})
|
2017-11-18 05:10:24 +00:00
|
|
|
|
2019-06-17 20:50:01 +00:00
|
|
|
alexa_config = MockConfig(hass)
|
2019-06-13 18:58:08 +00:00
|
|
|
alexa_config.should_expose = entityfilter.generate_filter(
|
2019-07-31 19:25:30 +00:00
|
|
|
include_domains=["automation", "group"],
|
|
|
|
include_entities=["script.deny"],
|
2019-06-13 18:58:08 +00:00
|
|
|
exclude_domains=[],
|
|
|
|
exclude_entities=[],
|
|
|
|
)
|
2017-11-18 05:10:24 +00:00
|
|
|
|
2019-06-13 15:43:57 +00:00
|
|
|
msg = await smart_home.async_handle_message(hass, alexa_config, request)
|
2018-10-29 21:57:27 +00:00
|
|
|
await hass.async_block_till_done()
|
2017-11-18 05:10:24 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
msg = msg["event"]
|
2017-11-18 05:10:24 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert len(msg["payload"]["endpoints"]) == 3
|
2017-11-18 05:10:24 +00:00
|
|
|
|
|
|
|
|
Add support for locks in google assistant component (#18233)
* Add support for locks in google assistant component
This is supported by the smarthome API, but there is no documentation
for it. This work is based on an article I found with screenshots of
documentation that was erroneously uploaded:
https://www.androidpolice.com/2018/01/17/google-assistant-home-can-now-natively-control-smart-locks-august-vivint-first-supported/
Google Assistant now supports unlocking certain locks - Nest and August
come to mind - via this API, and this commit allows Home Assistant to
do so as well.
Notably, I've added a config option `allow_unlock` that controls
whether we actually honor requests to unlock a lock via the google
assistant. It defaults to false.
Additionally, we add the functionNotSupported error, which makes a
little more sense when we're unable to execute the desired state
transition.
https://developers.google.com/actions/reference/smarthome/errors-exceptions#exception_list
* Fix linter warnings
* Ensure that certain groups are never exposed to cloud entities
For example, the group.all_locks entity - we should probably never
expose this to third party cloud integrations. It's risky.
This is not configurable, but can be extended by adding to the
cloud.const.NEVER_EXPOSED_ENTITIES array.
It's implemented in a modestly hacky fashion, because we determine
whether or not a entity should be excluded/included in several ways.
Notably, we define this array in the top level const.py, to avoid
circular import problems between the cloud/alexa components.
2018-11-06 09:39:10 +00:00
|
|
|
async def test_never_exposed_entities(hass):
|
|
|
|
"""Test never exposed locks do not get discovered."""
|
2019-07-31 19:25:30 +00:00
|
|
|
request = get_new_request("Alexa.Discovery", "Discover")
|
Add support for locks in google assistant component (#18233)
* Add support for locks in google assistant component
This is supported by the smarthome API, but there is no documentation
for it. This work is based on an article I found with screenshots of
documentation that was erroneously uploaded:
https://www.androidpolice.com/2018/01/17/google-assistant-home-can-now-natively-control-smart-locks-august-vivint-first-supported/
Google Assistant now supports unlocking certain locks - Nest and August
come to mind - via this API, and this commit allows Home Assistant to
do so as well.
Notably, I've added a config option `allow_unlock` that controls
whether we actually honor requests to unlock a lock via the google
assistant. It defaults to false.
Additionally, we add the functionNotSupported error, which makes a
little more sense when we're unable to execute the desired state
transition.
https://developers.google.com/actions/reference/smarthome/errors-exceptions#exception_list
* Fix linter warnings
* Ensure that certain groups are never exposed to cloud entities
For example, the group.all_locks entity - we should probably never
expose this to third party cloud integrations. It's risky.
This is not configurable, but can be extended by adding to the
cloud.const.NEVER_EXPOSED_ENTITIES array.
It's implemented in a modestly hacky fashion, because we determine
whether or not a entity should be excluded/included in several ways.
Notably, we define this array in the top level const.py, to avoid
circular import problems between the cloud/alexa components.
2018-11-06 09:39:10 +00:00
|
|
|
|
|
|
|
# setup test devices
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.states.async_set("group.all_locks", "on", {"friendly_name": "Blocked locks"})
|
Add support for locks in google assistant component (#18233)
* Add support for locks in google assistant component
This is supported by the smarthome API, but there is no documentation
for it. This work is based on an article I found with screenshots of
documentation that was erroneously uploaded:
https://www.androidpolice.com/2018/01/17/google-assistant-home-can-now-natively-control-smart-locks-august-vivint-first-supported/
Google Assistant now supports unlocking certain locks - Nest and August
come to mind - via this API, and this commit allows Home Assistant to
do so as well.
Notably, I've added a config option `allow_unlock` that controls
whether we actually honor requests to unlock a lock via the google
assistant. It defaults to false.
Additionally, we add the functionNotSupported error, which makes a
little more sense when we're unable to execute the desired state
transition.
https://developers.google.com/actions/reference/smarthome/errors-exceptions#exception_list
* Fix linter warnings
* Ensure that certain groups are never exposed to cloud entities
For example, the group.all_locks entity - we should probably never
expose this to third party cloud integrations. It's risky.
This is not configurable, but can be extended by adding to the
cloud.const.NEVER_EXPOSED_ENTITIES array.
It's implemented in a modestly hacky fashion, because we determine
whether or not a entity should be excluded/included in several ways.
Notably, we define this array in the top level const.py, to avoid
circular import problems between the cloud/alexa components.
2018-11-06 09:39:10 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.states.async_set("group.allow", "off", {"friendly_name": "Allowed group"})
|
Add support for locks in google assistant component (#18233)
* Add support for locks in google assistant component
This is supported by the smarthome API, but there is no documentation
for it. This work is based on an article I found with screenshots of
documentation that was erroneously uploaded:
https://www.androidpolice.com/2018/01/17/google-assistant-home-can-now-natively-control-smart-locks-august-vivint-first-supported/
Google Assistant now supports unlocking certain locks - Nest and August
come to mind - via this API, and this commit allows Home Assistant to
do so as well.
Notably, I've added a config option `allow_unlock` that controls
whether we actually honor requests to unlock a lock via the google
assistant. It defaults to false.
Additionally, we add the functionNotSupported error, which makes a
little more sense when we're unable to execute the desired state
transition.
https://developers.google.com/actions/reference/smarthome/errors-exceptions#exception_list
* Fix linter warnings
* Ensure that certain groups are never exposed to cloud entities
For example, the group.all_locks entity - we should probably never
expose this to third party cloud integrations. It's risky.
This is not configurable, but can be extended by adding to the
cloud.const.NEVER_EXPOSED_ENTITIES array.
It's implemented in a modestly hacky fashion, because we determine
whether or not a entity should be excluded/included in several ways.
Notably, we define this array in the top level const.py, to avoid
circular import problems between the cloud/alexa components.
2018-11-06 09:39:10 +00:00
|
|
|
|
2019-06-17 20:50:01 +00:00
|
|
|
alexa_config = MockConfig(hass)
|
2019-06-13 18:58:08 +00:00
|
|
|
alexa_config.should_expose = entityfilter.generate_filter(
|
2019-07-31 19:25:30 +00:00
|
|
|
include_domains=["group"],
|
2019-06-13 18:58:08 +00:00
|
|
|
include_entities=[],
|
|
|
|
exclude_domains=[],
|
|
|
|
exclude_entities=[],
|
|
|
|
)
|
Add support for locks in google assistant component (#18233)
* Add support for locks in google assistant component
This is supported by the smarthome API, but there is no documentation
for it. This work is based on an article I found with screenshots of
documentation that was erroneously uploaded:
https://www.androidpolice.com/2018/01/17/google-assistant-home-can-now-natively-control-smart-locks-august-vivint-first-supported/
Google Assistant now supports unlocking certain locks - Nest and August
come to mind - via this API, and this commit allows Home Assistant to
do so as well.
Notably, I've added a config option `allow_unlock` that controls
whether we actually honor requests to unlock a lock via the google
assistant. It defaults to false.
Additionally, we add the functionNotSupported error, which makes a
little more sense when we're unable to execute the desired state
transition.
https://developers.google.com/actions/reference/smarthome/errors-exceptions#exception_list
* Fix linter warnings
* Ensure that certain groups are never exposed to cloud entities
For example, the group.all_locks entity - we should probably never
expose this to third party cloud integrations. It's risky.
This is not configurable, but can be extended by adding to the
cloud.const.NEVER_EXPOSED_ENTITIES array.
It's implemented in a modestly hacky fashion, because we determine
whether or not a entity should be excluded/included in several ways.
Notably, we define this array in the top level const.py, to avoid
circular import problems between the cloud/alexa components.
2018-11-06 09:39:10 +00:00
|
|
|
|
2019-06-13 15:43:57 +00:00
|
|
|
msg = await smart_home.async_handle_message(hass, alexa_config, request)
|
Add support for locks in google assistant component (#18233)
* Add support for locks in google assistant component
This is supported by the smarthome API, but there is no documentation
for it. This work is based on an article I found with screenshots of
documentation that was erroneously uploaded:
https://www.androidpolice.com/2018/01/17/google-assistant-home-can-now-natively-control-smart-locks-august-vivint-first-supported/
Google Assistant now supports unlocking certain locks - Nest and August
come to mind - via this API, and this commit allows Home Assistant to
do so as well.
Notably, I've added a config option `allow_unlock` that controls
whether we actually honor requests to unlock a lock via the google
assistant. It defaults to false.
Additionally, we add the functionNotSupported error, which makes a
little more sense when we're unable to execute the desired state
transition.
https://developers.google.com/actions/reference/smarthome/errors-exceptions#exception_list
* Fix linter warnings
* Ensure that certain groups are never exposed to cloud entities
For example, the group.all_locks entity - we should probably never
expose this to third party cloud integrations. It's risky.
This is not configurable, but can be extended by adding to the
cloud.const.NEVER_EXPOSED_ENTITIES array.
It's implemented in a modestly hacky fashion, because we determine
whether or not a entity should be excluded/included in several ways.
Notably, we define this array in the top level const.py, to avoid
circular import problems between the cloud/alexa components.
2018-11-06 09:39:10 +00:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
msg = msg["event"]
|
Add support for locks in google assistant component (#18233)
* Add support for locks in google assistant component
This is supported by the smarthome API, but there is no documentation
for it. This work is based on an article I found with screenshots of
documentation that was erroneously uploaded:
https://www.androidpolice.com/2018/01/17/google-assistant-home-can-now-natively-control-smart-locks-august-vivint-first-supported/
Google Assistant now supports unlocking certain locks - Nest and August
come to mind - via this API, and this commit allows Home Assistant to
do so as well.
Notably, I've added a config option `allow_unlock` that controls
whether we actually honor requests to unlock a lock via the google
assistant. It defaults to false.
Additionally, we add the functionNotSupported error, which makes a
little more sense when we're unable to execute the desired state
transition.
https://developers.google.com/actions/reference/smarthome/errors-exceptions#exception_list
* Fix linter warnings
* Ensure that certain groups are never exposed to cloud entities
For example, the group.all_locks entity - we should probably never
expose this to third party cloud integrations. It's risky.
This is not configurable, but can be extended by adding to the
cloud.const.NEVER_EXPOSED_ENTITIES array.
It's implemented in a modestly hacky fashion, because we determine
whether or not a entity should be excluded/included in several ways.
Notably, we define this array in the top level const.py, to avoid
circular import problems between the cloud/alexa components.
2018-11-06 09:39:10 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert len(msg["payload"]["endpoints"]) == 1
|
Add support for locks in google assistant component (#18233)
* Add support for locks in google assistant component
This is supported by the smarthome API, but there is no documentation
for it. This work is based on an article I found with screenshots of
documentation that was erroneously uploaded:
https://www.androidpolice.com/2018/01/17/google-assistant-home-can-now-natively-control-smart-locks-august-vivint-first-supported/
Google Assistant now supports unlocking certain locks - Nest and August
come to mind - via this API, and this commit allows Home Assistant to
do so as well.
Notably, I've added a config option `allow_unlock` that controls
whether we actually honor requests to unlock a lock via the google
assistant. It defaults to false.
Additionally, we add the functionNotSupported error, which makes a
little more sense when we're unable to execute the desired state
transition.
https://developers.google.com/actions/reference/smarthome/errors-exceptions#exception_list
* Fix linter warnings
* Ensure that certain groups are never exposed to cloud entities
For example, the group.all_locks entity - we should probably never
expose this to third party cloud integrations. It's risky.
This is not configurable, but can be extended by adding to the
cloud.const.NEVER_EXPOSED_ENTITIES array.
It's implemented in a modestly hacky fashion, because we determine
whether or not a entity should be excluded/included in several ways.
Notably, we define this array in the top level const.py, to avoid
circular import problems between the cloud/alexa components.
2018-11-06 09:39:10 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_api_entity_not_exists(hass):
|
2017-09-16 19:35:28 +00:00
|
|
|
"""Test api turn on process without entity."""
|
2019-07-31 19:25:30 +00:00
|
|
|
request = get_new_request("Alexa.PowerController", "TurnOn", "switch#test")
|
2017-09-16 19:35:28 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
call_switch = async_mock_service(hass, "switch", "turn_on")
|
2017-09-16 19:35:28 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
msg = await smart_home.async_handle_message(hass, DEFAULT_CONFIG, request)
|
2018-10-29 21:57:27 +00:00
|
|
|
await hass.async_block_till_done()
|
2017-10-07 20:31:57 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert "event" in msg
|
|
|
|
msg = msg["event"]
|
2017-10-07 20:31:57 +00:00
|
|
|
|
2018-01-30 04:33:39 +00:00
|
|
|
assert not call_switch
|
2019-07-31 19:25:30 +00:00
|
|
|
assert msg["header"]["name"] == "ErrorResponse"
|
|
|
|
assert msg["header"]["namespace"] == "Alexa"
|
|
|
|
assert msg["payload"]["type"] == "NO_SUCH_ENDPOINT"
|
2017-10-07 20:31:57 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_api_function_not_implemented(hass):
|
2017-10-07 20:31:57 +00:00
|
|
|
"""Test api call that is not implemented to us."""
|
2019-07-31 19:25:30 +00:00
|
|
|
request = get_new_request("Alexa.HAHAAH", "Sweet")
|
|
|
|
msg = await smart_home.async_handle_message(hass, DEFAULT_CONFIG, request)
|
2017-10-07 20:31:57 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert "event" in msg
|
|
|
|
msg = msg["event"]
|
2017-10-07 20:31:57 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert msg["header"]["name"] == "ErrorResponse"
|
|
|
|
assert msg["header"]["namespace"] == "Alexa"
|
|
|
|
assert msg["payload"]["type"] == "INTERNAL_ERROR"
|
2017-09-16 19:35:28 +00:00
|
|
|
|
|
|
|
|
2019-01-03 21:28:43 +00:00
|
|
|
async def test_api_accept_grant(hass):
|
|
|
|
"""Test api AcceptGrant process."""
|
|
|
|
request = get_new_request("Alexa.Authorization", "AcceptGrant")
|
|
|
|
|
|
|
|
# add payload
|
2019-07-31 19:25:30 +00:00
|
|
|
request["directive"]["payload"] = {
|
|
|
|
"grant": {
|
|
|
|
"type": "OAuth2.AuthorizationCode",
|
|
|
|
"code": "VGhpcyBpcyBhbiBhdXRob3JpemF0aW9uIGNvZGUuIDotKQ==",
|
2019-06-13 15:43:57 +00:00
|
|
|
},
|
2019-07-31 19:25:30 +00:00
|
|
|
"grantee": {"type": "BearerToken", "token": "access-token-from-skill"},
|
2019-01-03 21:28:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# setup test devices
|
2019-07-31 19:25:30 +00:00
|
|
|
msg = await smart_home.async_handle_message(hass, DEFAULT_CONFIG, request)
|
2019-01-03 21:28:43 +00:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert "event" in msg
|
|
|
|
msg = msg["event"]
|
2019-01-03 21:28:43 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert msg["header"]["name"] == "AcceptGrant.Response"
|
2019-01-03 21:28:43 +00:00
|
|
|
|
|
|
|
|
2018-10-29 21:57:27 +00:00
|
|
|
async def test_entity_config(hass):
|
2018-01-30 04:33:39 +00:00
|
|
|
"""Test that we can configure things via entity config."""
|
2019-07-31 19:25:30 +00:00
|
|
|
request = get_new_request("Alexa.Discovery", "Discover")
|
2018-01-26 05:06:57 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.states.async_set("light.test_1", "on", {"friendly_name": "Test light 1"})
|
2018-01-26 05:06:57 +00:00
|
|
|
|
2019-06-17 20:50:01 +00:00
|
|
|
alexa_config = MockConfig(hass)
|
2019-06-13 18:58:08 +00:00
|
|
|
alexa_config.entity_config = {
|
2019-07-31 19:25:30 +00:00
|
|
|
"light.test_1": {
|
|
|
|
"name": "Config name",
|
|
|
|
"display_categories": "SWITCH",
|
|
|
|
"description": "Config description",
|
2018-01-30 04:33:39 +00:00
|
|
|
}
|
2019-06-13 18:58:08 +00:00
|
|
|
}
|
2018-01-26 05:06:57 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
msg = await smart_home.async_handle_message(hass, alexa_config, request)
|
2018-01-26 05:06:57 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert "event" in msg
|
|
|
|
msg = msg["event"]
|
2018-01-26 05:06:57 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert len(msg["payload"]["endpoints"]) == 1
|
2018-01-05 20:33:22 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
appliance = msg["payload"]["endpoints"][0]
|
|
|
|
assert appliance["endpointId"] == "light#test_1"
|
|
|
|
assert appliance["displayCategories"][0] == "SWITCH"
|
|
|
|
assert appliance["friendlyName"] == "Config name"
|
|
|
|
assert appliance["description"] == "Config description"
|
2019-01-10 23:52:21 +00:00
|
|
|
assert_endpoint_capabilities(
|
2019-07-31 19:25:30 +00:00
|
|
|
appliance, "Alexa.PowerController", "Alexa.EndpointHealth"
|
2019-01-10 23:52:21 +00:00
|
|
|
)
|
2018-01-23 18:45:28 +00:00
|
|
|
|
|
|
|
|
2018-08-20 12:18:07 +00:00
|
|
|
async def test_logging_request(hass, events):
|
|
|
|
"""Test that we log requests."""
|
|
|
|
context = Context()
|
2019-07-31 19:25:30 +00:00
|
|
|
request = get_new_request("Alexa.Discovery", "Discover")
|
|
|
|
await smart_home.async_handle_message(hass, DEFAULT_CONFIG, request, context)
|
2018-08-20 12:18:07 +00:00
|
|
|
|
|
|
|
# To trigger event listener
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert len(events) == 1
|
|
|
|
event = events[0]
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert event.data["request"] == {"namespace": "Alexa.Discovery", "name": "Discover"}
|
|
|
|
assert event.data["response"] == {
|
|
|
|
"namespace": "Alexa.Discovery",
|
|
|
|
"name": "Discover.Response",
|
2018-08-20 12:18:07 +00:00
|
|
|
}
|
|
|
|
assert event.context == context
|
|
|
|
|
|
|
|
|
|
|
|
async def test_logging_request_with_entity(hass, events):
|
|
|
|
"""Test that we log requests."""
|
|
|
|
context = Context()
|
2019-07-31 19:25:30 +00:00
|
|
|
request = get_new_request("Alexa.PowerController", "TurnOn", "switch#xy")
|
|
|
|
await smart_home.async_handle_message(hass, DEFAULT_CONFIG, request, context)
|
2018-08-20 12:18:07 +00:00
|
|
|
|
|
|
|
# To trigger event listener
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert len(events) == 1
|
|
|
|
event = events[0]
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert event.data["request"] == {
|
|
|
|
"namespace": "Alexa.PowerController",
|
|
|
|
"name": "TurnOn",
|
|
|
|
"entity_id": "switch.xy",
|
2018-08-20 12:18:07 +00:00
|
|
|
}
|
|
|
|
# Entity doesn't exist
|
2019-07-31 19:25:30 +00:00
|
|
|
assert event.data["response"] == {"namespace": "Alexa", "name": "ErrorResponse"}
|
2018-08-20 12:18:07 +00:00
|
|
|
assert event.context == context
|
Refactor Alexa API, fix thermostats (#17969)
* Refactor Alexa API to use objects for requests
This introduces _AlexaDirective to stand in for the previous model of passing
basic dict and list data structures to and from handlers. This gives a more
expressive platform for functionality common to most or all handlers.
I had two use cases in mind:
1) Most responses should include current properties. In the case of locks and
thermostats, the response must include the properties or Alexa will give the
user a vague error like "Hmm, $device is not responding." Locks currently work,
but thermostats do not. I wanted a way to automatically include properties in
all responses. This is implemented in a subsequent commit.
2) The previous model had a 1:1 mapping between Alexa endpoints and Home
Assistant entities. This works most of the time, but sometimes it's not so
great. For example, my Z-wave thermostat shows as three devices in Alexa: one
for the temperature sensor, one for the heat, and one for the AC. I'd like to
merge these into one device from Alexa's perspective. I believe this will be
facilitated with the `endpoint` attribute on `_AlexaDirective`.
* Include properties in all Alexa responses
The added _AlexaResponse class provides a richer vocabulary for handlers.
Among that vocabulary is .merge_context_properties(), which is invoked
automatically for any request directed at an endpoint. This adds all supported
properties to the response as recommended by the Alexa API docs, and in some
cases (locks, thermostats at least) the user will get an error "Hmm, $device is
not responding" if properties are not provided in the response.
* Fix setting temperature with Alexa thermostats
Fixes https://github.com/home-assistant/home-assistant/issues/16577
2018-10-30 02:16:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_disabled(hass):
|
|
|
|
"""When enabled=False, everything fails."""
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.states.async_set("switch.test", "on", {"friendly_name": "Test switch"})
|
|
|
|
request = get_new_request("Alexa.PowerController", "TurnOn", "switch#test")
|
Refactor Alexa API, fix thermostats (#17969)
* Refactor Alexa API to use objects for requests
This introduces _AlexaDirective to stand in for the previous model of passing
basic dict and list data structures to and from handlers. This gives a more
expressive platform for functionality common to most or all handlers.
I had two use cases in mind:
1) Most responses should include current properties. In the case of locks and
thermostats, the response must include the properties or Alexa will give the
user a vague error like "Hmm, $device is not responding." Locks currently work,
but thermostats do not. I wanted a way to automatically include properties in
all responses. This is implemented in a subsequent commit.
2) The previous model had a 1:1 mapping between Alexa endpoints and Home
Assistant entities. This works most of the time, but sometimes it's not so
great. For example, my Z-wave thermostat shows as three devices in Alexa: one
for the temperature sensor, one for the heat, and one for the AC. I'd like to
merge these into one device from Alexa's perspective. I believe this will be
facilitated with the `endpoint` attribute on `_AlexaDirective`.
* Include properties in all Alexa responses
The added _AlexaResponse class provides a richer vocabulary for handlers.
Among that vocabulary is .merge_context_properties(), which is invoked
automatically for any request directed at an endpoint. This adds all supported
properties to the response as recommended by the Alexa API docs, and in some
cases (locks, thermostats at least) the user will get an error "Hmm, $device is
not responding" if properties are not provided in the response.
* Fix setting temperature with Alexa thermostats
Fixes https://github.com/home-assistant/home-assistant/issues/16577
2018-10-30 02:16:35 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
call_switch = async_mock_service(hass, "switch", "turn_on")
|
Refactor Alexa API, fix thermostats (#17969)
* Refactor Alexa API to use objects for requests
This introduces _AlexaDirective to stand in for the previous model of passing
basic dict and list data structures to and from handlers. This gives a more
expressive platform for functionality common to most or all handlers.
I had two use cases in mind:
1) Most responses should include current properties. In the case of locks and
thermostats, the response must include the properties or Alexa will give the
user a vague error like "Hmm, $device is not responding." Locks currently work,
but thermostats do not. I wanted a way to automatically include properties in
all responses. This is implemented in a subsequent commit.
2) The previous model had a 1:1 mapping between Alexa endpoints and Home
Assistant entities. This works most of the time, but sometimes it's not so
great. For example, my Z-wave thermostat shows as three devices in Alexa: one
for the temperature sensor, one for the heat, and one for the AC. I'd like to
merge these into one device from Alexa's perspective. I believe this will be
facilitated with the `endpoint` attribute on `_AlexaDirective`.
* Include properties in all Alexa responses
The added _AlexaResponse class provides a richer vocabulary for handlers.
Among that vocabulary is .merge_context_properties(), which is invoked
automatically for any request directed at an endpoint. This adds all supported
properties to the response as recommended by the Alexa API docs, and in some
cases (locks, thermostats at least) the user will get an error "Hmm, $device is
not responding" if properties are not provided in the response.
* Fix setting temperature with Alexa thermostats
Fixes https://github.com/home-assistant/home-assistant/issues/16577
2018-10-30 02:16:35 +00:00
|
|
|
|
|
|
|
msg = await smart_home.async_handle_message(
|
2019-07-31 19:25:30 +00:00
|
|
|
hass, DEFAULT_CONFIG, request, enabled=False
|
|
|
|
)
|
Refactor Alexa API, fix thermostats (#17969)
* Refactor Alexa API to use objects for requests
This introduces _AlexaDirective to stand in for the previous model of passing
basic dict and list data structures to and from handlers. This gives a more
expressive platform for functionality common to most or all handlers.
I had two use cases in mind:
1) Most responses should include current properties. In the case of locks and
thermostats, the response must include the properties or Alexa will give the
user a vague error like "Hmm, $device is not responding." Locks currently work,
but thermostats do not. I wanted a way to automatically include properties in
all responses. This is implemented in a subsequent commit.
2) The previous model had a 1:1 mapping between Alexa endpoints and Home
Assistant entities. This works most of the time, but sometimes it's not so
great. For example, my Z-wave thermostat shows as three devices in Alexa: one
for the temperature sensor, one for the heat, and one for the AC. I'd like to
merge these into one device from Alexa's perspective. I believe this will be
facilitated with the `endpoint` attribute on `_AlexaDirective`.
* Include properties in all Alexa responses
The added _AlexaResponse class provides a richer vocabulary for handlers.
Among that vocabulary is .merge_context_properties(), which is invoked
automatically for any request directed at an endpoint. This adds all supported
properties to the response as recommended by the Alexa API docs, and in some
cases (locks, thermostats at least) the user will get an error "Hmm, $device is
not responding" if properties are not provided in the response.
* Fix setting temperature with Alexa thermostats
Fixes https://github.com/home-assistant/home-assistant/issues/16577
2018-10-30 02:16:35 +00:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert "event" in msg
|
|
|
|
msg = msg["event"]
|
Refactor Alexa API, fix thermostats (#17969)
* Refactor Alexa API to use objects for requests
This introduces _AlexaDirective to stand in for the previous model of passing
basic dict and list data structures to and from handlers. This gives a more
expressive platform for functionality common to most or all handlers.
I had two use cases in mind:
1) Most responses should include current properties. In the case of locks and
thermostats, the response must include the properties or Alexa will give the
user a vague error like "Hmm, $device is not responding." Locks currently work,
but thermostats do not. I wanted a way to automatically include properties in
all responses. This is implemented in a subsequent commit.
2) The previous model had a 1:1 mapping between Alexa endpoints and Home
Assistant entities. This works most of the time, but sometimes it's not so
great. For example, my Z-wave thermostat shows as three devices in Alexa: one
for the temperature sensor, one for the heat, and one for the AC. I'd like to
merge these into one device from Alexa's perspective. I believe this will be
facilitated with the `endpoint` attribute on `_AlexaDirective`.
* Include properties in all Alexa responses
The added _AlexaResponse class provides a richer vocabulary for handlers.
Among that vocabulary is .merge_context_properties(), which is invoked
automatically for any request directed at an endpoint. This adds all supported
properties to the response as recommended by the Alexa API docs, and in some
cases (locks, thermostats at least) the user will get an error "Hmm, $device is
not responding" if properties are not provided in the response.
* Fix setting temperature with Alexa thermostats
Fixes https://github.com/home-assistant/home-assistant/issues/16577
2018-10-30 02:16:35 +00:00
|
|
|
|
|
|
|
assert not call_switch
|
2019-07-31 19:25:30 +00:00
|
|
|
assert msg["header"]["name"] == "ErrorResponse"
|
|
|
|
assert msg["header"]["namespace"] == "Alexa"
|
|
|
|
assert msg["payload"]["type"] == "BRIDGE_UNREACHABLE"
|
2019-01-03 21:28:43 +00:00
|
|
|
|
|
|
|
|
2019-01-10 23:52:21 +00:00
|
|
|
async def test_endpoint_good_health(hass):
|
|
|
|
"""Test endpoint health reporting."""
|
|
|
|
device = (
|
2019-07-31 19:25:30 +00:00
|
|
|
"binary_sensor.test_contact",
|
|
|
|
"on",
|
|
|
|
{"friendly_name": "Test Contact Sensor", "device_class": "door"},
|
2019-01-10 23:52:21 +00:00
|
|
|
)
|
|
|
|
await discovery_test(device, hass)
|
2019-07-31 19:25:30 +00:00
|
|
|
properties = await reported_properties(hass, "binary_sensor#test_contact")
|
|
|
|
properties.assert_equal("Alexa.EndpointHealth", "connectivity", {"value": "OK"})
|
2019-01-10 23:52:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_endpoint_bad_health(hass):
|
|
|
|
"""Test endpoint health reporting."""
|
|
|
|
device = (
|
2019-07-31 19:25:30 +00:00
|
|
|
"binary_sensor.test_contact",
|
|
|
|
"unavailable",
|
|
|
|
{"friendly_name": "Test Contact Sensor", "device_class": "door"},
|
2019-01-10 23:52:21 +00:00
|
|
|
)
|
|
|
|
await discovery_test(device, hass)
|
2019-07-31 19:25:30 +00:00
|
|
|
properties = await reported_properties(hass, "binary_sensor#test_contact")
|
|
|
|
properties.assert_equal(
|
|
|
|
"Alexa.EndpointHealth", "connectivity", {"value": "UNREACHABLE"}
|
|
|
|
)
|