Modules
API Reference¶
Client¶
Client
¶
Asynchronous client for talking to a GivEnergy inverter over Modbus TCP.
Holds a long-lived connection drained by a single producer/consumer task pair. All public methods are coroutines and assume they're awaited from the same asyncio event loop.
Concurrency contract¶
The client is designed to be used from multiple concurrent callers — e.g. a
polling loop calling refresh_plant() and entity-write handlers calling
one_shot_command() independently. The following invariants hold:
Safe to interleave
- Reads (
refresh_plant,load_config,refresh) and writes (one_shot_command) may run concurrently. Their request/response pairs occupy disjoint shape-hash spaces, so they never collide in the in-flight tracking dict. tx_queueis a FIFO drained by a single producer task with rate limiting between frames; bytes from one frame never interleave with another. A queued frame whose response future is already done (i.e. resolved by a late arrival from a previous attempt) is skipped at dequeue time rather than written to the wire, so retry storms don't duplicate work the inverter has already done.- Incoming frames are reassembled and dispatched serially by the consumer task, so register-cache mutations are applied one PDU at a time.
Must be serialised
detect()mutatesplant.capabilities(including in-place appends to its address lists) and must not run concurrently with anything that reads those fields — most importantlyrefresh()andload_config(). In typical usedetect()runs once at connect time before the polling loop starts, which satisfies this naturally. Downstream consumers caching capabilities across restarts can bypassdetect()on reconnect entirely.
Practical guidance for downstream consumers
- Take a per-client lock around
refresh_plant()so successive polls don't overlap. Writes don't need the same lock — they're free to land between polls. - Connection loss is surfaced via
self.connectedflipping toFalse; the consumer task logs CRITICAL when this happens.connect()is idempotent and tears down the previous connection on its own, so it can be called directly as a reconnect primitive.
Source code in givenergy_modbus/client/client.py
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 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 | |
capture_frames(sink, duration=60.0)
async
¶
Tee redacted TX/RX wire frames to sink for duration seconds.
sink is called with the direction ('rx' or 'tx') and the redacted bytes. The library always redacts before invoking the sink so callers can't accidentally see raw hardware identifiers; persistence, formatting and forwarding are the caller's choice.
Redaction is frame-aware: each complete GivEnergy frame is decoded, its serial-bearing fields (envelope serials, C.serial-tagged register values, LAN-config IPs) are zeroed by type, and the frame is re-encoded with a freshly-computed CRC. Frames that cannot be decoded (unknown function codes, malformed/truncated frames) are emitted intact with a log message — they are never dropped or mangled. The sink sees complete frames (one call per complete frame) rather than raw socket chunks.
Runs alongside the normal refresh loop — does not suspend reads or writes, just tees a copy of each frame to sink. Only one capture may run on a Client at a time; calling while one is in flight raises RuntimeError.
Source code in givenergy_modbus/client/client.py
1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 | |
close()
async
¶
Disconnect from the remote host and clean up tasks and queues.
Source code in givenergy_modbus/client/client.py
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 | |
connect()
async
¶
Connect to the remote host and start background tasks.
Idempotent: if the client is already connected, the existing connection
and background tasks are torn down before establishing a new one. This
makes connect() safe to use as a reconnect primitive without a
separate close() step, and guarantees the new background tasks see
_shutting_down as False even after a prior close().
Source code in givenergy_modbus/client/client.py
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 | |
detect(timeout=2.0, retries=3, probe_timeout=0.5, probe_retries=1, prior=None)
async
¶
Discover device type and peripheral topology.
Reads HR(0) and HR(21) from the inverter to resolve the model, then probes for BCUs (HV systems), meters, and LV battery devices.
Both returns the PlantCapabilities instance and assigns it to
self.plant.capabilities — the returned object and the one stored on
the plant are the same. Subsequent calls to Client.refresh() and
Client.load_config() will use it automatically.
When prior is supplied, the probe sweep restricts itself to the
addresses listed in it — empty addresses from a cold sweep are skipped.
If reality doesn't match prior (device_type changed, or any hinted
address fails to confirm), raises PlantTopologyMismatch and leaves
self.plant.capabilities as None. The exception carries prior and
actual so callers can decide whether to retry, fall back to a cold
detect(), or surface the change to the user.
Uses a two-tier timeout: timeout/retries for the known inverter device
(where a response is expected), and probe_timeout/probe_retries for
speculative probes where absence is the common case.
On a connection-level failure (TimeoutError / CommunicationError) the
connection is torn down via close(), so connect()+detect() is atomic:
connected flips to False and the standard "reconnect if not connected"
idiom recovers (#274). A PlantTopologyMismatch is raised on a healthy
connection (only the hint was wrong) and leaves it up so the caller can
retry a cold detect().
Source code in givenergy_modbus/client/client.py
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 | |
execute(requests, timeout, retries, retry_delay=0.5, return_exceptions=False)
¶
Helper to perform multiple requests in bulk.
Source code in givenergy_modbus/client/client.py
1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 | |
load_config(timeout=2.0, retries=3, retry_delay=0.5)
async
¶
Read HR configuration blocks for the inverter.
Returns the populated plant on full success. On partial/total read
failure raises RefreshPartiallySucceeded / RefreshFailed.
Success does not imply fresh: the keep-last-good guards (CRC #255, sub-bus
splice #256, bank holds) report a successful poll while serving last-known-good
content for a device whose live read was rejected. Display consumers should gate
on Plant.register_age() / Plant.block_age(), not on a poll returning.
Source code in givenergy_modbus/client/client.py
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 | |
one_shot_command(requests, timeout=1.5, retries=0, retry_delay=0.5, dry_run=False)
async
¶
Execute write requests, validating each against the detected inverter model.
Raises InvalidPduState for any write to a register not permitted for the detected model. When capabilities are not yet known, falls back to the universally-applicable single-phase register set (conservative).
If dry_run is True, validates but does not transmit — running the same PDU
validation (ensure_valid_state) the live encode path runs, so a dry run
never passes for a request real execution would reject.
Source code in givenergy_modbus/client/client.py
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 | |
refresh(timeout=2.0, retries=1, retry_delay=0.5, ir0_max_age=None)
async
¶
Read IR measurement blocks for all known devices.
Returns the populated plant on full success. On partial/total read
failure raises RefreshPartiallySucceeded / RefreshFailed.
Success does not imply fresh: the keep-last-good guards (CRC #255, sub-bus
splice #256, bank holds) report a successful poll while serving last-known-good
content for a device whose live read was rejected. Display consumers should gate
on Plant.register_age() / Plant.block_age(), not on a poll returning.
The timeout=2.0, retries=1 defaults are tuned for a contended bus: the
inverter serialises requests, so when other clients (GivTCP, the vendor app,
Predbat) poll the same unit a tighter budget produces spurious timeouts even
though the device is responsive (#132). Pass a tighter budget if you own the
bus exclusively and want genuine failures surfaced faster.
ir0_max_age (seconds) opts in to skip-if-fresh for the IR(0,60) live block
(#196): GivEnergy dongles fan out the responses to whoever is polling them (the
cloud, the app, another client), so the network consumer often already has a
recent IR(0,60) in cache without us asking. When set, if IR(0,60) was committed
within ir0_max_age seconds it is not re-solicited this cycle, sparing the
(often flaky) dongle a request. Defaults to None — always solicit, the
historic behaviour. Scoped to IR(0,60) only for now; broaden once soak-tested.
Note the fan-out only exists while something else is polling the unit; on a
cloud-disconnected dongle the block ages out and we solicit it as normal.
Source code in givenergy_modbus/client/client.py
986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 | |
refresh_plant(full_refresh=True, max_batteries=5, timeout=2.0, retries=1, retry_delay=0.5)
async
¶
Deprecated orchestrator — run detect() once, then drive your own loop.
.. deprecated::
Will be removed in 3.0 (soon). This composes detect() (when needed) +
load_config() + refresh(), which is trivial to do in the consumer
where the partial-failure policy belongs. It propagates
RefreshPartiallySucceeded / RefreshFailed like the primitives —
note that on a full refresh a partial failure in load_config()
short-circuits before refresh() runs; call the primitives directly for
full control.
Unlike the primitives, this wrapper runs ``detect()`` for you if
capabilities are absent (preserving the legacy connect-then-refresh shape).
New code should call ``detect()`` then ``load_config()`` / ``refresh()``
directly — the primitives raise ``PlantNotDetected`` rather than guessing
an address.
Source code in givenergy_modbus/client/client.py
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 | |
send_request_and_await_response(request, timeout, retries, retry_delay=0.5, warn_timeout=True)
async
¶
Send a request to the remote, await and return the response.
On timeout, retry_delay seconds pass before the next attempt is
enqueued. The default of 0.5s was chosen to overcome the multi-second
silent-window failure mode observed in the field — firing the retry
immediately tends to land it inside the same silent window as the
original request, accomplishing nothing. Callers that want the
original "retry immediately" behaviour (e.g. fast probes, latency-
sensitive interactive commands) should pass retry_delay=0.
Source code in givenergy_modbus/client/client.py
1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 | |
watch_plant(handler=None, refresh_period=15.0, max_batteries=5, timeout=2.0, retries=1, retry_delay=0.5, passive=False)
async
¶
Deprecated poll loop — own the loop in the consumer instead.
.. deprecated::
Will be removed in 3.0. Connect, detect(), then loop over
load_config() / refresh() yourself, handling
RefreshPartiallySucceeded / RefreshFailed as suits the consumer.
Source code in givenergy_modbus/client/client.py
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 | |
FrameRedactor
¶
Frame-aware stateful redactor for a captured GivEnergy byte stream.
Replaces StreamRedactor: instead of running byte-level regex over raw socket
chunks, it reassembles complete GivEnergy frames (using the same 0x5959 marker
scan the Framer uses), decodes each one, redacts only the known-sensitive
fields by type (envelope serials, C.serial-tagged register values, LAN-config IPs),
and re-encodes with a freshly-computed CRC.
Any bytes that cannot be decoded — InvalidFrame results, inter-frame garbage,
or a partial frame held at stream end — are emitted intact (not mangled) with
a log message. Nothing on the wire is ever dropped: the capture is always complete.
Not thread-safe; use one instance per capture direction.
See #158 B-3 for the design rationale and the LanConfigBroadcast PDU that
handles the #100 WO-dongle LAN-config broadcasts.
Source code in givenergy_modbus/client/client.py
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 | |
feed(chunk)
¶
Absorb raw bytes; return redacted output for any complete frames found.
Source code in givenergy_modbus/client/client.py
143 144 145 146 | |
flush()
¶
Emit any remaining buffered bytes intact and reset. Call at stream end.
Source code in givenergy_modbus/client/client.py
148 149 150 151 152 153 154 | |
Commands¶
High-level methods for interacting with a remote system.
RegisterMap
¶
Mapping of holding register function to location.
Source code in givenergy_modbus/client/commands.py
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 | |
disable_charge()
¶
Prevent the battery from charging at all.
Source code in givenergy_modbus/client/commands.py
220 221 222 223 | |
disable_charge_target()
¶
Removes SOC limit and target 100% charging.
Source code in givenergy_modbus/client/commands.py
153 154 155 156 157 158 | |
disable_charge_target_3ph()
¶
Remove SOC limit and target 100% charging on three-phase inverters (HR 1111, shadows HR 116).
Source code in givenergy_modbus/client/commands.py
280 281 282 283 284 285 | |
disable_discharge()
¶
Prevent the battery from discharging at all.
Source code in givenergy_modbus/client/commands.py
232 233 234 235 | |
enable_charge()
¶
Enable the battery to charge, depending on the mode and slots set.
Source code in givenergy_modbus/client/commands.py
214 215 216 217 | |
enable_discharge()
¶
Enable the battery to discharge, depending on the mode and slots set.
Source code in givenergy_modbus/client/commands.py
226 227 228 229 | |
refresh_plant_data(complete, number_batteries=1, max_batteries=5)
¶
This helper hardcoded device_address=0x32 for every read, which silently
failed on models answering elsewhere (e.g. an All-in-One at 0x11 — issue #105).
Capability-aware polling — Client.detect() then Client.load_config() /
Client.refresh() — replaces it and addresses each device correctly.
Kept as an import-compatible stub so existing imports don't break with an
ImportError; it raises PlantNotDetected to signpost the migration rather
than rebuild the unsafe blind poll.
Source code in givenergy_modbus/client/commands.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
reset_charge_slot(idx, slot_map)
¶
Reset charge slot to zero/disabled by index (1-based).
Source code in givenergy_modbus/client/commands.py
656 657 658 | |
reset_charge_slot_1(slot_map=SINGLE_PHASE_SLOTS)
¶
Source code in givenergy_modbus/client/commands.py
679 680 681 682 | |
reset_charge_slot_2(slot_map=SINGLE_PHASE_SLOTS)
¶
Source code in givenergy_modbus/client/commands.py
691 692 693 694 | |
reset_discharge_slot(idx, slot_map)
¶
Reset discharge slot to zero/disabled by index (1-based).
Source code in givenergy_modbus/client/commands.py
668 669 670 | |
reset_discharge_slot_1(slot_map=SINGLE_PHASE_SLOTS)
¶
Source code in givenergy_modbus/client/commands.py
703 704 705 706 | |
reset_discharge_slot_2(slot_map=SINGLE_PHASE_SLOTS)
¶
Source code in givenergy_modbus/client/commands.py
715 716 717 718 | |
set_ac_charge(enabled)
¶
Enable AC charging on three-phase inverters.
Source code in givenergy_modbus/client/commands.py
457 458 459 | |
set_active_power_rate(target)
¶
Set the inverter's active power output as a percentage of its rated capacity.
Source code in givenergy_modbus/client/commands.py
358 359 360 361 362 363 | |
set_battery_charge_limit(val)
¶
Set the battery charge power limit as a percentage of rated charge power (0–50).
Source code in givenergy_modbus/client/commands.py
329 330 331 332 333 334 | |
set_battery_charge_limit_ac(val)
¶
Set the battery AC charge power limit as a percentage.
Source code in givenergy_modbus/client/commands.py
396 397 398 399 400 401 | |
set_battery_discharge_limit(val)
¶
Set the battery discharge power limit as a percentage of rated discharge power (0–50).
Source code in givenergy_modbus/client/commands.py
337 338 339 340 341 342 | |
set_battery_discharge_limit_ac(val)
¶
Set the battery AC discharge power limit as a percentage.
Source code in givenergy_modbus/client/commands.py
404 405 406 407 408 409 | |
set_battery_pause_mode(val)
¶
Set the battery pause mode.
Source code in givenergy_modbus/client/commands.py
412 413 414 | |
set_battery_power_reserve(val)
¶
Set the battery power reserve to maintain.
Bounds [4-100]% are unconfirmed against GE firmware docs (gone) but match GivTCP's independent choice for the same register — treat as the working assumption until a portal capture contradicts it.
Source code in givenergy_modbus/client/commands.py
345 346 347 348 349 350 351 352 353 354 355 | |
set_battery_reserve_soc(val)
¶
Set the battery reserve SOC on three-phase inverters (HR 1078, "Battery Reserve %").
Three-phase only — single-phase units use set_battery_soc_reserve() (HR 110) instead. Bounds [4-100]% are unconfirmed (no GivTCP cross-reference exists for this register); treat as the working assumption until a live three-phase capture confirms them.
Source code in givenergy_modbus/client/commands.py
267 268 269 270 271 272 273 274 275 276 277 | |
set_battery_soc_reserve(val)
¶
Set the minimum level of charge to maintain.
Bounds [4-100]% are unconfirmed against GE firmware docs (gone) but match GivTCP's independent choice for the same register — treat as the working assumption until a portal capture contradicts it.
Source code in givenergy_modbus/client/commands.py
254 255 256 257 258 259 260 261 262 263 264 | |
set_battery_soc_reserve_3ph(val)
¶
Set the minimum SOC reserve on three-phase inverters (HR 1109, shadows single-phase HR 110).
Source code in givenergy_modbus/client/commands.py
288 289 290 291 292 293 | |
set_calibrate_battery_soc(val=1)
¶
Set the inverter to recalibrate the battery state of charge estimation.
val: 0 = Stop, 1 = Start, 3 = Charge Only
Source code in givenergy_modbus/client/commands.py
204 205 206 207 208 209 210 211 | |
set_charge_slot(idx, timeslot, slot_map)
¶
Set charge slot start & end times by index (1-based).
Source code in givenergy_modbus/client/commands.py
649 650 651 652 653 | |
set_charge_slot_1(timeslot, slot_map=SINGLE_PHASE_SLOTS)
¶
Source code in givenergy_modbus/client/commands.py
673 674 675 676 | |
set_charge_slot_2(timeslot, slot_map=SINGLE_PHASE_SLOTS)
¶
Source code in givenergy_modbus/client/commands.py
685 686 687 688 | |
set_charge_slot_end(idx, t, slot_map)
¶
Set just the end of a charge slot by index (1-based), or clear it if t is None.
Source code in givenergy_modbus/client/commands.py
631 632 633 634 | |
set_charge_slot_start(idx, t, slot_map)
¶
Set just the start of a charge slot by index (1-based), or clear it if t is None.
Source code in givenergy_modbus/client/commands.py
625 626 627 628 | |
set_charge_target(target_soc)
¶
Source code in givenergy_modbus/client/commands.py
175 176 177 178 | |
set_charge_target_3ph(target_soc)
¶
Source code in givenergy_modbus/client/commands.py
315 316 317 318 | |
set_charge_target_enabled(target_soc)
¶
Enable charging and stop once SOC reaches target_soc. Also referred to as "winter mode".
Source code in givenergy_modbus/client/commands.py
161 162 163 164 165 166 167 168 169 170 171 172 | |
set_charge_target_enabled_3ph(target_soc)
¶
Enable AC charging and set the charge target on three-phase inverters (HR 1111, shadows single-phase HR 116).
Source code in givenergy_modbus/client/commands.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
set_charge_target_soc(target_soc)
¶
Set only the charge target SOC (HR 116), leaving the charge / charge-target enable bits untouched.
Source code in givenergy_modbus/client/commands.py
181 182 183 184 185 186 | |
set_charge_target_soc_3ph(target_soc)
¶
Set only the charge target SOC on three-phase inverters (HR 1111), leaving enable bits untouched.
Source code in givenergy_modbus/client/commands.py
321 322 323 324 325 326 | |
set_discharge_mode_max_power()
¶
Set the battery discharge mode to maximum power, exporting to the grid if it exceeds load demand.
Source code in givenergy_modbus/client/commands.py
238 239 240 | |
set_discharge_mode_to_match_demand()
¶
Set the battery discharge mode to match demand, avoiding exporting power to the grid.
Source code in givenergy_modbus/client/commands.py
243 244 245 | |
set_discharge_slot(idx, timeslot, slot_map)
¶
Set discharge slot start & end times by index (1-based).
Source code in givenergy_modbus/client/commands.py
661 662 663 664 665 | |
set_discharge_slot_1(timeslot, slot_map=SINGLE_PHASE_SLOTS)
¶
Source code in givenergy_modbus/client/commands.py
697 698 699 700 | |
set_discharge_slot_2(timeslot, slot_map=SINGLE_PHASE_SLOTS)
¶
Source code in givenergy_modbus/client/commands.py
709 710 711 712 | |
set_discharge_slot_end(idx, t, slot_map)
¶
Set just the end of a discharge slot by index (1-based), or clear it if t is None.
Source code in givenergy_modbus/client/commands.py
643 644 645 646 | |
set_discharge_slot_start(idx, t, slot_map)
¶
Set just the start of a discharge slot by index (1-based), or clear it if t is None.
Source code in givenergy_modbus/client/commands.py
637 638 639 640 | |
set_ems_charge_slot(idx, timeslot)
¶
Set an EMS plant charge time slot by index (1-3), or clear it if None.
Source code in givenergy_modbus/client/commands.py
512 513 514 515 516 | |
set_ems_charge_slot_end(idx, t)
¶
Set just the end of EMS plant charge slot idx (1-3), or clear it if None.
Source code in givenergy_modbus/client/commands.py
524 525 526 | |
set_ems_charge_slot_start(idx, t)
¶
Set just the start of EMS plant charge slot idx (1-3), or clear it if None.
Source code in givenergy_modbus/client/commands.py
519 520 521 | |
set_ems_charge_target_soc(idx, target_soc)
¶
Set the SoC target (0-100%) for EMS plant charge slot idx (1-3).
Source code in givenergy_modbus/client/commands.py
546 547 548 549 550 551 552 553 | |
set_ems_discharge_slot(idx, timeslot)
¶
Set an EMS plant discharge time slot by index (1-3), or clear it if None.
Source code in givenergy_modbus/client/commands.py
529 530 531 532 533 | |
set_ems_discharge_slot_end(idx, t)
¶
Set just the end of EMS plant discharge slot idx (1-3), or clear it if None.
Source code in givenergy_modbus/client/commands.py
541 542 543 | |
set_ems_discharge_slot_start(idx, t)
¶
Set just the start of EMS plant discharge slot idx (1-3), or clear it if None.
Source code in givenergy_modbus/client/commands.py
536 537 538 | |
set_ems_discharge_target_soc(idx, target_soc)
¶
Set the SoC target (0-100%) for EMS plant discharge slot idx (1-3).
Source code in givenergy_modbus/client/commands.py
556 557 558 559 560 561 562 563 564 565 | |
set_ems_export_power_limit(watts)
¶
Set the EMS plant export power limit in watts.
Bounded to a 16-bit holding register (0-65535) so an out-of-range value fails here rather than later at PDU-encode time as InvalidPduState.
Source code in givenergy_modbus/client/commands.py
598 599 600 601 602 603 604 605 606 607 | |
set_ems_export_slot(idx, timeslot)
¶
Set an EMS plant export time slot by index (1-3), or clear it if None.
EMS export slots are the same HR(2062-2069) registers as set_export_slot
(export slots are EMS-only and already target the EMS address 0x11) — this is
the EMS-named alias for parity with set_ems_charge_slot/set_ems_discharge_slot.
Source code in givenergy_modbus/client/commands.py
568 569 570 571 572 573 574 575 | |
set_ems_export_slot_end(idx, t)
¶
Set just the end of EMS plant export slot idx (1-3), or clear it if None.
Source code in givenergy_modbus/client/commands.py
583 584 585 | |
set_ems_export_slot_start(idx, t)
¶
Set just the start of EMS plant export slot idx (1-3), or clear it if None.
Source code in givenergy_modbus/client/commands.py
578 579 580 | |
set_ems_export_target_soc(idx, target_soc)
¶
Set the SoC target (0-100%) for EMS plant export slot idx (1-3).
Source code in givenergy_modbus/client/commands.py
588 589 590 591 592 593 594 595 | |
set_ems_plant(enabled)
¶
Enable EMS plant control.
Source code in givenergy_modbus/client/commands.py
472 473 474 | |
set_enable_charge(enabled)
¶
Enable the battery to charge, depending on the mode and slots set.
Source code in givenergy_modbus/client/commands.py
189 190 191 | |
set_enable_discharge(enabled)
¶
Enable the battery to discharge, depending on the mode and slots set.
Source code in givenergy_modbus/client/commands.py
194 195 196 | |
set_enable_eps(enabled)
¶
Enable or disable Emergency Power Supply (EPS) mode on AC-coupled inverters.
Confirmed writable on Model.AC via direct portal observations (hass#52).
Source code in givenergy_modbus/client/commands.py
388 389 390 391 392 393 | |
set_enable_rtc(enabled)
¶
Enable the Real Time Clock register to persist settings to EEPROM.
Source code in givenergy_modbus/client/commands.py
366 367 368 | |
set_export_priority(priority)
¶
Set the export priority for surplus power on AC-coupled inverters.
Determines where surplus energy goes: battery first, grid first, or load first. Confirmed writable on Model.AC via direct portal observations (hass#52).
Source code in givenergy_modbus/client/commands.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
set_export_slot(idx, slot)
¶
Set an export time slot by index (1–3), or clear it if slot is None.
Source code in givenergy_modbus/client/commands.py
496 497 498 499 500 501 | |
set_export_slot_end(idx, t)
¶
Set just the end of an export time slot by index (1–3), or clear it if t is None.
Source code in givenergy_modbus/client/commands.py
490 491 492 493 | |
set_export_slot_start(idx, t)
¶
Set just the start of an export time slot by index (1–3), or clear it if t is None.
Source code in givenergy_modbus/client/commands.py
484 485 486 487 | |
set_force_charge(enabled)
¶
Enable forced battery charging on three-phase inverters.
Source code in givenergy_modbus/client/commands.py
462 463 464 | |
set_force_discharge(enabled)
¶
Enable forced battery discharging on three-phase inverters.
Source code in givenergy_modbus/client/commands.py
467 468 469 | |
set_inverter_reboot()
¶
Restart the inverter.
Source code in givenergy_modbus/client/commands.py
199 200 201 | |
set_mode_dynamic()
¶
Set system to Dynamic / Eco mode.
This mode is designed to maximise use of solar generation. The battery will charge from excess solar generation to avoid exporting power, and discharge to meet load demand when solar power is insufficient to avoid importing power. This mode is useful if you want to maximise self-consumption of renewable generation and minimise the amount of energy drawn from the grid.
Source code in givenergy_modbus/client/commands.py
737 738 739 740 741 742 743 744 745 746 | |
set_mode_storage(discharge_slot_1=TimeSlot.from_repr(1600, 700), discharge_slot_2=None, discharge_for_export=False, slot_map=SINGLE_PHASE_SLOTS)
¶
Set system to storage mode with specific discharge slots(s).
This mode stores excess solar generation during the day and holds that energy ready for use later in the day. By default, the battery will start to discharge from 4pm-7am to cover energy demand during typical peak hours. This mode is particularly useful if you get charged more for your electricity at certain times to utilise the battery when it is most effective. If the second time slot isn't specified, it will be cleared.
You can optionally also choose to export excess energy: instead of discharging to meet only your load demand, the battery will discharge at full power and any excess will be exported to the grid. This is useful if you have a variable export tariff (e.g. Agile export) and you want to target the peak times of day (e.g. 4pm-7pm) when it is most valuable to export energy.
Source code in givenergy_modbus/client/commands.py
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 | |
set_pause_slot(slot)
¶
Set the battery pause time slot, or clear it if slot is None.
Source code in givenergy_modbus/client/commands.py
427 428 429 430 431 | |
set_pause_slot_end(t)
¶
Set just the end of the battery pause slot, or clear it if t is None.
Source code in givenergy_modbus/client/commands.py
422 423 424 | |
set_pause_slot_start(t)
¶
Set just the start of the battery pause slot, or clear it if t is None.
Source code in givenergy_modbus/client/commands.py
417 418 419 | |
set_shallow_charge(val)
¶
Set the minimum level of charge to maintain.
Source code in givenergy_modbus/client/commands.py
248 249 250 251 | |
set_smart_load_slot(idx, slot)
¶
Set Smart Load slot idx (1-based, 1–10) atomically, or clear it if slot is None.
Source code in givenergy_modbus/client/commands.py
450 451 452 453 454 | |
set_smart_load_slot_end(idx, t)
¶
Set the end time of Smart Load slot idx (1-based, 1–10), or clear it if t is None.
Source code in givenergy_modbus/client/commands.py
442 443 444 445 446 447 | |
set_smart_load_slot_start(idx, t)
¶
Set the start time of Smart Load slot idx (1-based, 1–10), or clear it if t is None.
Source code in givenergy_modbus/client/commands.py
434 435 436 437 438 439 | |
set_system_date_time(dt)
¶
Set the date & time of the inverter.
Source code in givenergy_modbus/client/commands.py
721 722 723 724 725 726 727 728 729 730 731 732 733 734 | |
Model¶
Plant
¶
Bases: GivEnergyBaseModel
Representation of a complete GivEnergy plant.
Source code in givenergy_modbus/model/plant.py
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 | |
aio_battery_modules
property
¶
Return per-module AIO battery models (#192), one per separate-address module cache.
All-in-One units expose each removable module at its own device address (0x50-0x53), each carrying 24 cell voltages, temperatures, and the module's own serial. Empty for non-AIO plants and until the module caches have been polled.
batteries
property
¶
Return Battery models for the Plant.
devices
property
¶
Enumerate every device on this plant as typed :class:PlantDevice rows.
Each row carries a generic :class:DeviceType discriminator, a serial
(where the device exposes a valid one), the plant's model where
meaningful, and the already-decoded typed model in
:attr:PlantDevice.device. Built by composing the existing accessors —
:attr:inverters, :attr:ems, :attr:gateway, :attr:meters — so the
EMS-rollup-vs-direct decision is honoured once and a controller (EMS or
gateway) can never appear as an INVERTER row.
Batteries and HV stacks are owned by their inverter (#106 Phase 2):
they ride on the INVERTER row's device.batteries /
device.hv_stacks rather than as top-level rows. Meters are not
inverter-owned, so they stay flat rows (the Phase 1 meter-identity
limitation).
ems
property
¶
Return Ems model for EMS/EMS_COMMERCIAL device types; None otherwise.
gateway
property
¶
Return GatewayV1 or GatewayV2 model for GATEWAY device type; None otherwise.
hv_stacks
property
¶
Return HV battery stacks (BCU + BMUs) for HV systems; empty list for LV systems.
inverter
property
¶
Return the inverter model, dispatching on device type when capabilities are available.
Tolerates the inverter-address cache not yet existing — a pre-#189 persisted capability may still point at 0x31, which detect() doesn't populate (it reads identity at 0x11), so this would otherwise KeyError between detect() and the first poll. Returns an empty-cache model in that window, matching the .ems / .gateway accessors. (#119, #189)
inverter_serial
property
¶
Single authoritative inverter serial, robust across the whole plant lifecycle (#227).
Resolves the earliest-available inverter identity by trying, in order:
- HR(13-17) in the capability-selected inverter cache (
inverter_address— 0x11 since #189; 0x31 only via a pre-#189 persisted capability); - HR(13-17) in the 0x11 cache —
detect()'sHR(0,60)identity read lands here for every model, so this covers the detect→first-refresh window when a stale capability still points at 0x31; - the
inverter_serial_numberenvelope field — populated atdetect()and the only home on a persisted/bare plant carrying no register caches.
A register block is only accepted if it decodes to a valid serial (is_valid_serial —
the same coherence gate _commit_bank ingestion uses), so a malformed/partial block in a
restored or tampered cache falls through to the envelope rather than outranking it.
Deliberately never reads the 0x32 battery cache, so a bare or pre-detect plant can't
surface a battery pack's serial as the inverter's. Reads via .get() so it never
mutates the (defaultdict) caches. Once consumers move to this accessor, the envelope
field can be deprecated.
inverters
property
¶
Return one :class:Inverter facade per inverter in this plant.
For an EMS plant without direct sources: yields one :class:Inverter per
non-empty managed-inverter slot in the EMS's IR(2040+) rollup
(data_source="ems_rollup").
For an EMS plant with direct sources (injected via :meth:add_direct_source):
reconciles EMS summaries with direct-inverter caches by serial number.
Matching serials produce merged inverters (data_source="merged"); EMS
slots without a matching direct source stay blinded; direct sources whose
serial is not in the EMS rollup appear as orphan data_source="direct"
entries (#106 Phase 3).
For a non-EMS plant: yields a single :class:Inverter wrapping the existing
:attr:inverter (data_source="direct"). The legacy :attr:inverter
(singular) accessor remains for back-compat.
lv_bcu
property
¶
Return the LV BCU stack-level block, or None when absent.
None when capabilities are unset, the block wasn't detected (firmware-gated — see model/lv_bcu.py), or its cache hasn't been populated yet.
meters
property
¶
Return Meter models keyed by device address.
number_batteries
property
¶
Determine the number of batteries connected to the system based on whether the register data is valid.
serial_index
property
¶
Map each known inverter serial number to its :class:Inverter facade.
Built from :attr:inverters, so the same reconciliation logic applies:
merged entries (direct + EMS rollup) have data_source="merged",
blinded EMS-only entries have data_source="ems_rollup", and direct-only
entries have data_source="direct".
add_direct_source(caches)
¶
Store direct-inverter register caches for serial reconciliation (#106 Phase 3).
Caches are stored separately from register_caches to avoid the Modbus
address collision (both the EMS controller and a directly-connected inverter
live at 0x11). Call this on an EMS plant after collecting data from a second
Client pointing at one of the EMS-managed inverters; inverters and
serial_index will then return merged views for matching serials.
Source code in givenergy_modbus/model/plant.py
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 | |
block_age(device_address, reg_type, base_register, register_count, *, now=None)
¶
Seconds since a register block was last committed, or None if never seen.
reg_type is "HR" or "IR". register_count must match the count used
when the block was stamped — typically 60 for standard GivEnergy IR/HR blocks. This
prevents a partial response (e.g. IR(0,1)) from being mistaken for a full IR(0,60)
block by the skip-if-fresh logic in refresh() (#196).
Used to reason about freshness and staleness in the fan-out skip (#196) and Pattern B all-zero rejection (#206).
Source code in givenergy_modbus/model/plant.py
931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 | |
content_unchanged_seconds(device_address, reg_type, base_register, register_count, *, now=None)
¶
Seconds a register block's content has been byte-identical, or None if never seen (#91).
Reports a raw duration, not a freeze verdict: a high value may indicate a frozen BMS cache (e.g. a battery whose BMS is in firmware-update bootloader mode), but on the real capture corpus healthy LV batteries also hold IR(60,60) content steady for long stretches (dongle fan-out + genuinely-static telemetry). Distinguishing a freeze from a live-but- static device needs a threshold validated against more freeze captures than currently exist, so this method deliberately makes no claim — callers compose it with their own policy. See #91.
reg_type is "HR" or "IR"; register_count must match the committed block.
Source code in givenergy_modbus/model/plant.py
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 | |
model_post_init(__context)
¶
Ensure a default register cache is always present.
Source code in givenergy_modbus/model/plant.py
561 562 563 564 | |
redact()
¶
Return a share-safe copy: every register cache redacted and the header serials cleared.
redact_serials() only covers the register caches; inverter_serial_number and
data_adapter_serial_number live on the Plant itself (populated from the PDU envelope),
so a dumped Plant still leaks both unless they're redacted here too. The original is left
untouched (#212/#214 share-safe-export guarantee).
Source code in givenergy_modbus/model/plant.py
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 | |
register_age(device_address, register, *, now=None)
¶
Seconds since the freshest stamped block containing register was committed (#247).
Unlike block_age(), the caller doesn't need to know block boundaries or the
stamped count — every stamped window for the device whose [base, base+count) span
covers the register is considered, and the freshest wins. None if no stamped
window covers it. Pair with RegisterGetter.registers_of() to reason about a
model attribute's freshness.
Source code in givenergy_modbus/model/plant.py
958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 | |
update(pdu, *, received_at=None)
¶
Update the Plant state from a PDU message.
received_at overrides the ingestion timestamp recorded for a committed
register block (see register_block_updated_at / #65); it defaults to the
current UTC time and is provided mainly for deterministic testing and replay.
Source code in givenergy_modbus/model/plant.py
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 | |
PlantCapabilities
¶
Bases: BaseModel
Describes the hardware topology discovered by Client.detect().
Returned by Client.detect(); callers assign it to plant.capabilities or persist it for faster restarts (see fork-merge-plan deferred items).
Legacy *_slave(s) keyword aliases are mapped to the canonical names
in __init__ (for PlantCapabilities(...) callers) and again in the
_accept_legacy_aliases model_validator (for model_validate({...})
callers). Both paths emit a DeprecationWarning.
Source code in givenergy_modbus/model/plant.py
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 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
bcu_slaves
property
writable
¶
Deprecated alias for bcu_stacks.
has_ac_config_block
property
¶
Return True if this system exposes the HR(300–359) AC-output config block.
Covers export priority, EPS enable, AC charge/discharge limits and pause mode —
present on AC-coupled inverters and the All-in-One, absent (times out) on
DC-coupled/hybrid models. See _AC_CONFIG_BLOCK_MODELS (#162).
has_extended_slots
property
¶
Return True if this system supports the extended 10-slot map (HR 240–299).
has_smart_load_block
property
¶
Return True if this system exposes a readable HR(540–599) Smart Load block.
Currently False for every model: no inverter has been confirmed to answer the
read on real hardware, and HYBRID_GEN1 is confirmed to time out on it. See
_SMART_LOAD_CAPABLE_MODELS (#179).
inverter_slave
property
writable
¶
Deprecated alias for inverter_address.
is_ac_coupled
property
¶
Return True if this system is AC-coupled (no integrated DC battery).
is_ems
property
¶
Return True if this system is an EMS plant controller (HR/IR 2040-range).
is_gateway
property
¶
Return True if this system is a Gateway (IR 1600-range).
is_hv
property
¶
Return True if this system uses HV battery stacks (BCU/BMU) rather than LV packs.
is_three_phase
property
¶
Return True if this system uses three-phase registers (HR/IR 1000-range).
lv_battery_slaves
property
writable
¶
Deprecated alias for lv_battery_addresses.
meter_slaves
property
writable
¶
Deprecated alias for meter_addresses.
from_dict(data)
classmethod
¶
Reconstruct from a to_dict() payload.
Accepts two on-disk shapes:
- v2.0.0 (legacy, no
schema_version):device_typeas the enum value (e.g."2"), addresses as raw integers, noschema_versionkey. Persisted by the v2.0.0to_dict(). - v2.0.1+ (versioned):
schema_versionpresent and equal toSCHEMA_VERSION,device_typeas enum name (e.g."HYBRID_GEN1"), addresses as"0x..."hex strings.
A schema_version that's present but doesn't match SCHEMA_VERSION
raises ValueError — callers can catch and re-run detect() without
prior. Pre-rename *_slave(s) key aliases are normalised silently so
state persisted under the older conventions still loads cleanly.
Source code in givenergy_modbus/model/plant.py
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 | |
to_dict()
¶
Serialise to a JSON-safe dict for caller-managed persistence.
Round-trips through from_dict(). Addresses render as 0x.. strings to
match the form used in logs, exceptions, and code. The schema_version
field gives future-us an escape hatch for format changes.
Source code in givenergy_modbus/model/plant.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
BatteryCalibrationStage
¶
Bases: int, Enum
Battery calibration stages.
Source code in givenergy_modbus/model/inverter.py
266 267 268 269 270 271 272 273 274 275 276 | |
BatteryPowerMode
¶
Bases: int, Enum
Battery discharge strategy.
Source code in givenergy_modbus/model/inverter.py
259 260 261 262 263 | |
BatteryType
¶
Bases: int, Enum
Installed battery type.
Source code in givenergy_modbus/model/inverter.py
286 287 288 289 290 | |
Certification
¶
Bases: IntEnum
Grid compliance certification.
Source code in givenergy_modbus/model/inverter.py
329 330 331 332 333 334 335 336 337 338 339 340 | |
ChargeStatus
¶
Bases: IntEnum
Known charge-status codes observed on single-phase inverters (IR(14), #222).
Raw int accessible via charge_status; typed label via charge_status_label.
Unknown codes decode to None via charge_status_label rather than raising.
Source code in givenergy_modbus/model/inverter.py
393 394 395 396 397 398 399 400 401 402 403 | |
Generation
¶
Bases: StrEnum
Inverter hardware generation.
Source code in givenergy_modbus/model/inverter.py
356 357 358 359 360 361 362 363 364 365 | |
InverterType
¶
Bases: IntEnum
Inverter phase and voltage type.
Source code in givenergy_modbus/model/inverter.py
343 344 345 346 347 348 349 350 351 352 353 | |
MeterType
¶
Bases: int, Enum
Installed meter type.
Source code in givenergy_modbus/model/inverter.py
279 280 281 282 283 | |
Model
¶
Bases: str, Enum
Known models of inverters.
Single-digit values are the coarse family (first digit of the DTC); these are
what Model(dtc_string) returns via _missing_ for backward compatibility.
Two-character and "20gN" values are more specific variants reachable via
resolve_model(raw_dtc, arm_fw) or by direct construction e.g. Model("81").
Note: Gen 2 inverters with an 'EA' serial prefix were previously mapped via a serial-prefix lookup table (removed in 1.0). Their device type code first digit is unknown — if EA-prefix units report a code not listed here, missing will raise ValueError. A field report from a Gen 2 owner is needed to add support.
Source code in givenergy_modbus/model/inverter.py
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 | |
system_battery_voltage
property
¶
Represent nominal battery voltage for this system.
Phase
¶
Bases: IntEnum
Number of AC phases.
Source code in givenergy_modbus/model/inverter.py
379 380 381 382 383 384 385 386 387 388 389 390 | |
PowerFactorFunctionModel
¶
Bases: int, Enum
Power Factor function model.
Source code in givenergy_modbus/model/inverter.py
293 294 295 296 297 298 299 300 301 302 | |
SinglePhaseInverter
¶
Bases: _SinglePhaseInverterBase, _InverterCommands, RegisterMetadataMixin
GivEnergy single-phase inverter data model.
Composes the _InverterCommands mixin so consumers can call
inverter.set_*(...) directly instead of routing through
givenergy_modbus.client.commands.*. The mixin reads self.slot_map so
slot setters no longer need it threaded through by callers. Model-specific
command mixins (three-phase, EMS, pause-mode) will compose in additively
in later 2.x minors — see #75.
Source code in givenergy_modbus/model/inverter.py
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 | |
battery_capacity_kwh
property
¶
Returns the nominal battery capacity in kWh, derived from Ah and model voltage.
battery_charge_power
property
¶
Non-negative battery charge power (W); zero when discharging or idle (#205).
battery_discharge_power
property
¶
Non-negative battery discharge power (W); zero when charging or idle (#205).
battery_max_power
property
¶
Returns the rated battery charge/discharge power in watts, derived from model and firmware.
e_battery_charge_today
property
¶
Canonical daily battery charge energy (kWh), routed by model (see #76).
e_battery_charge_total
property
¶
Canonical total battery charge energy (kWh), routed by model (see #76).
e_battery_discharge_today
property
¶
Canonical daily battery discharge energy (kWh), routed by model (see #76).
e_battery_discharge_total
property
¶
Canonical total battery discharge energy (kWh), routed by model (see #76).
e_consumption_today
property
¶
House consumption today (kWh), matching the GE app's "Consumption today".
DERIVED, not metered: single-phase units expose no consumption register, so the GE app computes this value. Sentinel cross-correlation against the app's Energy-today screen (#174) recovered the exact formula:
consumption = pv_generation + grid_import − grid_export − ac_charge
Battery DC charge/discharge throughput nets out and is not a term. The result carries the same conversion-loss bias the app shows (energy balance overshoots real consumption by a few %). This is the GE-universe definition of "consumption" specifically — other plant equipment may define it differently.
Three-phase units have a native e_load_today register and so do NOT get this computed field (it lives on SinglePhaseInverter only, not in the register LUT). Returns None if any input is unavailable.
e_inverter_out_day
property
¶
Deprecated alias for e_pv_generation_today.
e_inverter_out_total
property
¶
Deprecated alias for e_pv_generation_total.
enable_standard_self_consumption_logic
property
¶
Deprecated alias for enable_inverter_parallel_mode.
grid_export_power
property
¶
Non-negative grid export power (W); zero when importing or idle (#205).
grid_import_power
property
¶
Non-negative grid import power (W); zero when exporting or idle (#205).
inverter_max_power
property
¶
Returns the rated inverter power in watts, derived from the device type code.
is_ac_coupled
property
¶
True for AC-coupled inverters (no integrated DC battery).
Coarse-family resolution is correct here: AC DTCs resolve to Model.AC / Model.AC_3PH and neither has specific sub-variants. False when the model is unknown (DTC unread).
slot_map
property
¶
Register address pairs for the charge/discharge time slots on this model.
work_time_total
property
¶
Deprecated alias for work_time_total_hours.
e_pv_day()
¶
Computes the total PV energy for the day, or None if either input is unavailable.
Source code in givenergy_modbus/model/inverter.py
794 795 796 797 798 | |
from_register_cache(register_cache)
classmethod
¶
Construct a SinglePhaseInverter from a RegisterCache.
Source code in givenergy_modbus/model/inverter.py
783 784 785 786 | |
p_pv()
¶
Computes the total PV power, or None if either input is unavailable.
Source code in givenergy_modbus/model/inverter.py
788 789 790 791 792 | |
SinglePhaseInverterRegisterGetter
¶
Bases: RegisterGetter
Structured format for all inverter attributes.
Source code in givenergy_modbus/model/inverter.py
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 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 | |
Status
¶
Bases: int, Enum
Inverter status.
Source code in givenergy_modbus/model/inverter.py
305 306 307 308 309 310 311 312 | |
UsbDevice
¶
Bases: int, Enum
USB devices that can be inserted into inverters.
Source code in givenergy_modbus/model/inverter.py
251 252 253 254 255 256 | |
WorkMode
¶
Bases: IntEnum
Inverter work mode.
Source code in givenergy_modbus/model/inverter.py
315 316 317 318 319 320 321 322 323 324 325 326 | |
inverter_address_for(model)
¶
Return the modbus device address the inverter's registers are served at.
0x11 is the canonical inverter address for all models. AC and HYBRID_GEN1
units additionally expose their registers at 0x31 — a facade over the same
register file (value-equality verified across 114 shared HR registers on a
live HYBRID_GEN1, and byte-identical HR banks on two live AC units; #189) —
but 0x11 is where the official app reads and writes, and where detect()
always reads identity. EMS and All-in-One controllers likewise serve all
their data — including the IR/HR(2040) rollup — at 0x11.
Capabilities persisted before the 0x31 retirement may still carry an
explicit inverter_address of 0x31; that keeps working (the hardware
facade still answers there) and self-heals to 0x11 on the next
detect().
Source code in givenergy_modbus/model/inverter.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
resolve_model(raw_dtc, arm_fw)
¶
Return the most specific Model for a given device type code and ARM firmware version.
raw_dtc is the raw integer value of HR(0) (e.g. 0x2001).
arm_fw is the raw ARM firmware version integer from HR(21).
Use this in preference to plain Model(dtc) when you have both values available.
Model(dtc) continues to work and returns the coarse family for backward compat.
Source code in givenergy_modbus/model/inverter.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
Battery
¶
Bases: _BatteryBase, RegisterMetadataMixin
GivEnergy battery data model.
Source code in givenergy_modbus/model/battery.py
105 106 107 108 109 110 111 112 113 114 115 116 117 | |
from_register_cache(register_cache)
classmethod
¶
Construct a Battery from a RegisterCache.
Source code in givenergy_modbus/model/battery.py
110 111 112 113 | |
is_valid()
¶
Try to detect if a battery exists based on its attributes.
Source code in givenergy_modbus/model/battery.py
115 116 117 | |
BatteryMaintenance
¶
Bases: IntEnum
Battery maintenance mode.
Source code in givenergy_modbus/model/battery.py
158 159 160 161 162 163 164 165 166 167 168 | |
BatteryPauseMode
¶
Bases: IntEnum
Battery pause mode.
Source code in givenergy_modbus/model/battery.py
145 146 147 148 149 150 151 152 153 154 155 | |
BatteryRegisterGetter
¶
Bases: RegisterGetter
Structured format for all battery attributes.
Source code in givenergy_modbus/model/battery.py
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 | |
ExportPriority
¶
Bases: IntEnum
Dispatch priority for surplus power on AC-coupled inverters.
Confirmed writable on Model.AC via direct portal observations (hass#52): HR(311) was written with values 0/1/2 while the portal's "Export Priority" control was cycled through its three options.
Source code in givenergy_modbus/model/battery.py
132 133 134 135 136 137 138 139 140 141 142 | |
State
¶
Bases: IntEnum
Battery charge/discharge state.
Source code in givenergy_modbus/model/battery.py
120 121 122 123 124 125 126 127 128 129 | |
RegisterCache
¶
Bases: defaultdict[Register, int]
Holds a cache of Registers populated after querying a device.
Source code in givenergy_modbus/model/register_cache.py
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 | |
from_json(data)
classmethod
¶
Instantiate a RegisterCache from its JSON form.
Source code in givenergy_modbus/model/register_cache.py
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 | |
json()
¶
Return JSON representation of the register cache, to mirror from_json().
.. warning::
This emits unredacted serial-number registers (and any other raw values).
For a share-safe export, redact first: cache.redact_serials().json().
Source code in givenergy_modbus/model/register_cache.py
90 91 92 93 94 95 96 97 | |
redact_serials()
¶
Return a copy of this cache with all known serial-number registers redacted.
Identifies every register group tagged as Converter.serial in the model
LUTs (plus BMU serial groups, which are decoded manually), decodes each fully-
present group, and date-redacts values that match a known GE serial pattern
(prefix + manufacture date kept, unit digits zeroed).
Fails open for HR/IR groups by necessity. Serial groups are applied without
device-type context and overlap: the BMU serial groups (e.g. IR(114-118)) are
real serials only on HV BMU stacks, but on an LV battery those addresses hold the
battery serial's last register (IR114) and ordinary data (IR115 = usb_device_inserted).
With no way to tell a non-GE serial from non-serial data, anything that doesn't
match a serial pattern is left unchanged — blanking it would destroy legitimate
data and corrupt overlapping serials. The share-safe-export guarantee (#212/#214)
is enforced fail-closed where it is unambiguous: the inverter/dongle header serials
(:meth:Plant.redact) and the meter product identifier (MR, a distinct register
namespace, blanked below).
Produces the same AAYYWWA000-style placeholders as :class:FrameRedactor,
so a redacted export is indistinguishable from a redacted capture.
Source code in givenergy_modbus/model/register_cache.py
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 | |
to_datetime(y, m, d, h, min, s)
¶
Combine 6 registers into a datetime, with safe defaults for zeroes.
Source code in givenergy_modbus/model/register_cache.py
172 173 174 | |
to_duint8(*registers)
¶
Split registers into two unsigned 8-bit integers each.
Source code in givenergy_modbus/model/register_cache.py
164 165 166 | |
to_hex_string(*registers)
¶
Render a register as a 2-byte hexadecimal value.
Source code in givenergy_modbus/model/register_cache.py
154 155 156 157 158 159 160 161 162 | |
to_string(*registers)
¶
Combine registers into an ASCII string.
Source code in givenergy_modbus/model/register_cache.py
149 150 151 152 | |
to_timeslot(start, end)
¶
Combine two registers into a time slot, or None if either is unset.
Mirrors Converter.timeslot: a missing/None endpoint, or the raw value 60 (a hardware sentinel for an unset slot — the portal shows '--:--'), means "unset". Both would otherwise raise ValueError in TimeSlot.from_repr.
Source code in givenergy_modbus/model/register_cache.py
228 229 230 231 232 233 234 235 236 237 238 239 240 | |
to_uint32(high_register, low_register)
¶
Combine two registers into an unsigned 32-bit integer.
Source code in givenergy_modbus/model/register_cache.py
168 169 170 | |
parse_compact(text)
¶
Parse a compact probe-dump back into device caches (inverse of :func:to_compact).
Lenient and order-agnostic — the input is human-pasted diagnostic text. Accepts the
device-inline grammar emitted by :func:to_compact and (transitionally) the legacy
header format. Hex reflowed across lines by copy-paste is reassembled; a row that still
doesn't reach its declared length is skipped without aborting the rest. # comments
(provenance), Probing … status, .. timed-out ranges and blank lines are ignored.
Source code in givenergy_modbus/model/register_cache.py
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 | |
to_compact(caches)
¶
Serialise device register caches to the compact hex probe-dump format.
Peer to :meth:RegisterCache.json — a pure str projection with no file I/O. Each
row is self-describing::
0x32:HR(0,60) 0000000500ff…
0x<dev> is the device address, HR/IR/MR the bank, (<base>,<count>) the
range, then count × 4 lowercase hex chars (one 16-bit register per 4). Blocks are split
on the 60-register grid GivEnergy probes read on, so whole-block caches round-trip as clean,
non-overlapping rows. Rows are emitted in (device, bank, base) order for stable output.
Provenance (host:port) is the caller's to add as an ignored # comment.
Source code in givenergy_modbus/model/register_cache.py
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 | |
Data model.
DefaultUnknownIntEnum
¶
Bases: IntEnum
Enum that returns unknown instead of blowing up.
Source code in givenergy_modbus/model/__init__.py
24 25 26 27 28 29 | |
GivEnergyBaseModel
¶
Bases: BaseModel
Structured format for all other attributes.
Source code in givenergy_modbus/model/__init__.py
13 14 15 16 17 18 19 20 21 | |
from_registers(register_cache)
classmethod
¶
Constructor parsing registers directly.
Source code in givenergy_modbus/model/__init__.py
18 19 20 21 | |
TimeSlot
¶
Represents a time slot with a start and end time.
Source code in givenergy_modbus/model/__init__.py
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 | |
__get_pydantic_core_schema__(source_type, handler)
classmethod
¶
Keep TimeSlot instances as-is in model_dump(mode='python').
Source code in givenergy_modbus/model/__init__.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
from_components(start_hour, start_minute, end_hour, end_minute)
classmethod
¶
Shorthand for the individual datetime.time constructors.
Source code in givenergy_modbus/model/__init__.py
63 64 65 66 | |
from_repr(start, end)
classmethod
¶
Converts from human-readable/ASCII representation: '0034' -> 00:34.
Source code in givenergy_modbus/model/__init__.py
68 69 70 71 72 73 74 75 76 77 78 79 | |
PDU¶
Package for the tree of PDU messages.
BasePDU
¶
Bases: ABC
Base of the PDU Message network_timeout_handler class tree.
The Protocol Data Unit (PDU) defines the basic unit of message exchange for Modbus. It is routed to devices with specific addresses, and targets specific operations through function codes. This tree defines the hierarchy of functions, along with the attributes they specify and how they are encoded.
The tree branches at the top based on the directionality of the messages – either client-focused (messages a client should expect to receive and send) or server-focused (less important for this library, but messages that a server would emit and expect to receive). It is mirrored in that a Request message from a client would have a matching Response message the server should reply with.
The PDU classes are also codecs – they know how to convert between binary network frames and instantiated objects that can be manipulated programmatically.
Source code in givenergy_modbus/pdu/base.py
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 | |
decode_bytes(data)
classmethod
¶
Decode raw byte frame to populated PDU instance.
Source code in givenergy_modbus/pdu/base.py
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 | |
encode()
¶
Encode PDU message from instance attributes.
Source code in givenergy_modbus/pdu/base.py
39 40 41 42 43 44 45 46 47 48 49 | |
ensure_valid_state()
¶
Sanity check our internal state.
Source code in givenergy_modbus/pdu/base.py
111 112 113 | |
has_same_shape(o)
¶
Calculates whether a given message has the "same shape".
Messages are similarly shaped when they match message type (response, error state), location (device address, register type, register indexes) etc. but not data / register values.
This is not an identity check but could be used both for creating template expected responses from outgoing requests (to facilitate tracking future responses), but also allows incoming messages to be hashed consistently to avoid (e.g.) multiple messages of the same shape getting enqueued unnecessarily – the theory being that newer messages being enqueued might as well replace older ones of the same shape.
Source code in givenergy_modbus/pdu/base.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
shape_hash()
¶
Calculates the "shape hash" for a given message.
Source code in givenergy_modbus/pdu/base.py
130 131 132 | |
ClientIncomingMessage
¶
Bases: BasePDU, ABC
Root of the hierarchy for PDUs clients are expected to receive and handle.
Source code in givenergy_modbus/pdu/base.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
expected_response()
¶
Create a template of a correctly shaped Response expected for this Request.
Source code in givenergy_modbus/pdu/base.py
157 158 159 | |
ClientOutgoingMessage
¶
Bases: BasePDU, ABC
Root of the hierarchy for PDUs clients are expected to send to servers.
Source code in givenergy_modbus/pdu/base.py
162 163 164 165 166 167 168 169 170 171 172 173 174 | |
HeartbeatMessage
¶
Bases: BasePDU, ABC
Root of the hierarchy for 1/Heartbeat function PDUs.
Source code in givenergy_modbus/pdu/heartbeat.py
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 | |
ensure_valid_state()
¶
Sanity check our internal state.
Source code in givenergy_modbus/pdu/heartbeat.py
41 42 | |
HeartbeatRequest
¶
Bases: HeartbeatMessage, ClientIncomingMessage, ABC
PDU sent by remote server to check liveness of client.
Source code in givenergy_modbus/pdu/heartbeat.py
52 53 54 55 56 57 | |
expected_response()
¶
Create an appropriate response for an incoming HeartbeatRequest.
Source code in givenergy_modbus/pdu/heartbeat.py
55 56 57 | |
HeartbeatResponse
¶
Bases: HeartbeatMessage, ClientOutgoingMessage, ABC
PDU returned by client (within 5s) to confirm liveness.
Source code in givenergy_modbus/pdu/heartbeat.py
60 61 62 63 64 65 66 67 68 69 70 71 | |
decode(data)
¶
Decode response PDU message and populate instance attributes.
Source code in givenergy_modbus/pdu/heartbeat.py
63 64 65 66 67 68 | |
expected_response()
¶
No replies expected for HeartbeatResponse.
Source code in givenergy_modbus/pdu/heartbeat.py
70 71 | |
LanConfigBroadcast
¶
Bases: ClientIncomingMessage
Dongle LAN-configuration broadcast (function 0x02 / CSV body).
Some WO-prefix inverter dongles periodically broadcast their network configuration as a function-code 2 frame whose body is:
adapter_serial[10] 6_zeros[6] null[1] ,<ip>,<netmask>,<gateway>\r\n\r\n check[2]
The standard transparent decoder reads the null byte as transparent_function_code (0x30 / '0') and bails to InvalidFrame. This class intercepts those frames at decode time before the transparent path is attempted (discriminator: remaining_payload[6]0 and remaining_payload[7]',').
Refs: #100 (original discovery), #158 (B-3 redactor).
Source code in givenergy_modbus/pdu/lan_config.py
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 | |
decode_main_function(decoder, **attrs)
classmethod
¶
Called by TransparentMessage.decode_main_function after reading the serial.
attrs already contains data_adapter_serial_number. Consume the 7 padding bytes
then parse the CSV from the remaining payload.
Source code in givenergy_modbus/pdu/lan_config.py
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 | |
encode()
¶
Re-encode to wire bytes; length-preserving. CRC is not recomputed.
Source code in givenergy_modbus/pdu/lan_config.py
97 98 99 100 101 102 103 104 105 106 107 | |
ensure_valid_state()
¶
No state validation required for LAN-config broadcast frames.
Source code in givenergy_modbus/pdu/lan_config.py
109 110 | |
expected_response()
¶
No response expected for LAN-config broadcasts.
Source code in givenergy_modbus/pdu/lan_config.py
112 113 114 | |
is_lan_config(remaining_after_serial)
classmethod
¶
Return True if the remaining decoder bytes look like a LAN config broadcast.
Source code in givenergy_modbus/pdu/lan_config.py
49 50 51 52 53 54 55 56 57 58 59 60 | |
lookup_main_function_decoder(function_code)
classmethod
¶
Not used — LanConfigBroadcast is decoded directly, not via lookup.
Source code in givenergy_modbus/pdu/lan_config.py
119 120 121 122 | |
redact()
¶
Return a new instance with the adapter serial and all IP fields zeroed.
The trailing 2-byte check field is carried through verbatim. Its
derivation for this non-standard frame type is unknown — verified to not
follow the CRC16/Modbus(payload[18:], byte-swapped) scheme used by
all other GivEnergy frames (no candidate span produces a match). This is
consistent with the fact that real captures arrive with the IPs already
zeroed and a check value computed by the dongle over those zeroed bytes;
redaction of a live frame would leave the check inconsistent with the new CSV
bytes, but without understanding the formula it cannot be corrected. A comment
in the test documents the implication.
Source code in givenergy_modbus/pdu/lan_config.py
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 | |
NullResponse
¶
Bases: TransparentResponse
Concrete PDU implementation for handling function #0/Null Response messages.
This seems to be a quirk of the GivEnergy implementation – from time to time these responses will be sent unprompted by the remote device and this just handles it gracefully and allows further debugging. The function data payload seems to be invariably just a series of nulls.
Source code in givenergy_modbus/pdu/null.py
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 | |
ensure_valid_state()
¶
Sanity check our internal state.
Source code in givenergy_modbus/pdu/null.py
46 47 48 49 50 51 52 53 54 | |
expected_response()
¶
No response expected.
Source code in givenergy_modbus/pdu/null.py
43 44 | |
ReadHoldingRegisters
¶
Bases: ReadRegistersMessage, ABC
Request & Response PDUs for function #3/Read Holding Registers.
Source code in givenergy_modbus/pdu/read_registers.py
194 195 196 197 | |
ReadHoldingRegistersRequest
¶
Bases: ReadHoldingRegisters, ReadRegistersRequest
Concrete PDU implementation for handling function #3/Read Holding Registers request messages.
Source code in givenergy_modbus/pdu/read_registers.py
200 201 202 203 204 205 206 | |
ReadHoldingRegistersResponse
¶
Bases: ReadHoldingRegisters, ReadRegistersResponse
Concrete PDU implementation for handling function #3/Read Holding Registers response messages.
Source code in givenergy_modbus/pdu/read_registers.py
209 210 211 212 213 | |
ReadInputRegisters
¶
Bases: ReadRegistersMessage, ABC
Request & Response PDUs for function #4/Read Input Registers.
Source code in givenergy_modbus/pdu/read_registers.py
216 217 218 219 | |
ReadInputRegistersRequest
¶
Bases: ReadInputRegisters, ReadRegistersRequest
Concrete PDU implementation for handling function #4/Read Input Registers request messages.
Source code in givenergy_modbus/pdu/read_registers.py
222 223 224 225 226 227 228 | |
ReadInputRegistersResponse
¶
Bases: ReadInputRegisters, ReadRegistersResponse
Concrete PDU implementation for handling function #4/Read Input Registers response messages.
Source code in givenergy_modbus/pdu/read_registers.py
231 232 233 234 235 | |
ReadMeterProductRegisters
¶
Bases: ReadRegistersMessage, ABC
Request & Response PDUs for function #0x16/Read Meter Product Registers.
Source code in givenergy_modbus/pdu/read_registers.py
238 239 240 241 | |
ReadMeterProductRegistersRequest
¶
Bases: ReadMeterProductRegisters, ReadRegistersRequest
Concrete PDU implementation for handling function #0x16/Read Meter Product Registers request messages.
Source code in givenergy_modbus/pdu/read_registers.py
244 245 246 247 248 249 250 | |
ReadMeterProductRegistersResponse
¶
Bases: ReadMeterProductRegisters, ReadRegistersResponse
Concrete PDU implementation for handling function #0x16/Read Meter Product Registers response messages.
Source code in givenergy_modbus/pdu/read_registers.py
257 258 259 260 261 | |
ReadRegistersMessage
¶
Bases: TransparentMessage, ABC
Mixin for commands that specify base register and register count semantics.
Source code in givenergy_modbus/pdu/read_registers.py
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 | |
ReadRegistersRequest
¶
Bases: ReadRegistersMessage, TransparentRequest, ABC
Handles all messages that request a range of registers.
Source code in givenergy_modbus/pdu/read_registers.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
ensure_valid_state()
¶
Sanity check our internal state.
Source code in givenergy_modbus/pdu/read_registers.py
61 62 63 64 65 66 67 68 69 70 | |
ReadRegistersResponse
¶
Bases: ReadRegistersMessage, TransparentResponse, ABC
Handles all messages that respond with a range of registers.
Source code in givenergy_modbus/pdu/read_registers.py
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 | |
ensure_valid_state()
¶
Sanity check our internal state.
Source code in givenergy_modbus/pdu/read_registers.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
is_suspicious()
¶
Try to identify known-bad data in register lookup calls and prevent them from entering the dispatching.
Source code in givenergy_modbus/pdu/read_registers.py
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 | |
to_dict()
¶
Return the registers as a dict of register_index:value. Accounts for base_register offsets.
Source code in givenergy_modbus/pdu/read_registers.py
159 160 161 | |
TransparentMessage
¶
Bases: BasePDU, ABC
Root of the hierarchy for 2/Transparent PDUs.
Source code in givenergy_modbus/pdu/transparent.py
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 | |
TransparentRequest
¶
Bases: TransparentMessage, ClientOutgoingMessage, ABC
Root of the hierarchy for Transparent Request PDUs.
Source code in givenergy_modbus/pdu/transparent.py
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 | |
expected_response()
¶
Create a template of a correctly shaped Response expected for this Request.
Source code in givenergy_modbus/pdu/transparent.py
191 192 193 | |
TransparentResponse
¶
Bases: TransparentMessage, ClientIncomingMessage, ABC
Root of the hierarchy for Transparent Response PDUs.
Source code in givenergy_modbus/pdu/transparent.py
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 | |
WriteHoldingRegister
¶
Bases: TransparentMessage, ABC
Request & Response PDUs for function #6/Write Holding Register.
Source code in givenergy_modbus/pdu/write_registers.py
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 | |
ensure_valid_state()
¶
Sanity check our internal state.
Source code in givenergy_modbus/pdu/write_registers.py
240 241 242 243 244 245 246 247 248 | |
WriteHoldingRegisterRequest
¶
Bases: WriteHoldingRegister, TransparentRequest
Concrete PDU implementation for handling function #6/Write Holding Register request messages.
Source code in givenergy_modbus/pdu/write_registers.py
251 252 253 254 255 256 257 258 259 260 261 262 263 | |
ensure_valid_state()
¶
Sanity check our internal state.
Source code in givenergy_modbus/pdu/write_registers.py
254 255 256 257 258 | |
WriteHoldingRegisterResponse
¶
Bases: WriteHoldingRegister, TransparentResponse
Concrete PDU implementation for handling function #6/Write Holding Register response messages.
Source code in givenergy_modbus/pdu/write_registers.py
266 267 268 269 270 271 272 273 | |
ensure_valid_state()
¶
Sanity check our internal state.
Source code in givenergy_modbus/pdu/write_registers.py
269 270 271 272 273 | |
Codec¶
PayloadDecoder
¶
Decoder to unpack a raw binary payload into sequential typed fields.
Source code in givenergy_modbus/codec.py
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 | |
decoded_bytes
property
¶
Return the number of bytes of the payload that have been decoded.
decoding_complete
property
¶
Returns whether the payload has been completely decoded.
payload_size
property
¶
Return the number of bytes the payload consists of.
remaining_bytes
property
¶
Return the number of bytes of the payload that have been decoded.
remaining_payload
property
¶
Return the unprocessed / remaining tail of the payload.
decode_16bit_uint()
¶
Decodes a 16-bit unsigned int from the buffer.
Source code in givenergy_modbus/codec.py
28 29 30 31 32 | |
decode_32bit_uint()
¶
Decodes a 32-bit unsigned int from the buffer.
Source code in givenergy_modbus/codec.py
34 35 36 37 38 | |
decode_64bit_uint()
¶
Decodes a 64-bit unsigned int from the buffer.
Source code in givenergy_modbus/codec.py
40 41 42 43 44 | |
decode_8bit_uint()
¶
Decodes an 8-bit unsigned int from the buffer.
Source code in givenergy_modbus/codec.py
22 23 24 25 26 | |
decode_string(size=1)
¶
Decodes a string from the buffer.
Source code in givenergy_modbus/codec.py
46 47 48 49 50 51 52 53 | |
PayloadEncoder
¶
Encode sequential typed fields into a raw binary payload.
Source code in givenergy_modbus/codec.py
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 | |
crc
property
¶
Calculate a Modbus-compatible CRC based on the buffer contents.
payload
property
¶
Return the payload buffer.
add_16bit_uint(value)
¶
Adds a 16-bit unsigned int to the buffer.
Source code in givenergy_modbus/codec.py
109 110 111 112 | |
add_32bit_uint(value)
¶
Adds a 32-bit unsigned int to the buffer.
Source code in givenergy_modbus/codec.py
114 115 116 117 | |
add_64bit_uint(value)
¶
Adds a 64-bit unsigned int to the buffer.
Source code in givenergy_modbus/codec.py
119 120 121 122 | |
add_8bit_uint(value)
¶
Adds an 8-bit unsigned int to the buffer.
Source code in givenergy_modbus/codec.py
104 105 106 107 | |
add_string(value, length)
¶
Adds a string to the buffer.
Source code in givenergy_modbus/codec.py
124 125 126 127 128 | |
reset()
¶
Reset the payload buffer.
Source code in givenergy_modbus/codec.py
90 91 92 | |
Exceptions¶
CommunicationError
¶
Bases: ExceptionBase
Exception to indicate a communication error.
Source code in givenergy_modbus/exceptions.py
37 38 | |
ExceptionBase
¶
Bases: Exception
Base exception.
Source code in givenergy_modbus/exceptions.py
9 10 11 12 13 14 15 16 | |
InvalidFrame
¶
Bases: ExceptionBase
Thrown during framing when a message cannot be extracted from a frame buffer.
Source code in givenergy_modbus/exceptions.py
27 28 29 30 31 32 33 34 | |
InvalidPduState
¶
Bases: ExceptionBase
Thrown during PDU self-validation.
Source code in givenergy_modbus/exceptions.py
19 20 21 22 23 24 | |
PlantNotDetected
¶
Bases: CommunicationError
Raised when a capability-aware poll is attempted before detect() has run.
load_config() / refresh() route by plant.capabilities (device kind,
inverter address, slot layout). With no capabilities there is no safe default —
guessing an inverter address (historically 0x32) silently times out on models
that answer elsewhere (e.g. an All-in-One at 0x11). Rather than guess, the poll
refuses: call detect() once first, or restore a persisted PlantCapabilities
onto client.plant.capabilities before polling.
Source code in givenergy_modbus/exceptions.py
41 42 43 44 45 46 47 48 49 50 | |
PlantTopologyMismatch
¶
Bases: CommunicationError
Raised when detect(prior=...) finds the plant doesn't match the supplied prior.
Carries both prior (what the caller asserted) and actual (a PlantCapabilities
reflecting what confirmed on this run). On raise, the Client's plant.capabilities
is left as None — callers that wish to accept the new topology must explicitly
assign client.plant.capabilities = exc.actual.
Caller policy decides whether to retry (e.g. with longer timeouts), fall back to detect() without prior, or surface the change to the user.
Source code in givenergy_modbus/exceptions.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
ReadFailure
¶
Bases: NamedTuple
Identifies a single register read that failed (after retries) during a poll.
Structured so a consumer can reason about which device and bank dropped (e.g. "battery 0x34 is offline") without parsing log lines.
Source code in givenergy_modbus/exceptions.py
76 77 78 79 80 81 82 83 84 85 86 | |
RefreshError
¶
Bases: CommunicationError
Base for a refresh()/load_config() that did not fully succeed.
Carries the structured set of reads that failed (failures) plus the raw
underlying exceptions grouped as an ExceptionGroup (cause) for
tracebacks / drill-down.
Source code in givenergy_modbus/exceptions.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
RefreshFailed
¶
Bases: RefreshError
Every register read in the poll failed — the link is effectively dead.
No usable data came back, so (unlike RefreshPartiallySucceeded) there is
no partial plant to hand over; callers should treat the device as
unavailable.
Source code in givenergy_modbus/exceptions.py
124 125 126 127 128 129 130 | |
RefreshPartiallySucceeded
¶
Bases: RefreshError
Some — but not all — register reads in a poll failed.
The data that was collected is attached as plant. This exception is
the consumer's one opportunity to do something useful with that partial
data — cache it, surface it, count the gap — before deciding how to treat
the missing reads. Catching it and carrying on (even ignoring it) is a
legitimate choice; the point is that it's the consumer's choice, made
here, rather than something the library silently decided for them.
Source code in givenergy_modbus/exceptions.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |