Skip to content

Commit 9adf493

Browse files
authored
Use non-autospec mock for Reolink's init tests (home-assistant#146991)
1 parent a29d5fb commit 9adf493

File tree

3 files changed

+125
-128
lines changed

3 files changed

+125
-128
lines changed

tests/components/reolink/conftest.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,14 @@ def mock_setup_entry() -> Generator[AsyncMock]:
6565
def _init_host_mock(host_mock: MagicMock) -> None:
6666
host_mock.get_host_data = AsyncMock(return_value=None)
6767
host_mock.get_states = AsyncMock(return_value=None)
68+
host_mock.get_state = AsyncMock()
6869
host_mock.check_new_firmware = AsyncMock(return_value=False)
70+
host_mock.subscribe = AsyncMock()
6971
host_mock.unsubscribe = AsyncMock(return_value=True)
7072
host_mock.logout = AsyncMock(return_value=True)
7173
host_mock.reboot = AsyncMock()
7274
host_mock.set_ptz_command = AsyncMock()
75+
host_mock.get_motion_state_all_ch = AsyncMock(return_value=False)
7376
host_mock.is_nvr = True
7477
host_mock.is_hub = False
7578
host_mock.mac_address = TEST_MAC
@@ -138,8 +141,10 @@ def _init_host_mock(host_mock: MagicMock) -> None:
138141
# Disable tcp push by default for tests
139142
host_mock.baichuan.port = TEST_BC_PORT
140143
host_mock.baichuan.events_active = False
144+
host_mock.baichuan.subscribe_events = AsyncMock()
141145
host_mock.baichuan.unsubscribe_events = AsyncMock()
142146
host_mock.baichuan.check_subscribe_events = AsyncMock()
147+
host_mock.baichuan.get_privacy_mode = AsyncMock()
143148
host_mock.baichuan.mac_address.return_value = TEST_MAC_CAM
144149
host_mock.baichuan.privacy_mode.return_value = False
145150
host_mock.baichuan.day_night_state.return_value = "day"
@@ -242,3 +247,26 @@ def test_chime(reolink_connect: MagicMock) -> None:
242247
reolink_connect.chime_list = [TEST_CHIME]
243248
reolink_connect.chime.return_value = TEST_CHIME
244249
return TEST_CHIME
250+
251+
252+
@pytest.fixture
253+
def reolink_chime(reolink_host: MagicMock) -> None:
254+
"""Mock a reolink chime."""
255+
TEST_CHIME = Chime(
256+
host=reolink_host,
257+
dev_id=12345678,
258+
channel=0,
259+
)
260+
TEST_CHIME.name = "Test chime"
261+
TEST_CHIME.volume = 3
262+
TEST_CHIME.connect_state = 2
263+
TEST_CHIME.led_state = True
264+
TEST_CHIME.event_info = {
265+
"md": {"switch": 0, "musicId": 0},
266+
"people": {"switch": 0, "musicId": 1},
267+
"visitor": {"switch": 1, "musicId": 2},
268+
}
269+
270+
reolink_host.chime_list = [TEST_CHIME]
271+
reolink_host.chime.return_value = TEST_CHIME
272+
return TEST_CHIME

tests/components/reolink/test_host.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ async def test_webhook_callback(
115115
assert hass.states.get(entity_id).state == STATE_OFF
116116

117117
# test webhook callback success all channels
118+
reolink_connect.get_motion_state_all_ch.return_value = True
118119
reolink_connect.motion_detected.return_value = True
119120
reolink_connect.ONVIF_event_callback.return_value = None
120121
await client.post(f"/api/webhook/{webhook_id}")

0 commit comments

Comments
 (0)