Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions homeassistant/components/shelly/device_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ async def async_get_triggers(
append_input_triggers(triggers, input_triggers, device_id)
return triggers

if not block_wrapper.device.initialized:
return triggers

assert block_wrapper.device.blocks

for block in block_wrapper.device.blocks:
Expand Down
36 changes: 36 additions & 0 deletions tests/components/shelly/test_device_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,42 @@ async def test_get_triggers_button(hass):
assert_lists_same(triggers, expected_triggers)


async def test_get_triggers_non_initialized_devices(hass):
"""Test we get the empty triggers for non-initialized devices."""
await async_setup_component(hass, "shelly", {})

config_entry = MockConfigEntry(
domain=DOMAIN,
data={"sleep_period": 43200, "model": "SHDW-2", "host": "1.2.3.4"},
unique_id="12345678",
)
config_entry.add_to_hass(hass)

device = Mock(
blocks=None,
settings=None,
shelly=None,
update=AsyncMock(),
initialized=False,
)

hass.data[DOMAIN] = {DATA_CONFIG_ENTRY: {}}
hass.data[DOMAIN][DATA_CONFIG_ENTRY][config_entry.entry_id] = {}
coap_wrapper = hass.data[DOMAIN][DATA_CONFIG_ENTRY][config_entry.entry_id][
BLOCK
] = BlockDeviceWrapper(hass, config_entry, device)

coap_wrapper.async_setup()

expected_triggers = []

triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, coap_wrapper.device_id
)

assert_lists_same(triggers, expected_triggers)


async def test_get_triggers_for_invalid_device_id(hass, device_reg, coap_wrapper):
"""Test error raised for invalid shelly device_id."""
assert coap_wrapper
Expand Down