mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Add tests to Rova (#114285)
This commit is contained in:
parent
a3059fe504
commit
45da6f8f2c
@ -1 +1,18 @@
|
|||||||
"""Tests for the Rova component."""
|
"""Tests for the Rova component."""
|
||||||
|
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from homeassistant.const import Platform
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
|
async def setup_with_selected_platforms(
|
||||||
|
hass: HomeAssistant, entry: MockConfigEntry, platforms: list[Platform]
|
||||||
|
) -> None:
|
||||||
|
"""Set up the Rova integration with the selected platforms."""
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
with patch("homeassistant.components.rova.PLATFORMS", platforms):
|
||||||
|
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
@ -4,6 +4,15 @@ from unittest.mock import MagicMock, patch
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.components.rova.const import (
|
||||||
|
CONF_HOUSE_NUMBER,
|
||||||
|
CONF_HOUSE_NUMBER_SUFFIX,
|
||||||
|
CONF_ZIP_CODE,
|
||||||
|
DOMAIN,
|
||||||
|
)
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry, load_json_array_fixture
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_rova():
|
def mock_rova():
|
||||||
@ -18,4 +27,22 @@ def mock_rova():
|
|||||||
patch("homeassistant.components.rova.Rova", return_value=api),
|
patch("homeassistant.components.rova.Rova", return_value=api),
|
||||||
):
|
):
|
||||||
api.is_rova_area.return_value = True
|
api.is_rova_area.return_value = True
|
||||||
|
api.get_calendar_items.return_value = load_json_array_fixture(
|
||||||
|
"calendar_items.json", DOMAIN
|
||||||
|
)
|
||||||
yield api
|
yield api
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mock_config_entry() -> MockConfigEntry:
|
||||||
|
"""Mock config entry."""
|
||||||
|
return MockConfigEntry(
|
||||||
|
domain=DOMAIN,
|
||||||
|
unique_id="8381BE13",
|
||||||
|
title="8381BE 13",
|
||||||
|
data={
|
||||||
|
CONF_ZIP_CODE: "8381BE",
|
||||||
|
CONF_HOUSE_NUMBER: "13",
|
||||||
|
CONF_HOUSE_NUMBER_SUFFIX: "",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
18
tests/components/rova/fixtures/calendar_items.json
Normal file
18
tests/components/rova/fixtures/calendar_items.json
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"GarbageTypeCode": "GFT",
|
||||||
|
"Date": "2024-02-21T00:00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"GarbageTypeCode": "PAPIER",
|
||||||
|
"Date": "2024-03-06T00:00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"GarbageTypeCode": "PMD",
|
||||||
|
"Date": "2024-03-12T00:00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"GarbageTypeCode": "RESTAFVAL",
|
||||||
|
"Date": "2024-03-12T00:00:00"
|
||||||
|
}
|
||||||
|
]
|
193
tests/components/rova/snapshots/test_sensor.ambr
Normal file
193
tests/components/rova/snapshots/test_sensor.ambr
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_all_entities[sensor.8381be13_gft-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'sensor',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'sensor.8381be13_gft',
|
||||||
|
'has_entity_name': False,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <SensorDeviceClass.TIMESTAMP: 'timestamp'>,
|
||||||
|
'original_icon': 'mdi:recycle',
|
||||||
|
'original_name': '8381BE13_gft',
|
||||||
|
'platform': 'rova',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': None,
|
||||||
|
'unique_id': '8381BE13_gft',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_all_entities[sensor.8381be13_gft-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'timestamp',
|
||||||
|
'friendly_name': '8381BE13_gft',
|
||||||
|
'icon': 'mdi:recycle',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.8381be13_gft',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '2024-02-20T23:00:00+00:00',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_all_entities[sensor.8381be13_papier-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'sensor',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'sensor.8381be13_papier',
|
||||||
|
'has_entity_name': False,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <SensorDeviceClass.TIMESTAMP: 'timestamp'>,
|
||||||
|
'original_icon': 'mdi:recycle',
|
||||||
|
'original_name': '8381BE13_papier',
|
||||||
|
'platform': 'rova',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': None,
|
||||||
|
'unique_id': '8381BE13_papier',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_all_entities[sensor.8381be13_papier-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'timestamp',
|
||||||
|
'friendly_name': '8381BE13_papier',
|
||||||
|
'icon': 'mdi:recycle',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.8381be13_papier',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '2024-03-05T23:00:00+00:00',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_all_entities[sensor.8381be13_pmd-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'sensor',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'sensor.8381be13_pmd',
|
||||||
|
'has_entity_name': False,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <SensorDeviceClass.TIMESTAMP: 'timestamp'>,
|
||||||
|
'original_icon': 'mdi:recycle',
|
||||||
|
'original_name': '8381BE13_pmd',
|
||||||
|
'platform': 'rova',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': None,
|
||||||
|
'unique_id': '8381BE13_pmd',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_all_entities[sensor.8381be13_pmd-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'timestamp',
|
||||||
|
'friendly_name': '8381BE13_pmd',
|
||||||
|
'icon': 'mdi:recycle',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.8381be13_pmd',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '2024-03-11T23:00:00+00:00',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_all_entities[sensor.8381be13_restafval-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'sensor',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'sensor.8381be13_restafval',
|
||||||
|
'has_entity_name': False,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <SensorDeviceClass.TIMESTAMP: 'timestamp'>,
|
||||||
|
'original_icon': 'mdi:recycle',
|
||||||
|
'original_name': '8381BE13_restafval',
|
||||||
|
'platform': 'rova',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': None,
|
||||||
|
'unique_id': '8381BE13_restafval',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_all_entities[sensor.8381be13_restafval-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'timestamp',
|
||||||
|
'friendly_name': '8381BE13_restafval',
|
||||||
|
'icon': 'mdi:recycle',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.8381be13_restafval',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '2024-03-11T23:00:00+00:00',
|
||||||
|
})
|
||||||
|
# ---
|
34
tests/components/rova/test_sensor.py
Normal file
34
tests/components/rova/test_sensor.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
"""Tests for the Rova component."""
|
||||||
|
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
from syrupy import SnapshotAssertion
|
||||||
|
|
||||||
|
from homeassistant.const import Platform
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
|
from . import setup_with_selected_platforms
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
|
async def test_all_entities(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
mock_rova: MagicMock,
|
||||||
|
mock_config_entry: MockConfigEntry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
) -> None:
|
||||||
|
"""Test all entities."""
|
||||||
|
await setup_with_selected_platforms(hass, mock_config_entry, [Platform.SENSOR])
|
||||||
|
entity_entries = er.async_entries_for_config_entry(
|
||||||
|
entity_registry, mock_config_entry.entry_id
|
||||||
|
)
|
||||||
|
|
||||||
|
assert entity_entries
|
||||||
|
for entity_entry in entity_entries:
|
||||||
|
assert hass.states.get(entity_entry.entity_id) == snapshot(
|
||||||
|
name=f"{entity_entry.entity_id}-state"
|
||||||
|
)
|
||||||
|
assert entity_entry == snapshot(name=f"{entity_entry.entity_id}-entry")
|
Loading…
x
Reference in New Issue
Block a user