1
0
mirror of https://github.com/home-assistant/core.git synced 2026-06-30 03:06:10 +01:00
Files
core/tests/components/github/test_sensor.py
T
2026-06-10 12:55:39 +02:00

54 lines
1.8 KiB
Python

"""Test GitHub sensor."""
from unittest.mock import AsyncMock, patch
from freezegun.api import FrozenDateTimeFactory
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.github.const import FALLBACK_UPDATE_INTERVAL
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, async_fire_time_changed, snapshot_platform
TEST_SENSOR_ENTITY = "sensor.octocat_hello_world_latest_release"
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_all_entities(
hass: HomeAssistant,
github_client: AsyncMock,
mock_config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test all entities."""
with patch("homeassistant.components.github.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_updates_with_empty_release_array(
hass: HomeAssistant,
github_client: AsyncMock,
mock_config_entry: MockConfigEntry,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the sensor updates by default GitHub sensors."""
await setup_integration(hass, mock_config_entry)
state = hass.states.get(TEST_SENSOR_ENTITY)
assert state.state == "v1.0.0"
github_client.graphql.return_value.data["data"]["repository"]["release"] = None
freezer.tick(FALLBACK_UPDATE_INTERVAL)
async_fire_time_changed(hass)
await hass.async_block_till_done()
new_state = hass.states.get(TEST_SENSOR_ENTITY)
assert new_state.state == STATE_UNAVAILABLE