-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(z2m_integration): add
listen_to
attribute to choose between HA…
… state and MQTT related to #109
- Loading branch information
Showing
5 changed files
with
101 additions
and
4 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from typing import Any | ||
import pytest | ||
|
||
from cx_core.integration.z2m import Z2MIntegration | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"data, action_key, handle_action_called, expected_called_with", | ||
[ | ||
({"payload": '{"event_1": "action_1"}'}, "event_1", True, "action_1"), | ||
({}, None, False, Any), | ||
({"payload": '{"action": "action_1"}'}, None, True, "action_1"), | ||
({"payload": '{"event_1": "action_1"}'}, "event_2", False, Any), | ||
], | ||
) | ||
@pytest.mark.asyncio | ||
async def test_event_callback( | ||
fake_controller, | ||
mocker, | ||
data, | ||
action_key, | ||
handle_action_called, | ||
expected_called_with, | ||
): | ||
handle_action_patch = mocker.patch.object(fake_controller, "handle_action") | ||
z2m_integration = Z2MIntegration(fake_controller, {}) | ||
z2m_integration.kwargs = ( | ||
{"action_key": action_key} if action_key is not None else {} | ||
) | ||
await z2m_integration.event_callback("test", data, {}) | ||
|
||
if handle_action_called: | ||
handle_action_patch.assert_called_once_with(expected_called_with) | ||
else: | ||
handle_action_patch.assert_not_called() |