mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 04:50:05 +00:00
* Initial commit prototype with empty inverters * Use modern methods and global variable for character strings * Platform that get the value of the meter in an entity * Add check if inverter already configured * Add tests for config_flow * Update "imeon_inverter_api" in manifest.json * Update "imeon_inverter_api" in requirements_all.txt * Remove async_setup, clean comments, use of const PLATFORM * Use of global variable and remove configuration of device name * Use of entry.data instead of user_input variable * Remove services.yaml * No quality scale * Use of common string * Add sensors, use of EntityDescription and '_attr_device_info' * Remove name from config_flow tests * Use sentence case and change integration from hub to device * Check connection before add platform in config_flow * Use of _async_setup and minor changes * Improve sensor description * Add quality_scale.yaml * Update the quality_scale.json * Add tests for host invalid, route invalid, exception and invalid auth * Type more precisely 'DataUpdateCoordinator' * Don't use 'self.data' directly in coordinator and minor corrections * Complete full quality_scale.yaml * Use of fixtures in the tests * Add snapshot tests for sensors * Refactor the try except and use serial as unique id * Change API version * Add test for sensor * Mock the api to generate the snapshot * New type for async_add_entries * Except timeout error for get_serial * Add test for get_serial timeout error * Move store data out of the try * Use sentence case * Use of fixtures * Use separates fixtures * Mock the api * Put sensors fake data in json fixture file * Use of a const interval, remove except timeout, enhance lisibility * Try to use same fixture in test_config_flow * Try use same fixture for all mock of inverter * Modify the fixture in the context manager, correct the tests * Fixture return mock.__aenter__ directly * Adjust code clarity * Bring all tests to either ABORT or CREATE_ENTRY * Make the try except more concise * Synthetize exception tests into one * Add code clarity * Nitpick with the tests * Use unique id sensor * Log an error on unknown error * Remove useless comments, disable always_update and better use of timeout * Adjust units, set the model and software version * Set full name for Battery SOC and use ip instead of url * Use of host instead of IP * Fix the unit of economy factor * Reduce mornitoring data display precision and update snapshots * Remove unused variable HUBs * Fix device info * Set address label 'Host or IP' * Fix the config_flow tests * Re evaluate the quality_scale * Use of 'host' instead of 'address' * Make inverter discoverable by ssdp * Add test ssdp configuration already exist * Add exemption in quality scale * Test abort ssdp if serial is unknown * Handle update error * Raise other exceptions * Handle ClientError and ValueError from the api * Update homeassistant/components/imeon_inverter/quality_scale.yaml --------- Co-authored-by: Franck Nijhof <git@frenck.dev> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Josef Zweck <josef@zweck.dev>
86 lines
2.4 KiB
Python
86 lines
2.4 KiB
Python
"""Configuration for the Imeon Inverter integration tests."""
|
|
|
|
from collections.abc import Generator
|
|
from unittest.mock import AsyncMock, MagicMock
|
|
|
|
import pytest
|
|
|
|
from homeassistant.components.imeon_inverter.const import DOMAIN
|
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
|
from homeassistant.helpers.service_info.ssdp import (
|
|
ATTR_UPNP_DEVICE_TYPE,
|
|
ATTR_UPNP_FRIENDLY_NAME,
|
|
ATTR_UPNP_MANUFACTURER,
|
|
ATTR_UPNP_MODEL_NAME,
|
|
ATTR_UPNP_SERIAL,
|
|
ATTR_UPNP_UDN,
|
|
SsdpServiceInfo,
|
|
)
|
|
|
|
from tests.common import MockConfigEntry, load_json_object_fixture, patch
|
|
|
|
# Sample test data
|
|
TEST_USER_INPUT = {
|
|
CONF_HOST: "192.168.200.1",
|
|
CONF_USERNAME: "user@local",
|
|
CONF_PASSWORD: "password",
|
|
}
|
|
|
|
TEST_SERIAL = "111111111111111"
|
|
|
|
TEST_DISCOVER = SsdpServiceInfo(
|
|
ssdp_usn="mock_usn",
|
|
ssdp_st="mock_st",
|
|
ssdp_location=f"http://{TEST_USER_INPUT[CONF_HOST]}:8088/imeon.xml",
|
|
upnp={
|
|
ATTR_UPNP_MANUFACTURER: "IMEON",
|
|
ATTR_UPNP_MODEL_NAME: "IMEON",
|
|
ATTR_UPNP_FRIENDLY_NAME: f"IMEON-{TEST_SERIAL}",
|
|
ATTR_UPNP_SERIAL: TEST_SERIAL,
|
|
ATTR_UPNP_UDN: "uuid:01234567-89ab-cdef-0123-456789abcdef",
|
|
ATTR_UPNP_DEVICE_TYPE: "urn:schemas-upnp-org:device:Basic:1",
|
|
},
|
|
)
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def mock_imeon_inverter() -> Generator[MagicMock]:
|
|
"""Mock data from the device."""
|
|
with (
|
|
patch(
|
|
"homeassistant.components.imeon_inverter.coordinator.Inverter",
|
|
autospec=True,
|
|
) as inverter_mock,
|
|
patch(
|
|
"homeassistant.components.imeon_inverter.config_flow.Inverter",
|
|
new=inverter_mock,
|
|
),
|
|
):
|
|
inverter = inverter_mock.return_value
|
|
inverter.__aenter__.return_value = inverter
|
|
inverter.login.return_value = True
|
|
inverter.get_serial.return_value = TEST_SERIAL
|
|
inverter.storage = load_json_object_fixture("sensor_data.json", DOMAIN)
|
|
yield inverter
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_async_setup_entry() -> Generator[AsyncMock]:
|
|
"""Fixture for mocking async_setup_entry."""
|
|
with patch(
|
|
"homeassistant.components.imeon_inverter.async_setup_entry",
|
|
return_value=True,
|
|
) as mock:
|
|
yield mock
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_config_entry() -> MockConfigEntry:
|
|
"""Mock a config entry."""
|
|
return MockConfigEntry(
|
|
title="Imeon inverter",
|
|
domain=DOMAIN,
|
|
data=TEST_USER_INPUT,
|
|
unique_id=TEST_SERIAL,
|
|
)
|