From 27c9e96865d421a68422cdf90ecdfcab8902b895 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 19 Apr 2022 11:38:07 -1000 Subject: [PATCH] Fix flapping goalzero tests (#70298) --- tests/components/goalzero/__init__.py | 15 --------------- tests/components/goalzero/test_binary_sensor.py | 6 +++--- tests/components/goalzero/test_sensor.py | 16 +++++++++------- tests/components/goalzero/test_switch.py | 4 ++-- 4 files changed, 14 insertions(+), 27 deletions(-) diff --git a/tests/components/goalzero/__init__.py b/tests/components/goalzero/__init__.py index 8ffbbc11825..18ac689017f 100644 --- a/tests/components/goalzero/__init__.py +++ b/tests/components/goalzero/__init__.py @@ -7,7 +7,6 @@ from homeassistant.components.goalzero.const import DEFAULT_NAME from homeassistant.const import CONF_HOST, CONF_NAME from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import format_mac -from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry, load_fixture from tests.test_util.aiohttp import AiohttpClientMocker @@ -79,17 +78,3 @@ async def async_init_integration( await hass.async_block_till_done() return entry - - -async def async_setup_platform( - hass: HomeAssistant, - aioclient_mock: AiohttpClientMocker, - platform: str, -): - """Set up the platform.""" - entry = await async_init_integration(hass, aioclient_mock) - - with patch("homeassistant.components.goalzero.PLATFORMS", [platform]): - assert await async_setup_component(hass, DOMAIN, {}) - - return entry diff --git a/tests/components/goalzero/test_binary_sensor.py b/tests/components/goalzero/test_binary_sensor.py index 4f2ffd751b5..1d539816814 100644 --- a/tests/components/goalzero/test_binary_sensor.py +++ b/tests/components/goalzero/test_binary_sensor.py @@ -1,17 +1,17 @@ """Binary sensor tests for the Goalzero integration.""" -from homeassistant.components.binary_sensor import DOMAIN, BinarySensorDeviceClass +from homeassistant.components.binary_sensor import BinarySensorDeviceClass from homeassistant.components.goalzero.const import DEFAULT_NAME from homeassistant.const import ATTR_DEVICE_CLASS, STATE_OFF, STATE_ON from homeassistant.core import HomeAssistant -from . import async_setup_platform +from . import async_init_integration from tests.test_util.aiohttp import AiohttpClientMocker async def test_binary_sensors(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker): """Test we get sensor data.""" - await async_setup_platform(hass, aioclient_mock, DOMAIN) + await async_init_integration(hass, aioclient_mock) state = hass.states.get(f"binary_sensor.{DEFAULT_NAME}_backlight") assert state.state == STATE_ON diff --git a/tests/components/goalzero/test_sensor.py b/tests/components/goalzero/test_sensor.py index 67878d702db..ce67351c978 100644 --- a/tests/components/goalzero/test_sensor.py +++ b/tests/components/goalzero/test_sensor.py @@ -1,9 +1,9 @@ """Sensor tests for the Goalzero integration.""" +from unittest.mock import AsyncMock + from homeassistant.components.goalzero.const import DEFAULT_NAME -from homeassistant.components.goalzero.sensor import SENSOR_TYPES from homeassistant.components.sensor import ( ATTR_STATE_CLASS, - DOMAIN, SensorDeviceClass, SensorStateClass, ) @@ -22,16 +22,18 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant -from . import async_setup_platform +from . import async_init_integration from tests.test_util.aiohttp import AiohttpClientMocker -async def test_sensors(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker): +async def test_sensors( + hass: HomeAssistant, + aioclient_mock: AiohttpClientMocker, + entity_registry_enabled_by_default: AsyncMock, +): """Test we get sensor data.""" - for description in SENSOR_TYPES: - description.entity_registry_enabled_default = True - await async_setup_platform(hass, aioclient_mock, DOMAIN) + await async_init_integration(hass, aioclient_mock) state = hass.states.get(f"sensor.{DEFAULT_NAME}_watts_in") assert state.state == "0.0" diff --git a/tests/components/goalzero/test_switch.py b/tests/components/goalzero/test_switch.py index 4c625653033..0dd601fe70a 100644 --- a/tests/components/goalzero/test_switch.py +++ b/tests/components/goalzero/test_switch.py @@ -10,7 +10,7 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant -from . import async_setup_platform +from . import async_init_integration from tests.common import load_fixture from tests.test_util.aiohttp import AiohttpClientMocker @@ -20,7 +20,7 @@ async def test_switches_states( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker ): """Test we get sensor data.""" - await async_setup_platform(hass, aioclient_mock, DOMAIN) + await async_init_integration(hass, aioclient_mock) assert hass.states.get(f"switch.{DEFAULT_NAME}_usb_port_status").state == STATE_OFF assert hass.states.get(f"switch.{DEFAULT_NAME}_ac_port_status").state == STATE_ON