mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Add diagnostics download to goodwe integration (#102928)
* Add diagnostics download to goodwe integration * Revert change not related to test * Use MagicMock for mock inverter * Use spec with mock
This commit is contained in:
parent
22b2c588eb
commit
0548f9f342
35
homeassistant/components/goodwe/diagnostics.py
Normal file
35
homeassistant/components/goodwe/diagnostics.py
Normal file
@ -0,0 +1,35 @@
|
||||
"""Diagnostics support for Goodwe."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from goodwe import Inverter
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DOMAIN, KEY_INVERTER
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
inverter: Inverter = hass.data[DOMAIN][config_entry.entry_id][KEY_INVERTER]
|
||||
|
||||
diagnostics_data = {
|
||||
"config_entry": config_entry.as_dict(),
|
||||
"inverter": {
|
||||
"model_name": inverter.model_name,
|
||||
"rated_power": inverter.rated_power,
|
||||
"firmware": inverter.firmware,
|
||||
"arm_firmware": inverter.arm_firmware,
|
||||
"dsp1_version": inverter.dsp1_version,
|
||||
"dsp2_version": inverter.dsp2_version,
|
||||
"dsp_svn_version": inverter.dsp_svn_version,
|
||||
"arm_version": inverter.arm_version,
|
||||
"arm_svn_version": inverter.arm_svn_version,
|
||||
},
|
||||
}
|
||||
|
||||
return diagnostics_data
|
25
tests/components/goodwe/conftest.py
Normal file
25
tests/components/goodwe/conftest.py
Normal file
@ -0,0 +1,25 @@
|
||||
"""Fixtures for the Aladdin Connect integration tests."""
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
from goodwe import Inverter
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture(name="mock_inverter")
|
||||
def fixture_mock_inverter():
|
||||
"""Set up inverter fixture."""
|
||||
mock_inverter = MagicMock(spec=Inverter)
|
||||
mock_inverter.serial_number = "dummy_serial_nr"
|
||||
mock_inverter.arm_version = 1
|
||||
mock_inverter.arm_svn_version = 2
|
||||
mock_inverter.arm_firmware = "dummy.arm.version"
|
||||
mock_inverter.firmware = "dummy.fw.version"
|
||||
mock_inverter.model_name = "MOCK"
|
||||
mock_inverter.rated_power = 10000
|
||||
mock_inverter.dsp1_version = 3
|
||||
mock_inverter.dsp2_version = 4
|
||||
mock_inverter.dsp_svn_version = 5
|
||||
|
||||
mock_inverter.read_runtime_data = AsyncMock(return_value={})
|
||||
|
||||
return mock_inverter
|
33
tests/components/goodwe/snapshots/test_diagnostics.ambr
Normal file
33
tests/components/goodwe/snapshots/test_diagnostics.ambr
Normal file
@ -0,0 +1,33 @@
|
||||
# serializer version: 1
|
||||
# name: test_entry_diagnostics
|
||||
dict({
|
||||
'config_entry': dict({
|
||||
'data': dict({
|
||||
'host': 'localhost',
|
||||
'model_family': 'ET',
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'domain': 'goodwe',
|
||||
'entry_id': '3bd2acb0e4f0476d40865546d0d91921',
|
||||
'options': dict({
|
||||
}),
|
||||
'pref_disable_new_entities': False,
|
||||
'pref_disable_polling': False,
|
||||
'source': 'user',
|
||||
'title': 'Mock Title',
|
||||
'unique_id': None,
|
||||
'version': 1,
|
||||
}),
|
||||
'inverter': dict({
|
||||
'arm_firmware': 'dummy.arm.version',
|
||||
'arm_svn_version': 2,
|
||||
'arm_version': 1,
|
||||
'dsp1_version': 3,
|
||||
'dsp2_version': 4,
|
||||
'dsp_svn_version': 5,
|
||||
'firmware': 'dummy.fw.version',
|
||||
'model_name': 'MOCK',
|
||||
'rated_power': 10000,
|
||||
}),
|
||||
})
|
||||
# ---
|
34
tests/components/goodwe/test_diagnostics.py
Normal file
34
tests/components/goodwe/test_diagnostics.py
Normal file
@ -0,0 +1,34 @@
|
||||
"""Test the CO2Signal diagnostics."""
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.goodwe import CONF_MODEL_FAMILY, DOMAIN
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
mock_inverter: MagicMock,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={CONF_HOST: "localhost", CONF_MODEL_FAMILY: "ET"},
|
||||
entry_id="3bd2acb0e4f0476d40865546d0d91921",
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
with patch("homeassistant.components.goodwe.connect", return_value=mock_inverter):
|
||||
assert await async_setup_component(hass, DOMAIN, {})
|
||||
|
||||
result = await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
||||
assert result == snapshot
|
Loading…
x
Reference in New Issue
Block a user