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 support for vacuum cleaner and traits #15575
Closed
Closed
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7208a02
Add support for vacuum cleaner and traits
cnrd 8990b4a
Updated to latest vacuum code
cnrd d50bb05
Return if vacuum is pausable, use new start and pause service calls
cnrd 9184b64
Review comments @balloob
sliepie 8fc2ffb
Merge pull request #1 from JarnoNijboer/google_assistant_vacuum
cnrd File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,12 @@ | |
scene, | ||
script, | ||
switch, | ||
vacuum, | ||
) | ||
from homeassistant.const import ( | ||
ATTR_ENTITY_ID, | ||
ATTR_UNIT_OF_MEASUREMENT, | ||
ATTR_SUPPORTED_FEATURES, | ||
SERVICE_TURN_OFF, | ||
SERVICE_TURN_ON, | ||
STATE_OFF, | ||
|
@@ -33,6 +35,8 @@ | |
TRAIT_COLOR_TEMP = PREFIX_TRAITS + 'ColorTemperature' | ||
TRAIT_SCENE = PREFIX_TRAITS + 'Scene' | ||
TRAIT_TEMPERATURE_SETTING = PREFIX_TRAITS + 'TemperatureSetting' | ||
TRAIT_STARTSTOP = PREFIX_TRAITS + 'StartStop' | ||
TRAIT_DOCK = PREFIX_TRAITS + 'Dock' | ||
|
||
PREFIX_COMMANDS = 'action.devices.commands.' | ||
COMMAND_ONOFF = PREFIX_COMMANDS + 'OnOff' | ||
|
@@ -44,7 +48,9 @@ | |
COMMAND_THERMOSTAT_TEMPERATURE_SET_RANGE = ( | ||
PREFIX_COMMANDS + 'ThermostatTemperatureSetRange') | ||
COMMAND_THERMOSTAT_SET_MODE = PREFIX_COMMANDS + 'ThermostatSetMode' | ||
|
||
COMMAND_STARTSTOP = PREFIX_COMMANDS + 'StartStop' | ||
COMMAND_PAUSEUNPAUSE = PREFIX_COMMANDS + 'PauseUnpause' | ||
COMMAND_DOCK = PREFIX_COMMANDS + 'Dock' | ||
|
||
TRAITS = [] | ||
|
||
|
@@ -520,3 +526,128 @@ async def execute(self, hass, command, params): | |
climate.ATTR_OPERATION_MODE: | ||
self.google_to_hass[params['thermostatMode']], | ||
}, blocking=True) | ||
|
||
|
||
@register_trait | ||
class StartStopTrait(_Trait): | ||
"""Trait to offer start, stop, and pause functionality. | ||
|
||
https://developers.google.com/actions/smarthome/traits/startstop | ||
""" | ||
|
||
name = TRAIT_STARTSTOP | ||
commands = [ | ||
COMMAND_STARTSTOP, | ||
COMMAND_PAUSEUNPAUSE | ||
] | ||
|
||
@staticmethod | ||
def supported(domain, features): | ||
"""Test if state is supported.""" | ||
if domain == vacuum.DOMAIN: | ||
return features & vacuum.SUPPORT_STATE | ||
|
||
return False | ||
|
||
def sync_attributes(self): | ||
"""Return if vacuum is pausable.""" | ||
return {'pausable': (self.state.attributes.get(ATTR_SUPPORTED_FEATURES) | ||
& vacuum.SUPPORT_PAUSE) != 0} | ||
|
||
def query_attributes(self): | ||
"""Return the running/paused state.""" | ||
domain = self.state.domain | ||
response = {} | ||
|
||
if domain == vacuum.DOMAIN: | ||
|
||
state = self.state.state | ||
|
||
if state == vacuum.STATE_PAUSED: | ||
response['isPaused'] = True | ||
response['isRunning'] = False | ||
elif state == vacuum.STATE_CLEANING: | ||
response['isPaused'] = False | ||
response['isRunning'] = True | ||
else: | ||
response['isPaused'] = False | ||
response['isRunning'] = False | ||
|
||
return response | ||
|
||
async def execute(self, hass, command, params): | ||
"""Execute a start, stop, pause, or unpause command.""" | ||
domain = self.state.domain | ||
param_start = 'start' | ||
param_pause = 'pause' | ||
start_stop_command = 'action.devices.commands.StartStop' | ||
pause_unpause_command = 'action.devices.commands.PauseUnpause' | ||
|
||
if domain == vacuum.DOMAIN: | ||
service_domain = domain | ||
state = self.state.state | ||
|
||
if command == start_stop_command: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if params[param_start]: | ||
service = vacuum.SERVICE_START | ||
else: | ||
service = vacuum.SERVICE_STOP | ||
|
||
if command == pause_unpause_command: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if params[param_pause]: | ||
if state == vacuum.STATE_CLEANING: | ||
service = vacuum.SERVICE_PAUSE | ||
else: | ||
if state == vacuum.STATE_PAUSED: | ||
service = vacuum.SERVICE_START | ||
|
||
await hass.services.async_call(service_domain, service, { | ||
ATTR_ENTITY_ID: self.state.entity_id | ||
}, blocking=True) | ||
|
||
|
||
@register_trait | ||
class DockTrait(_Trait): | ||
"""Trait to offer docking. | ||
|
||
https://developers.google.com/actions/smarthome/traits/dock | ||
""" | ||
|
||
name = TRAIT_DOCK | ||
commands = {COMMAND_DOCK} | ||
|
||
@staticmethod | ||
def supported(domain, features): | ||
"""Test if state is supported.""" | ||
if domain == vacuum.DOMAIN: | ||
return features & vacuum.SUPPORT_STATE | ||
|
||
return False | ||
|
||
def sync_attributes(self): | ||
"""No attributes required.""" | ||
return {} | ||
|
||
def query_attributes(self): | ||
"""Return if docked.""" | ||
domain = self.state.domain | ||
response = {} | ||
|
||
if domain == vacuum.DOMAIN: | ||
state = self.state.state | ||
|
||
response['isDocked'] = bool(state == vacuum.STATE_DOCKED) | ||
|
||
return response | ||
|
||
async def execute(self, hass, command, params): | ||
"""Execute a return to dock command.""" | ||
domain = self.state.domain | ||
|
||
if domain == vacuum.DOMAIN: | ||
service_domain = domain | ||
service = vacuum.SERVICE_RETURN_TO_BASE | ||
|
||
await hass.services.async_call(service_domain, service, { | ||
ATTR_ENTITY_ID: self.state.entity_id | ||
}, blocking=True) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return features & vacuum.SUPPORT_STATE
Probably a good idea to check for SUPPORT_STATE here. That will exclude any platforms that haven't been ported yet