-
Notifications
You must be signed in to change notification settings - Fork 55
Add support for service blocking #85
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
craigbarratt
merged 5 commits into
custom-components:master
from
raman325:service_blocking
Nov 6, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
028656f
add support for service blocking
raman325 936ac3b
fix type check for kwargs and add function tests
raman325 44c1129
add tests for changes to state module
raman325 5c79bf7
add reaper_stop to test_service_call_params so that tests don't break
raman325 1dfab0f
add new feature entry
raman325 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Test pyscripts test module.""" | ||
from custom_components.pyscript.state import State | ||
from pytest_homeassistant_custom_component.async_mock import patch | ||
|
||
from homeassistant.core import Context | ||
from homeassistant.helpers.state import State as HassState | ||
|
||
|
||
async def test_service_call(hass): | ||
"""Test calling a service using the entity_id as a property.""" | ||
with patch( | ||
"custom_components.pyscript.state.async_get_all_descriptions", | ||
return_value={ | ||
"test": { | ||
"test": {"description": None, "fields": {"entity_id": "blah", "other_service_data": "blah"}} | ||
} | ||
}, | ||
), patch.object(hass.states, "get", return_value=HassState("test.entity", "True")), patch.object( | ||
hass.services, "async_call" | ||
) as call: | ||
State.init(hass) | ||
await State.get_service_params() | ||
|
||
func = await State.get("test.entity.test") | ||
await func(context=Context(id="test"), blocking=True, limit=1, other_service_data="test") | ||
assert call.called | ||
assert call.call_args[0] == ( | ||
"test", | ||
"test", | ||
{"other_service_data": "test", "entity_id": "test.entity"}, | ||
) | ||
assert call.call_args[1] == {"context": Context(id="test"), "blocking": True, "limit": 1} | ||
call.reset_mock() | ||
|
||
func = await State.get("test.entity.test") | ||
await func(context=Context(id="test"), blocking=False, other_service_data="test") | ||
assert call.called | ||
assert call.call_args[0] == ( | ||
"test", | ||
"test", | ||
{"other_service_data": "test", "entity_id": "test.entity"}, | ||
) | ||
assert call.call_args[1] == {"context": Context(id="test"), "blocking": False} |
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.
Uh oh!
There was an error while loading. Please reload this page.