core/tests/components/smlight/test_sensor.py
TimL 98a007cb2f
New Integration: SMLIGHT SLZB-06 Adapters Integration (#118675)
* Initial SMLIGHT integration

Signed-off-by: Tim Lunn <tl@smlight.tech>

* Generated content

Signed-off-by: Tim Lunn <tl@smlight.tech>

* Cleanup LOGGING

* Use runtime data

* Call super first

* coordinator instance attributes

* Move coordinatorEntity and attr to base class

* cleanup sensors

* update strings to use sentence case

* Improve reauth flow on incorrect credentials

* Use fixture for config_flow tests and test to completion

* Split uptime hndling into a new uptime sensor entity

* Drop server side events and internet callback

will bring this back with binary sensor Platform

* consolidate coordinator setup

* entity always include connections

* get_hostname tweak

* Add tests for init, coordinator and sensor

* Use custom type SmConfigEntry

* update sensor snapshot

* Drop reauth flow for later PR

* Use _async_setup for initial setup

* drop internet to be set later

* sensor fixes

* config flow re

* typing fixes

* Bump pysmlight dependency to 0.0.12

* dont trigger invalid auth message when first loading auth step

* Merge uptime sensors back into main sensor class

* clarify uptime handling

* Apply suggestions from code review

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* address review comments

* pass host as parameter to the dataCoordinator

* drop uptime sensors for a later PR

* update sensor test snapshot

* move coordinator unique_id to _async_setup

* fix CI

* Apply suggestions from code review

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* drop invalid_auth test tag

* use snapshot_platform, update fixtures

* Finish all tests with abort or create entry

* drop coordinator tests and remove hostname support

* add test for update failure on connection error

* use freezer for update_failed test

* fix pysmlight imports

---------

Signed-off-by: Tim Lunn <tl@smlight.tech>
Co-authored-by: Tim Lunn <tim@feathertop.org>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-08-20 10:44:06 +02:00

55 lines
1.6 KiB
Python

"""Tests for the SMLIGHT sensor platform."""
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr, entity_registry as er
from .conftest import setup_integration
from tests.common import MockConfigEntry, snapshot_platform
pytestmark = [
pytest.mark.usefixtures(
"mock_smlight_client",
)
]
@pytest.fixture
def platforms() -> Platform | list[Platform]:
"""Platforms, which should be loaded during the test."""
return Platform.SENSOR
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_sensors(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
mock_config_entry: MockConfigEntry,
snapshot: SnapshotAssertion,
) -> None:
"""Test the SMLIGHT sensors."""
entry = await setup_integration(hass, mock_config_entry)
await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)
async def test_disabled_by_default_sensors(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test the disabled by default SMLIGHT sensors."""
await setup_integration(hass, mock_config_entry)
for sensor in ("ram_usage", "filesystem_usage"):
assert not hass.states.get(f"sensor.mock_title_{sensor}")
assert (entry := entity_registry.async_get(f"sensor.mock_title_{sensor}"))
assert entry.disabled
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION