Files
core/tests/components/version/test_sensor.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.4 KiB
Python
Raw Normal View History

2017-08-12 08:52:56 +02:00
"""The test for the version sensor platform."""
from __future__ import annotations
2023-08-25 16:01:48 +02:00
from freezegun.api import FrozenDateTimeFactory
from pyhaversion.exceptions import HaVersionException
2021-08-10 01:24:18 +02:00
import pytest
from homeassistant.core import HomeAssistant
2021-08-10 15:03:34 +02:00
from .common import MOCK_VERSION, mock_get_version_update, setup_version_integration
async def test_version_sensor(hass: HomeAssistant) -> None:
"""Test the Version sensor with different sources."""
await setup_version_integration(hass)
state = hass.states.get("sensor.local_installation")
assert state.state == MOCK_VERSION
assert "source" not in state.attributes
assert "channel" not in state.attributes
2023-08-25 16:01:48 +02:00
async def test_update(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test updates."""
await setup_version_integration(hass)
assert hass.states.get("sensor.local_installation").state == MOCK_VERSION
2023-08-25 16:01:48 +02:00
await mock_get_version_update(hass, freezer, version="1970.1.1")
assert hass.states.get("sensor.local_installation").state == "1970.1.1"
assert "Error fetching version data" not in caplog.text
2023-08-25 16:01:48 +02:00
await mock_get_version_update(hass, freezer, side_effect=HaVersionException)
assert hass.states.get("sensor.local_installation").state == "unavailable"
assert "Error fetching version data" in caplog.text