Add 100% coverage of Reolink sensor platform (#124472)
* Add 100% sensor test coverage * use DOMAIN instead of const.DOMAIN * snake_case * better split tests * styling * Use entity_registry_enabled_by_default fixturepull/124926/head
parent
c9335598db
commit
928ff7c78c
|
@ -0,0 +1,62 @@
|
||||||
|
"""Test the Reolink sensor platform."""
|
||||||
|
|
||||||
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
|
from homeassistant.const import STATE_UNAVAILABLE, Platform
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from .conftest import TEST_NVR_NAME
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||||
|
async def test_sensors(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
|
reolink_connect: MagicMock,
|
||||||
|
) -> None:
|
||||||
|
"""Test sensor entities."""
|
||||||
|
reolink_connect.ptz_pan_position.return_value = 1200
|
||||||
|
reolink_connect.wifi_connection = True
|
||||||
|
reolink_connect.wifi_signal = 3
|
||||||
|
reolink_connect.hdd_list = [0]
|
||||||
|
reolink_connect.hdd_storage.return_value = 95
|
||||||
|
|
||||||
|
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.SENSOR]):
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert config_entry.state is ConfigEntryState.LOADED
|
||||||
|
|
||||||
|
entity_id = f"{Platform.SENSOR}.{TEST_NVR_NAME}_ptz_pan_position"
|
||||||
|
assert hass.states.get(entity_id).state == "1200"
|
||||||
|
|
||||||
|
entity_id = f"{Platform.SENSOR}.{TEST_NVR_NAME}_wi_fi_signal"
|
||||||
|
assert hass.states.get(entity_id).state == "3"
|
||||||
|
|
||||||
|
entity_id = f"{Platform.SENSOR}.{TEST_NVR_NAME}_sd_0_storage"
|
||||||
|
assert hass.states.get(entity_id).state == "95"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||||
|
async def test_hdd_sensors(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
|
reolink_connect: MagicMock,
|
||||||
|
) -> None:
|
||||||
|
"""Test hdd sensor entity."""
|
||||||
|
reolink_connect.hdd_list = [0]
|
||||||
|
reolink_connect.hdd_type.return_value = "HDD"
|
||||||
|
reolink_connect.hdd_storage.return_value = 85
|
||||||
|
reolink_connect.hdd_available.return_value = False
|
||||||
|
|
||||||
|
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.SENSOR]):
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert config_entry.state is ConfigEntryState.LOADED
|
||||||
|
|
||||||
|
entity_id = f"{Platform.SENSOR}.{TEST_NVR_NAME}_hdd_0_storage"
|
||||||
|
assert hass.states.get(entity_id).state == STATE_UNAVAILABLE
|
Loading…
Reference in New Issue