8000 Updated Emulated_Hue to send request info as variables to scripts by brentahughes · Pull Request #4010 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 5 commits into from
Nov 6, 2016
Merged

Updated Emulated_Hue to send request info as variables to scripts #4010

merged 5 commits into from
Nov 6, 2016

Conversation

brentahughes
Copy link

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

  1. Alexa, turn {requested_state} {entity_name} at {requested_level}%
  2. Alexa, set {entity_name} to {requested_level}%
  • Using this will send the "on" requested_state by default

@mention-bot
Copy link

@bah2830, thanks for your PR! By analyzing the history of the files in this pull request, we identified @fabaff, @lwis and @mweinelt to be potential reviewers.

Copy link
Member
@lwis lwis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brentahughes
Copy link
Author

I'm not sure the existing tests are working. From my branch and from a clean dev branch I get

`
root@87bf67bb95f3:/app# py.test -v --timeout=30 --duration=10 tests/components/test_emulated_hue.py
==================================================================== test session starts ====================================================================
platform linux -- Python 3.5.2, pytest-3.0.3, py-1.4.31, pluggy-0.4.0 -- /usr/local/bin/python3.5
cachedir: .cache
rootdir: /app, inifile: setup.cfg
plugins: asyncio-0.5.0, catchlog-1.2.2, cov-2.4.0, timeout-1.0.0
collected 10 items

tests/components/test_emulated_hue.py::TestEmulatedHue::test_create_username
`

It never moves past this test.

@lwis
Copy link
Member
lwis commented Oct 23, 2016

@bah2830 they are, https://travis-ci.org/home-assistant/home-assistant/jobs/169963949#L386 - have you run script/setup, do they run using tox?

@brentahughes
Copy link
Author

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.

@lwis
Copy link
Member
lwis commented Oct 23, 2016

@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.

@balloob
Copy link
Member
balloob commented Oct 28, 2016

The emulated_hue tests have been cleaned up in #4068. Please rebase and fix tests accordingly.

@balloob balloob self-assigned this Oct 28, 2016
@brentahughes
Copy link
Author

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):
Copy link
Member

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.

Copy link
Author
@brentahughes brentahughes Nov 3, 2016

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.

10000

Copy link
Author

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale print.

Copy link
Author

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)
Copy link
Member

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()

@balloob balloob merged commit 1ad14b8 into home-assistant:dev Nov 6, 2016
@technicalpickles
Copy link
Contributor

Are there any examples of how to use this with scripts? I didn't see anything on https://home-assistant.io/components/emulated_hue/

@noahbeach
Copy link

Yeah I am interested in some examples as well!

@balloob
Copy link
Member
balloob commented Dec 11, 2016

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?

@home-assistant home-assistant locked and limited conversation to collaborators Mar 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
0