100% test coverage for Fronius integration (#60515)

* support for multiple fixture sets

* add test data from Fronius Gen24 device

* test Gen24 with Storage

* test Gen24 inverter without storage

* 100% coverage

* copy&paste fail
pull/60115/head
Matthias Alphart 2021-11-29 09:15:10 +01:00 committed by GitHub
parent ef8cf9e597
commit 823c37f4c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 831 additions and 77 deletions

View File

@ -1,6 +1,8 @@
"""Tests for the Fronius integration."""
from homeassistant.components.fronius.const import DOMAIN
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.util import dt
@ -11,14 +13,16 @@ MOCK_HOST = "http://fronius"
MOCK_UID = "123.4567890" # has to match mocked logger unique_id
async def setup_fronius_integration(hass):
async def setup_fronius_integration(
hass: HomeAssistant, is_logger: bool = True
) -> ConfigEntry:
"""Create the Fronius integration."""
entry = MockConfigEntry(
domain=DOMAIN,
unique_id=MOCK_UID,
data={
CONF_HOST: MOCK_HOST,
"is_logger": True,
"is_logger": is_logger,
},
)
entry.add_to_hass(hass)
@ -30,48 +34,50 @@ async def setup_fronius_integration(hass):
def mock_responses(
aioclient_mock: AiohttpClientMocker,
host: str = MOCK_HOST,
fixture_set: str = "symo",
night: bool = False,
) -> None:
"""Mock responses for Fronius Symo inverter with meter."""
aioclient_mock.clear_requests()
_day_or_night = "night" if night else "day"
_night = "_night" if night else ""
aioclient_mock.get(
f"{host}/solar_api/GetAPIVersion.cgi",
text=load_fixture("symo/GetAPIVersion.json", "fronius"),
text=load_fixture(f"{fixture_set}/GetAPIVersion.json", "fronius"),
)
aioclient_mock.get(
f"{host}/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&"
"DeviceId=1&DataCollection=CommonInverterData",
text=load_fixture(
f"symo/GetInverterRealtimeDate_Device_1_{_day_or_night}.json", "fronius"
f"{fixture_set}/GetInverterRealtimeData_Device_1{_night}.json",
"fronius",
),
)
aioclient_mock.get(
f"{host}/solar_api/v1/GetInverterInfo.cgi",
text=load_fixture("symo/GetInverterInfo.json", "fronius"),
text=load_fixture(f"{fixture_set}/GetInverterInfo.json", "fronius"),
)
aioclient_mock.get(
f"{host}/solar_api/v1/GetLoggerInfo.cgi",
text=load_fixture("symo/GetLoggerInfo.json", "fronius"),
)
aioclient_mock.get(
f"{host}/solar_api/v1/GetMeterRealtimeData.cgi?Scope=Device&DeviceId=0",
text=load_fixture("symo/GetMeterRealtimeData_Device_0.json", "fronius"),
text=load_fixture(f"{fixture_set}/GetLoggerInfo.json", "fronius"),
)
aioclient_mock.get(
f"{host}/solar_api/v1/GetMeterRealtimeData.cgi?Scope=System",
text=load_fixture("symo/GetMeterRealtimeData_System.json", "fronius"),
text=load_fixture(f"{fixture_set}/GetMeterRealtimeData.json", "fronius"),
)
aioclient_mock.get(
f"{host}/solar_api/v1/GetPowerFlowRealtimeData.fcgi",
text=load_fixture(
f"symo/GetPowerFlowRealtimeData_{_day_or_night}.json", "fronius"
f"{fixture_set}/GetPowerFlowRealtimeData{_night}.json", "fronius"
),
)
aioclient_mock.get(
f"{host}/solar_api/v1/GetStorageRealtimeData.cgi?Scope=System",
text=load_fixture("symo/GetStorageRealtimeData_System.json", "fronius"),
text=load_fixture(f"{fixture_set}/GetStorageRealtimeData.json", "fronius"),
)
aioclient_mock.get(
f"{host}/solar_api/v1/GetOhmPilotRealtimeData.cgi?Scope=System",
text=load_fixture(f"{fixture_set}/GetOhmPilotRealtimeData.json", "fronius"),
)

View File

@ -0,0 +1,5 @@
{
"APIVersion" : 1,
"BaseURL" : "/solar_api/v1/",
"CompatibilityRange" : "1.7-3"
}

View File

@ -0,0 +1,25 @@
{
"Body" : {
"Data" : {
"1" : {
"CustomName" : "Inverter name",
"DT" : 1,
"ErrorCode" : 0,
"InverterState" : "Running",
"PVPower" : 9360,
"Show" : 1,
"StatusCode" : 7,
"UniqueID" : "12345678"
}
}
},
"Head" : {
"RequestArguments" : {},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2021-11-26T11:07:53+00:00"
}
}

View File

@ -0,0 +1,80 @@
{
"Body" : {
"Data" : {
"DAY_ENERGY" : {
"Unit" : "Wh",
"Value" : null
},
"DeviceStatus" : {
"ErrorCode" : 0,
"InverterState" : "Running",
"StatusCode" : 7
},
"FAC" : {
"Unit" : "Hz",
"Value" : 49.99169921875
},
"IAC" : {
"Unit" : "A",
"Value" : 0.15894582867622375
},
"IDC" : {
"Unit" : "A",
"Value" : 0.078323781490325928
},
"IDC_2" : {
"Unit" : "A",
"Value" : 0.075399093329906464
},
"IDC_3" : {
"Unit" : "A",
"Value" : null
},
"PAC" : {
"Unit" : "W",
"Value" : 37.320449829101562
},
"SAC" : {
"Unit" : "VA",
"Value" : 37.40447998046875
},
"TOTAL_ENERGY" : {
"Unit" : "Wh",
"Value" : 1530193.4199999999
},
"UAC" : {
"Unit" : "V",
"Value" : 234.91676330566406
},
"UDC" : {
"Unit" : "V",
"Value" : 411.38107299804688
},
"UDC_2" : {
"Unit" : "V",
"Value" : 403.43124389648438
},
"UDC_3" : {
"Unit" : "V",
"Value" : null
},
"YEAR_ENERGY" : {
"Unit" : "Wh",
"Value" : null
}
}
},
"Head" : {
"RequestArguments" : {
"DataCollection" : "CommonInverterData",
"DeviceId" : "1",
"Scope" : "Device"
},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2021-11-26T11:07:53+00:00"
}
}

View File

@ -0,0 +1,14 @@
{
"Body" : {
"Data" : {}
},
"Head" : {
"RequestArguments" : {},
"Status" : {
"Code" : 11,
"Reason" : "v1/GetLoggerInfo.cgi request is not supported.",
"UserMessage" : ""
},
"Timestamp" : "2021-11-26T11:07:53+00:00"
}
}

View File

@ -0,0 +1,61 @@
{
"Body" : {
"Data" : {
"0" : {
"Current_AC_Phase_1" : 1.145,
"Current_AC_Phase_2" : 2.3300000000000001,
"Current_AC_Phase_3" : 1.825,
"Current_AC_Sum" : 5.2999999999999998,
"Details" : {
"Manufacturer" : "Fronius",
"Model" : "Smart Meter TS 65A-3",
"Serial" : "1234567890"
},
"Enable" : 1,
"EnergyReactive_VArAC_Sum_Consumed" : 88221.0,
"EnergyReactive_VArAC_Sum_Produced" : 1989125.0,
"EnergyReal_WAC_Minus_Absolute" : 3863340.0,
"EnergyReal_WAC_Plus_Absolute" : 2013105.0,
"EnergyReal_WAC_Sum_Consumed" : 2013105.0,
"EnergyReal_WAC_Sum_Produced" : 3863340.0,
"Frequency_Phase_Average" : 49.899999999999999,
"Meter_Location_Current" : 0.0,
"PowerApparent_S_Phase_1" : 243.30000000000001,
"PowerApparent_S_Phase_2" : 323.39999999999998,
"PowerApparent_S_Phase_3" : 301.19999999999999,
"PowerApparent_S_Sum" : 868.0,
"PowerFactor_Phase_1" : 0.441,
"PowerFactor_Phase_2" : 0.93400000000000005,
"PowerFactor_Phase_3" : 0.83199999999999996,
"PowerFactor_Sum" : 0.82799999999999996,
"PowerReactive_Q_Phase_1" : -218.59999999999999,
"PowerReactive_Q_Phase_2" : -132.80000000000001,
"PowerReactive_Q_Phase_3" : -166.0,
"PowerReactive_Q_Sum" : -517.39999999999998,
"PowerReal_P_Phase_1" : 106.8,
"PowerReal_P_Phase_2" : 294.89999999999998,
"PowerReal_P_Phase_3" : 251.30000000000001,
"PowerReal_P_Sum" : 653.10000000000002,
"TimeStamp" : 1637924872.0,
"Visible" : 1.0,
"Voltage_AC_PhaseToPhase_12" : 408.69999999999999,
"Voltage_AC_PhaseToPhase_23" : 409.60000000000002,
"Voltage_AC_PhaseToPhase_31" : 409.39999999999998,
"Voltage_AC_Phase_1" : 235.90000000000001,
"Voltage_AC_Phase_2" : 236.09999999999999,
"Voltage_AC_Phase_3" : 236.90000000000001
}
}
},
"Head" : {
"RequestArguments" : {
"Scope" : "System"
},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2021-11-26T11:07:52+00:00"
}
}

View File

@ -0,0 +1,16 @@
{
"Body" : {
"Data" : {}
},
"Head" : {
"RequestArguments" : {
"Scope" : "System"
},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2021-11-26T11:07:53+00:00"
}
}

View File

@ -0,0 +1,45 @@
{
"Body" : {
"Data" : {
"Inverters" : {
"1" : {
"Battery_Mode" : "disabled",
"DT" : 1,
"E_Day" : null,
"E_Total" : 1530193.4199999999,
"E_Year" : null,
"P" : 37.320449829101562,
"SOC" : 0.0
}
},
"Site" : {
"BackupMode" : false,
"BatteryStandby" : false,
"E_Day" : null,
"E_Total" : 1530193.4199999999,
"E_Year" : null,
"Meter_Location" : "grid",
"Mode" : "meter",
"P_Akku" : null,
"P_Grid" : 658.39999999999998,
"P_Load" : -695.68274917602537,
"P_PV" : 62.948148727416992,
"rel_Autonomy" : 5.3591596485874495,
"rel_SelfConsumption" : 100.0
},
"Smartloads" : {
"Ohmpilots" : {}
},
"Version" : "12"
}
},
"Head" : {
"RequestArguments" : {},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2021-11-26T11:07:53+00:00"
}
}

View File

@ -0,0 +1,16 @@
{
"Body" : {
"Data" : {}
},
"Head" : {
"RequestArguments" : {
"Scope" : "System"
},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2021-11-26T11:07:52+00:00"
}
}

View File

@ -0,0 +1,5 @@
{
"APIVersion" : 1,
"BaseURL" : "/solar_api/v1/",
"CompatibilityRange" : "1.7-3"
}

View File

@ -0,0 +1,25 @@
{
"Body" : {
"Data" : {
"1" : {
"CustomName" : "Gen24 Storage",
"DT" : 1,
"ErrorCode" : 0,
"InverterState" : "Running",
"PVPower" : 13930,
"Show" : 1,
"StatusCode" : 7,
"UniqueID" : "12345678"
}
}
},
"Head" : {
"RequestArguments" : {},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2021-11-28T13:12:59+00:00"
}
}

View File

@ -0,0 +1,80 @@
{
"Body" : {
"Data" : {
"DAY_ENERGY" : {
"Unit" : "Wh",
"Value" : null
},
"DeviceStatus" : {
"ErrorCode" : 0,
"InverterState" : "Running",
"StatusCode" : 7
},
"FAC" : {
"Unit" : "Hz",
"Value" : 49.981552124023438
},
"IAC" : {
"Unit" : "A",
"Value" : 1.1086627244949341
},
"IDC" : {
"Unit" : "A",
"Value" : 0.39519637823104858
},
"IDC_2" : {
"Unit" : "A",
"Value" : 0.35640031099319458
},
"IDC_3" : {
"Unit" : "A",
"Value" : null
},
"PAC" : {
"Unit" : "W",
"Value" : 250.90925598144531
},
"SAC" : {
"Unit" : "VA",
"Value" : 250.9410400390625
},
"TOTAL_ENERGY" : {
"Unit" : "Wh",
"Value" : 7512794.0116666667
},
"UAC" : {
"Unit" : "V",
"Value" : 227.35398864746094
},
"UDC" : {
"Unit" : "V",
"Value" : 419.10092163085938
},
"UDC_2" : {
"Unit" : "V",
"Value" : 318.81027221679688
},
"UDC_3" : {
"Unit" : "V",
"Value" : null
},
"YEAR_ENERGY" : {
"Unit" : "Wh",
"Value" : null
}
}
},
"Head" : {
"RequestArguments" : {
"DataCollection" : "CommonInverterData",
"DeviceId" : "1",
"Scope" : "Device"
},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2021-11-28T13:51:45+00:00"
}
}

View File

@ -0,0 +1,14 @@
{
"Body" : {
"Data" : {}
},
"Head" : {
"RequestArguments" : {},
"Status" : {
"Code" : 11,
"Reason" : "v1/GetLoggerInfo.cgi request is not supported.",
"UserMessage" : ""
},
"Timestamp" : "2021-11-28T13:17:43+00:00"
}
}

View File

@ -0,0 +1,61 @@
{
"Body" : {
"Data" : {
"0" : {
"Current_AC_Phase_1" : 1.7010000000000001,
"Current_AC_Phase_2" : 1.8320000000000001,
"Current_AC_Phase_3" : 0.64500000000000002,
"Current_AC_Sum" : 4.1780000000000008,
"Details" : {
"Manufacturer" : "Fronius",
"Model" : "Smart Meter TS 65A-3",
"Serial" : "1234567890"
},
"Enable" : 1,
"EnergyReactive_VArAC_Sum_Consumed" : 5482.0,
"EnergyReactive_VArAC_Sum_Produced" : 3266105.0,
"EnergyReal_WAC_Minus_Absolute" : 1705128.0,
"EnergyReal_WAC_Plus_Absolute" : 1247204.0,
"EnergyReal_WAC_Sum_Consumed" : 1247204.0,
"EnergyReal_WAC_Sum_Produced" : 1705128.0,
"Frequency_Phase_Average" : 49.899999999999999,
"Meter_Location_Current" : 0.0,
"PowerApparent_S_Phase_1" : 319.5,
"PowerApparent_S_Phase_2" : 383.89999999999998,
"PowerApparent_S_Phase_3" : 118.40000000000001,
"PowerApparent_S_Sum" : 821.89999999999998,
"PowerFactor_Phase_1" : 0.995,
"PowerFactor_Phase_2" : 0.38900000000000001,
"PowerFactor_Phase_3" : 0.16300000000000001,
"PowerFactor_Sum" : 0.69799999999999995,
"PowerReactive_Q_Phase_1" : -31.300000000000001,
"PowerReactive_Q_Phase_2" : -353.39999999999998,
"PowerReactive_Q_Phase_3" : -116.7,
"PowerReactive_Q_Sum" : -501.5,
"PowerReal_P_Phase_1" : 317.89999999999998,
"PowerReal_P_Phase_2" : 150.0,
"PowerReal_P_Phase_3" : 19.600000000000001,
"PowerReal_P_Sum" : 487.69999999999999,
"TimeStamp" : 1638104813.0,
"Visible" : 1.0,
"Voltage_AC_PhaseToPhase_12" : 396.0,
"Voltage_AC_PhaseToPhase_23" : 393.0,
"Voltage_AC_PhaseToPhase_31" : 394.30000000000001,
"Voltage_AC_Phase_1" : 229.40000000000001,
"Voltage_AC_Phase_2" : 225.59999999999999,
"Voltage_AC_Phase_3" : 228.30000000000001
}
}
},
"Head" : {
"RequestArguments" : {
"Scope" : "System"
},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2021-11-28T13:06:54+00:00"
}
}

View File

@ -0,0 +1,30 @@
{
"Body" : {
"Data" : {
"0" : {
"CodeOfState" : 0.0,
"Details" : {
"Hardware" : "6",
"Manufacturer" : "Fronius",
"Model" : "Ohmpilot",
"Serial" : "23456789",
"Software" : "1.0.25-3"
},
"EnergyReal_WAC_Sum_Consumed" : 1233295.0,
"PowerReal_PAC_Sum" : 0.0,
"Temperature_Channel_1" : 38.899999999999999
}
}
},
"Head" : {
"RequestArguments" : {
"Scope" : "System"
},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2021-11-28T13:11:42+00:00"
}
}

View File

@ -0,0 +1,51 @@
{
"Body" : {
"Data" : {
"Inverters" : {
"1" : {
"Battery_Mode" : "suspended",
"DT" : 1,
"E_Day" : null,
"E_Total" : 7512664.4041666668,
"E_Year" : null,
"P" : 186.54914855957031,
"SOC" : 4.5999999999999996
}
},
"Site" : {
"BackupMode" : true,
"BatteryStandby" : false,
"E_Day" : null,
"E_Total" : 7512664.4041666668,
"E_Year" : null,
"Meter_Location" : "grid",
"Mode" : "bidirectional",
"P_Akku" : 0.15907810628414154,
"P_Grid" : 2274.9000000000001,
"P_Load" : -2459.3092254638673,
"P_PV" : 216.43276786804199,
"rel_Autonomy" : 7.4984155532163506,
"rel_SelfConsumption" : 100.0
},
"Smartloads" : {
"Ohmpilots" : {
"0" : {
"P_AC_Total" : 0.0,
"State" : "normal",
"Temperature" : 38.799999999999997
}
}
},
"Version" : "12"
}
},
"Head" : {
"RequestArguments" : {},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2021-11-28T13:12:20+00:00"
}
}

View File

@ -0,0 +1,36 @@
{
"Body" : {
"Data" : {
"0" : {
"Controller" : {
"Capacity_Maximum" : 16588,
"Current_DC" : 0.0,
"DesignedCapacity" : 16588,
"Details" : {
"Manufacturer" : "BYD",
"Model" : "BYD Battery-Box Premium HV",
"Serial" : "P030T020Z2001234567 "
},
"Enable" : 1,
"StateOfCharge_Relative" : 4.5999999999999996,
"Status_BatteryCell" : 0.0,
"Temperature_Cell" : 21.5,
"TimeStamp" : 1638105056.0,
"Voltage_DC" : 0.0
},
"Modules" : []
}
}
},
"Head" : {
"RequestArguments" : {
"Scope" : "System"
},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2021-11-28T13:10:57+00:00"
}
}

View File

@ -1,60 +0,0 @@
{
"Body": {
"Data": {
"Current_AC_Phase_1": 7.7549999999999999,
"Current_AC_Phase_2": 6.6799999999999997,
"Current_AC_Phase_3": 10.102,
"Details": {
"Manufacturer": "Fronius",
"Model": "Smart Meter 63A",
"Serial": "12345678"
},
"Enable": 1,
"EnergyReactive_VArAC_Sum_Consumed": 59960790,
"EnergyReactive_VArAC_Sum_Produced": 723160,
"EnergyReal_WAC_Minus_Absolute": 35623065,
"EnergyReal_WAC_Plus_Absolute": 15303334,
"EnergyReal_WAC_Sum_Consumed": 15303334,
"EnergyReal_WAC_Sum_Produced": 35623065,
"Frequency_Phase_Average": 50,
"Meter_Location_Current": 0,
"PowerApparent_S_Phase_1": 1772.7929999999999,
"PowerApparent_S_Phase_2": 1527.048,
"PowerApparent_S_Phase_3": 2333.5619999999999,
"PowerApparent_S_Sum": 5592.5699999999997,
"PowerFactor_Phase_1": -0.98999999999999999,
"PowerFactor_Phase_2": -0.98999999999999999,
"PowerFactor_Phase_3": 0.98999999999999999,
"PowerFactor_Sum": 1,
"PowerReactive_Q_Phase_1": 51.479999999999997,
"PowerReactive_Q_Phase_2": 115.63,
"PowerReactive_Q_Phase_3": -164.24000000000001,
"PowerReactive_Q_Sum": 2.8700000000000001,
"PowerReal_P_Phase_1": 1765.55,
"PowerReal_P_Phase_2": 1515.8,
"PowerReal_P_Phase_3": 2311.2199999999998,
"PowerReal_P_Sum": 5592.5699999999997,
"TimeStamp": 1633977078,
"Visible": 1,
"Voltage_AC_PhaseToPhase_12": 395.89999999999998,
"Voltage_AC_PhaseToPhase_23": 398,
"Voltage_AC_PhaseToPhase_31": 398,
"Voltage_AC_Phase_1": 228.59999999999999,
"Voltage_AC_Phase_2": 228.59999999999999,
"Voltage_AC_Phase_3": 231
}
},
"Head": {
"RequestArguments": {
"DeviceClass": "Meter",
"DeviceId": "0",
"Scope": "Device"
},
"Status": {
"Code": 0,
"Reason": "",
"UserMessage": ""
},
"Timestamp": "2021-10-11T20:31:18+02:00"
}
}

View File

@ -0,0 +1,17 @@
{
"Body" : {
"Data" : {}
},
"Head" : {
"RequestArguments" : {
"DeviceClass" : "OhmPilot",
"Scope" : "System"
},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2021-11-28T22:36:04+01:00"
}
}

View File

@ -1,4 +1,8 @@
"""Test the Fronius integration."""
from unittest.mock import patch
from pyfronius import FroniusError
from homeassistant.components.fronius.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState
@ -21,3 +25,22 @@ async def test_unload_config_entry(hass, aioclient_mock):
assert test_entry.state is ConfigEntryState.NOT_LOADED
assert not hass.data.get(DOMAIN)
async def test_logger_error(hass, aioclient_mock):
"""Test setup when logger reports an error."""
# gen24 dataset will raise FroniusError when logger is called
mock_responses(aioclient_mock, fixture_set="gen24")
config_entry = await setup_fronius_integration(hass, is_logger=True)
assert config_entry.state is ConfigEntryState.SETUP_RETRY
async def test_inverter_error(hass, aioclient_mock):
"""Test setup when inverter_info reports an error."""
mock_responses(aioclient_mock)
with patch(
"pyfronius.Fronius.inverter_info",
side_effect=FroniusError,
):
config_entry = await setup_fronius_integration(hass)
assert config_entry.state is ConfigEntryState.SETUP_RETRY

View File

@ -57,6 +57,17 @@ async def test_symo_inverter(hass, aioclient_mock):
assert_state("sensor.power_ac_fronius_inverter_1_http_fronius", 1190)
assert_state("sensor.voltage_ac_fronius_inverter_1_http_fronius", 227.90)
# Third test at nighttime - additional AC entities aren't changed
mock_responses(aioclient_mock, night=True)
async_fire_time_changed(
hass, dt.utcnow() + FroniusInverterUpdateCoordinator.default_interval
)
await hass.async_block_till_done()
assert_state("sensor.current_ac_fronius_inverter_1_http_fronius", 5.19)
assert_state("sensor.frequency_ac_fronius_inverter_1_http_fronius", 49.94)
assert_state("sensor.power_ac_fronius_inverter_1_http_fronius", 1190)
assert_state("sensor.voltage_ac_fronius_inverter_1_http_fronius", 227.90)
async def test_symo_logger(hass, aioclient_mock):
"""Test Fronius Symo logger entities."""
@ -75,7 +86,7 @@ async def test_symo_logger(hass, aioclient_mock):
# software_version, time_zone, time_zone_location
# time_stamp, unique_identifier, utc_offset
#
# states are rounded to 2 decimals
# states are rounded to 4 decimals
assert_state(
"sensor.cash_factor_fronius_logger_info_0_http_fronius",
0.078,
@ -109,7 +120,7 @@ async def test_symo_meter(hass, aioclient_mock):
# ignored entities:
# manufacturer, model, serial, enable, timestamp, visible, meter_location
#
# states are rounded to 2 decimals
# states are rounded to 4 decimals
assert_state("sensor.current_ac_phase_1_fronius_meter_0_http_fronius", 7.755)
assert_state("sensor.current_ac_phase_2_fronius_meter_0_http_fronius", 6.68)
assert_state("sensor.current_ac_phase_3_fronius_meter_0_http_fronius", 10.102)
@ -173,7 +184,7 @@ async def test_symo_power_flow(hass, aioclient_mock):
assert len(hass.states.async_all(domain_filter=SENSOR_DOMAIN)) == 55
# ignored: location, mode, timestamp
#
# states are rounded to 2 decimals
# states are rounded to 4 decimals
assert_state(
"sensor.energy_day_fronius_power_flow_0_http_fronius",
10828,
@ -255,3 +266,196 @@ async def test_symo_power_flow(hass, aioclient_mock):
"sensor.relative_self_consumption_fronius_power_flow_0_http_fronius",
100,
)
async def test_gen24(hass, aioclient_mock):
"""Test Fronius Gen24 inverter entities."""
def assert_state(entity_id, expected_state):
state = hass.states.get(entity_id)
assert state
assert state.state == str(expected_state)
mock_responses(aioclient_mock, fixture_set="gen24")
config_entry = await setup_fronius_integration(hass, is_logger=False)
assert len(hass.states.async_all(domain_filter=SENSOR_DOMAIN)) == 25
await enable_all_entities(
hass, config_entry.entry_id, FroniusMeterUpdateCoordinator.default_interval
)
assert len(hass.states.async_all(domain_filter=SENSOR_DOMAIN)) == 57
# inverter 1
assert_state("sensor.energy_year_fronius_inverter_1_http_fronius", STATE_UNKNOWN)
assert_state("sensor.current_ac_fronius_inverter_1_http_fronius", 0.1589)
assert_state("sensor.current_dc_2_fronius_inverter_1_http_fronius", 0.0754)
assert_state("sensor.status_code_fronius_inverter_1_http_fronius", 7)
assert_state("sensor.energy_day_fronius_inverter_1_http_fronius", STATE_UNKNOWN)
assert_state("sensor.current_dc_fronius_inverter_1_http_fronius", 0.0783)
assert_state("sensor.voltage_dc_2_fronius_inverter_1_http_fronius", 403.4312)
assert_state("sensor.power_ac_fronius_inverter_1_http_fronius", 37.3204)
assert_state("sensor.error_code_fronius_inverter_1_http_fronius", 0)
assert_state("sensor.voltage_dc_fronius_inverter_1_http_fronius", 411.3811)
assert_state("sensor.energy_total_fronius_inverter_1_http_fronius", 1530193.42)
assert_state("sensor.inverter_state_fronius_inverter_1_http_fronius", "Running")
assert_state("sensor.voltage_ac_fronius_inverter_1_http_fronius", 234.9168)
assert_state("sensor.frequency_ac_fronius_inverter_1_http_fronius", 49.9917)
# meter
assert_state("sensor.energy_real_produced_fronius_meter_0_http_fronius", 3863340.0)
assert_state("sensor.energy_real_consumed_fronius_meter_0_http_fronius", 2013105.0)
assert_state("sensor.power_real_fronius_meter_0_http_fronius", 653.1)
assert_state("sensor.frequency_phase_average_fronius_meter_0_http_fronius", 49.9)
assert_state("sensor.meter_location_fronius_meter_0_http_fronius", 0.0)
assert_state("sensor.power_factor_fronius_meter_0_http_fronius", 0.828)
assert_state(
"sensor.energy_reactive_ac_consumed_fronius_meter_0_http_fronius", 88221.0
)
assert_state("sensor.energy_real_ac_minus_fronius_meter_0_http_fronius", 3863340.0)
assert_state("sensor.current_ac_phase_2_fronius_meter_0_http_fronius", 2.33)
assert_state("sensor.voltage_ac_phase_1_fronius_meter_0_http_fronius", 235.9)
assert_state(
"sensor.voltage_ac_phase_to_phase_12_fronius_meter_0_http_fronius", 408.7
)
assert_state("sensor.power_real_phase_2_fronius_meter_0_http_fronius", 294.9)
assert_state("sensor.energy_real_ac_plus_fronius_meter_0_http_fronius", 2013105.0)
assert_state("sensor.voltage_ac_phase_2_fronius_meter_0_http_fronius", 236.1)
assert_state(
"sensor.energy_reactive_ac_produced_fronius_meter_0_http_fronius", 1989125.0
)
assert_state("sensor.voltage_ac_phase_3_fronius_meter_0_http_fronius", 236.9)
assert_state("sensor.power_factor_phase_1_fronius_meter_0_http_fronius", 0.441)
assert_state(
"sensor.voltage_ac_phase_to_phase_23_fronius_meter_0_http_fronius", 409.6
)
assert_state("sensor.current_ac_phase_3_fronius_meter_0_http_fronius", 1.825)
assert_state("sensor.power_factor_phase_3_fronius_meter_0_http_fronius", 0.832)
assert_state("sensor.power_apparent_phase_1_fronius_meter_0_http_fronius", 243.3)
assert_state(
"sensor.voltage_ac_phase_to_phase_31_fronius_meter_0_http_fronius", 409.4
)
assert_state("sensor.power_apparent_phase_2_fronius_meter_0_http_fronius", 323.4)
assert_state("sensor.power_apparent_phase_3_fronius_meter_0_http_fronius", 301.2)
assert_state("sensor.power_real_phase_1_fronius_meter_0_http_fronius", 106.8)
assert_state("sensor.power_factor_phase_2_fronius_meter_0_http_fronius", 0.934)
assert_state("sensor.power_real_phase_3_fronius_meter_0_http_fronius", 251.3)
assert_state("sensor.power_reactive_phase_1_fronius_meter_0_http_fronius", -218.6)
assert_state("sensor.power_reactive_phase_2_fronius_meter_0_http_fronius", -132.8)
assert_state("sensor.power_reactive_phase_3_fronius_meter_0_http_fronius", -166.0)
assert_state("sensor.power_apparent_fronius_meter_0_http_fronius", 868.0)
assert_state("sensor.power_reactive_fronius_meter_0_http_fronius", -517.4)
assert_state("sensor.current_ac_phase_1_fronius_meter_0_http_fronius", 1.145)
# power_flow
assert_state("sensor.power_grid_fronius_power_flow_0_http_fronius", 658.4)
assert_state(
"sensor.relative_self_consumption_fronius_power_flow_0_http_fronius", 100.0
)
assert_state(
"sensor.power_photovoltaics_fronius_power_flow_0_http_fronius", 62.9481
)
assert_state("sensor.power_load_fronius_power_flow_0_http_fronius", -695.6827)
assert_state("sensor.meter_mode_fronius_power_flow_0_http_fronius", "meter")
assert_state("sensor.relative_autonomy_fronius_power_flow_0_http_fronius", 5.3592)
assert_state(
"sensor.power_battery_fronius_power_flow_0_http_fronius", STATE_UNKNOWN
)
assert_state("sensor.energy_year_fronius_power_flow_0_http_fronius", STATE_UNKNOWN)
assert_state("sensor.energy_day_fronius_power_flow_0_http_fronius", STATE_UNKNOWN)
assert_state("sensor.energy_total_fronius_power_flow_0_http_fronius", 1530193.42)
async def test_gen24_storage(hass, aioclient_mock):
"""Test Fronius Gen24 inverter with BYD battery and Ohmpilot entities."""
def assert_state(entity_id, expected_state):
state = hass.states.get(entity_id)
assert state
assert state.state == str(expected_state)
mock_responses(aioclient_mock, fixture_set="gen24_storage")
config_entry = await setup_fronius_integration(hass, is_logger=False)
assert len(hass.states.async_all(domain_filter=SENSOR_DOMAIN)) == 31
await enable_all_entities(
hass, config_entry.entry_id, FroniusMeterUpdateCoordinator.default_interval
)
assert len(hass.states.async_all(domain_filter=SENSOR_DOMAIN)) == 63
# inverter 1
assert_state("sensor.current_dc_fronius_inverter_1_http_fronius", 0.3952)
assert_state("sensor.voltage_dc_2_fronius_inverter_1_http_fronius", 318.8103)
assert_state("sensor.current_dc_2_fronius_inverter_1_http_fronius", 0.3564)
assert_state("sensor.energy_year_fronius_inverter_1_http_fronius", STATE_UNKNOWN)
assert_state("sensor.current_ac_fronius_inverter_1_http_fronius", 1.1087)
assert_state("sensor.power_ac_fronius_inverter_1_http_fronius", 250.9093)
assert_state("sensor.energy_day_fronius_inverter_1_http_fronius", STATE_UNKNOWN)
assert_state("sensor.error_code_fronius_inverter_1_http_fronius", 0)
assert_state("sensor.status_code_fronius_inverter_1_http_fronius", 7)
assert_state("sensor.energy_total_fronius_inverter_1_http_fronius", 7512794.0117)
assert_state("sensor.inverter_state_fronius_inverter_1_http_fronius", "Running")
assert_state("sensor.voltage_dc_fronius_inverter_1_http_fronius", 419.1009)
assert_state("sensor.voltage_ac_fronius_inverter_1_http_fronius", 227.354)
assert_state("sensor.frequency_ac_fronius_inverter_1_http_fronius", 49.9816)
# meter
assert_state("sensor.energy_real_produced_fronius_meter_0_http_fronius", 1705128.0)
assert_state("sensor.power_real_fronius_meter_0_http_fronius", 487.7)
assert_state("sensor.power_factor_fronius_meter_0_http_fronius", 0.698)
assert_state("sensor.energy_real_consumed_fronius_meter_0_http_fronius", 1247204.0)
assert_state("sensor.frequency_phase_average_fronius_meter_0_http_fronius", 49.9)
assert_state("sensor.meter_location_fronius_meter_0_http_fronius", 0.0)
assert_state("sensor.power_reactive_fronius_meter_0_http_fronius", -501.5)
assert_state(
"sensor.energy_reactive_ac_produced_fronius_meter_0_http_fronius", 3266105.0
)
assert_state("sensor.power_real_phase_3_fronius_meter_0_http_fronius", 19.6)
assert_state("sensor.current_ac_phase_3_fronius_meter_0_http_fronius", 0.645)
assert_state("sensor.energy_real_ac_minus_fronius_meter_0_http_fronius", 1705128.0)
assert_state("sensor.power_apparent_phase_2_fronius_meter_0_http_fronius", 383.9)
assert_state("sensor.current_ac_phase_1_fronius_meter_0_http_fronius", 1.701)
assert_state("sensor.current_ac_phase_2_fronius_meter_0_http_fronius", 1.832)
assert_state("sensor.power_apparent_phase_1_fronius_meter_0_http_fronius", 319.5)
assert_state("sensor.voltage_ac_phase_1_fronius_meter_0_http_fronius", 229.4)
assert_state("sensor.power_real_phase_2_fronius_meter_0_http_fronius", 150.0)
assert_state(
"sensor.voltage_ac_phase_to_phase_31_fronius_meter_0_http_fronius", 394.3
)
assert_state("sensor.voltage_ac_phase_2_fronius_meter_0_http_fronius", 225.6)
assert_state(
"sensor.energy_reactive_ac_consumed_fronius_meter_0_http_fronius", 5482.0
)
assert_state("sensor.energy_real_ac_plus_fronius_meter_0_http_fronius", 1247204.0)
assert_state("sensor.power_factor_phase_1_fronius_meter_0_http_fronius", 0.995)
assert_state("sensor.power_factor_phase_3_fronius_meter_0_http_fronius", 0.163)
assert_state("sensor.power_factor_phase_2_fronius_meter_0_http_fronius", 0.389)
assert_state("sensor.power_reactive_phase_1_fronius_meter_0_http_fronius", -31.3)
assert_state("sensor.power_reactive_phase_3_fronius_meter_0_http_fronius", -116.7)
assert_state(
"sensor.voltage_ac_phase_to_phase_12_fronius_meter_0_http_fronius", 396.0
)
assert_state(
"sensor.voltage_ac_phase_to_phase_23_fronius_meter_0_http_fronius", 393.0
)
assert_state("sensor.power_reactive_phase_2_fronius_meter_0_http_fronius", -353.4)
assert_state("sensor.power_real_phase_1_fronius_meter_0_http_fronius", 317.9)
assert_state("sensor.voltage_ac_phase_3_fronius_meter_0_http_fronius", 228.3)
assert_state("sensor.power_apparent_fronius_meter_0_http_fronius", 821.9)
assert_state("sensor.power_apparent_phase_3_fronius_meter_0_http_fronius", 118.4)
# power_flow
assert_state("sensor.power_grid_fronius_power_flow_0_http_fronius", 2274.9)
assert_state("sensor.power_battery_fronius_power_flow_0_http_fronius", 0.1591)
assert_state("sensor.power_load_fronius_power_flow_0_http_fronius", -2459.3092)
assert_state(
"sensor.relative_self_consumption_fronius_power_flow_0_http_fronius", 100.0
)
assert_state(
"sensor.power_photovoltaics_fronius_power_flow_0_http_fronius", 216.4328
)
assert_state("sensor.relative_autonomy_fronius_power_flow_0_http_fronius", 7.4984)
assert_state("sensor.meter_mode_fronius_power_flow_0_http_fronius", "bidirectional")
assert_state("sensor.energy_year_fronius_power_flow_0_http_fronius", STATE_UNKNOWN)
assert_state("sensor.energy_day_fronius_power_flow_0_http_fronius", STATE_UNKNOWN)
assert_state("sensor.energy_total_fronius_power_flow_0_http_fronius", 7512664.4042)
# storage
assert_state("sensor.current_dc_fronius_storage_0_http_fronius", 0.0)
assert_state("sensor.state_of_charge_fronius_storage_0_http_fronius", 4.6)
assert_state("sensor.capacity_maximum_fronius_storage_0_http_fronius", 16588)
assert_state("sensor.temperature_cell_fronius_storage_0_http_fronius", 21.5)
assert_state("sensor.capacity_designed_fronius_storage_0_http_fronius", 16588)
assert_state("sensor.voltage_dc_fronius_storage_0_http_fronius", 0.0)