Refactor sensor platform of Pyload integration (#119716)
This commit is contained in:
parent
a10f9a5f6d
commit
7fa74fcb07
4 changed files with 66 additions and 32 deletions
|
@ -9,12 +9,15 @@ from syrupy.assertion import SnapshotAssertion
|
|||
|
||||
from homeassistant.components.pyload.sensor import SCAN_INTERVAL
|
||||
from homeassistant.components.sensor import DOMAIN
|
||||
from homeassistant.const import STATE_UNAVAILABLE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
SENSORS = ["sensor.pyload_speed"]
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_pyloadapi")
|
||||
async def test_setup(
|
||||
|
@ -27,8 +30,9 @@ async def test_setup(
|
|||
assert await async_setup_component(hass, DOMAIN, pyload_config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
result = hass.states.get("sensor.pyload_speed")
|
||||
assert result == snapshot
|
||||
for sensor in SENSORS:
|
||||
result = hass.states.get(sensor)
|
||||
assert result == snapshot
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -76,6 +80,8 @@ async def test_sensor_update_exceptions(
|
|||
exception: Exception,
|
||||
expected_exception: str,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
snapshot: SnapshotAssertion,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
) -> None:
|
||||
"""Test exceptions during update of pyLoad sensor."""
|
||||
|
||||
|
@ -87,6 +93,9 @@ async def test_sensor_update_exceptions(
|
|||
assert len(hass.states.async_all(DOMAIN)) == 1
|
||||
assert expected_exception in caplog.text
|
||||
|
||||
for sensor in SENSORS:
|
||||
assert hass.states.get(sensor).state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_sensor_invalid_auth(
|
||||
hass: HomeAssistant,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue