core/tests/components/ipp/test_sensor.py

57 lines
1.8 KiB
Python

"""Tests for the IPP sensor platform."""
from unittest.mock import AsyncMock
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from tests.common import MockConfigEntry, snapshot_platform
@pytest.mark.freeze_time("2019-11-11 09:10:32+00:00")
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_sensors(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
init_integration: MockConfigEntry,
) -> None:
"""Test the creation and values of the IPP sensors."""
await snapshot_platform(hass, entity_registry, snapshot, init_integration.entry_id)
async def test_disabled_by_default_sensors(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
) -> None:
"""Test the disabled by default IPP sensors."""
state = hass.states.get("sensor.test_ha_1000_series_uptime")
assert state is None
entry = entity_registry.async_get("sensor.test_ha_1000_series_uptime")
assert entry
assert entry.disabled
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
async def test_missing_entry_unique_id(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_config_entry: MockConfigEntry,
mock_ipp: AsyncMock,
) -> None:
"""Test the unique_id of IPP sensor when printer is missing identifiers."""
mock_config_entry.add_to_hass(hass)
hass.config_entries.async_update_entry(mock_config_entry, unique_id=None)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
entity = entity_registry.async_get("sensor.test_ha_1000_series")
assert entity
assert entity.unique_id == f"{mock_config_entry.entry_id}_printer"