mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +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_THERMOSTAT = PREFIX_TYPES + 'THERMOSTAT'
|
||||||
TYPE_LOCK = PREFIX_TYPES + 'LOCK'
|
TYPE_LOCK = PREFIX_TYPES + 'LOCK'
|
||||||
TYPE_BLINDS = PREFIX_TYPES + 'BLINDS'
|
TYPE_BLINDS = PREFIX_TYPES + 'BLINDS'
|
||||||
|
TYPE_GARAGE = PREFIX_TYPES + 'GARAGE'
|
||||||
|
|
||||||
SERVICE_REQUEST_SYNC = 'request_sync'
|
SERVICE_REQUEST_SYNC = 'request_sync'
|
||||||
HOMEGRAPH_URL = 'https://homegraph.googleapis.com/'
|
HOMEGRAPH_URL = 'https://homegraph.googleapis.com/'
|
||||||
|
@ -31,7 +31,7 @@ from homeassistant.components import (
|
|||||||
from . import trait
|
from . import trait
|
||||||
from .const import (
|
from .const import (
|
||||||
TYPE_LIGHT, TYPE_LOCK, TYPE_SCENE, TYPE_SWITCH, TYPE_VACUUM,
|
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,
|
CONF_ALIASES, CONF_ROOM_HINT,
|
||||||
ERR_FUNCTION_NOT_SUPPORTED, ERR_PROTOCOL_ERROR, ERR_DEVICE_OFFLINE,
|
ERR_FUNCTION_NOT_SUPPORTED, ERR_PROTOCOL_ERROR, ERR_DEVICE_OFFLINE,
|
||||||
ERR_UNKNOWN_ERROR,
|
ERR_UNKNOWN_ERROR,
|
||||||
@ -58,6 +58,10 @@ DOMAIN_TO_GOOGLE_TYPES = {
|
|||||||
vacuum.DOMAIN: TYPE_VACUUM,
|
vacuum.DOMAIN: TYPE_VACUUM,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEVICE_CLASS_TO_GOOGLE_TYPES = {
|
||||||
|
(cover.DOMAIN, cover.DEVICE_CLASS_GARAGE): TYPE_GARAGE,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def deep_update(target, source):
|
def deep_update(target, source):
|
||||||
"""Update a nested dictionary with another nested dictionary."""
|
"""Update a nested dictionary with another nested dictionary."""
|
||||||
@ -69,6 +73,13 @@ def deep_update(target, source):
|
|||||||
return target
|
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:
|
class _GoogleEntity:
|
||||||
"""Adaptation of Entity expressed in Google's terms."""
|
"""Adaptation of Entity expressed in Google's terms."""
|
||||||
|
|
||||||
@ -114,6 +125,8 @@ class _GoogleEntity:
|
|||||||
|
|
||||||
entity_config = self.config.entity_config.get(state.entity_id, {})
|
entity_config = self.config.entity_config.get(state.entity_id, {})
|
||||||
name = (entity_config.get(CONF_NAME) or state.name).strip()
|
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 an empty string
|
||||||
if not name:
|
if not name:
|
||||||
@ -133,7 +146,7 @@ class _GoogleEntity:
|
|||||||
'attributes': {},
|
'attributes': {},
|
||||||
'traits': [trait.name for trait in traits],
|
'traits': [trait.name for trait in traits],
|
||||||
'willReportState': False,
|
'willReportState': False,
|
||||||
'type': DOMAIN_TO_GOOGLE_TYPES[state.domain],
|
'type': get_google_type(domain, device_class),
|
||||||
}
|
}
|
||||||
|
|
||||||
# use aliases
|
# use aliases
|
||||||
|
@ -116,7 +116,7 @@ DEMO_DEVICES = [{
|
|||||||
},
|
},
|
||||||
'traits': ['action.devices.traits.OpenClose'],
|
'traits': ['action.devices.traits.OpenClose'],
|
||||||
'type':
|
'type':
|
||||||
'action.devices.types.BLINDS',
|
'action.devices.types.GARAGE',
|
||||||
'willReportState': False
|
'willReportState': False
|
||||||
}, {
|
}, {
|
||||||
'id': 'cover.kitchen_window',
|
'id': 'cover.kitchen_window',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user