1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
|
"""Test endpoint for envoy v7 and newer firmware"""
import logging
from typing import Any
import aiohttp
import pytest
from aioresponses import aioresponses
from syrupy.assertion import SnapshotAssertion
from pyenphase.const import PhaseNames
from pyenphase.envoy import SupportedFeatures
from pyenphase.models.envoy import EnvoyData
from .common import get_mock_envoy, prep_envoy, start_7_firmware_mock
LOGGER = logging.getLogger(__name__)
@pytest.mark.asyncio
async def test_with_4_2_27_firmware(
mock_aioresponse: aioresponses, test_client_session: aiohttp.ClientSession
) -> None:
"""Verify with 4.2.27 firmware."""
version = "4.2.27"
await prep_envoy(mock_aioresponse, "127.0.0.1", version)
envoy = await get_mock_envoy(test_client_session)
data: EnvoyData | None = envoy.data
assert data is not None
assert envoy._supported_features is not None
assert not (envoy._supported_features & SupportedFeatures.TOTAL_CONSUMPTION)
assert not (envoy._supported_features & SupportedFeatures.NET_CONSUMPTION)
assert not data.system_net_consumption
assert not data.system_net_consumption_phases
@pytest.mark.parametrize(
(
"version",
"supported_features",
"phase_count",
"net_consumption",
"net_consumption_phases",
),
[
(
"5.0.62",
SupportedFeatures.INVERTERS
| SupportedFeatures.PRODUCTION
| SupportedFeatures.TARIFF,
1,
{},
{},
),
(
"4.10.35",
SupportedFeatures.METERING
| SupportedFeatures.INVERTERS
| SupportedFeatures.TOTAL_CONSUMPTION
| SupportedFeatures.NET_CONSUMPTION
| SupportedFeatures.PRODUCTION
| SupportedFeatures.TARIFF
| SupportedFeatures.DUALPHASE
| SupportedFeatures.CTMETERS,
2,
{},
{},
),
(
"7.3.130",
SupportedFeatures.METERING
| SupportedFeatures.TOTAL_CONSUMPTION
| SupportedFeatures.NET_CONSUMPTION
| SupportedFeatures.INVERTERS
| SupportedFeatures.PRODUCTION,
1,
{},
{},
),
(
"7.3.130_no_consumption",
SupportedFeatures.METERING
| SupportedFeatures.INVERTERS
| SupportedFeatures.PRODUCTION
| SupportedFeatures.TARIFF
| SupportedFeatures.DUALPHASE
| SupportedFeatures.CTMETERS,
2,
{},
{},
),
(
"7.3.517",
SupportedFeatures.METERING
| SupportedFeatures.TOTAL_CONSUMPTION
| SupportedFeatures.NET_CONSUMPTION
| SupportedFeatures.ENPOWER
| SupportedFeatures.ENCHARGE
| SupportedFeatures.INVERTERS
| SupportedFeatures.PRODUCTION
| SupportedFeatures.TARIFF,
1,
{},
{},
),
(
"7.3.517_legacy_savings_mode",
SupportedFeatures.METERING
| SupportedFeatures.TOTAL_CONSUMPTION
| SupportedFeatures.NET_CONSUMPTION
| SupportedFeatures.ENPOWER
| SupportedFeatures.ENCHARGE
| SupportedFeatures.INVERTERS
| SupportedFeatures.PRODUCTION
| SupportedFeatures.TARIFF,
1,
{},
{},
),
(
"7.3.517_system_2",
SupportedFeatures.METERING
| SupportedFeatures.TOTAL_CONSUMPTION
| SupportedFeatures.NET_CONSUMPTION
| SupportedFeatures.ENPOWER
| SupportedFeatures.ENCHARGE
| SupportedFeatures.INVERTERS
| SupportedFeatures.PRODUCTION
| SupportedFeatures.TARIFF
| SupportedFeatures.DUALPHASE
| SupportedFeatures.CTMETERS,
2,
{
"watt_hours_lifetime": -2662919,
"watt_hours_last_7_days": 0,
"watt_hours_today": 0,
"watts_now": 48,
},
{},
),
(
"7.3.466_metered_disabled_cts",
SupportedFeatures.INVERTERS
| SupportedFeatures.PRODUCTION
| SupportedFeatures.TARIFF,
1,
{},
{},
),
(
"7.6.114_without_cts",
SupportedFeatures.INVERTERS | SupportedFeatures.PRODUCTION,
1,
{},
{},
),
(
"7.6.175",
SupportedFeatures.INVERTERS | SupportedFeatures.PRODUCTION,
1,
{},
{},
),
(
"7.6.175_total",
SupportedFeatures.INVERTERS
| SupportedFeatures.PRODUCTION
| SupportedFeatures.TARIFF,
1,
{},
{},
),
(
"7.6.175_standard",
SupportedFeatures.INVERTERS | SupportedFeatures.PRODUCTION,
1,
{
"watt_hours_lifetime": 1961513,
"watt_hours_last_7_days": 0,
"watt_hours_today": 0,
"watts_now": -11,
},
{},
),
(
"7.6.175_with_cts",
SupportedFeatures.INVERTERS
| SupportedFeatures.METERING
| SupportedFeatures.TOTAL_CONSUMPTION
| SupportedFeatures.NET_CONSUMPTION
| SupportedFeatures.PRODUCTION
| SupportedFeatures.TARIFF
| SupportedFeatures.CTMETERS,
1,
{},
{},
),
(
"7.6.175_with_cts_3phase",
SupportedFeatures.INVERTERS
| SupportedFeatures.METERING
| SupportedFeatures.TOTAL_CONSUMPTION
| SupportedFeatures.NET_CONSUMPTION
| SupportedFeatures.PRODUCTION
| SupportedFeatures.TARIFF
| SupportedFeatures.THREEPHASE
| SupportedFeatures.CTMETERS,
3,
{
"watt_hours_lifetime": 2886562,
"watt_hours_last_7_days": 29891,
"watt_hours_today": 2200,
"watts_now": 216,
},
{
PhaseNames.PHASE_1: {
"watt_hours_lifetime": 1625201,
"watt_hours_last_7_days": 0,
"watt_hours_today": 0,
"watts_now": 91,
},
PhaseNames.PHASE_2: {
"watt_hours_lifetime": 629892,
"watt_hours_last_7_days": 0,
"watt_hours_today": 0,
"watts_now": 123,
},
PhaseNames.PHASE_3: {
"watt_hours_lifetime": 631469,
"watt_hours_last_7_days": 0,
"watt_hours_today": 0,
"watts_now": 1,
},
},
),
(
"7.3.466_with_cts_3phase",
SupportedFeatures.INVERTERS
| SupportedFeatures.METERING
| SupportedFeatures.TOTAL_CONSUMPTION
| SupportedFeatures.NET_CONSUMPTION
| SupportedFeatures.PRODUCTION
| SupportedFeatures.TARIFF
| SupportedFeatures.THREEPHASE
| SupportedFeatures.CTMETERS,
3,
{
"watt_hours_lifetime": 2886562,
"watt_hours_last_7_days": 0,
"watt_hours_today": 0,
"watts_now": 216,
},
{
PhaseNames.PHASE_1: {
"watt_hours_lifetime": 1625201,
"watt_hours_last_7_days": 0,
"watt_hours_today": 0,
"watts_now": 91,
},
PhaseNames.PHASE_2: {
"watt_hours_lifetime": 629892,
"watt_hours_last_7_days": 0,
"watt_hours_today": 0,
"watts_now": 123,
},
PhaseNames.PHASE_3: {
"watt_hours_lifetime": 631469,
"watt_hours_last_7_days": 0,
"watt_hours_today": 0,
"watts_now": 1,
},
},
),
(
"7.6.185_with_cts_and_battery_3t",
SupportedFeatures.INVERTERS
| SupportedFeatures.METERING
| SupportedFeatures.TOTAL_CONSUMPTION
| SupportedFeatures.NET_CONSUMPTION
| SupportedFeatures.PRODUCTION
| SupportedFeatures.ENCHARGE
| SupportedFeatures.TARIFF
| SupportedFeatures.CTMETERS,
1,
{
"watt_hours_lifetime": 1279038,
"watt_hours_last_7_days": 0,
"watt_hours_today": 0,
"watts_now": 525,
},
{},
),
(
"8.1.41",
SupportedFeatures.INVERTERS
| SupportedFeatures.METERING
| SupportedFeatures.TOTAL_CONSUMPTION
| SupportedFeatures.NET_CONSUMPTION
| SupportedFeatures.ENCHARGE
| SupportedFeatures.ENPOWER
| SupportedFeatures.PRODUCTION,
1,
{
"watt_hours_lifetime": 1279038,
"watt_hours_last_7_days": 0,
"watt_hours_today": 0,
"watts_now": -7812,
},
{},
),
(
"8.2.127_with_3cts_and_battery_split",
SupportedFeatures.INVERTERS
| SupportedFeatures.METERING
| SupportedFeatures.TOTAL_CONSUMPTION
| SupportedFeatures.NET_CONSUMPTION
| SupportedFeatures.PRODUCTION
| SupportedFeatures.ENCHARGE
| SupportedFeatures.ENPOWER
| SupportedFeatures.TARIFF
| SupportedFeatures.DUALPHASE
| SupportedFeatures.CTMETERS,
2,
{
"watt_hours_lifetime": 4744550,
"watt_hours_last_7_days": 0,
"watt_hours_today": 0,
"watts_now": 129,
},
{},
),
(
"8.2.127_with_generator_running",
SupportedFeatures.INVERTERS
| SupportedFeatures.METERING
| SupportedFeatures.TOTAL_CONSUMPTION
| SupportedFeatures.NET_CONSUMPTION
| SupportedFeatures.PRODUCTION
| SupportedFeatures.ENCHARGE
| SupportedFeatures.ENPOWER
| SupportedFeatures.TARIFF
| SupportedFeatures.DUALPHASE
| SupportedFeatures.CTMETERS
| SupportedFeatures.GENERATOR,
2,
{
"watt_hours_lifetime": 7298714,
"watt_hours_last_7_days": 0,
"watt_hours_today": 0,
"watts_now": 240,
},
{},
),
(
"8.2.4345_with_device_data",
SupportedFeatures.INVERTERS
| SupportedFeatures.METERING
| SupportedFeatures.TOTAL_CONSUMPTION
| SupportedFeatures.NET_CONSUMPTION
| SupportedFeatures.PRODUCTION
| SupportedFeatures.ENCHARGE
| SupportedFeatures.ENPOWER
| SupportedFeatures.TARIFF
| SupportedFeatures.DUALPHASE
| SupportedFeatures.CTMETERS,
1,
{},
{},
),
],
ids=[
"5.0.62",
"4.10.35",
"7.3.130",
"7.3.130_no_consumption",
"7.3.517",
"7.3.517_legacy_savings_mode",
"7.3.517_system_2",
"7.3.466_metered_disabled_cts",
"7.6.114_without_cts",
"7.6.175",
"7.6.175_total",
"7.6.175_standard",
"7.6.175_with_cts",
"7.6.175_with_cts_3phase",
"7.3.466_with_cts_3phase",
"7.6.185_with_cts_and_battery_3t",
"8.1.41",
"8.2.127_with_3cts_and_battery_split",
"8.2.127_with_generator_running",
"8.2.4345_with_device_data",
],
)
@pytest.mark.asyncio
async def test_with_7_x_firmware(
version: str,
snapshot: SnapshotAssertion,
supported_features: SupportedFeatures,
caplog: pytest.LogCaptureFixture,
phase_count: int,
net_consumption: dict[str, Any],
net_consumption_phases: dict[str, dict[str, Any]],
mock_aioresponse: aioresponses,
test_client_session: aiohttp.ClientSession,
) -> None:
"""Verify with 7.x firmware."""
start_7_firmware_mock(mock_aioresponse)
await prep_envoy(mock_aioresponse, "127.0.0.1", version)
caplog.set_level(logging.DEBUG)
envoy = await get_mock_envoy(test_client_session)
data = envoy.data
assert data
assert data == snapshot
assert envoy.phase_count == phase_count
# are all net consumption phases reported
expected_phases = net_consumption_phases == {}
actual_phases = data.system_net_consumption_phases is None
assert not (expected_phases ^ actual_phases)
reported_phase_count = envoy.active_phase_count
# are all net consumption phases reported
expected_phase_count = len(net_consumption_phases)
assert expected_phase_count == reported_phase_count
# are all consumption phases reported
assert (
envoy.active_phase_count == 0
if data.system_net_consumption_phases is None
else len(data.system_net_consumption_phases)
)
# Test each consumption phase
for phase in net_consumption_phases:
assert data.system_net_consumption_phases
assert (consdata := data.system_net_consumption_phases[phase])
modeldata = net_consumption_phases[phase]
# test each element of the phase data
assert consdata.watt_hours_lifetime == modeldata["watt_hours_lifetime"]
assert consdata.watt_hours_last_7_days == modeldata["watt_hours_last_7_days"]
assert consdata.watt_hours_today == modeldata["watt_hours_today"]
assert consdata.watts_now == modeldata["watts_now"]
|