From bc51a4c524efe54f7e89333727d5ec6818e4efb8 Mon Sep 17 00:00:00 2001
From: epenet <6771947+epenet@users.noreply.github.com>
Date: Thu, 23 May 2024 11:54:20 +0200
Subject: [PATCH] Add snapshot tests to moehlenhoff_alpha2 (#117967)
* Add tests to moehlenhoff_alpha2
* Adjust coverage
* Adjust coverage
* Adjust coverage
* Adjust patch
* Adjust
---
.coveragerc | 2 -
.../components/moehlenhoff_alpha2/__init__.py | 40 +++
.../moehlenhoff_alpha2/fixtures/static2.xml | 268 ++++++++++++++++++
.../snapshots/test_binary_sensor.ambr | 48 ++++
.../snapshots/test_button.ambr | 47 +++
.../snapshots/test_climate.ambr | 77 +++++
.../snapshots/test_sensor.ambr | 48 ++++
.../moehlenhoff_alpha2/test_binary_sensor.py | 28 ++
.../moehlenhoff_alpha2/test_button.py | 28 ++
.../moehlenhoff_alpha2/test_climate.py | 28 ++
.../moehlenhoff_alpha2/test_config_flow.py | 22 +-
.../moehlenhoff_alpha2/test_sensor.py | 28 ++
12 files changed, 647 insertions(+), 17 deletions(-)
create mode 100644 tests/components/moehlenhoff_alpha2/fixtures/static2.xml
create mode 100644 tests/components/moehlenhoff_alpha2/snapshots/test_binary_sensor.ambr
create mode 100644 tests/components/moehlenhoff_alpha2/snapshots/test_button.ambr
create mode 100644 tests/components/moehlenhoff_alpha2/snapshots/test_climate.ambr
create mode 100644 tests/components/moehlenhoff_alpha2/snapshots/test_sensor.ambr
create mode 100644 tests/components/moehlenhoff_alpha2/test_binary_sensor.py
create mode 100644 tests/components/moehlenhoff_alpha2/test_button.py
create mode 100644 tests/components/moehlenhoff_alpha2/test_climate.py
create mode 100644 tests/components/moehlenhoff_alpha2/test_sensor.py
diff --git a/.coveragerc b/.coveragerc
index 8fa48ea3cf7..039882221b7 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -805,9 +805,7 @@ omit =
homeassistant/components/modem_callerid/button.py
homeassistant/components/modem_callerid/sensor.py
homeassistant/components/moehlenhoff_alpha2/__init__.py
- homeassistant/components/moehlenhoff_alpha2/binary_sensor.py
homeassistant/components/moehlenhoff_alpha2/climate.py
- homeassistant/components/moehlenhoff_alpha2/sensor.py
homeassistant/components/monzo/__init__.py
homeassistant/components/monzo/api.py
homeassistant/components/motion_blinds/__init__.py
diff --git a/tests/components/moehlenhoff_alpha2/__init__.py b/tests/components/moehlenhoff_alpha2/__init__.py
index 76bd1fd00aa..1470cfa43f6 100644
--- a/tests/components/moehlenhoff_alpha2/__init__.py
+++ b/tests/components/moehlenhoff_alpha2/__init__.py
@@ -1 +1,41 @@
"""Tests for the moehlenhoff_alpha2 integration."""
+
+from unittest.mock import patch
+
+import xmltodict
+
+from homeassistant.components.moehlenhoff_alpha2.const import DOMAIN
+from homeassistant.const import CONF_HOST
+from homeassistant.core import HomeAssistant
+
+from tests.common import MockConfigEntry, load_fixture
+
+MOCK_BASE_HOST = "fake-base-host"
+
+
+async def mock_update_data(self):
+ """Mock moehlenhoff_alpha2.Alpha2Base.update_data."""
+ data = xmltodict.parse(load_fixture("static2.xml", DOMAIN))
+ for _type in ("HEATAREA", "HEATCTRL", "IODEVICE"):
+ if not isinstance(data["Devices"]["Device"][_type], list):
+ data["Devices"]["Device"][_type] = [data["Devices"]["Device"][_type]]
+ self.static_data = data
+
+
+async def init_integration(hass: HomeAssistant) -> MockConfigEntry:
+ """Mock integration setup."""
+ with patch(
+ "homeassistant.components.moehlenhoff_alpha2.Alpha2Base.update_data",
+ mock_update_data,
+ ):
+ entry = MockConfigEntry(
+ domain=DOMAIN,
+ data={
+ CONF_HOST: MOCK_BASE_HOST,
+ },
+ entry_id="6fa019921cf8e7a3f57a3c2ed001a10d",
+ )
+ entry.add_to_hass(hass)
+ await hass.config_entries.async_setup(entry.entry_id)
+ await hass.async_block_till_done()
+ return entry
diff --git a/tests/components/moehlenhoff_alpha2/fixtures/static2.xml b/tests/components/moehlenhoff_alpha2/fixtures/static2.xml
new file mode 100644
index 00000000000..9ac21ba4bd8
--- /dev/null
+++ b/tests/components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+ 0
+ 0
+ 0
+ 0
+
+
+ 0
+ 0
+ 0
+ 0
+ 0
+
+
+ 0
+ 0
+ 0
+ 0
+ 0
+
+
+ 0
+ 0
+ 0
+ 0
+ 0
+
+
+ 0
+ 0
+ 0
+ 0
+ 0
+
+
+ 0
+ 0
+ 0
+ 0
+ 0
+
+
+ 0
+ 0
+ 0
+ 0
+ 0
+
+
+ 0
+ 0
+ 0
+ 0
+ 0
+
+
+ 0
+ 0
+ 0
+ 0
+ 0
+
+
+ 0
+ 0
+ 0
+ 0
+ 0
+
+
+ 0
+ 0
+ 0
+ 0
+ 0
+
+
+ 0
+ 1
+ 1
+ 02.10
+ 1
+ 2
+ 2
+ 0
+ 0
+ 1
+
+
+
\ No newline at end of file
diff --git a/tests/components/moehlenhoff_alpha2/snapshots/test_binary_sensor.ambr b/tests/components/moehlenhoff_alpha2/snapshots/test_binary_sensor.ambr
new file mode 100644
index 00000000000..dc6680ff99a
--- /dev/null
+++ b/tests/components/moehlenhoff_alpha2/snapshots/test_binary_sensor.ambr
@@ -0,0 +1,48 @@
+# serializer version: 1
+# name: test_binary_sensors[binary_sensor.buro_io_device_1_battery-entry]
+ EntityRegistryEntrySnapshot({
+ 'aliases': set({
+ }),
+ 'area_id': None,
+ 'capabilities': None,
+ 'config_entry_id': ,
+ 'device_class': None,
+ 'device_id': ,
+ 'disabled_by': None,
+ 'domain': 'binary_sensor',
+ 'entity_category': ,
+ 'entity_id': 'binary_sensor.buro_io_device_1_battery',
+ 'has_entity_name': False,
+ 'hidden_by': None,
+ 'icon': None,
+ 'id': ,
+ 'labels': set({
+ }),
+ 'name': None,
+ 'options': dict({
+ }),
+ 'original_device_class': ,
+ 'original_icon': None,
+ 'original_name': 'Büro IO device 1 battery',
+ 'platform': 'moehlenhoff_alpha2',
+ 'previous_unique_id': None,
+ 'supported_features': 0,
+ 'translation_key': None,
+ 'unique_id': 'Alpha2Test:1:battery',
+ 'unit_of_measurement': None,
+ })
+# ---
+# name: test_binary_sensors[binary_sensor.buro_io_device_1_battery-state]
+ StateSnapshot({
+ 'attributes': ReadOnlyDict({
+ 'device_class': 'battery',
+ 'friendly_name': 'Büro IO device 1 battery',
+ }),
+ 'context': ,
+ 'entity_id': 'binary_sensor.buro_io_device_1_battery',
+ 'last_changed': ,
+ 'last_reported': ,
+ 'last_updated': ,
+ 'state': 'off',
+ })
+# ---
diff --git a/tests/components/moehlenhoff_alpha2/snapshots/test_button.ambr b/tests/components/moehlenhoff_alpha2/snapshots/test_button.ambr
new file mode 100644
index 00000000000..7dfb9edb2e8
--- /dev/null
+++ b/tests/components/moehlenhoff_alpha2/snapshots/test_button.ambr
@@ -0,0 +1,47 @@
+# serializer version: 1
+# name: test_buttons[button.sync_time-entry]
+ EntityRegistryEntrySnapshot({
+ 'aliases': set({
+ }),
+ 'area_id': None,
+ 'capabilities': None,
+ 'config_entry_id': ,
+ 'device_class': None,
+ 'device_id': ,
+ 'disabled_by': None,
+ 'domain': 'button',
+ 'entity_category': ,
+ 'entity_id': 'button.sync_time',
+ 'has_entity_name': False,
+ 'hidden_by': None,
+ 'icon': None,
+ 'id': ,
+ 'labels': set({
+ }),
+ 'name': None,
+ 'options': dict({
+ }),
+ 'original_device_class': None,
+ 'original_icon': None,
+ 'original_name': 'Sync time',
+ 'platform': 'moehlenhoff_alpha2',
+ 'previous_unique_id': None,
+ 'supported_features': 0,
+ 'translation_key': None,
+ 'unique_id': '6fa019921cf8e7a3f57a3c2ed001a10d:sync_time',
+ 'unit_of_measurement': None,
+ })
+# ---
+# name: test_buttons[button.sync_time-state]
+ StateSnapshot({
+ 'attributes': ReadOnlyDict({
+ 'friendly_name': 'Sync time',
+ }),
+ 'context': ,
+ 'entity_id': 'button.sync_time',
+ 'last_changed': ,
+ 'last_reported': ,
+ 'last_updated': ,
+ 'state': 'unknown',
+ })
+# ---
diff --git a/tests/components/moehlenhoff_alpha2/snapshots/test_climate.ambr b/tests/components/moehlenhoff_alpha2/snapshots/test_climate.ambr
new file mode 100644
index 00000000000..c1a63271a33
--- /dev/null
+++ b/tests/components/moehlenhoff_alpha2/snapshots/test_climate.ambr
@@ -0,0 +1,77 @@
+# serializer version: 1
+# name: test_climate[climate.buro-entry]
+ EntityRegistryEntrySnapshot({
+ 'aliases': set({
+ }),
+ 'area_id': None,
+ 'capabilities': dict({
+ 'hvac_modes': list([
+ ,
+ ,
+ ]),
+ 'max_temp': 30.0,
+ 'min_temp': 5.0,
+ 'preset_modes': list([
+ 'auto',
+ 'day',
+ 'night',
+ ]),
+ 'target_temp_step': 0.2,
+ }),
+ 'config_entry_id': ,
+ 'device_class': None,
+ 'device_id': ,
+ 'disabled_by': None,
+ 'domain': 'climate',
+ 'entity_category': None,
+ 'entity_id': 'climate.buro',
+ 'has_entity_name': False,
+ 'hidden_by': None,
+ 'icon': None,
+ 'id': ,
+ 'labels': set({
+ }),
+ 'name': None,
+ 'options': dict({
+ }),
+ 'original_device_class': None,
+ 'original_icon': None,
+ 'original_name': 'Büro',
+ 'platform': 'moehlenhoff_alpha2',
+ 'previous_unique_id': None,
+ 'supported_features': ,
+ 'translation_key': None,
+ 'unique_id': 'Alpha2Test:1',
+ 'unit_of_measurement': None,
+ })
+# ---
+# name: test_climate[climate.buro-state]
+ StateSnapshot({
+ 'attributes': ReadOnlyDict({
+ 'current_temperature': 21.1,
+ 'friendly_name': 'Büro',
+ 'hvac_action': ,
+ 'hvac_modes': list([
+ ,
+ ,
+ ]),
+ 'max_temp': 30.0,
+ 'min_temp': 5.0,
+ 'preset_mode': 'day',
+ 'preset_modes': list([
+ 'auto',
+ 'day',
+ 'night',
+ ]),
+ 'supported_features': ,
+ 'target_temp_step': 0.2,
+ 'temperature': 21.0,
+ }),
+ 'context': ,
+ 'entity_id': 'climate.buro',
+ 'last_changed': ,
+ 'last_reported': ,
+ 'last_updated': ,
+ 'state': 'heat',
+ })
+# ---
diff --git a/tests/components/moehlenhoff_alpha2/snapshots/test_sensor.ambr b/tests/components/moehlenhoff_alpha2/snapshots/test_sensor.ambr
new file mode 100644
index 00000000000..3fee26a6ed5
--- /dev/null
+++ b/tests/components/moehlenhoff_alpha2/snapshots/test_sensor.ambr
@@ -0,0 +1,48 @@
+# serializer version: 1
+# name: test_sensors[sensor.buro_heat_control_1_valve_opening-entry]
+ EntityRegistryEntrySnapshot({
+ 'aliases': set({
+ }),
+ 'area_id': None,
+ 'capabilities': None,
+ 'config_entry_id': ,
+ 'device_class': None,
+ 'device_id': ,
+ 'disabled_by': None,
+ 'domain': 'sensor',
+ 'entity_category': None,
+ 'entity_id': 'sensor.buro_heat_control_1_valve_opening',
+ 'has_entity_name': False,
+ 'hidden_by': None,
+ 'icon': None,
+ 'id': ,
+ 'labels': set({
+ }),
+ 'name': None,
+ 'options': dict({
+ }),
+ 'original_device_class': None,
+ 'original_icon': None,
+ 'original_name': 'Büro heat control 1 valve opening',
+ 'platform': 'moehlenhoff_alpha2',
+ 'previous_unique_id': None,
+ 'supported_features': 0,
+ 'translation_key': None,
+ 'unique_id': 'Alpha2Test:1:valve_opening',
+ 'unit_of_measurement': '%',
+ })
+# ---
+# name: test_sensors[sensor.buro_heat_control_1_valve_opening-state]
+ StateSnapshot({
+ 'attributes': ReadOnlyDict({
+ 'friendly_name': 'Büro heat control 1 valve opening',
+ 'unit_of_measurement': '%',
+ }),
+ 'context': ,
+ 'entity_id': 'sensor.buro_heat_control_1_valve_opening',
+ 'last_changed': ,
+ 'last_reported': ,
+ 'last_updated': ,
+ 'state': '28',
+ })
+# ---
diff --git a/tests/components/moehlenhoff_alpha2/test_binary_sensor.py b/tests/components/moehlenhoff_alpha2/test_binary_sensor.py
new file mode 100644
index 00000000000..e650e9f9ba6
--- /dev/null
+++ b/tests/components/moehlenhoff_alpha2/test_binary_sensor.py
@@ -0,0 +1,28 @@
+"""Tests for the Moehlenhoff Alpha2 binary sensors."""
+
+from unittest.mock import patch
+
+from syrupy import SnapshotAssertion
+
+from homeassistant.const import Platform
+from homeassistant.core import HomeAssistant
+from homeassistant.helpers import entity_registry as er
+
+from . import init_integration
+
+from tests.common import snapshot_platform
+
+
+async def test_binary_sensors(
+ hass: HomeAssistant,
+ entity_registry: er.EntityRegistry,
+ snapshot: SnapshotAssertion,
+) -> None:
+ """Test binary sensors."""
+ with patch(
+ "homeassistant.components.moehlenhoff_alpha2.PLATFORMS",
+ [Platform.BINARY_SENSOR],
+ ):
+ entry = await init_integration(hass)
+
+ await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)
diff --git a/tests/components/moehlenhoff_alpha2/test_button.py b/tests/components/moehlenhoff_alpha2/test_button.py
new file mode 100644
index 00000000000..d4465746d53
--- /dev/null
+++ b/tests/components/moehlenhoff_alpha2/test_button.py
@@ -0,0 +1,28 @@
+"""Tests for the Moehlenhoff Alpha2 buttons."""
+
+from unittest.mock import patch
+
+from syrupy import SnapshotAssertion
+
+from homeassistant.const import Platform
+from homeassistant.core import HomeAssistant
+from homeassistant.helpers import entity_registry as er
+
+from . import init_integration
+
+from tests.common import snapshot_platform
+
+
+async def test_buttons(
+ hass: HomeAssistant,
+ entity_registry: er.EntityRegistry,
+ snapshot: SnapshotAssertion,
+) -> None:
+ """Test buttons."""
+ with patch(
+ "homeassistant.components.moehlenhoff_alpha2.PLATFORMS",
+ [Platform.BUTTON],
+ ):
+ entry = await init_integration(hass)
+
+ await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)
diff --git a/tests/components/moehlenhoff_alpha2/test_climate.py b/tests/components/moehlenhoff_alpha2/test_climate.py
new file mode 100644
index 00000000000..a32f2b5bd4f
--- /dev/null
+++ b/tests/components/moehlenhoff_alpha2/test_climate.py
@@ -0,0 +1,28 @@
+"""Tests for the Moehlenhoff Alpha2 climate."""
+
+from unittest.mock import patch
+
+from syrupy import SnapshotAssertion
+
+from homeassistant.const import Platform
+from homeassistant.core import HomeAssistant
+from homeassistant.helpers import entity_registry as er
+
+from . import init_integration
+
+from tests.common import snapshot_platform
+
+
+async def test_climate(
+ hass: HomeAssistant,
+ entity_registry: er.EntityRegistry,
+ snapshot: SnapshotAssertion,
+) -> None:
+ """Test climate."""
+ with patch(
+ "homeassistant.components.moehlenhoff_alpha2.PLATFORMS",
+ [Platform.CLIMATE],
+ ):
+ entry = await init_integration(hass)
+
+ await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)
diff --git a/tests/components/moehlenhoff_alpha2/test_config_flow.py b/tests/components/moehlenhoff_alpha2/test_config_flow.py
index 33c67421958..24697765901 100644
--- a/tests/components/moehlenhoff_alpha2/test_config_flow.py
+++ b/tests/components/moehlenhoff_alpha2/test_config_flow.py
@@ -7,21 +7,10 @@ from homeassistant.components.moehlenhoff_alpha2.const import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
+from . import MOCK_BASE_HOST, mock_update_data
+
from tests.common import MockConfigEntry
-MOCK_BASE_ID = "fake-base-id"
-MOCK_BASE_NAME = "fake-base-name"
-MOCK_BASE_HOST = "fake-base-host"
-
-
-async def mock_update_data(self):
- """Mock moehlenhoff_alpha2.Alpha2Base.update_data."""
- self.static_data = {
- "Devices": {
- "Device": {"ID": MOCK_BASE_ID, "NAME": MOCK_BASE_NAME, "HEATAREA": []}
- }
- }
-
async def test_form(hass: HomeAssistant) -> None:
"""Test we get the form."""
@@ -33,7 +22,10 @@ async def test_form(hass: HomeAssistant) -> None:
assert not result["errors"]
with (
- patch("moehlenhoff_alpha2.Alpha2Base.update_data", mock_update_data),
+ patch(
+ "homeassistant.components.moehlenhoff_alpha2.config_flow.Alpha2Base.update_data",
+ mock_update_data,
+ ),
patch(
"homeassistant.components.moehlenhoff_alpha2.async_setup_entry",
return_value=True,
@@ -46,7 +38,7 @@ async def test_form(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
assert result2["type"] is FlowResultType.CREATE_ENTRY
- assert result2["title"] == MOCK_BASE_NAME
+ assert result2["title"] == "Alpha2Test"
assert result2["data"] == {"host": MOCK_BASE_HOST}
assert len(mock_setup_entry.mock_calls) == 1
diff --git a/tests/components/moehlenhoff_alpha2/test_sensor.py b/tests/components/moehlenhoff_alpha2/test_sensor.py
new file mode 100644
index 00000000000..931c744faea
--- /dev/null
+++ b/tests/components/moehlenhoff_alpha2/test_sensor.py
@@ -0,0 +1,28 @@
+"""Tests for the Moehlenhoff Alpha2 sensors."""
+
+from unittest.mock import patch
+
+from syrupy import SnapshotAssertion
+
+from homeassistant.const import Platform
+from homeassistant.core import HomeAssistant
+from homeassistant.helpers import entity_registry as er
+
+from . import init_integration
+
+from tests.common import snapshot_platform
+
+
+async def test_sensors(
+ hass: HomeAssistant,
+ entity_registry: er.EntityRegistry,
+ snapshot: SnapshotAssertion,
+) -> None:
+ """Test sensors."""
+ with patch(
+ "homeassistant.components.moehlenhoff_alpha2.PLATFORMS",
+ [Platform.SENSOR],
+ ):
+ entry = await init_integration(hass)
+
+ await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)