Fix flapping goalzero tests (#70298)
parent
cec2a40602
commit
27c9e96865
|
@ -7,7 +7,6 @@ from homeassistant.components.goalzero.const import DEFAULT_NAME
|
||||||
from homeassistant.const import CONF_HOST, CONF_NAME
|
from homeassistant.const import CONF_HOST, CONF_NAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import format_mac
|
from homeassistant.helpers.device_registry import format_mac
|
||||||
from homeassistant.setup import async_setup_component
|
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, load_fixture
|
from tests.common import MockConfigEntry, load_fixture
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
@ -79,17 +78,3 @@ async def async_init_integration(
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
return entry
|
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
|
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
"""Binary sensor tests for the Goalzero integration."""
|
"""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.components.goalzero.const import DEFAULT_NAME
|
||||||
from homeassistant.const import ATTR_DEVICE_CLASS, STATE_OFF, STATE_ON
|
from homeassistant.const import ATTR_DEVICE_CLASS, STATE_OFF, STATE_ON
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import async_setup_platform
|
from . import async_init_integration
|
||||||
|
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
|
||||||
|
|
||||||
async def test_binary_sensors(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker):
|
async def test_binary_sensors(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker):
|
||||||
"""Test we get sensor data."""
|
"""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")
|
state = hass.states.get(f"binary_sensor.{DEFAULT_NAME}_backlight")
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
"""Sensor tests for the Goalzero integration."""
|
"""Sensor tests for the Goalzero integration."""
|
||||||
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
from homeassistant.components.goalzero.const import DEFAULT_NAME
|
from homeassistant.components.goalzero.const import DEFAULT_NAME
|
||||||
from homeassistant.components.goalzero.sensor import SENSOR_TYPES
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
ATTR_STATE_CLASS,
|
ATTR_STATE_CLASS,
|
||||||
DOMAIN,
|
|
||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
|
@ -22,16 +22,18 @@ from homeassistant.const import (
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import async_setup_platform
|
from . import async_init_integration
|
||||||
|
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
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."""
|
"""Test we get sensor data."""
|
||||||
for description in SENSOR_TYPES:
|
await async_init_integration(hass, aioclient_mock)
|
||||||
description.entity_registry_enabled_default = True
|
|
||||||
await async_setup_platform(hass, aioclient_mock, DOMAIN)
|
|
||||||
|
|
||||||
state = hass.states.get(f"sensor.{DEFAULT_NAME}_watts_in")
|
state = hass.states.get(f"sensor.{DEFAULT_NAME}_watts_in")
|
||||||
assert state.state == "0.0"
|
assert state.state == "0.0"
|
||||||
|
|
|
@ -10,7 +10,7 @@ from homeassistant.const import (
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import async_setup_platform
|
from . import async_init_integration
|
||||||
|
|
||||||
from tests.common import load_fixture
|
from tests.common import load_fixture
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
@ -20,7 +20,7 @@ async def test_switches_states(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
):
|
):
|
||||||
"""Test we get sensor data."""
|
"""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}_usb_port_status").state == STATE_OFF
|
||||||
assert hass.states.get(f"switch.{DEFAULT_NAME}_ac_port_status").state == STATE_ON
|
assert hass.states.get(f"switch.{DEFAULT_NAME}_ac_port_status").state == STATE_ON
|
||||||
|
|
Loading…
Reference in New Issue