"""Test the Teslemetry binary sensor platform.""" from unittest.mock import AsyncMock from freezegun.api import FrozenDateTimeFactory import pytest from syrupy.assertion import SnapshotAssertion from homeassistant.components.teslemetry.coordinator import VEHICLE_INTERVAL from homeassistant.const import Platform from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er from . import assert_entities, assert_entities_alt, setup_platform from .const import VEHICLE_DATA_ALT from tests.common import async_fire_time_changed @pytest.mark.usefixtures("entity_registry_enabled_by_default") async def test_binary_sensor( hass: HomeAssistant, snapshot: SnapshotAssertion, entity_registry: er.EntityRegistry, ) -> None: """Tests that the binary sensor entities are correct.""" entry = await setup_platform(hass, [Platform.BINARY_SENSOR]) assert_entities(hass, entry.entry_id, entity_registry, snapshot) @pytest.mark.usefixtures("entity_registry_enabled_by_default") async def test_binary_sensor_refresh( hass: HomeAssistant, snapshot: SnapshotAssertion, entity_registry: er.EntityRegistry, mock_vehicle_data: AsyncMock, freezer: FrozenDateTimeFactory, ) -> None: """Tests that the binary sensor entities are correct.""" entry = await setup_platform(hass, [Platform.BINARY_SENSOR]) # Refresh mock_vehicle_data.return_value = VEHICLE_DATA_ALT freezer.tick(VEHICLE_INTERVAL) async_fire_time_changed(hass) await hass.async_block_till_done() assert_entities_alt(hass, entry.entry_id, entity_registry, snapshot)