Add configurable optimizer area sensors
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from homeassistant import config_entries
|
||||
@@ -9,9 +10,11 @@ from homeassistant.const import CONF_URL
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
from homeassistant.helpers.service_info.hassio import HassioServiceInfo
|
||||
from pytest_homeassistant_custom_component.common import MockConfigEntry
|
||||
|
||||
from custom_components.solaredge_optimizers.api import parse_snapshot
|
||||
from custom_components.solaredge_optimizers.const import (
|
||||
CONF_AREA_MAPPING,
|
||||
CONF_SCAN_INTERVAL,
|
||||
DOMAIN,
|
||||
)
|
||||
@@ -68,3 +71,55 @@ async def test_hassio_discovery_flow(hass: HomeAssistant) -> None:
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["data"][CONF_URL] == "http://abc-solaredge-optimizer-data:8099"
|
||||
|
||||
|
||||
async def test_options_flow_configures_areas(hass: HomeAssistant) -> None:
|
||||
"""Configure area mappings through the options flow."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title="SolarEdge Site 4886699",
|
||||
unique_id="4886699",
|
||||
data={CONF_URL: "http://app:8099", CONF_SCAN_INTERVAL: 600},
|
||||
version=2,
|
||||
)
|
||||
entry.runtime_data = SimpleNamespace(data=parse_snapshot(SAMPLE_PAYLOAD))
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.options.async_init(entry.entry_id)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_AREA_MAPPING: {"west": ["1.1.1", "1.1.2"]}},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert entry.options[CONF_AREA_MAPPING] == {"west": ["1.1.1", "1.1.2"]}
|
||||
|
||||
|
||||
async def test_options_flow_rejects_duplicate_optimizer(hass: HomeAssistant) -> None:
|
||||
"""Reject assigning one optimizer to multiple areas."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title="SolarEdge Site 4886699",
|
||||
unique_id="4886699",
|
||||
data={CONF_URL: "http://app:8099", CONF_SCAN_INTERVAL: 600},
|
||||
version=2,
|
||||
)
|
||||
entry.runtime_data = SimpleNamespace(data=parse_snapshot(SAMPLE_PAYLOAD))
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.options.async_init(entry.entry_id)
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_AREA_MAPPING: {
|
||||
"west": ["1.1.1"],
|
||||
"roof": ["1.1.1"],
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {"base": "duplicate_optimizer"}
|
||||
|
||||
Reference in New Issue
Block a user