mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Add slots to the service registry (#95857)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
"""The tests for the Group Light platform."""
|
||||
import unittest.mock
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import async_timeout
|
||||
@@ -16,7 +15,6 @@ from homeassistant.components.light import (
|
||||
ATTR_COLOR_TEMP_KELVIN,
|
||||
ATTR_EFFECT,
|
||||
ATTR_EFFECT_LIST,
|
||||
ATTR_FLASH,
|
||||
ATTR_HS_COLOR,
|
||||
ATTR_MAX_COLOR_TEMP_KELVIN,
|
||||
ATTR_MIN_COLOR_TEMP_KELVIN,
|
||||
@@ -26,7 +24,6 @@ from homeassistant.components.light import (
|
||||
ATTR_SUPPORTED_COLOR_MODES,
|
||||
ATTR_TRANSITION,
|
||||
ATTR_WHITE,
|
||||
ATTR_XY_COLOR,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
SERVICE_TOGGLE,
|
||||
SERVICE_TURN_OFF,
|
||||
@@ -39,16 +36,17 @@ from homeassistant.components.light import (
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
EVENT_CALL_SERVICE,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core import Event, HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import get_fixture_path
|
||||
from tests.common import async_capture_events, get_fixture_path
|
||||
|
||||
|
||||
async def test_default_state(hass: HomeAssistant) -> None:
|
||||
@@ -1443,6 +1441,7 @@ async def test_invalid_service_calls(hass: HomeAssistant) -> None:
|
||||
await group.async_setup_platform(
|
||||
hass, {"name": "test", "entities": ["light.test1", "light.test2"]}, add_entities
|
||||
)
|
||||
await async_setup_component(hass, "light", {})
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
await hass.async_block_till_done()
|
||||
@@ -1451,35 +1450,38 @@ async def test_invalid_service_calls(hass: HomeAssistant) -> None:
|
||||
grouped_light = add_entities.call_args[0][0][0]
|
||||
grouped_light.hass = hass
|
||||
|
||||
with unittest.mock.patch.object(hass.services, "async_call") as mock_call:
|
||||
await grouped_light.async_turn_on(brightness=150, four_oh_four="404")
|
||||
data = {ATTR_ENTITY_ID: ["light.test1", "light.test2"], ATTR_BRIGHTNESS: 150}
|
||||
mock_call.assert_called_once_with(
|
||||
LIGHT_DOMAIN, SERVICE_TURN_ON, data, blocking=True, context=None
|
||||
)
|
||||
mock_call.reset_mock()
|
||||
service_call_events = async_capture_events(hass, EVENT_CALL_SERVICE)
|
||||
|
||||
await grouped_light.async_turn_off(transition=4, four_oh_four="404")
|
||||
data = {ATTR_ENTITY_ID: ["light.test1", "light.test2"], ATTR_TRANSITION: 4}
|
||||
mock_call.assert_called_once_with(
|
||||
LIGHT_DOMAIN, SERVICE_TURN_OFF, data, blocking=True, context=None
|
||||
)
|
||||
mock_call.reset_mock()
|
||||
await grouped_light.async_turn_on(brightness=150, four_oh_four="404")
|
||||
data = {ATTR_ENTITY_ID: ["light.test1", "light.test2"], ATTR_BRIGHTNESS: 150}
|
||||
assert len(service_call_events) == 1
|
||||
service_event_call: Event = service_call_events[0]
|
||||
assert service_event_call.data["domain"] == LIGHT_DOMAIN
|
||||
assert service_event_call.data["service"] == SERVICE_TURN_ON
|
||||
assert service_event_call.data["service_data"] == data
|
||||
service_call_events.clear()
|
||||
|
||||
data = {
|
||||
ATTR_BRIGHTNESS: 150,
|
||||
ATTR_XY_COLOR: (0.5, 0.42),
|
||||
ATTR_RGB_COLOR: (80, 120, 50),
|
||||
ATTR_COLOR_TEMP_KELVIN: 1234,
|
||||
ATTR_EFFECT: "Sunshine",
|
||||
ATTR_TRANSITION: 4,
|
||||
ATTR_FLASH: "long",
|
||||
}
|
||||
await grouped_light.async_turn_on(**data)
|
||||
data[ATTR_ENTITY_ID] = ["light.test1", "light.test2"]
|
||||
mock_call.assert_called_once_with(
|
||||
LIGHT_DOMAIN, SERVICE_TURN_ON, data, blocking=True, context=None
|
||||
)
|
||||
await grouped_light.async_turn_off(transition=4, four_oh_four="404")
|
||||
data = {ATTR_ENTITY_ID: ["light.test1", "light.test2"], ATTR_TRANSITION: 4}
|
||||
assert len(service_call_events) == 1
|
||||
service_event_call: Event = service_call_events[0]
|
||||
assert service_event_call.data["domain"] == LIGHT_DOMAIN
|
||||
assert service_event_call.data["service"] == SERVICE_TURN_OFF
|
||||
assert service_event_call.data["service_data"] == data
|
||||
service_call_events.clear()
|
||||
|
||||
data = {
|
||||
ATTR_BRIGHTNESS: 150,
|
||||
ATTR_COLOR_TEMP_KELVIN: 1234,
|
||||
ATTR_TRANSITION: 4,
|
||||
}
|
||||
await grouped_light.async_turn_on(**data)
|
||||
data[ATTR_ENTITY_ID] = ["light.test1", "light.test2"]
|
||||
service_event_call: Event = service_call_events[0]
|
||||
assert service_event_call.data["domain"] == LIGHT_DOMAIN
|
||||
assert service_event_call.data["service"] == SERVICE_TURN_ON
|
||||
assert service_event_call.data["service_data"] == data
|
||||
service_call_events.clear()
|
||||
|
||||
|
||||
async def test_reload(hass: HomeAssistant) -> None:
|
||||
|
||||
Reference in New Issue
Block a user