-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Updated Emulated_Hue to send request info as var 8000 iables to scripts #4010
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
Updated Emulated_Hue to send request info as variables to scripts #4010
Conversation
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.
https://github.com/home-assistant/home-assistant/blob/dev/tests/components/test_emulated_hue.py will need to be updated.
I'm not sure the existing tests are working. From my branch and from a clean dev branch I get ` tests/components/test_emulated_hue.py::TestEmulatedHue::test_create_username It never moves past this test. |
@bah2830 they are, https://travis-ci.org/home-assistant/home-assistant/jobs/169963949#L386 - have you run |
It looks like it's expecting an endpoint and mqtt broker on 127.0.0.1 which is not the case for my setup. I will see what it takes to get this working in a non all-in-one setup. |
@bah2830 Ah yes, there were talks of mocking the broker. You may want to consult the folks on Gitter if you get stuck/need some guidance. |
The emulated_hue tests have been cleaned up in #4068. Please rebase and fix tests accordingly. |
Sorry for the delay, had another thing that required my attention. |
@@ -233,6 +263,40 @@ def test_put_light_state(self): | |||
'light.kitchen_light', True) | |||
self.assertEqual(kitchen_result.status_code, 404) | |||
|
|||
def test_put_light_state_script(self): |
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.
You're not testing any of the variables that are being passed in.
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.
I was actually going to ask how I can check variables from here. Since it makes an async call and I don't get anything back about what the script did or was.
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.
Actually I figured it out. Now I just have an odd issue of waiting for script to complete before validating it.
I'm open to any suggestions on how to get around the sleep(.01)
) | ||
|
||
script_result_json = script_result.json() | ||
print(script_result_json) |
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.
Stale print.
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.
whoops. Removing
self.assertEqual(len(script_result_json), 2) | ||
|
||
# Sleep for short time so script has time to complete | ||
time.sleep(.01) |
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.
Use this instead:
self.hass.block_till_done()
Are there any examples of how to use this with scripts? I didn't see anything on https://home-assistant.io/components/emulated_hue/ |
Yeah I am interested in some examples as well! |
See https://home-assistant.io/components/script/#passing-variables-to-scripts . requested_state and requested_level are available to be used within data_template. I agree that we should update the docs to give an example. Anyone wants to open a PR? |
The Problem
When using emulated_hue there are some requests in the command that we already know. However those are not exposed to any scripts that could of been called.
My Solution
I have updated it to get the requested state (on|off) and the requested level(0-100) and pass them into scripts as variables. This allows a single script to be used for turn on and turn off as well as passing in a value 0-100.
The original behavior for treating off as on for scripts is still in place and the service called is not changed. Only difference is if the entity is a script then it will add the actual requested command to the script as variables.
Alexa commands parsed