mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Add button support to Google Assistant (#60158)
This commit is contained in:
parent
7359083e98
commit
42ed6ddba3
@ -2,6 +2,7 @@
|
|||||||
from homeassistant.components import (
|
from homeassistant.components import (
|
||||||
alarm_control_panel,
|
alarm_control_panel,
|
||||||
binary_sensor,
|
binary_sensor,
|
||||||
|
button,
|
||||||
camera,
|
camera,
|
||||||
climate,
|
climate,
|
||||||
cover,
|
cover,
|
||||||
@ -120,6 +121,7 @@ EVENT_SYNC_RECEIVED = "google_assistant_sync"
|
|||||||
|
|
||||||
DOMAIN_TO_GOOGLE_TYPES = {
|
DOMAIN_TO_GOOGLE_TYPES = {
|
||||||
alarm_control_panel.DOMAIN: TYPE_ALARM,
|
alarm_control_panel.DOMAIN: TYPE_ALARM,
|
||||||
|
button.DOMAIN: TYPE_SCENE,
|
||||||
camera.DOMAIN: TYPE_CAMERA,
|
camera.DOMAIN: TYPE_CAMERA,
|
||||||
climate.DOMAIN: TYPE_THERMOSTAT,
|
climate.DOMAIN: TYPE_THERMOSTAT,
|
||||||
cover.DOMAIN: TYPE_BLINDS,
|
cover.DOMAIN: TYPE_BLINDS,
|
||||||
|
@ -6,6 +6,7 @@ import logging
|
|||||||
from homeassistant.components import (
|
from homeassistant.components import (
|
||||||
alarm_control_panel,
|
alarm_control_panel,
|
||||||
binary_sensor,
|
binary_sensor,
|
||||||
|
button,
|
||||||
camera,
|
camera,
|
||||||
cover,
|
cover,
|
||||||
fan,
|
fan,
|
||||||
@ -513,11 +514,11 @@ class SceneTrait(_Trait):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def supported(domain, features, device_class, _):
|
def supported(domain, features, device_class, _):
|
||||||
"""Test if state is supported."""
|
"""Test if state is supported."""
|
||||||
return domain in (scene.DOMAIN, script.DOMAIN)
|
return domain in (button.DOMAIN, scene.DOMAIN, script.DOMAIN)
|
||||||
|
|
||||||
def sync_attributes(self):
|
def sync_attributes(self):
|
||||||
"""Return scene attributes for a sync request."""
|
"""Return scene attributes for a sync request."""
|
||||||
# Neither supported domain can support sceneReversible
|
# None of the supported domains can support sceneReversible
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def query_attributes(self):
|
def query_attributes(self):
|
||||||
@ -526,12 +527,16 @@ class SceneTrait(_Trait):
|
|||||||
|
|
||||||
async def execute(self, command, data, params, challenge):
|
async def execute(self, command, data, params, challenge):
|
||||||
"""Execute a scene command."""
|
"""Execute a scene command."""
|
||||||
# Don't block for scripts as they can be slow.
|
service = SERVICE_TURN_ON
|
||||||
|
if self.state.domain == button.DOMAIN:
|
||||||
|
service = button.SERVICE_PRESS
|
||||||
|
|
||||||
|
# Don't block for scripts or buttons, as they can be slow.
|
||||||
await self.hass.services.async_call(
|
await self.hass.services.async_call(
|
||||||
self.state.domain,
|
self.state.domain,
|
||||||
SERVICE_TURN_ON,
|
service,
|
||||||
{ATTR_ENTITY_ID: self.state.entity_id},
|
{ATTR_ENTITY_ID: self.state.entity_id},
|
||||||
blocking=self.state.domain != script.DOMAIN,
|
blocking=self.state.domain not in (button.DOMAIN, script.DOMAIN),
|
||||||
context=data.context,
|
context=data.context,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -94,6 +94,7 @@ ALLOWED_USED_COMPONENTS = {
|
|||||||
# Internal integrations
|
# Internal integrations
|
||||||
"alert",
|
"alert",
|
||||||
"automation",
|
"automation",
|
||||||
|
"button",
|
||||||
"conversation",
|
"conversation",
|
||||||
"button",
|
"button",
|
||||||
"device_automation",
|
"device_automation",
|
||||||
|
@ -7,6 +7,7 @@ import pytest
|
|||||||
from homeassistant.components import (
|
from homeassistant.components import (
|
||||||
alarm_control_panel,
|
alarm_control_panel,
|
||||||
binary_sensor,
|
binary_sensor,
|
||||||
|
button,
|
||||||
camera,
|
camera,
|
||||||
cover,
|
cover,
|
||||||
fan,
|
fan,
|
||||||
@ -767,6 +768,26 @@ async def test_light_modes(hass):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_scene_button(hass):
|
||||||
|
"""Test Scene trait support for the button domain."""
|
||||||
|
assert helpers.get_google_type(button.DOMAIN, None) is not None
|
||||||
|
assert trait.SceneTrait.supported(button.DOMAIN, 0, None, None)
|
||||||
|
|
||||||
|
trt = trait.SceneTrait(hass, State("button.bla", STATE_UNKNOWN), BASIC_CONFIG)
|
||||||
|
assert trt.sync_attributes() == {}
|
||||||
|
assert trt.query_attributes() == {}
|
||||||
|
assert trt.can_execute(trait.COMMAND_ACTIVATE_SCENE, {})
|
||||||
|
|
||||||
|
calls = async_mock_service(hass, button.DOMAIN, button.SERVICE_PRESS)
|
||||||
|
await trt.execute(trait.COMMAND_ACTIVATE_SCENE, BASIC_DATA, {}, {})
|
||||||
|
|
||||||
|
# We don't wait till button press is done.
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert len(calls) == 1
|
||||||
|
assert calls[0].data == {ATTR_ENTITY_ID: "button.bla"}
|
||||||
|
|
||||||
|
|
||||||
async def test_scene_scene(hass):
|
async def test_scene_scene(hass):
|
||||||
"""Test Scene trait support for scene domain."""
|
"""Test Scene trait support for scene domain."""
|
||||||
assert helpers.get_google_type(scene.DOMAIN, None) is not None
|
assert helpers.get_google_type(scene.DOMAIN, None) is not None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user