Fix flapping goalzero tests (#70298)

pull/70303/head
J. Nick Koston 2022-04-19 11:38:07 -10:00 committed by GitHub
parent cec2a40602
commit 27c9e96865
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 27 deletions

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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