From 17061f360f4d3870d70e714b67a018deb832cd23 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Mon, 29 Aug 2022 18:28:54 -0700 Subject: [PATCH] Add test_area test, reproduce issue of #75 --- tests/test_switch.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/test_switch.py b/tests/test_switch.py index 2038fe8d..1473a29e 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -59,11 +59,12 @@ from homeassistant.const import ( STATE_ON, ) from homeassistant.core import Context, State +from homeassistant.helpers import device_registry, entity_registry from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util import pytest -from tests.common import MockConfigEntry +from tests.common import MockConfigEntry, mock_device_registry, mock_registry from tests.components.demo.test_light import ENTITY_LIGHT _LOGGER = logging.getLogger(__name__) @@ -867,3 +868,32 @@ async def test_separate_turn_on_commands(hass, separate_turn_on_commands): assert sleep_brightness != brightness assert sleep_color_temp != color_temp + + +async def test_area(hass): + _, (light, *_) = await setup_lights_and_switch(hass) + device_in_area = device_registry.DeviceEntry(area_id="test-area") + + mock_device_registry(hass, {device_in_area.id: device_in_area}) + entity_in_area = entity_registry.RegistryEntry( + entity_id=light.entity_id, + unique_id="in-area-id", + platform="test", + device_id=device_in_area.id, + ) + mock_registry(hass, {entity_in_area.entity_id: entity_in_area}) + await hass.services.async_call( + LIGHT_DOMAIN, + SERVICE_TURN_ON, + {ATTR_ENTITY_ID: light.entity_id}, + blocking=True, + ) + await hass.async_block_till_done() + + await hass.services.async_call( + LIGHT_DOMAIN, + SERVICE_TURN_OFF, + {"area_id": "in-area-id"}, + blocking=True, + ) + await hass.async_block_till_done()