Conversation
| assert result | ||
| await hass.async_block_till_done() | ||
|
|
||
| assert len(events) == 1 |
| for site_id in config[DOMAIN].get(CONF_SITE_IDS): | ||
| payload = json.dumps({'siteId': site_id}) | ||
| hass.components.mqtt.async_publish( | ||
| FEEDBACK_ON_TOPIC, None, qos=0, retain=False) |
There was a problem hiding this comment.
What are you doing here? Is this to clear the retained message?
| site_ids = ([call.data.get(ATTR_SITE_ID)] | ||
| if call.data.get(ATTR_SITE_ID) | ||
| else config[DOMAIN].get(CONF_SITE_IDS)) | ||
| for site_id in site_ids: |
There was a problem hiding this comment.
Extract this into helper methods please.
| hass.components.mqtt.async_publish( | ||
| FEEDBACK_ON_TOPIC, payload, qos=1, retain=True) | ||
| else: | ||
| for site_id in config[DOMAIN].get(CONF_SITE_IDS): |
| CONFIG_SCHEMA = vol.Schema({ | ||
| DOMAIN: {} | ||
| DOMAIN: vol.Schema({ | ||
| vol.Optional(CONF_FEEDBACK, default=False): cv.boolean, |
There was a problem hiding this comment.
Shouldn't this be configurable per site id?
There was a problem hiding this comment.
Figured that was enough of an edge case it wasn't worth complicating the config for. They can turn on or off a site via the service but I can't imagine there are many cases where anyone wants to do that.
There was a problem hiding this comment.
Would it make sense to limit this functionality to just the service? You don't need to change it all the time?
There was a problem hiding this comment.
I don't think so, it's pretty minor to add it and I think a lot of users will like to set it here, especially considering snips doesn't have the option yet.
There was a problem hiding this comment.
Especially for something like hassio where you reboot and it's nice to have it back on if you want it.
| for site_id in site_ids: | ||
| payload = json.dumps({'siteId': site_id}) | ||
| hass.components.mqtt.async_publish( | ||
| FEEDBACK_ON_TOPIC, None, qos=0, retain=False) |
There was a problem hiding this comment.
Shouldn't you clear the retained message on the off topic if setting the on topic?
There was a problem hiding this comment.
Off isn't set to be retained since that is the default if snips restarts Edit: Doh, I see what you mean I didn't have it set before, fixed.
| """Activate Snips component.""" | ||
| @asyncio.coroutine | ||
| def message_received(topic, payload, qos): | ||
| def set_feedback(site_ids, state): |
There was a problem hiding this comment.
Since this is called from inside async context, plase add @callback decorator and prefix name with async_
| hass.components.mqtt.async_publish( | ||
| topic, payload, qos=1, retain=True) | ||
|
|
||
| set_feedback(None, config[DOMAIN].get(CONF_FEEDBACK)) |
There was a problem hiding this comment.
I don't think this should have a default. If no value is given, we should not send any messages. That way it can be controlled by the outside.
There was a problem hiding this comment.
Yeah, was back and forth there and could see it either way but ok.
There was a problem hiding this comment.
OK, there has to be a better way to do this. I think it should be if nothing is configured we don't send anything, if false is configured we do. But this seems hacky but how to test for not set?
if not config[DOMAIN].get(CONF_FEEDBACK, 'no_conf') == 'no_conf':
async_set_feedback(None, config[DOMAIN].get(CONF_FEEDBACK))
| return | ||
|
|
||
| if (request['intent']['probability'] | ||
| < config[DOMAIN].get(CONF_PROBABILITY)): |
There was a problem hiding this comment.
default for probability is 0. So if none is configured, nothing will ever pass? Better to not have a probability default and just check if probability is None or intentProb < probability
There was a problem hiding this comment.
Probability (editL was: default) is checked for greater than, so 0 matches all. It's a lower limit not upper.
There was a problem hiding this comment.
The config option defaults to 0.
Snips probability is between 0 and 1.
If not configured, probability defaults to 0.
So you're checking here things like if 0.8 < 0. Which will always be false?
Also, if you know a key exists, prefer to use square brackets over get
There was a problem hiding this comment.
0.8 < 0 is false yes, so we accept the intent. If I set the default to 1 then we would by default not accept any intents.
| hass.components.mqtt.async_publish( | ||
| topic, payload, qos=int(state), retain=state) | ||
|
|
||
| if not config[DOMAIN].get(CONF_FEEDBACK, 'no_conf') == 'no_conf': |
There was a problem hiding this comment.
this is weird… instead try this
if CONF_FEEDBACK in config[DOMAIN]:
async_set_feedback(None, config[DOMAIN][CONF_FEEDBACK])| events = [] | ||
|
|
||
| @callback | ||
| def record_event(event): |
There was a problem hiding this comment.
We have a helper for this, it's called async_mock_service and can be imported from tests.common
* Added feedback sound configuration * Added feedback sound configuration * Cleaned up feedback off * Cleaned up whitespace * Moved feedback pus to helper funx * Async * Used async_mock_service for tests * Lint
Description:
Added configuration to enable feedback sounds.
Added probability threshold
Related issue (if applicable): fixes #N/A
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#5133
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices: