From c104e66964f0818726b77627b27f9bf32eaff3b5 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Sat, 5 Oct 2024 12:13:52 +0200 Subject: [PATCH] Fix snooz tests (#127468) --- tests/components/snooz/test_fan.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/components/snooz/test_fan.py b/tests/components/snooz/test_fan.py index 69b06692557..127895d7de7 100644 --- a/tests/components/snooz/test_fan.py +++ b/tests/components/snooz/test_fan.py @@ -3,7 +3,7 @@ from __future__ import annotations from datetime import timedelta -from unittest.mock import Mock +from unittest.mock import Mock, patch from pysnooz.api import SnoozDeviceState, UnknownSnoozState from pysnooz.commands import SnoozCommandResult, SnoozCommandResultStatus @@ -32,6 +32,8 @@ from homeassistant.helpers import entity_registry as er from . import SnoozFixture, create_mock_snooz, create_mock_snooz_config_entry +from tests.components.bluetooth import generate_ble_device + async def test_turn_on(hass: HomeAssistant, snooz_fan_entity_id: str) -> None: """Test turning on the device.""" @@ -200,7 +202,14 @@ async def test_restore_state( assert state.state == STATE_UNAVAILABLE # reload entry - await create_mock_snooz_config_entry(hass, device) + with ( + patch("homeassistant.components.snooz.SnoozDevice", return_value=device), + patch( + "homeassistant.components.snooz.async_ble_device_from_address", + return_value=generate_ble_device(device.address, device.name), + ), + ): + await hass.config_entries.async_setup(entry.entry_id) # should match last known state state = hass.states.get(entity_id) @@ -225,7 +234,14 @@ async def test_restore_unknown_state( assert state.state == STATE_UNAVAILABLE # reload entry - await create_mock_snooz_config_entry(hass, device) + with ( + patch("homeassistant.components.snooz.SnoozDevice", return_value=device), + patch( + "homeassistant.components.snooz.async_ble_device_from_address", + return_value=generate_ble_device(device.address, device.name), + ), + ): + await hass.config_entries.async_setup(entry.entry_id) # should match last known state state = hass.states.get(entity_id)