Add additional tests for solarlog (#119928)
This commit is contained in:
parent
904cf26d31
commit
af9f4f310b
9 changed files with 2376 additions and 18 deletions
59
tests/components/solarlog/test_sensor.py
Normal file
59
tests/components/solarlog/test_sensor.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
"""Test the Home Assistant solarlog sensor module."""
|
||||
|
||||
from datetime import timedelta
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
from solarlog_cli.solarlog_exceptions import (
|
||||
SolarLogConnectionError,
|
||||
SolarLogUpdateError,
|
||||
)
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.const import STATE_UNAVAILABLE, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import setup_platform
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_platform
|
||||
|
||||
|
||||
async def test_all_entities(
|
||||
hass: HomeAssistant,
|
||||
snapshot: SnapshotAssertion,
|
||||
mock_solarlog_connector: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test all entities."""
|
||||
|
||||
await setup_platform(hass, mock_config_entry, [Platform.SENSOR])
|
||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"exception",
|
||||
[
|
||||
SolarLogConnectionError,
|
||||
SolarLogUpdateError,
|
||||
],
|
||||
)
|
||||
async def test_connection_error(
|
||||
hass: HomeAssistant,
|
||||
exception: Exception,
|
||||
mock_solarlog_connector: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
) -> None:
|
||||
"""Test connection error."""
|
||||
await setup_platform(hass, mock_config_entry, [Platform.SENSOR])
|
||||
|
||||
mock_solarlog_connector.update_data.side_effect = exception
|
||||
|
||||
freezer.tick(delta=timedelta(hours=12))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("sensor.solarlog_power_ac").state == STATE_UNAVAILABLE
|
Loading…
Add table
Add a link
Reference in a new issue