Use fixture for enabling entities in Sonarr tests (#68177)
parent
42cec38b66
commit
f4c443ac86
|
@ -1,12 +1,11 @@
|
||||||
"""Tests for the Sonarr sensor platform."""
|
"""Tests for the Sonarr sensor platform."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import AsyncMock, MagicMock, patch
|
||||||
|
|
||||||
from aiopyarr import ArrException
|
from aiopyarr import ArrException
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||||
from homeassistant.components.sonarr.const import DOMAIN
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ICON,
|
ATTR_ICON,
|
||||||
ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
|
@ -26,12 +25,11 @@ async def test_sensors(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_config_entry: MockConfigEntry,
|
mock_config_entry: MockConfigEntry,
|
||||||
mock_sonarr: MagicMock,
|
mock_sonarr: MagicMock,
|
||||||
|
entity_registry_enabled_by_default: AsyncMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the creation and values of the sensors."""
|
"""Test the creation and values of the sensors."""
|
||||||
entry = mock_config_entry
|
|
||||||
registry = er.async_get(hass)
|
registry = er.async_get(hass)
|
||||||
|
|
||||||
# Pre-create registry entries for disabled by default sensors
|
|
||||||
sensors = {
|
sensors = {
|
||||||
"commands": "sonarr_commands",
|
"commands": "sonarr_commands",
|
||||||
"diskspace": "sonarr_disk_space",
|
"diskspace": "sonarr_disk_space",
|
||||||
|
@ -40,23 +38,14 @@ async def test_sensors(
|
||||||
"wanted": "sonarr_wanted",
|
"wanted": "sonarr_wanted",
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unique, oid) in sensors.items():
|
|
||||||
registry.async_get_or_create(
|
|
||||||
SENSOR_DOMAIN,
|
|
||||||
DOMAIN,
|
|
||||||
f"{entry.entry_id}_{unique}",
|
|
||||||
suggested_object_id=oid,
|
|
||||||
disabled_by=None,
|
|
||||||
)
|
|
||||||
|
|
||||||
mock_config_entry.add_to_hass(hass)
|
mock_config_entry.add_to_hass(hass)
|
||||||
await hass.config_entries.async_setup(entry.entry_id)
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
for (unique, oid) in sensors.items():
|
for (unique, oid) in sensors.items():
|
||||||
entity = registry.async_get(f"sensor.{oid}")
|
entity = registry.async_get(f"sensor.{oid}")
|
||||||
assert entity
|
assert entity
|
||||||
assert entity.unique_id == f"{entry.entry_id}_{unique}"
|
assert entity.unique_id == f"{mock_config_entry.entry_id}_{unique}"
|
||||||
|
|
||||||
state = hass.states.get("sensor.sonarr_commands")
|
state = hass.states.get("sensor.sonarr_commands")
|
||||||
assert state
|
assert state
|
||||||
|
|
Loading…
Reference in New Issue