mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Modernize Twentemilieu tests (#88640)
This commit is contained in:
parent
f8314fe007
commit
6112793b19
@ -46,22 +46,14 @@ def mock_setup_entry() -> Generator[None, None, None]:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_twentemilieu_config_flow() -> Generator[None, MagicMock, None]:
|
||||
"""Return a mocked Twente Milieu client."""
|
||||
with patch(
|
||||
"homeassistant.components.twentemilieu.config_flow.TwenteMilieu", autospec=True
|
||||
) as twentemilieu_mock:
|
||||
twentemilieu = twentemilieu_mock.return_value
|
||||
twentemilieu.unique_id.return_value = 12345
|
||||
yield twentemilieu
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_twentemilieu() -> Generator[None, MagicMock, None]:
|
||||
def mock_twentemilieu() -> Generator[MagicMock, None, None]:
|
||||
"""Return a mocked Twente Milieu client."""
|
||||
with patch(
|
||||
"homeassistant.components.twentemilieu.TwenteMilieu", autospec=True
|
||||
) as twentemilieu_mock:
|
||||
) as twentemilieu_mock, patch(
|
||||
"homeassistant.components.twentemilieu.config_flow.TwenteMilieu",
|
||||
new=twentemilieu_mock,
|
||||
):
|
||||
twentemilieu = twentemilieu_mock.return_value
|
||||
twentemilieu.unique_id.return_value = 12345
|
||||
twentemilieu.update.return_value = {
|
||||
|
103
tests/components/twentemilieu/snapshots/test_calendar.ambr
Normal file
103
tests/components/twentemilieu/snapshots/test_calendar.ambr
Normal file
@ -0,0 +1,103 @@
|
||||
# serializer version: 1
|
||||
# name: test_api_calendar
|
||||
list([
|
||||
dict({
|
||||
'entity_id': 'calendar.twente_milieu',
|
||||
'name': 'Twente Milieu',
|
||||
}),
|
||||
])
|
||||
# ---
|
||||
# name: test_api_events
|
||||
list([
|
||||
dict({
|
||||
'description': None,
|
||||
'end': dict({
|
||||
'date': '2022-01-06',
|
||||
}),
|
||||
'location': None,
|
||||
'recurrence_id': None,
|
||||
'rrule': None,
|
||||
'start': dict({
|
||||
'date': '2022-01-06',
|
||||
}),
|
||||
'summary': 'Christmas tree pickup',
|
||||
'uid': None,
|
||||
}),
|
||||
])
|
||||
# ---
|
||||
# name: test_waste_pickup_calendar
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'all_day': True,
|
||||
'description': '',
|
||||
'end_time': '2022-01-06 00:00:00',
|
||||
'friendly_name': 'Twente Milieu',
|
||||
'icon': 'mdi:delete-empty',
|
||||
'location': '',
|
||||
'message': 'Christmas tree pickup',
|
||||
'start_time': '2022-01-06 00:00:00',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'calendar.twente_milieu',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_waste_pickup_calendar.1
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'calendar',
|
||||
'entity_category': None,
|
||||
'entity_id': 'calendar.twente_milieu',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': 'mdi:delete-empty',
|
||||
'original_name': None,
|
||||
'platform': 'twentemilieu',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '12345',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_waste_pickup_calendar.2
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': 'https://www.twentemilieu.nl',
|
||||
'connections': set({
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': <DeviceEntryType.SERVICE: 'service'>,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'twentemilieu',
|
||||
'12345',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'manufacturer': 'Twente Milieu',
|
||||
'model': None,
|
||||
'name': 'Twente Milieu',
|
||||
'name_by_user': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': None,
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
@ -0,0 +1,85 @@
|
||||
# serializer version: 1
|
||||
# name: test_full_user_flow
|
||||
FlowResultSnapshot({
|
||||
'context': dict({
|
||||
'source': 'user',
|
||||
'unique_id': '12345',
|
||||
}),
|
||||
'data': dict({
|
||||
'house_letter': 'A',
|
||||
'house_number': '1',
|
||||
'id': 12345,
|
||||
'post_code': '1234AB',
|
||||
}),
|
||||
'description': None,
|
||||
'description_placeholders': None,
|
||||
'flow_id': <ANY>,
|
||||
'handler': 'twentemilieu',
|
||||
'options': dict({
|
||||
}),
|
||||
'result': ConfigEntrySnapshot({
|
||||
'data': dict({
|
||||
'house_letter': 'A',
|
||||
'house_number': '1',
|
||||
'id': 12345,
|
||||
'post_code': '1234AB',
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'domain': 'twentemilieu',
|
||||
'entry_id': <ANY>,
|
||||
'options': dict({
|
||||
}),
|
||||
'pref_disable_new_entities': False,
|
||||
'pref_disable_polling': False,
|
||||
'source': 'user',
|
||||
'title': '12345',
|
||||
'unique_id': '12345',
|
||||
'version': 1,
|
||||
}),
|
||||
'title': '12345',
|
||||
'type': <FlowResultType.CREATE_ENTRY: 'create_entry'>,
|
||||
'version': 1,
|
||||
})
|
||||
# ---
|
||||
# name: test_invalid_address
|
||||
FlowResultSnapshot({
|
||||
'context': dict({
|
||||
'source': 'user',
|
||||
'unique_id': '12345',
|
||||
}),
|
||||
'data': dict({
|
||||
'house_letter': None,
|
||||
'house_number': '1',
|
||||
'id': 12345,
|
||||
'post_code': '1234AB',
|
||||
}),
|
||||
'description': None,
|
||||
'description_placeholders': None,
|
||||
'flow_id': <ANY>,
|
||||
'handler': 'twentemilieu',
|
||||
'options': dict({
|
||||
}),
|
||||
'result': ConfigEntrySnapshot({
|
||||
'data': dict({
|
||||
'house_letter': None,
|
||||
'house_number': '1',
|
||||
'id': 12345,
|
||||
'post_code': '1234AB',
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'domain': 'twentemilieu',
|
||||
'entry_id': <ANY>,
|
||||
'options': dict({
|
||||
}),
|
||||
'pref_disable_new_entities': False,
|
||||
'pref_disable_polling': False,
|
||||
'source': 'user',
|
||||
'title': '12345',
|
||||
'unique_id': '12345',
|
||||
'version': 1,
|
||||
}),
|
||||
'title': '12345',
|
||||
'type': <FlowResultType.CREATE_ENTRY: 'create_entry'>,
|
||||
'version': 1,
|
||||
})
|
||||
# ---
|
@ -0,0 +1,20 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'WasteType.NON_RECYCLABLE': list([
|
||||
'2021-11-01',
|
||||
'2021-12-01',
|
||||
]),
|
||||
'WasteType.ORGANIC': list([
|
||||
'2021-11-02',
|
||||
]),
|
||||
'WasteType.PACKAGES': list([
|
||||
'2021-11-03',
|
||||
]),
|
||||
'WasteType.PAPER': list([
|
||||
]),
|
||||
'WasteType.TREE': list([
|
||||
'2022-01-06',
|
||||
]),
|
||||
})
|
||||
# ---
|
356
tests/components/twentemilieu/snapshots/test_sensor.ambr
Normal file
356
tests/components/twentemilieu/snapshots/test_sensor.ambr
Normal file
@ -0,0 +1,356 @@
|
||||
# serializer version: 1
|
||||
# name: test_sensors[sensor.twente_milieu_christmas_tree_pickup]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'date',
|
||||
'friendly_name': 'Twente Milieu Christmas tree pickup',
|
||||
'icon': 'mdi:pine-tree',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.twente_milieu_christmas_tree_pickup',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '2022-01-06',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.twente_milieu_christmas_tree_pickup].1
|
||||
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.twente_milieu_christmas_tree_pickup',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.DATE: 'date'>,
|
||||
'original_icon': 'mdi:pine-tree',
|
||||
'original_name': 'Christmas tree pickup',
|
||||
'platform': 'twentemilieu',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'twentemilieu_12345_tree',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.twente_milieu_christmas_tree_pickup].2
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': 'https://www.twentemilieu.nl',
|
||||
'connections': set({
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': <DeviceEntryType.SERVICE: 'service'>,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'twentemilieu',
|
||||
'12345',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'manufacturer': 'Twente Milieu',
|
||||
'model': None,
|
||||
'name': 'Twente Milieu',
|
||||
'name_by_user': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': None,
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.twente_milieu_non_recyclable_waste_pickup]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'date',
|
||||
'friendly_name': 'Twente Milieu Non-recyclable waste pickup',
|
||||
'icon': 'mdi:delete-empty',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.twente_milieu_non_recyclable_waste_pickup',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '2021-11-01',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.twente_milieu_non_recyclable_waste_pickup].1
|
||||
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.twente_milieu_non_recyclable_waste_pickup',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.DATE: 'date'>,
|
||||
'original_icon': 'mdi:delete-empty',
|
||||
'original_name': 'Non-recyclable waste pickup',
|
||||
'platform': 'twentemilieu',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'twentemilieu_12345_Non-recyclable',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.twente_milieu_non_recyclable_waste_pickup].2
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': 'https://www.twentemilieu.nl',
|
||||
'connections': set({
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': <DeviceEntryType.SERVICE: 'service'>,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'twentemilieu',
|
||||
'12345',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'manufacturer': 'Twente Milieu',
|
||||
'model': None,
|
||||
'name': 'Twente Milieu',
|
||||
'name_by_user': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': None,
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.twente_milieu_organic_waste_pickup]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'date',
|
||||
'friendly_name': 'Twente Milieu Organic waste pickup',
|
||||
'icon': 'mdi:delete-empty',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.twente_milieu_organic_waste_pickup',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '2021-11-02',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.twente_milieu_organic_waste_pickup].1
|
||||
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.twente_milieu_organic_waste_pickup',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.DATE: 'date'>,
|
||||
'original_icon': 'mdi:delete-empty',
|
||||
'original_name': 'Organic waste pickup',
|
||||
'platform': 'twentemilieu',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'twentemilieu_12345_Organic',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.twente_milieu_organic_waste_pickup].2
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': 'https://www.twentemilieu.nl',
|
||||
'connections': set({
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': <DeviceEntryType.SERVICE: 'service'>,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'twentemilieu',
|
||||
'12345',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'manufacturer': 'Twente Milieu',
|
||||
'model': None,
|
||||
'name': 'Twente Milieu',
|
||||
'name_by_user': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': None,
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.twente_milieu_packages_waste_pickup]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'date',
|
||||
'friendly_name': 'Twente Milieu Packages waste pickup',
|
||||
'icon': 'mdi:delete-empty',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.twente_milieu_packages_waste_pickup',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '2021-11-03',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.twente_milieu_packages_waste_pickup].1
|
||||
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.twente_milieu_packages_waste_pickup',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.DATE: 'date'>,
|
||||
'original_icon': 'mdi:delete-empty',
|
||||
'original_name': 'Packages waste pickup',
|
||||
'platform': 'twentemilieu',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'twentemilieu_12345_Plastic',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.twente_milieu_packages_waste_pickup].2
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': 'https://www.twentemilieu.nl',
|
||||
'connections': set({
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': <DeviceEntryType.SERVICE: 'service'>,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'twentemilieu',
|
||||
'12345',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'manufacturer': 'Twente Milieu',
|
||||
'model': None,
|
||||
'name': 'Twente Milieu',
|
||||
'name_by_user': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': None,
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.twente_milieu_paper_waste_pickup]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'date',
|
||||
'friendly_name': 'Twente Milieu Paper waste pickup',
|
||||
'icon': 'mdi:delete-empty',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.twente_milieu_paper_waste_pickup',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.twente_milieu_paper_waste_pickup].1
|
||||
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.twente_milieu_paper_waste_pickup',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.DATE: 'date'>,
|
||||
'original_icon': 'mdi:delete-empty',
|
||||
'original_name': 'Paper waste pickup',
|
||||
'platform': 'twentemilieu',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'twentemilieu_12345_Paper',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.twente_milieu_paper_waste_pickup].2
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': 'https://www.twentemilieu.nl',
|
||||
'connections': set({
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': <DeviceEntryType.SERVICE: 'service'>,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'twentemilieu',
|
||||
'12345',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'manufacturer': 'Twente Milieu',
|
||||
'model': None,
|
||||
'name': 'Twente Milieu',
|
||||
'name_by_user': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': None,
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
@ -2,71 +2,50 @@
|
||||
from http import HTTPStatus
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.twentemilieu.const import DOMAIN
|
||||
from homeassistant.const import ATTR_ICON, STATE_OFF
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("init_integration")
|
||||
|
||||
|
||||
@pytest.mark.freeze_time("2022-01-05 00:00:00+00:00")
|
||||
async def test_waste_pickup_calendar(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test the Twente Milieu waste pickup calendar."""
|
||||
entity_registry = er.async_get(hass)
|
||||
device_registry = dr.async_get(hass)
|
||||
assert (state := hass.states.get("calendar.twente_milieu"))
|
||||
assert state == snapshot
|
||||
|
||||
state = hass.states.get("calendar.twente_milieu")
|
||||
entry = entity_registry.async_get("calendar.twente_milieu")
|
||||
assert entry
|
||||
assert state
|
||||
assert entry.unique_id == "12345"
|
||||
assert state.attributes[ATTR_ICON] == "mdi:delete-empty"
|
||||
assert state.attributes["all_day"] is True
|
||||
assert state.attributes["message"] == "Christmas tree pickup"
|
||||
assert not state.attributes["location"]
|
||||
assert not state.attributes["description"]
|
||||
assert state.state == STATE_OFF
|
||||
assert (entity_entry := entity_registry.async_get(state.entity_id))
|
||||
assert entity_entry == snapshot
|
||||
|
||||
assert entry.device_id
|
||||
device_entry = device_registry.async_get(entry.device_id)
|
||||
assert device_entry
|
||||
assert device_entry.identifiers == {(DOMAIN, "12345")}
|
||||
assert device_entry.manufacturer == "Twente Milieu"
|
||||
assert device_entry.name == "Twente Milieu"
|
||||
assert device_entry.entry_type is dr.DeviceEntryType.SERVICE
|
||||
assert device_entry.configuration_url == "https://www.twentemilieu.nl"
|
||||
assert not device_entry.model
|
||||
assert not device_entry.sw_version
|
||||
assert entity_entry.device_id
|
||||
assert (device_entry := device_registry.async_get(entity_entry.device_id))
|
||||
assert device_entry == snapshot
|
||||
|
||||
|
||||
async def test_api_calendar(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
hass_client: ClientSessionGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test the API returns the calendar."""
|
||||
client = await hass_client()
|
||||
response = await client.get("/api/calendars")
|
||||
assert response.status == HTTPStatus.OK
|
||||
data = await response.json()
|
||||
assert data == [
|
||||
{
|
||||
"entity_id": "calendar.twente_milieu",
|
||||
"name": "Twente Milieu",
|
||||
}
|
||||
]
|
||||
assert data == snapshot
|
||||
|
||||
|
||||
async def test_api_events(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
hass_client: ClientSessionGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test the Twente Milieu calendar view."""
|
||||
client = await hass_client()
|
||||
@ -76,13 +55,4 @@ async def test_api_events(
|
||||
assert response.status == HTTPStatus.OK
|
||||
events = await response.json()
|
||||
assert len(events) == 1
|
||||
assert events[0] == {
|
||||
"start": {"date": "2022-01-06"},
|
||||
"end": {"date": "2022-01-06"},
|
||||
"summary": "Christmas tree pickup",
|
||||
"description": None,
|
||||
"location": None,
|
||||
"uid": None,
|
||||
"recurrence_id": None,
|
||||
"rrule": None,
|
||||
}
|
||||
assert events == snapshot
|
||||
|
@ -1,6 +1,8 @@
|
||||
"""Tests for the Twente Milieu config flow."""
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
from twentemilieu import TwenteMilieuAddressError, TwenteMilieuConnectionError
|
||||
|
||||
from homeassistant import config_entries
|
||||
@ -12,18 +14,16 @@ from homeassistant.components.twentemilieu.const import (
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.const import CONF_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
||||
|
||||
async def test_full_user_flow(
|
||||
hass: HomeAssistant,
|
||||
mock_twentemilieu_config_flow: MagicMock,
|
||||
mock_setup_entry: MagicMock,
|
||||
) -> None:
|
||||
|
||||
@pytest.mark.usefixtures("mock_twentemilieu")
|
||||
async def test_full_user_flow(hass: HomeAssistant, snapshot: SnapshotAssertion) -> None:
|
||||
"""Test registering an integration and finishing flow works."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
@ -42,19 +42,13 @@ async def test_full_user_flow(
|
||||
)
|
||||
|
||||
assert result2.get("type") == FlowResultType.CREATE_ENTRY
|
||||
assert result2.get("title") == "12345"
|
||||
assert result2.get("data") == {
|
||||
CONF_ID: 12345,
|
||||
CONF_POST_CODE: "1234AB",
|
||||
CONF_HOUSE_NUMBER: "1",
|
||||
CONF_HOUSE_LETTER: "A",
|
||||
}
|
||||
assert result2 == snapshot
|
||||
|
||||
|
||||
async def test_invalid_address(
|
||||
hass: HomeAssistant,
|
||||
mock_twentemilieu_config_flow: MagicMock,
|
||||
mock_setup_entry: MagicMock,
|
||||
mock_twentemilieu: MagicMock,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test full user flow when the user enters an incorrect address.
|
||||
|
||||
@ -68,7 +62,7 @@ async def test_invalid_address(
|
||||
assert result.get("type") == FlowResultType.FORM
|
||||
assert result.get("step_id") == SOURCE_USER
|
||||
|
||||
mock_twentemilieu_config_flow.unique_id.side_effect = TwenteMilieuAddressError
|
||||
mock_twentemilieu.unique_id.side_effect = TwenteMilieuAddressError
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
@ -81,7 +75,7 @@ async def test_invalid_address(
|
||||
assert result2.get("step_id") == SOURCE_USER
|
||||
assert result2.get("errors") == {"base": "invalid_address"}
|
||||
|
||||
mock_twentemilieu_config_flow.unique_id.side_effect = None
|
||||
mock_twentemilieu.unique_id.side_effect = None
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
@ -91,21 +85,15 @@ async def test_invalid_address(
|
||||
)
|
||||
|
||||
assert result3.get("type") == FlowResultType.CREATE_ENTRY
|
||||
assert result3.get("title") == "12345"
|
||||
assert result3.get("data") == {
|
||||
CONF_ID: 12345,
|
||||
CONF_POST_CODE: "1234AB",
|
||||
CONF_HOUSE_NUMBER: "1",
|
||||
CONF_HOUSE_LETTER: None,
|
||||
}
|
||||
assert result3 == snapshot
|
||||
|
||||
|
||||
async def test_connection_error(
|
||||
hass: HomeAssistant,
|
||||
mock_twentemilieu_config_flow: MagicMock,
|
||||
mock_twentemilieu: MagicMock,
|
||||
) -> None:
|
||||
"""Test we show user form on Twente Milieu connection error."""
|
||||
mock_twentemilieu_config_flow.unique_id.side_effect = TwenteMilieuConnectionError
|
||||
mock_twentemilieu.unique_id.side_effect = TwenteMilieuConnectionError
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
@ -122,9 +110,9 @@ async def test_connection_error(
|
||||
assert result.get("errors") == {"base": "cannot_connect"}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_twentemilieu")
|
||||
async def test_address_already_set_up(
|
||||
hass: HomeAssistant,
|
||||
mock_twentemilieu_config_flow: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test we abort if address has already been set up."""
|
||||
|
@ -1,4 +1,5 @@
|
||||
"""Tests for the diagnostics data provided by the TwenteMilieu integration."""
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
@ -11,14 +12,10 @@ async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
init_integration: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics."""
|
||||
assert await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, init_integration
|
||||
) == {
|
||||
"WasteType.NON_RECYCLABLE": ["2021-11-01", "2021-12-01"],
|
||||
"WasteType.ORGANIC": ["2021-11-02"],
|
||||
"WasteType.PAPER": [],
|
||||
"WasteType.TREE": ["2022-01-06"],
|
||||
"WasteType.PACKAGES": ["2021-11-03"],
|
||||
}
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
|
||||
== snapshot
|
||||
)
|
||||
|
@ -1,5 +1,7 @@
|
||||
"""Tests for the Twente Milieu integration."""
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.twentemilieu.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
@ -8,10 +10,10 @@ from homeassistant.core import HomeAssistant
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_twentemilieu")
|
||||
async def test_load_unload_config_entry(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_twentemilieu: AsyncMock,
|
||||
) -> None:
|
||||
"""Test the Twente Milieu configuration entry loading/unloading."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
@ -45,10 +47,10 @@ async def test_config_entry_not_ready(
|
||||
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_twentemilieu")
|
||||
async def test_update_config_entry_unique_id(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_twentemilieu: AsyncMock,
|
||||
) -> None:
|
||||
"""Test the we update old config entries with an unique ID."""
|
||||
mock_config_entry.unique_id = None
|
||||
|
@ -1,104 +1,38 @@
|
||||
"""Tests for the Twente Milieu sensors."""
|
||||
from homeassistant.components.sensor import SensorDeviceClass
|
||||
from homeassistant.components.twentemilieu.const import DOMAIN
|
||||
from homeassistant.const import (
|
||||
ATTR_DEVICE_CLASS,
|
||||
ATTR_FRIENDLY_NAME,
|
||||
ATTR_ICON,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
pytestmark = pytest.mark.usefixtures("init_integration")
|
||||
|
||||
|
||||
async def test_waste_pickup_sensors(
|
||||
@pytest.mark.parametrize(
|
||||
"entity_id",
|
||||
[
|
||||
"sensor.twente_milieu_christmas_tree_pickup",
|
||||
"sensor.twente_milieu_non_recyclable_waste_pickup",
|
||||
"sensor.twente_milieu_organic_waste_pickup",
|
||||
"sensor.twente_milieu_packages_waste_pickup",
|
||||
"sensor.twente_milieu_paper_waste_pickup",
|
||||
],
|
||||
)
|
||||
async def test_sensors(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
entity_id: str,
|
||||
) -> None:
|
||||
"""Test the Twente Milieu waste pickup sensors."""
|
||||
entity_registry = er.async_get(hass)
|
||||
device_registry = dr.async_get(hass)
|
||||
assert (state := hass.states.get(entity_id))
|
||||
assert state == snapshot
|
||||
|
||||
state = hass.states.get("sensor.twente_milieu_christmas_tree_pickup")
|
||||
entry = entity_registry.async_get("sensor.twente_milieu_christmas_tree_pickup")
|
||||
assert entry
|
||||
assert state
|
||||
assert entry.unique_id == "twentemilieu_12345_tree"
|
||||
assert state.state == "2022-01-06"
|
||||
assert (
|
||||
state.attributes.get(ATTR_FRIENDLY_NAME)
|
||||
== "Twente Milieu Christmas tree pickup"
|
||||
)
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.DATE
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:pine-tree"
|
||||
assert ATTR_UNIT_OF_MEASUREMENT not in state.attributes
|
||||
assert (entity_entry := entity_registry.async_get(state.entity_id))
|
||||
assert entity_entry == snapshot
|
||||
|
||||
state = hass.states.get("sensor.twente_milieu_non_recyclable_waste_pickup")
|
||||
entry = entity_registry.async_get(
|
||||
"sensor.twente_milieu_non_recyclable_waste_pickup"
|
||||
)
|
||||
assert entry
|
||||
assert state
|
||||
assert entry.unique_id == "twentemilieu_12345_Non-recyclable"
|
||||
assert state.state == "2021-11-01"
|
||||
assert (
|
||||
state.attributes.get(ATTR_FRIENDLY_NAME)
|
||||
== "Twente Milieu Non-recyclable waste pickup"
|
||||
)
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.DATE
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:delete-empty"
|
||||
assert ATTR_UNIT_OF_MEASUREMENT not in state.attributes
|
||||
|
||||
state = hass.states.get("sensor.twente_milieu_organic_waste_pickup")
|
||||
entry = entity_registry.async_get("sensor.twente_milieu_organic_waste_pickup")
|
||||
assert entry
|
||||
assert state
|
||||
assert entry.unique_id == "twentemilieu_12345_Organic"
|
||||
assert state.state == "2021-11-02"
|
||||
assert (
|
||||
state.attributes.get(ATTR_FRIENDLY_NAME) == "Twente Milieu Organic waste pickup"
|
||||
)
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.DATE
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:delete-empty"
|
||||
assert ATTR_UNIT_OF_MEASUREMENT not in state.attributes
|
||||
|
||||
state = hass.states.get("sensor.twente_milieu_packages_waste_pickup")
|
||||
entry = entity_registry.async_get("sensor.twente_milieu_packages_waste_pickup")
|
||||
assert entry
|
||||
assert state
|
||||
assert entry.unique_id == "twentemilieu_12345_Plastic"
|
||||
assert state.state == "2021-11-03"
|
||||
assert (
|
||||
state.attributes.get(ATTR_FRIENDLY_NAME)
|
||||
== "Twente Milieu Packages waste pickup"
|
||||
)
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.DATE
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:delete-empty"
|
||||
assert ATTR_UNIT_OF_MEASUREMENT not in state.attributes
|
||||
|
||||
state = hass.states.get("sensor.twente_milieu_paper_waste_pickup")
|
||||
entry = entity_registry.async_get("sensor.twente_milieu_paper_waste_pickup")
|
||||
assert entry
|
||||
assert state
|
||||
assert entry.unique_id == "twentemilieu_12345_Paper"
|
||||
assert state.state == STATE_UNKNOWN
|
||||
assert (
|
||||
state.attributes.get(ATTR_FRIENDLY_NAME) == "Twente Milieu Paper waste pickup"
|
||||
)
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.DATE
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:delete-empty"
|
||||
assert ATTR_UNIT_OF_MEASUREMENT not in state.attributes
|
||||
|
||||
assert entry.device_id
|
||||
device_entry = device_registry.async_get(entry.device_id)
|
||||
assert device_entry
|
||||
assert device_entry.identifiers == {(DOMAIN, "12345")}
|
||||
assert device_entry.manufacturer == "Twente Milieu"
|
||||
assert device_entry.name == "Twente Milieu"
|
||||
assert device_entry.entry_type is dr.DeviceEntryType.SERVICE
|
||||
assert device_entry.configuration_url == "https://www.twentemilieu.nl"
|
||||
assert not device_entry.model
|
||||
assert not device_entry.sw_version
|
||||
assert entity_entry.device_id
|
||||
assert (device_entry := device_registry.async_get(entity_entry.device_id))
|
||||
assert device_entry == snapshot
|
||||
|
Loading…
x
Reference in New Issue
Block a user