From 497038b33229aaa63498ad4f02600a8d694f48dc Mon Sep 17 00:00:00 2001 From: giefca Date: Mon, 15 Apr 2019 22:05:53 +0200 Subject: [PATCH] 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 --- .../components/google_assistant/const.py | 1 + .../components/google_assistant/smart_home.py | 17 +++++++++++++++-- tests/components/google_assistant/__init__.py | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/google_assistant/const.py b/homeassistant/components/google_assistant/const.py index 852ea2469a2..585aa0027bb 100644 --- a/homeassistant/components/google_assistant/const.py +++ b/homeassistant/components/google_assistant/const.py @@ -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/' diff --git a/homeassistant/components/google_assistant/smart_home.py b/homeassistant/components/google_assistant/smart_home.py index cf31e3423a7..59d8334cdac 100644 --- a/homeassistant/components/google_assistant/smart_home.py +++ b/homeassistant/components/google_assistant/smart_home.py @@ -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 diff --git a/tests/components/google_assistant/__init__.py b/tests/components/google_assistant/__init__.py index 898bc04fbd9..d75b51df65b 100644 --- a/tests/components/google_assistant/__init__.py +++ b/tests/components/google_assistant/__init__.py @@ -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',