diff --git a/tests/components/esphome/test_voice_assistant.py b/tests/components/esphome/test_voice_assistant.py index 322e057ec15..4188e375907 100644 --- a/tests/components/esphome/test_voice_assistant.py +++ b/tests/components/esphome/test_voice_assistant.py @@ -273,7 +273,7 @@ async def test_error_event_type( ) ) - assert voice_assistant_udp_server_v1.handle_event.called_with( + voice_assistant_udp_server_v1.handle_event.assert_called_with( VoiceAssistantEventType.VOICE_ASSISTANT_ERROR, {"code": "code", "message": "message"}, ) diff --git a/tests/components/sonos/conftest.py b/tests/components/sonos/conftest.py index 730f0f5e8f3..bab2b89009f 100644 --- a/tests/components/sonos/conftest.py +++ b/tests/components/sonos/conftest.py @@ -107,6 +107,9 @@ def config_entry_fixture(): class MockSoCo(MagicMock): """Mock the Soco Object.""" + audio_delay = 2 + sub_gain = 5 + @property def visible_zones(self): """Return visible zones and allow property to be overridden by device classes.""" diff --git a/tests/components/sonos/test_number.py b/tests/components/sonos/test_number.py index d5da2af629e..38456058d8a 100644 --- a/tests/components/sonos/test_number.py +++ b/tests/components/sonos/test_number.py @@ -1,5 +1,5 @@ """Tests for the Sonos number platform.""" -from unittest.mock import patch +from unittest.mock import PropertyMock, patch from homeassistant.components.number import DOMAIN as NUMBER_DOMAIN, SERVICE_SET_VALUE from homeassistant.const import ATTR_ENTITY_ID @@ -37,24 +37,28 @@ async def test_number_entities( music_surround_level_state = hass.states.get(music_surround_level_number.entity_id) assert music_surround_level_state.state == "4" - with patch("soco.SoCo.audio_delay") as mock_audio_delay: + with patch.object( + type(soco), "audio_delay", new_callable=PropertyMock + ) as mock_audio_delay: await hass.services.async_call( NUMBER_DOMAIN, SERVICE_SET_VALUE, {ATTR_ENTITY_ID: audio_delay_number.entity_id, "value": 3}, blocking=True, ) - assert mock_audio_delay.called_with(3) + mock_audio_delay.assert_called_once_with(3) sub_gain_number = entity_registry.entities["number.zone_a_sub_gain"] sub_gain_state = hass.states.get(sub_gain_number.entity_id) assert sub_gain_state.state == "5" - with patch("soco.SoCo.sub_gain") as mock_sub_gain: + with patch.object( + type(soco), "sub_gain", new_callable=PropertyMock + ) as mock_sub_gain: await hass.services.async_call( NUMBER_DOMAIN, SERVICE_SET_VALUE, {ATTR_ENTITY_ID: sub_gain_number.entity_id, "value": -8}, blocking=True, ) - assert mock_sub_gain.called_with(-8) + mock_sub_gain.assert_called_once_with(-8)