mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Fix error with Axis light events without representation in light control (#45277)
This commit is contained in:
parent
cf9ea6f82d
commit
8e0addd216
@ -18,7 +18,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
"""Set up a Axis light."""
|
"""Set up a Axis light."""
|
||||||
device = hass.data[AXIS_DOMAIN][config_entry.unique_id]
|
device = hass.data[AXIS_DOMAIN][config_entry.unique_id]
|
||||||
|
|
||||||
if not device.api.vapix.light_control:
|
if (
|
||||||
|
device.api.vapix.light_control is None
|
||||||
|
or len(device.api.vapix.light_control) == 0
|
||||||
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -14,7 +14,12 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .test_device import API_DISCOVERY_RESPONSE, NAME, setup_axis_integration
|
from .test_device import (
|
||||||
|
API_DISCOVERY_RESPONSE,
|
||||||
|
LIGHT_CONTROL_RESPONSE,
|
||||||
|
NAME,
|
||||||
|
setup_axis_integration,
|
||||||
|
)
|
||||||
|
|
||||||
API_DISCOVERY_LIGHT_CONTROL = {
|
API_DISCOVERY_LIGHT_CONTROL = {
|
||||||
"id": "light-control",
|
"id": "light-control",
|
||||||
@ -57,6 +62,26 @@ async def test_no_lights(hass):
|
|||||||
assert not hass.states.async_entity_ids(LIGHT_DOMAIN)
|
assert not hass.states.async_entity_ids(LIGHT_DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_no_light_entity_without_light_control_representation(hass):
|
||||||
|
"""Verify no lights entities get created without light control representation."""
|
||||||
|
api_discovery = deepcopy(API_DISCOVERY_RESPONSE)
|
||||||
|
api_discovery["data"]["apiList"].append(API_DISCOVERY_LIGHT_CONTROL)
|
||||||
|
|
||||||
|
light_control = deepcopy(LIGHT_CONTROL_RESPONSE)
|
||||||
|
light_control["data"]["items"] = []
|
||||||
|
|
||||||
|
with patch.dict(API_DISCOVERY_RESPONSE, api_discovery), patch.dict(
|
||||||
|
LIGHT_CONTROL_RESPONSE, light_control
|
||||||
|
):
|
||||||
|
config_entry = await setup_axis_integration(hass)
|
||||||
|
device = hass.data[AXIS_DOMAIN][config_entry.unique_id]
|
||||||
|
|
||||||
|
device.api.event.update([EVENT_ON])
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert not hass.states.async_entity_ids(LIGHT_DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
async def test_lights(hass):
|
async def test_lights(hass):
|
||||||
"""Test that lights are loaded properly."""
|
"""Test that lights are loaded properly."""
|
||||||
api_discovery = deepcopy(API_DISCOVERY_RESPONSE)
|
api_discovery = deepcopy(API_DISCOVERY_RESPONSE)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user