Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Google Assistant garage type #23115

Merged
merged 5 commits into from Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions homeassistant/components/google_assistant/const.py
Expand Up @@ -30,6 +30,7 @@
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/'
Expand Down
17 changes: 15 additions & 2 deletions homeassistant/components/google_assistant/smart_home.py
Expand Up @@ -31,7 +31,7 @@
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,
Expand All @@ -58,6 +58,10 @@
vacuum.DOMAIN: TYPE_VACUUM,
}

DEVICE_CLASS_TO_GOOGLE_TYPES = {
cover.DEVICE_CLASS_GARAGE: TYPE_GARAGE,
}


def deep_update(target, source):
"""Update a nested dictionary with another nested dictionary."""
Expand All @@ -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."""
if DEVICE_CLASS_TO_GOOGLE_TYPES.get(device_class) is not None:
balloob marked this conversation as resolved.
Show resolved Hide resolved
return DEVICE_CLASS_TO_GOOGLE_TYPES[device_class]
return DOMAIN_TO_GOOGLE_TYPES[domain]


class _GoogleEntity:
"""Adaptation of Entity expressed in Google's terms."""

Expand Down Expand Up @@ -114,6 +125,8 @@ async def sync_serialize(self):

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:
Expand All @@ -133,7 +146,7 @@ async def sync_serialize(self):
'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
Expand Down
2 changes: 1 addition & 1 deletion tests/components/google_assistant/__init__.py
Expand Up @@ -116,7 +116,7 @@
},
'traits': ['action.devices.traits.OpenClose'],
'type':
'action.devices.types.BLINDS',
'action.devices.types.GARAGE',
balloob marked this conversation as resolved.
Show resolved Hide resolved
'willReportState': False
}, {
'id': 'cover.kitchen_window',
Expand Down