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
16 changes: 13 additions & 3 deletions tests/components/shelly/test_binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Tests for Shelly binary sensor platform."""

from copy import deepcopy
from unittest.mock import Mock, patch
from unittest.mock import AsyncMock, Mock, patch

from aioshelly.const import (
MODEL_BLU_GATEWAY_G3,
Expand Down Expand Up @@ -336,7 +336,12 @@ async def test_rpc_sleeping_binary_sensor(
entity_id = f"{BINARY_SENSOR_DOMAIN}.test_name_cloud"
monkeypatch.setattr(mock_rpc_device, "connected", False)
monkeypatch.setitem(mock_rpc_device.status["sys"], "wakeup_period", 1000)
with patch.object(mock_rpc_device, "initialize", side_effect=DeviceConnectionError):
with patch.object(
mock_rpc_device,
"initialize",
new_callable=AsyncMock,
side_effect=DeviceConnectionError,
):
config_entry = await init_integration(hass, 2, sleep_period=1000)

# Sensor should be created when device is online
Expand Down Expand Up @@ -378,7 +383,12 @@ async def test_rpc_sleeping_binary_sensor_with_channel_name(
entity_id = f"{BINARY_SENSOR_DOMAIN}.test_name_test_channel_name_smoke"
monkeypatch.setattr(mock_rpc_device, "connected", False)
monkeypatch.setitem(mock_rpc_device.status["sys"], "wakeup_period", 1000)
with patch.object(mock_rpc_device, "initialize", side_effect=DeviceConnectionError):
with patch.object(
mock_rpc_device,
"initialize",
new_callable=AsyncMock,
side_effect=DeviceConnectionError,
):
await init_integration(hass, 2, sleep_period=1000, model=MODEL_PLUS_SMOKE)

# Sensor should be created when device is online
Expand Down
9 changes: 7 additions & 2 deletions tests/components/shelly/test_button.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Tests for Shelly button platform."""

from copy import deepcopy
from unittest.mock import Mock, patch
from unittest.mock import AsyncMock, Mock, patch

from aioshelly.const import MODEL_BLU_GATEWAY_G3, MODEL_PLUS_SMOKE, MODEL_WALL_DISPLAY
from aioshelly.exceptions import DeviceConnectionError, InvalidAuthError, RpcCallError
Expand Down Expand Up @@ -494,7 +494,12 @@ async def test_rpc_smoke_mute_alarm_button(
monkeypatch.setitem(mock_rpc_device.status["sys"], "wakeup_period", 1000)
monkeypatch.setattr(mock_rpc_device, "config", {"smoke:0": {"id": 0, "name": None}})
monkeypatch.setattr(mock_rpc_device, "connected", False)
with patch.object(mock_rpc_device, "initialize", side_effect=DeviceConnectionError):
with patch.object(
mock_rpc_device,
"initialize",
new_callable=AsyncMock,
side_effect=DeviceConnectionError,
):
await init_integration(hass, 2, sleep_period=1000, model=MODEL_PLUS_SMOKE)

# Sensor should be created when device is online
Expand Down
46 changes: 32 additions & 14 deletions tests/components/shelly/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2758,8 +2758,14 @@ async def test_zeroconf_sleeping_device_not_triggers_refresh(
},
)
entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
with patch.object(
mock_rpc_device,
"initialize",
new_callable=AsyncMock,
side_effect=DeviceConnectionError,
):
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done(wait_background_tasks=True)

mock_rpc_device.mock_online()
await hass.async_block_till_done(wait_background_tasks=True)
Expand Down Expand Up @@ -2811,10 +2817,14 @@ async def test_zeroconf_sleeping_device_attempts_configure(
},
)
entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
mock_rpc_device.mock_disconnected()
await hass.async_block_till_done()
with patch.object(
mock_rpc_device,
"initialize",
new_callable=AsyncMock,
side_effect=DeviceConnectionError,
):
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done(wait_background_tasks=True)

mock_rpc_device.mock_online()
await hass.async_block_till_done(wait_background_tasks=True)
Expand Down Expand Up @@ -2877,10 +2887,14 @@ async def test_zeroconf_sleeping_device_attempts_configure_ws_disabled(
},
)
entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
mock_rpc_device.mock_disconnected()
await hass.async_block_till_done()
with patch.object(
mock_rpc_device,
"initialize",
new_callable=AsyncMock,
side_effect=DeviceConnectionError,
):
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done(wait_background_tasks=True)

mock_rpc_device.mock_online()
Comment thread
epenet marked this conversation as resolved.
await hass.async_block_till_done(wait_background_tasks=True)
Expand Down Expand Up @@ -2943,10 +2957,14 @@ async def test_zeroconf_sleeping_device_attempts_configure_no_url_available(
},
)
entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
mock_rpc_device.mock_disconnected()
await hass.async_block_till_done()
with patch.object(
mock_rpc_device,
"initialize",
new_callable=AsyncMock,
side_effect=DeviceConnectionError,
):
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done(wait_background_tasks=True)

mock_rpc_device.mock_online()
Comment thread
epenet marked this conversation as resolved.
await hass.async_block_till_done(wait_background_tasks=True)
Expand Down
10 changes: 8 additions & 2 deletions tests/components/shelly/test_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,8 +1099,14 @@ async def test_rpc_sleeping_device_late_setup(
register_device(device_registry, entry)
monkeypatch.setattr(mock_rpc_device, "connected", False)
monkeypatch.setattr(mock_rpc_device, "initialized", False)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
with patch.object(
mock_rpc_device,
"initialize",
new_callable=AsyncMock,
side_effect=DeviceConnectionError,
):
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done(wait_background_tasks=True)

monkeypatch.setattr(mock_rpc_device, "initialized", True)
mock_rpc_device.mock_online()
Expand Down
7 changes: 6 additions & 1 deletion tests/components/shelly/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,12 @@ async def test_rpc_sleeping_update(
},
)
entity_id = f"{UPDATE_DOMAIN}.test_name_firmware"
with patch.object(mock_rpc_device, "initialize", side_effect=DeviceConnectionError):
with patch.object(
mock_rpc_device,
"initialize",
new_callable=AsyncMock,
side_effect=DeviceConnectionError,
):
await init_integration(hass, 2, sleep_period=1000)

# Entity should be created when device is online
Expand Down