mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Multiple Hue activate scene (#41353)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
"""Test Hue bridge."""
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import hue
|
||||
from homeassistant.components.hue import bridge, errors
|
||||
from homeassistant.components.hue.const import (
|
||||
CONF_ALLOW_HUE_GROUPS,
|
||||
@@ -88,7 +90,7 @@ async def test_reset_unloads_entry_if_setup(hass):
|
||||
), patch.object(hass.config_entries, "async_forward_entry_setup") as mock_forward:
|
||||
assert await hue_bridge.async_setup() is True
|
||||
|
||||
assert len(hass.services.async_services()) == 1
|
||||
assert len(hass.services.async_services()) == 0
|
||||
assert len(mock_forward.mock_calls) == 3
|
||||
|
||||
with patch.object(
|
||||
@@ -120,3 +122,131 @@ async def test_handle_unauthorized(hass):
|
||||
assert hue_bridge.authorized is False
|
||||
assert len(mock_create.mock_calls) == 1
|
||||
assert mock_create.mock_calls[0][1][1] == "1.2.3.4"
|
||||
|
||||
|
||||
GROUP_RESPONSE = {
|
||||
"group_1": {
|
||||
"name": "Group 1",
|
||||
"lights": ["1", "2"],
|
||||
"type": "LightGroup",
|
||||
"action": {
|
||||
"on": True,
|
||||
"bri": 254,
|
||||
"hue": 10000,
|
||||
"sat": 254,
|
||||
"effect": "none",
|
||||
"xy": [0.5, 0.5],
|
||||
"ct": 250,
|
||||
"alert": "select",
|
||||
"colormode": "ct",
|
||||
},
|
||||
"state": {"any_on": True, "all_on": False},
|
||||
}
|
||||
}
|
||||
SCENE_RESPONSE = {
|
||||
"scene_1": {
|
||||
"name": "Cozy dinner",
|
||||
"lights": ["1", "2"],
|
||||
"owner": "ffffffffe0341b1b376a2389376a2389",
|
||||
"recycle": True,
|
||||
"locked": False,
|
||||
"appdata": {"version": 1, "data": "myAppData"},
|
||||
"picture": "",
|
||||
"lastupdated": "2015-12-03T10:09:22",
|
||||
"version": 2,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async def test_hue_activate_scene(hass, mock_api):
|
||||
"""Test successful hue_activate_scene."""
|
||||
config_entry = config_entries.ConfigEntry(
|
||||
1,
|
||||
hue.DOMAIN,
|
||||
"Mock Title",
|
||||
{"host": "mock-host", "username": "mock-username"},
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_POLL,
|
||||
system_options={},
|
||||
options={CONF_ALLOW_HUE_GROUPS: True, CONF_ALLOW_UNREACHABLE: False},
|
||||
)
|
||||
hue_bridge = bridge.HueBridge(hass, config_entry)
|
||||
|
||||
mock_api.mock_group_responses.append(GROUP_RESPONSE)
|
||||
mock_api.mock_scene_responses.append(SCENE_RESPONSE)
|
||||
|
||||
with patch("aiohue.Bridge", return_value=mock_api), patch.object(
|
||||
hass.config_entries, "async_forward_entry_setup"
|
||||
):
|
||||
assert await hue_bridge.async_setup() is True
|
||||
|
||||
assert hue_bridge.api is mock_api
|
||||
|
||||
call = Mock()
|
||||
call.data = {"group_name": "Group 1", "scene_name": "Cozy dinner"}
|
||||
with patch("aiohue.Bridge", return_value=mock_api):
|
||||
assert await hue_bridge.hue_activate_scene(call) is None
|
||||
|
||||
assert len(mock_api.mock_requests) == 3
|
||||
assert mock_api.mock_requests[2]["json"]["scene"] == "scene_1"
|
||||
assert mock_api.mock_requests[2]["path"] == "groups/group_1/action"
|
||||
|
||||
|
||||
async def test_hue_activate_scene_group_not_found(hass, mock_api):
|
||||
"""Test failed hue_activate_scene due to missing group."""
|
||||
config_entry = config_entries.ConfigEntry(
|
||||
1,
|
||||
hue.DOMAIN,
|
||||
"Mock Title",
|
||||
{"host": "mock-host", "username": "mock-username"},
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_POLL,
|
||||
system_options={},
|
||||
options={CONF_ALLOW_HUE_GROUPS: True, CONF_ALLOW_UNREACHABLE: False},
|
||||
)
|
||||
hue_bridge = bridge.HueBridge(hass, config_entry)
|
||||
|
||||
mock_api.mock_group_responses.append({})
|
||||
mock_api.mock_scene_responses.append(SCENE_RESPONSE)
|
||||
|
||||
with patch("aiohue.Bridge", return_value=mock_api), patch.object(
|
||||
hass.config_entries, "async_forward_entry_setup"
|
||||
):
|
||||
assert await hue_bridge.async_setup() is True
|
||||
|
||||
assert hue_bridge.api is mock_api
|
||||
|
||||
call = Mock()
|
||||
call.data = {"group_name": "Group 1", "scene_name": "Cozy dinner"}
|
||||
with patch("aiohue.Bridge", return_value=mock_api):
|
||||
assert await hue_bridge.hue_activate_scene(call) is False
|
||||
|
||||
|
||||
async def test_hue_activate_scene_scene_not_found(hass, mock_api):
|
||||
"""Test failed hue_activate_scene due to missing scene."""
|
||||
config_entry = config_entries.ConfigEntry(
|
||||
1,
|
||||
hue.DOMAIN,
|
||||
"Mock Title",
|
||||
{"host": "mock-host", "username": "mock-username"},
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_POLL,
|
||||
system_options={},
|
||||
options={CONF_ALLOW_HUE_GROUPS: True, CONF_ALLOW_UNREACHABLE: False},
|
||||
)
|
||||
hue_bridge = bridge.HueBridge(hass, config_entry)
|
||||
|
||||
mock_api.mock_group_responses.append(GROUP_RESPONSE)
|
||||
mock_api.mock_scene_responses.append({})
|
||||
|
||||
with patch("aiohue.Bridge", return_value=mock_api), patch.object(
|
||||
hass.config_entries, "async_forward_entry_setup"
|
||||
):
|
||||
assert await hue_bridge.async_setup() is True
|
||||
|
||||
assert hue_bridge.api is mock_api
|
||||
|
||||
call = Mock()
|
||||
call.data = {"group_name": "Group 1", "scene_name": "Cozy dinner"}
|
||||
with patch("aiohue.Bridge", return_value=mock_api):
|
||||
assert await hue_bridge.hue_activate_scene(call) is False
|
||||
|
||||
Reference in New Issue
Block a user