1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-26 22:18:40 +00:00

Implement Alexa temperature sensors (#11930)

This commit is contained in:
Phil Frost
2018-01-26 18:40:39 +00:00
committed by Paulus Schoutsen
parent 2d8ef36a6c
commit ffcc41d6ef
2 changed files with 133 additions and 7 deletions

View File

@@ -5,6 +5,7 @@ from uuid import uuid4
import pytest
from homeassistant.const import TEMP_FAHRENHEIT, CONF_UNIT_OF_MEASUREMENT
from homeassistant.setup import async_setup_component
from homeassistant.components import alexa
from homeassistant.components.alexa import smart_home
@@ -166,13 +167,27 @@ def test_discovery_request(hass):
'position': 85
})
hass.states.async_set(
'sensor.test_temp', '59', {
'friendly_name': "Test Temp Sensor",
'unit_of_measurement': TEMP_FAHRENHEIT,
})
# This sensor measures a quantity not applicable to Alexa, and should not
# be discovered.
hass.states.async_set(
'sensor.test_sickness', '0.1', {
'friendly_name': "Test Space Sickness Sensor",
'unit_of_measurement': 'garn',
})
msg = yield from smart_home.async_handle_message(
hass, DEFAULT_CONFIG, request)
assert 'event' in msg
msg = msg['event']
assert len(msg['payload']['endpoints']) == 16
assert len(msg['payload']['endpoints']) == 17
assert msg['header']['name'] == 'Discover.Response'
assert msg['header']['namespace'] == 'Alexa.Discovery'
@@ -334,6 +349,17 @@ def test_discovery_request(hass):
assert 'Alexa.PowerController' in caps
continue
if appliance['endpointId'] == 'sensor#test_temp':
assert appliance['displayCategories'][0] == 'TEMPERATURE_SENSOR'
assert appliance['friendlyName'] == 'Test Temp Sensor'
assert len(appliance['capabilities']) == 1
capability = appliance['capabilities'][0]
assert capability['interface'] == 'Alexa.TemperatureSensor'
assert capability['retrievable'] is True
properties = capability['properties']
assert {'name': 'temperature'} in properties['supported']
continue
raise AssertionError("Unknown appliance!")
@@ -1170,6 +1196,34 @@ def test_api_mute(hass, domain):
assert msg['header']['name'] == 'Response'
@asyncio.coroutine
def test_api_report_temperature(hass):
"""Test API ReportState response for a temperature sensor."""
request = get_new_request('Alexa', 'ReportState', 'sensor#test')
# setup test devices
hass.states.async_set(
'sensor.test', '42', {
'friendly_name': 'test sensor',
CONF_UNIT_OF_MEASUREMENT: TEMP_FAHRENHEIT,
})
msg = yield from smart_home.async_handle_message(
hass, DEFAULT_CONFIG, request)
yield from hass.async_block_till_done()
header = msg['event']['header']
assert header['namespace'] == 'Alexa'
assert header['name'] == 'StateReport'
properties = msg['context']['properties']
assert len(properties) == 1
prop = properties[0]
assert prop['namespace'] == 'Alexa.TemperatureSensor'
assert prop['name'] == 'temperature'
assert prop['value'] == {'value': 42.0, 'scale': 'FAHRENHEIT'}
@asyncio.coroutine
def test_entity_config(hass):
"""Test that we can configure things via entity config."""