From f4c443ac8698ed6a2121d2db62dc478107f54dd2 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Tue, 29 Mar 2022 22:04:13 -0500 Subject: [PATCH] Use fixture for enabling entities in Sonarr tests (#68177) --- tests/components/sonarr/test_sensor.py | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/tests/components/sonarr/test_sensor.py b/tests/components/sonarr/test_sensor.py index 1b17fc2726e..0eae7cfb8a8 100644 --- a/tests/components/sonarr/test_sensor.py +++ b/tests/components/sonarr/test_sensor.py @@ -1,12 +1,11 @@ """Tests for the Sonarr sensor platform.""" from datetime import timedelta -from unittest.mock import MagicMock, patch +from unittest.mock import AsyncMock, MagicMock, patch from aiopyarr import ArrException import pytest from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN -from homeassistant.components.sonarr.const import DOMAIN from homeassistant.const import ( ATTR_ICON, ATTR_UNIT_OF_MEASUREMENT, @@ -26,12 +25,11 @@ async def test_sensors( hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_sonarr: MagicMock, + entity_registry_enabled_by_default: AsyncMock, ) -> None: """Test the creation and values of the sensors.""" - entry = mock_config_entry registry = er.async_get(hass) - # Pre-create registry entries for disabled by default sensors sensors = { "commands": "sonarr_commands", "diskspace": "sonarr_disk_space", @@ -40,23 +38,14 @@ async def test_sensors( "wanted": "sonarr_wanted", } - for (unique, oid) in sensors.items(): - registry.async_get_or_create( - SENSOR_DOMAIN, - DOMAIN, - f"{entry.entry_id}_{unique}", - suggested_object_id=oid, - disabled_by=None, - ) - mock_config_entry.add_to_hass(hass) - await hass.config_entries.async_setup(entry.entry_id) + await hass.config_entries.async_setup(mock_config_entry.entry_id) await hass.async_block_till_done() for (unique, oid) in sensors.items(): entity = registry.async_get(f"sensor.{oid}") assert entity - assert entity.unique_id == f"{entry.entry_id}_{unique}" + assert entity.unique_id == f"{mock_config_entry.entry_id}_{unique}" state = hass.states.get("sensor.sonarr_commands") assert state