mirror of
https://github.com/home-assistant/core.git
synced 2026-07-14 18:14:35 +01:00
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
"""Test Qbus sensors."""
|
|
|
|
from collections.abc import Awaitable, Callable
|
|
from unittest.mock import patch
|
|
|
|
from syrupy.assertion import SnapshotAssertion
|
|
|
|
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, Platform
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers import entity_registry as er
|
|
|
|
from tests.common import MockConfigEntry, snapshot_platform
|
|
|
|
|
|
async def test_sensor(
|
|
hass: HomeAssistant,
|
|
setup_integration_deferred: Callable[[], Awaitable],
|
|
entity_registry: er.EntityRegistry,
|
|
snapshot: SnapshotAssertion,
|
|
mock_config_entry: MockConfigEntry,
|
|
) -> None:
|
|
"""Test sensor."""
|
|
|
|
with patch("homeassistant.components.qbus.PLATFORMS", [Platform.SENSOR]):
|
|
await setup_integration_deferred()
|
|
|
|
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
|
|
|
|
|
async def test_sensor_gauge_unit_applied(
|
|
hass: HomeAssistant, setup_integration: None
|
|
) -> None:
|
|
"""Test gauge sensor uses reported unit."""
|
|
|
|
entity = hass.states.get("sensor.garage_energie")
|
|
assert entity
|
|
assert entity.attributes[ATTR_UNIT_OF_MEASUREMENT] == "Wh"
|
|
|
|
|
|
async def test_sensor_gauge_unit_missing(
|
|
hass: HomeAssistant, setup_integration: None
|
|
) -> None:
|
|
"""Test gauge sensor falls back to description default."""
|
|
|
|
entity = hass.states.get("sensor.tuin_luchtkwaliteit")
|
|
assert entity
|
|
assert entity.attributes[ATTR_UNIT_OF_MEASUREMENT] == "ppm"
|