"""Tests for the Sonos number platform.""" from unittest.mock import patch from homeassistant.components.number import DOMAIN as NUMBER_DOMAIN, SERVICE_SET_VALUE from homeassistant.const import ATTR_ENTITY_ID from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er async def test_number_entities( hass: HomeAssistant, async_autosetup_sonos, soco, entity_registry: er.EntityRegistry ) -> None: """Test number entities.""" bass_number = entity_registry.entities["number.zone_a_bass"] bass_state = hass.states.get(bass_number.entity_id) assert bass_state.state == "1" treble_number = entity_registry.entities["number.zone_a_treble"] treble_state = hass.states.get(treble_number.entity_id) assert treble_state.state == "-1" audio_delay_number = entity_registry.entities["number.zone_a_audio_delay"] audio_delay_state = hass.states.get(audio_delay_number.entity_id) assert audio_delay_state.state == "2" surround_level_number = entity_registry.entities["number.zone_a_surround_level"] surround_level_state = hass.states.get(surround_level_number.entity_id) assert surround_level_state.state == "3" music_surround_level_number = entity_registry.entities[ "number.zone_a_music_surround_level" ] 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: 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) 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: 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)