mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 05:37:44 +00:00
Add Google Assistant garage type (#23115)
* Tests * Add Google Assistant GARAGE type * Update test_trait.py * Key device class by domain * Update smart_home.py
This commit is contained in:
parent
f5878e1f22
commit
497038b332
@ -30,6 +30,7 @@ TYPE_FAN = PREFIX_TYPES + 'FAN'
|
||||
TYPE_THERMOSTAT = PREFIX_TYPES + 'THERMOSTAT'
|
||||
TYPE_LOCK = PREFIX_TYPES + 'LOCK'
|
||||
TYPE_BLINDS = PREFIX_TYPES + 'BLINDS'
|
||||
TYPE_GARAGE = PREFIX_TYPES + 'GARAGE'
|
||||
|
||||
SERVICE_REQUEST_SYNC = 'request_sync'
|
||||
HOMEGRAPH_URL = 'https://homegraph.googleapis.com/'
|
||||
|
@ -31,7 +31,7 @@ from homeassistant.components import (
|
||||
from . import trait
|
||||
from .const import (
|
||||
TYPE_LIGHT, TYPE_LOCK, TYPE_SCENE, TYPE_SWITCH, TYPE_VACUUM,
|
||||
TYPE_THERMOSTAT, TYPE_FAN, TYPE_CAMERA, TYPE_BLINDS,
|
||||
TYPE_THERMOSTAT, TYPE_FAN, TYPE_CAMERA, TYPE_BLINDS, TYPE_GARAGE,
|
||||
CONF_ALIASES, CONF_ROOM_HINT,
|
||||
ERR_FUNCTION_NOT_SUPPORTED, ERR_PROTOCOL_ERROR, ERR_DEVICE_OFFLINE,
|
||||
ERR_UNKNOWN_ERROR,
|
||||
@ -58,6 +58,10 @@ DOMAIN_TO_GOOGLE_TYPES = {
|
||||
vacuum.DOMAIN: TYPE_VACUUM,
|
||||
}
|
||||
|
||||
DEVICE_CLASS_TO_GOOGLE_TYPES = {
|
||||
(cover.DOMAIN, cover.DEVICE_CLASS_GARAGE): TYPE_GARAGE,
|
||||
}
|
||||
|
||||
|
||||
def deep_update(target, source):
|
||||
"""Update a nested dictionary with another nested dictionary."""
|
||||
@ -69,6 +73,13 @@ def deep_update(target, source):
|
||||
return target
|
||||
|
||||
|
||||
def get_google_type(domain, device_class):
|
||||
"""Google type based on domain and device class."""
|
||||
typ = DEVICE_CLASS_TO_GOOGLE_TYPES.get((domain, device_class))
|
||||
|
||||
return typ if typ is not None else DOMAIN_TO_GOOGLE_TYPES.get(domain)
|
||||
|
||||
|
||||
class _GoogleEntity:
|
||||
"""Adaptation of Entity expressed in Google's terms."""
|
||||
|
||||
@ -114,6 +125,8 @@ class _GoogleEntity:
|
||||
|
||||
entity_config = self.config.entity_config.get(state.entity_id, {})
|
||||
name = (entity_config.get(CONF_NAME) or state.name).strip()
|
||||
domain = state.domain
|
||||
device_class = state.attributes.get(ATTR_DEVICE_CLASS)
|
||||
|
||||
# If an empty string
|
||||
if not name:
|
||||
@ -133,7 +146,7 @@ class _GoogleEntity:
|
||||
'attributes': {},
|
||||
'traits': [trait.name for trait in traits],
|
||||
'willReportState': False,
|
||||
'type': DOMAIN_TO_GOOGLE_TYPES[state.domain],
|
||||
'type': get_google_type(domain, device_class),
|
||||
}
|
||||
|
||||
# use aliases
|
||||
|
@ -116,7 +116,7 @@ DEMO_DEVICES = [{
|
||||
},
|
||||
'traits': ['action.devices.traits.OpenClose'],
|
||||
'type':
|
||||
'action.devices.types.BLINDS',
|
||||
'action.devices.types.GARAGE',
|
||||
'willReportState': False
|
||||
}, {
|
||||
'id': 'cover.kitchen_window',
|
||||
|
Loading…
x
Reference in New Issue
Block a user