mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
merge
This commit is contained in:
parent
72efcf0e94
commit
87a00eb80f
@ -1,5 +1,6 @@
|
|||||||
"""Tests for the Lutron Caseta integration."""
|
"""Tests for the Lutron Caseta integration."""
|
||||||
|
|
||||||
|
from collections import defaultdict
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant.components.lutron_caseta import DOMAIN
|
from homeassistant.components.lutron_caseta import DOMAIN
|
||||||
@ -84,7 +85,9 @@ _LEAP_DEVICE_TYPES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_integration(hass: HomeAssistant, mock_bridge) -> MockConfigEntry:
|
async def async_setup_integration(
|
||||||
|
hass: HomeAssistant, mock_bridge
|
||||||
|
) -> tuple[MockConfigEntry, "MockBridge"]:
|
||||||
"""Set up a mock bridge."""
|
"""Set up a mock bridge."""
|
||||||
mock_entry = MockConfigEntry(domain=DOMAIN, data=ENTRY_MOCK_DATA)
|
mock_entry = MockConfigEntry(domain=DOMAIN, data=ENTRY_MOCK_DATA)
|
||||||
mock_entry.add_to_hass(hass)
|
mock_entry.add_to_hass(hass)
|
||||||
@ -92,10 +95,12 @@ async def async_setup_integration(hass: HomeAssistant, mock_bridge) -> MockConfi
|
|||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.lutron_caseta.Smartbridge.create_tls"
|
"homeassistant.components.lutron_caseta.Smartbridge.create_tls"
|
||||||
) as create_tls:
|
) as create_tls:
|
||||||
create_tls.return_value = mock_bridge(can_connect=True)
|
mocked_bridge = mock_bridge(can_connect=True)
|
||||||
|
create_tls.return_value = mocked_bridge
|
||||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
return mock_entry
|
|
||||||
|
return mock_entry, mocked_bridge
|
||||||
|
|
||||||
|
|
||||||
class MockBridge:
|
class MockBridge:
|
||||||
@ -110,6 +115,7 @@ class MockBridge:
|
|||||||
self.scenes = self.get_scenes()
|
self.scenes = self.get_scenes()
|
||||||
self.devices = self.load_devices()
|
self.devices = self.load_devices()
|
||||||
self.buttons = self.load_buttons()
|
self.buttons = self.load_buttons()
|
||||||
|
self.button_subscribers: defaultdict[str, list] = defaultdict(list)
|
||||||
|
|
||||||
async def connect(self):
|
async def connect(self):
|
||||||
"""Connect the mock bridge."""
|
"""Connect the mock bridge."""
|
||||||
@ -121,6 +127,7 @@ class MockBridge:
|
|||||||
|
|
||||||
def add_button_subscriber(self, button_id: str, callback_):
|
def add_button_subscriber(self, button_id: str, callback_):
|
||||||
"""Mock a listener for button presses."""
|
"""Mock a listener for button presses."""
|
||||||
|
self.button_subscribers[button_id].append(callback_)
|
||||||
|
|
||||||
def is_connected(self):
|
def is_connected(self):
|
||||||
"""Return whether the mock bridge is connected."""
|
"""Return whether the mock bridge is connected."""
|
||||||
|
@ -157,6 +157,7 @@ async def test_get_triggers(hass: HomeAssistant) -> None:
|
|||||||
triggers = await async_get_device_automations(
|
triggers = await async_get_device_automations(
|
||||||
hass, DeviceAutomationType.TRIGGER, device_id
|
hass, DeviceAutomationType.TRIGGER, device_id
|
||||||
)
|
)
|
||||||
|
triggers = [trigger for trigger in triggers if trigger[CONF_DOMAIN] == DOMAIN]
|
||||||
|
|
||||||
assert triggers == unordered(expected_triggers)
|
assert triggers == unordered(expected_triggers)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user