mirror of
https://github.com/home-assistant/core.git
synced 2026-07-03 12:46:09 +01:00
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
"""Tests for the Yoto sensor platform."""
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
from syrupy.assertion 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_integration
|
|
|
|
from tests.common import MockConfigEntry, snapshot_platform
|
|
|
|
pytestmark = pytest.mark.usefixtures("setup_credentials")
|
|
|
|
ENTITY_ID = "sensor.nursery_yoto_battery"
|
|
|
|
|
|
@pytest.mark.usefixtures("mock_yoto_client")
|
|
async def test_all_entities(
|
|
hass: HomeAssistant,
|
|
mock_config_entry: MockConfigEntry,
|
|
entity_registry: er.EntityRegistry,
|
|
snapshot: SnapshotAssertion,
|
|
) -> None:
|
|
"""Snapshot every Yoto sensor entity."""
|
|
with patch("homeassistant.components.yoto.PLATFORMS", [Platform.SENSOR]):
|
|
await setup_integration(hass, mock_config_entry)
|
|
|
|
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
|
|
|
|
|
async def test_sensor_unavailable_when_offline(
|
|
hass: HomeAssistant,
|
|
mock_yoto_client: MagicMock,
|
|
mock_config_entry: MockConfigEntry,
|
|
) -> None:
|
|
"""Sensors are unavailable while the player is offline."""
|
|
player = next(iter(mock_yoto_client.players.values()))
|
|
player.is_online = False
|
|
|
|
with patch("homeassistant.components.yoto.PLATFORMS", [Platform.SENSOR]):
|
|
await setup_integration(hass, mock_config_entry)
|
|
|
|
state = hass.states.get(ENTITY_ID)
|
|
assert state is not None
|
|
assert state.state == STATE_UNAVAILABLE
|