Google assistant: add blinds trait for covers (#22336)

* Update const.py

* Update smart_home.py

* Update trait.py

* Update test_trait.py

* Update smart_home.py

* Update test_trait.py

* Update trait.py

* Update trait.py

* Update test_trait.py

* Update test_trait.py

* Update __init__.py

* Update test_trait.py

* Change email

* Trying to correct CLA

* Update __init__.py

* Update trait.py

* Update trait.py

* Update trait.py

* Update trait.py

* Update __init__.py

* Update test_trait.py

* Update test_google_assistant.py

* Update trait.py

* Update trait.py

* Update test_trait.py

* Update test_trait.py
This commit is contained in:
giefca authored and Paulus Schoutsen committed 2019-03-31 20:01:59 -07:00
1 parent ec9a58442b
commit 8af70d5d19
5 files changed
+110 -101

No files matched your search

+12 -8
View File
@@ -1,3 +1,5 @@
"""Tests for the Google Assistant integration."""
DEMO_DEVICES = [{
@@ -93,9 +95,9 @@ DEMO_DEVICES = [{
'name': 'Living Room Window'
},
'traits':
['action.devices.traits.OnOff', 'action.devices.traits.Brightness'],
['action.devices.traits.OpenClose'],
'type':
'action.devices.types.SWITCH',
'action.devices.types.BLINDS',
'willReportState':
False
}, {
@@ -105,9 +107,9 @@ DEMO_DEVICES = [{
'name': 'Hall Window'
},
'traits':
['action.devices.traits.OnOff', 'action.devices.traits.Brightness'],
['action.devices.traits.OpenClose'],
'type':
'action.devices.types.SWITCH',
'action.devices.types.BLINDS',
'willReportState':
False
}, {
@@ -115,16 +117,18 @@ DEMO_DEVICES = [{
'name': {
'name': 'Garage Door'
},
'traits': ['action.devices.traits.OnOff'],
'type': 'action.devices.types.SWITCH',
'traits': ['action.devices.traits.OpenClose'],
'type':
'action.devices.types.BLINDS',
'willReportState': False
}, {
'id': 'cover.kitchen_window',
'name': {
'name': 'Kitchen Window'
},
'traits': ['action.devices.traits.OnOff'],
'type': 'action.devices.types.SWITCH',
'traits': ['action.devices.traits.OpenClose'],
'type':
'action.devices.types.BLINDS',
'willReportState': False
}, {
'id': 'group.all_covers',
+27 -67
View File
@@ -83,33 +83,6 @@ async def test_brightness_light(hass):
}
async def test_brightness_cover(hass):
"""Test brightness trait support for cover domain."""
assert trait.BrightnessTrait.supported(cover.DOMAIN,
cover.SUPPORT_SET_POSITION)
trt = trait.BrightnessTrait(hass, State('cover.bla', cover.STATE_OPEN, {
cover.ATTR_CURRENT_POSITION: 75
}), BASIC_CONFIG)
assert trt.sync_attributes() == {}
assert trt.query_attributes() == {
'brightness': 75
}
calls = async_mock_service(
hass, cover.DOMAIN, cover.SERVICE_SET_COVER_POSITION)
await trt.execute(
trait.COMMAND_BRIGHTNESS_ABSOLUTE, BASIC_DATA,
{'brightness': 50})
assert len(calls) == 1
assert calls[0].data == {
ATTR_ENTITY_ID: 'cover.bla',
cover.ATTR_POSITION: 50
}
async def test_brightness_media_player(hass):
"""Test brightness trait support for media player domain."""
assert trait.BrightnessTrait.supported(media_player.DOMAIN,
@@ -358,46 +331,6 @@ async def test_onoff_light(hass):
}
async def test_onoff_cover(hass):
"""Test OnOff trait support for cover domain."""
assert trait.OnOffTrait.supported(cover.DOMAIN, 0)
trt_on = trait.OnOffTrait(hass, State('cover.bla', cover.STATE_OPEN),
BASIC_CONFIG)
assert trt_on.sync_attributes() == {}
assert trt_on.query_attributes() == {
'on': True
}
trt_off = trait.OnOffTrait(hass, State('cover.bla', cover.STATE_CLOSED),
BASIC_CONFIG)
assert trt_off.query_attributes() == {
'on': False
}
on_calls = async_mock_service(hass, cover.DOMAIN, cover.SERVICE_OPEN_COVER)
await trt_on.execute(
trait.COMMAND_ONOFF, BASIC_DATA,
{'on': True})
assert len(on_calls) == 1
assert on_calls[0].data == {
ATTR_ENTITY_ID: 'cover.bla',
}
off_calls = async_mock_service(hass, cover.DOMAIN,
cover.SERVICE_CLOSE_COVER)
await trt_on.execute(
trait.COMMAND_ONOFF, BASIC_DATA,
{'on': False})
assert len(off_calls) == 1
assert off_calls[0].data == {
ATTR_ENTITY_ID: 'cover.bla',
}
async def test_onoff_media_player(hass):
"""Test OnOff trait support for media_player domain."""
assert trait.OnOffTrait.supported(media_player.DOMAIN, 0)
@@ -1119,3 +1052,30 @@ async def test_modes(hass):
'entity_id': 'media_player.living_room',
'source': 'media'
}
async def test_openclose_cover(hass):
"""Test cover trait."""
assert trait.OpenCloseTrait.supported(cover.DOMAIN,
cover.SUPPORT_SET_POSITION)
trt = trait.OpenCloseTrait(hass, State('cover.bla', cover.STATE_OPEN, {
cover.ATTR_CURRENT_POSITION: 75
}), BASIC_CONFIG)
assert trt.sync_attributes() == {}
assert trt.query_attributes() == {
'openPercent': 75
}
calls = async_mock_service(
hass, cover.DOMAIN, cover.SERVICE_SET_COVER_POSITION)
await trt.execute(
trait.COMMAND_OPENCLOSE, BASIC_DATA,
{'openPercent': 50})
assert len(calls) == 1
assert calls[0].data == {
ATTR_ENTITY_ID: 'cover.bla',
cover.ATTR_POSITION: 50
}