mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +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.
This commit is contained in:
committed by
Paulus Schoutsen
parent
ddee5f8b86
commit
2bf2214d51
@@ -7,7 +7,9 @@ from homeassistant.util.decorator import Registry
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.const import (
|
||||
CONF_NAME, STATE_UNAVAILABLE, ATTR_SUPPORTED_FEATURES)
|
||||
CLOUD_NEVER_EXPOSED_ENTITIES, CONF_NAME, STATE_UNAVAILABLE,
|
||||
ATTR_SUPPORTED_FEATURES
|
||||
)
|
||||
from homeassistant.components import (
|
||||
climate,
|
||||
cover,
|
||||
@@ -15,6 +17,7 @@ from homeassistant.components import (
|
||||
group,
|
||||
input_boolean,
|
||||
light,
|
||||
lock,
|
||||
media_player,
|
||||
scene,
|
||||
script,
|
||||
@@ -22,12 +25,13 @@ from homeassistant.components import (
|
||||
vacuum,
|
||||
)
|
||||
|
||||
|
||||
from . import trait
|
||||
from .const import (
|
||||
TYPE_LIGHT, TYPE_SCENE, TYPE_SWITCH, TYPE_VACUUM,
|
||||
TYPE_LIGHT, TYPE_LOCK, TYPE_SCENE, TYPE_SWITCH, TYPE_VACUUM,
|
||||
TYPE_THERMOSTAT, TYPE_FAN,
|
||||
CONF_ALIASES, CONF_ROOM_HINT,
|
||||
ERR_NOT_SUPPORTED, ERR_PROTOCOL_ERROR, ERR_DEVICE_OFFLINE,
|
||||
ERR_FUNCTION_NOT_SUPPORTED, ERR_PROTOCOL_ERROR, ERR_DEVICE_OFFLINE,
|
||||
ERR_UNKNOWN_ERROR
|
||||
)
|
||||
from .helpers import SmartHomeError
|
||||
@@ -42,6 +46,7 @@ DOMAIN_TO_GOOGLE_TYPES = {
|
||||
group.DOMAIN: TYPE_SWITCH,
|
||||
input_boolean.DOMAIN: TYPE_SWITCH,
|
||||
light.DOMAIN: TYPE_LIGHT,
|
||||
lock.DOMAIN: TYPE_LOCK,
|
||||
media_player.DOMAIN: TYPE_SWITCH,
|
||||
scene.DOMAIN: TYPE_SCENE,
|
||||
script.DOMAIN: TYPE_SCENE,
|
||||
@@ -80,7 +85,7 @@ class _GoogleEntity:
|
||||
domain = state.domain
|
||||
features = state.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
||||
|
||||
return [Trait(self.hass, state) for Trait in trait.TRAITS
|
||||
return [Trait(self.hass, state, self.config) for Trait in trait.TRAITS
|
||||
if Trait.supported(domain, features)]
|
||||
|
||||
@callback
|
||||
@@ -168,7 +173,7 @@ class _GoogleEntity:
|
||||
|
||||
if not executed:
|
||||
raise SmartHomeError(
|
||||
ERR_NOT_SUPPORTED,
|
||||
ERR_FUNCTION_NOT_SUPPORTED,
|
||||
'Unable to execute {} for {}'.format(command,
|
||||
self.state.entity_id))
|
||||
|
||||
@@ -232,6 +237,9 @@ async def async_devices_sync(hass, config, payload):
|
||||
"""
|
||||
devices = []
|
||||
for state in hass.states.async_all():
|
||||
if state.entity_id in CLOUD_NEVER_EXPOSED_ENTITIES:
|
||||
continue
|
||||
|
||||
if not config.should_expose(state):
|
||||
continue
|
||||
|
||||
|
||||
Reference in New Issue
Block a user