Telemetry¶
Posting measurements and DER resources back to the server.
py20305.telemetry.coordinator ¶
Composition of the two telemetry managers for one running client.
TelemetryManager mirrors readings as MirrorUsagePoints; DerResourceManager
PUTs DERCapability, DERSettings and DERStatus. Both need the same things --
which devices, at what rate, to which discovered hrefs -- and both have to be
restarted when rediscovery moves those hrefs. That shared bookkeeping lives
here rather than in the runner so a host application embedding this library
starts telemetry the same way the runner does, instead of reimplementing it and
drifting.
The coordinator owns lifecycle, not protocol: every decision about what a resource contains stays in the managers it composes.
DeviceRoleConfig
dataclass
¶
What one device measures, and where a site meter's readings are mirrored.
Attributes:
| Name | Type | Description |
|---|---|---|
role |
DeviceRole
|
See :class: |
revenue_quality |
bool
|
Set isRevenueQuality in the MUP roleFlags. |
mirror_under |
Literal['site', 'own']
|
Site meters only. |
Source code in src/py20305/telemetry/coordinator.py
TelemetryCoordinator ¶
Starts, restarts and stops the telemetry managers for a set of devices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
CsipClient
|
The connected client. Its discovered state supplies every
href, so |
required |
lfdis
|
Iterable[str]
|
The devices to report on, as configured. Held as given: a device the server has temporarily forgotten stays registered, because configuration says what to manage and discovery says only where to send it. |
required |
connector_resolver
|
Callable[[str], BaseConnector | Awaitable[BaseConnector]]
|
Resolves an LFDI to its connector. Taken rather than derived from the client's dispatcher, so telemetry keeps no dependency on the connector layer and a host application can pass its own. |
required |
post_rate_seconds
|
int
|
Fallback interval for readings and DERStatus, used
when the server's |
DEFAULT_POST_RATE
|
der_capability_poll_rate_seconds
|
int
|
Interval for DERCapability PUTs. |
DEFAULT_CAPABILITY_POLL_RATE
|
der_settings_poll_rate_seconds
|
int
|
Interval for DERSettings PUTs. |
DEFAULT_SETTINGS_POLL_RATE
|
device_telemetry
|
DeviceTelemetryEmitter | None
|
Reports each device read to a monitoring system. |
None
|
source
|
MeasurementSource | None
|
Where measurements come from. Omitted, the metering cycle reads the connector directly; a host application serving several interfaces passes a store-backed source so a concurrent read does not become a second device poll. |
None
|
is_provisioned
|
Callable[[str], bool] | None
|
Optional per-cycle gate on mirroring a device. |
None
|
command_observer
|
CommandObserver | None
|
Offered the DERStatus the resource manager already reads, as confirmation evidence for outstanding commands. |
None
|
reading_profile
|
ReadingProfile
|
How MirrorMeterReadings are encoded; see
:class: |
DEFAULT
|
power_direction
|
PowerDirection
|
How W and var carry their direction under the
DEFAULT profile; see :class: |
DEFAULT
|
roles
|
Mapping[str, DeviceRoleConfig] | None
|
Each device's role, by LFDI. A device not named is a DER. |
None
|
site_lfdi
|
str | None
|
LFDI of the site's EndDevice, which a site meter's MUP is posted under by default. Defaults to this client's own certificate LFDI, the EndDevice it registers for itself. |
None
|
site_interval_history
|
IntervalHistory | None
|
Integrates site meter readings into the site series of the operations history. |
None
|
der_resource_put_policy
|
PutPolicy
|
When DERCapability and DERSettings are PUT;
see :data: |
'periodic'
|
Source code in src/py20305/telemetry/coordinator.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 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 | |
telemetry
property
¶
The metering manager, or None when the server mirrors nothing.
der_resources
property
¶
The DER resource manager, once setup has run.
restore_from_checkpoint ¶
Restore the registered readings from :meth:to_checkpoint data.
May be called before setup; the data is applied when the metering
manager is built. Data that cannot be used is ignored with a warning.
Source code in src/py20305/telemetry/coordinator.py
to_checkpoint ¶
Return the registered readings as JSON-safe data, or None with no metering manager.
set_on_registration_change ¶
Call callback after the readings registered with the server change.
Use it to store :meth:to_checkpoint.
Source code in src/py20305/telemetry/coordinator.py
setup ¶
start_device_telemetry ¶
Start metering and DER resource PUTs for one device, or all of them.
Devices already started are left alone, so this is safe to call when a
single device is added. Naming a device that was not in lfdis
registers it: a host application that registers devices while the
client runs is making the request explicitly, and skipping it silently
would report nothing for that device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lfdi
|
str | None
|
One device, or None for every registered device. |
None
|
Source code in src/py20305/telemetry/coordinator.py
stop_device_telemetry ¶
Stop reporting one device and unregister it.
For a device the server has deleted, or one an operator removed. Both managers drop it, and a later rediscovery does not bring it back -- unlike a device that is merely absent from the current discovery, which stays registered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lfdi
|
str
|
Device LFDI. |
required |
Source code in src/py20305/telemetry/coordinator.py
restart_device_telemetry
async
¶
Re-read every href from freshly discovered state.
Wired to the client's structural-change hook: an upstream restart or a topology change moves the paths both managers PUT to, and a snapshot taken at first discovery would keep posting where the server no longer serves. Devices absent from the new state stay registered and are started with no hrefs, which makes their cycles no-ops until the server publishes them again.
Source code in src/py20305/telemetry/coordinator.py
shutdown
async
¶
Stop metering, then the DER resource PUTs.
Metering first because it is the noisier of the two: a reading posted during teardown is a reading the server has to reconcile, while a DERStatus PUT is idempotent.
Source code in src/py20305/telemetry/coordinator.py
py20305.telemetry.manager ¶
TelemetryManager for IEEE 2030.5 MirrorUsagePoint posting.
Manages the lifecycle of telemetry posting for DER devices: - Creates MUP on first metering cycle - Posts meter readings on subsequent cycles - Handles 404 recovery by re-creating MUP - Posts LogEvents when alarm status is non-zero - PUTs DERAvailability when href is discovered
DeviceTelemetryState
dataclass
¶
Per-device telemetry tracking state.
Source code in src/py20305/telemetry/manager.py
posted_under
property
¶
Return the LFDI of the EndDevice this device's MUP is posted under.
TelemetryManager ¶
Manages telemetry posting for all devices.
The manager handles the full MUP lifecycle: 1. On first metering cycle, creates and POSTs the MUP 2. On subsequent cycles, POSTs meter reading updates 3. On 404 response, resets state to re-create MUP
Additionally, on each cycle (after the MUP/readings stage): 4. POSTs LogEvent if alarm status is non-zero 5. PUTs DERAvailability if href is discovered
Each posting stage is independently error-handled so failures don't cascade across posting types.
LFDI keys are normalized to lowercase to avoid case mismatch bugs.
Source code in src/py20305/telemetry/manager.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 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 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 | |
start_metering ¶
start_metering(lfdi: str, post_rate: int, log_event_list_href: str | None = None, der_availability_href: str | None = None, *, role: DeviceRole = DeviceRole.DER, revenue_quality: bool = False, mirror_lfdi: str | None = None) -> None
Start metering loop for a device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lfdi
|
str
|
Device LFDI |
required |
post_rate
|
int
|
Posting interval in seconds |
required |
log_event_list_href
|
str | None
|
Server path for LogEventList POST |
None
|
der_availability_href
|
str | None
|
Server path for DERAvailability PUT |
None
|
role
|
DeviceRole
|
What the device measures (see :class: |
DER
|
revenue_quality
|
bool
|
Set isRevenueQuality in the MUP roleFlags. |
False
|
mirror_lfdi
|
str | None
|
LFDI of the EndDevice to post the MUP under, when not
the device's own. The mRIDs still derive from |
None
|
Source code in src/py20305/telemetry/manager.py
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 | |
stop_metering ¶
Stop metering for a device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lfdi
|
str
|
Device LFDI |
required |
Source code in src/py20305/telemetry/manager.py
set_on_registration_change ¶
Call callback after a MUP POST registered a different set of readings.
Use it to store :meth:to_checkpoint. An exception the callback raises
is logged and does not stop the metering cycle.
Source code in src/py20305/telemetry/manager.py
to_checkpoint ¶
Return the registered readings of every device as JSON-safe data.
Store it and hand it to :meth:restore_from_checkpoint after a restart,
so the readings register again with the ReadingTypes the server holds.
Source code in src/py20305/telemetry/manager.py
restore_from_checkpoint ¶
Load registrations from :meth:to_checkpoint data; return how many devices.
Anything that cannot be used is ignored with a warning: data of another version or shape, a checkpoint written under another reading profile or power direction, and any device or reading that does not parse. A device already started with registrations of its own keeps them.
Source code in src/py20305/telemetry/manager.py
post_log_event
async
¶
POST a manually triggered LogEvent for a device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
DeviceTelemetryState
|
Device telemetry state (must have log_event_list_href). |
required |
alarm_status
|
int
|
Alarm status bitmap. |
required |
details
|
str | None
|
Optional human-readable detail string. |
None
|
Raises:
| Type | Description |
|---|---|
Sep2ProtocolError
|
If the POST fails. |
ValueError
|
If device has no log_event_list_href. |
Source code in src/py20305/telemetry/manager.py
post_log_event_burst
async
¶
post_log_event_burst(lfdi: str, alarm_status: int = 1, details: str | None = None, interval: float = 1.0) -> int
Post a burst of LogEvents for BASIC-027 conformance.
Posts exactly _LOG_EVENT_BURST_COUNT LogEvents with incrementing
logEventIDs, spaced by interval seconds so each has a distinct
createdDateTime.
alarm_status must resolve to exactly ONE mapped alarm bit. The
burst posts that bit's code N times, so the returned count is a true
POST count (the caller derives log_event_ids from it). Routing a
multi-bit bitmap through here would post N x bits events while
reporting N -- and BASIC-027 wants exactly N.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lfdi
|
str
|
Device LFDI (case-insensitive). |
required |
alarm_status
|
int
|
Alarm bitmap with exactly one IEEE-mapped bit set. |
1
|
details
|
str | None
|
Optional human-readable detail string. |
None
|
interval
|
float
|
Seconds between each POST (0 = no delay). |
1.0
|
Returns:
| Type | Description |
|---|---|
int
|
Number of events successfully posted. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the device is unknown, has no log_event_list_href,
or |
Source code in src/py20305/telemetry/manager.py
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 | |
find_device_with_log_events ¶
Return the first active device LFDI that has a log_event_list_href.
get_device_state ¶
get_all_posted_log_events ¶
Return all posted log events across all devices.
Source code in src/py20305/telemetry/manager.py
shutdown
async
¶
py20305.telemetry.mup ¶
MirrorUsagePoint creation for IEEE 2030.5 telemetry.
A connector returns a list of :class:~py20305.connectors.reading.Reading.
Each reading becomes a MirrorMeterReading whose mRID is derived from the
reading's identity (its ReadingType fields, see
:func:~py20305.connectors.reading.reading_identity), so a reading whose
ReadingType differs from another's always has a different mRID. IEEE
2030.5-2023 §10.11.3 Rule n forbids changing a MirrorMeterReading's ReadingType
once created, and this keeps that true without special cases.
Readings that release 0.16 registered keep the mRID it gave them. A fixed table maps each of those identities to its 0.16 slot, and the slot gives the mRID:
- 0: the MirrorUsagePoint itself.
- 1-7: system W, var, Hz, V (average), PF, VA, A.
- 8: state of energy (SIGNED_LOAD_CONVENTION only).
- 10-27: per-line W, var, V (average, line to neutral), PF, VA, A, six slots per line.
- 28-30: line-to-line voltage (SIGNED_LOAD_CONVENTION only).
- 31-38: W and var with flowDirection 4 (
PowerDirection.NET). - 41-48 and 51-58: W and var with flowDirection 1 and 19
(
PowerDirection.SPLIT). - 61 and 62: energy delivered forward and in reverse, DEFAULT profile only.
- 71-77 and 80-97: the system and per-line readings under
ReadingProfile.SIGNED_AS_REPORTED, whose ReadingTypes carry no flowDirection (the DEFAULT slot plus 70).
Every other identity gets an mRID hashed from the identity, in a layout that cannot collide with the slot layout: a slot is two decimal digits and the hash layout puts a hex letter at the same position. Under SIGNED_AS_REPORTED the hash also covers the profile, since a reading that omits flowDirection has a different ReadingType from the same identity under DEFAULT.
DeviceRole ¶
Bases: StrEnum
What a configured device measures, which sets its MUP roleFlags.
DER: a DER. Its readings are mirrored with roleFlags 0x49.SITE_METER: the meter at the premises point of delivery, mirrored with roleFlags 0x03. Positive real power is import, from the grid to the premises, which IEEE 2030.5 FlowDirectionType names Forward.DER_METER: a meter on one DER's circuit, mirrored with roleFlags 0x49 like the DER itself. Positive real power is the DER's output.
Reactive power takes the same orientation as real power. The role also
sets how SIGNED_LOAD_CONVENTION signs W and var (see
:class:ReadingProfile). A meter takes no controls and has no DER
resources.
Source code in src/py20305/telemetry/mup.py
ReadingProfile ¶
Bases: StrEnum
How a device's MirrorMeterReadings are encoded.
DEFAULT posts each reading's ReadingType as the connector states it,
with commodity 1 (electricity, secondary metered). A W, var, VA, A or PF
reading that sets no flowDirection takes it from the value's sign when the
reading is first registered and posts magnitudes.
SIGNED_LOAD_CONVENTION carries the sign on every value (flowDirection
0) using the load convention -- active power negative on export, reactive
power negative on injection -- with commodity, dataQualifier and kind left
Not Applicable, and current in whole amperes unless the reading sets a
multiplier.
How W and var are signed depends on the device's :class:DeviceRole. A
DER and a DER meter report them positive for the DER's output, which the
load convention counts as export, so both are negated. A site meter
reports them positive for import, from the grid to the premises, which is
already the load convention, so both are posted as reported.
SIGNED_AS_REPORTED posts W, var and PF with the sign the connector
reports, whatever the device's role -- for a DER, W positive while it
delivers and negative while it absorbs -- and omits flowDirection from a
ReadingType that does not state one (optional in IEEE 2030.5
ReadingType). Every other field keeps its DEFAULT value, and the other
quantities post as magnitudes. A connector can fix the registered set with
declared_readings().
Source code in src/py20305/telemetry/mup.py
PowerDirection ¶
Bases: StrEnum
How real and reactive power carry their direction under the DEFAULT profile.
IEEE 2030.5 forbids changing a MeterReading's ReadingType once created, and its flow directions other than Net carry a positive magnitude. So:
DEFAULTsets each reading's flowDirection once, from the value's sign when the reading is registered (1 Forward or 19 Reverse), and posts magnitudes. A value that changes sign later, a battery that registered while discharging and then charges, is posted under the first direction.NETposts flowDirection 4 (Net, forward minus reverse) with the sign on the value: positive while the DER delivers, negative while it absorbs.SPLITposts two readings per quantity, flowDirection 1 (Forward) and 19 (Reverse), each a magnitude, with the inactive one 0.
It applies to W and var readings that set no flowDirection. NET and
SPLIT readings have mRIDs of their own, so a device switched between
modes never posts a value under a ReadingType registered for another mode.
Source code in src/py20305/telemetry/mup.py
RegisteredReading
dataclass
¶
A MirrorMeterReading as registered in a MUP: its mRID, description and ReadingType.
Kept by the caller after a successful MUP POST and passed back, so a re-POST repeats each ReadingType exactly as the server already holds it.
Source code in src/py20305/telemetry/mup.py
role_flags_for ¶
Return the MUP roleFlags for a device role, with isRevenueQuality when set.
Source code in src/py20305/telemetry/mup.py
compute_sfdi ¶
Compute SFDI from LFDI using Luhn-like check digit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lfdi
|
str
|
40-character hex string (LFDI) |
required |
Returns:
| Type | Description |
|---|---|
int
|
SFDI as integer with check digit appended |
Source code in src/py20305/telemetry/mup.py
mup_mrid ¶
Return the mRID of the MirrorUsagePoint :func:create_mup builds for lfdi.
valid_readings ¶
Return the readings the library can post, each identity once.
A connector is third-party code. An entry that is not a valid
:class:Reading is logged and dropped, and so is a second reading with the
identity of an earlier one, which would otherwise post two values under
one mRID.
Source code in src/py20305/telemetry/mup.py
undeclared_readings ¶
undeclared_readings(readings: Iterable[object], declared: frozenset[ReadingIdentity]) -> frozenset[ReadingIdentity]
Return the identities in readings that declared leaves out, so are not posted.
Source code in src/py20305/telemetry/mup.py
plan_registration ¶
plan_registration(lfdi: str, readings: Sequence[Reading], *, profile: ReadingProfile = ReadingProfile.DEFAULT, power_direction: PowerDirection = PowerDirection.DEFAULT, registered: Mapping[bytes, RegisteredReading] | None = None, declared: frozenset[ReadingIdentity] | None = None) -> dict[bytes, RegisteredReading]
Return the MirrorMeterReadings a MUP built now registers, keyed by mRID.
Every reading in registered is kept with its ReadingType unchanged, so a
re-POST never drops a reading that is absent this cycle and never changes a
ReadingType the server holds (Rule a.4 writes the new MUP over the old one,
and Rule n forbids the change). A new reading is added with the ReadingType
it has now.
Under SIGNED_AS_REPORTED with declared, the declared readings are
registered whether or not this cycle supplies a value, and no other.
Source code in src/py20305/telemetry/mup.py
create_mup ¶
create_mup(lfdi: str, readings: Sequence[Reading], post_rate: int, *, profile: ReadingProfile = ReadingProfile.DEFAULT, registered: Mapping[bytes, RegisteredReading] | None = None, power_direction: PowerDirection = PowerDirection.DEFAULT, role: DeviceRole = DeviceRole.DER, revenue_quality: bool = False, device_lfdi: str | None = None, declared: frozenset[ReadingIdentity] | None = None) -> MirrorUsagePoint
Create a MirrorUsagePoint registering a MirrorMeterReading per reading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lfdi
|
str
|
Device LFDI. Every mRID is derived from it, so two devices
mirrored under one |
required |
readings
|
Sequence[Reading]
|
The connector's readings this cycle. |
required |
post_rate
|
int
|
Posting rate in seconds. |
required |
profile
|
ReadingProfile
|
How the readings are encoded (see :class: |
DEFAULT
|
registered
|
Mapping[bytes, RegisteredReading] | None
|
What an earlier POST of this MUP registered (see
:func: |
None
|
power_direction
|
PowerDirection
|
How W and var carry their direction under the
DEFAULT profile (see :class: |
DEFAULT
|
role
|
DeviceRole
|
What the device measures; sets roleFlags (see
:class: |
DER
|
revenue_quality
|
bool
|
Set isRevenueQuality in roleFlags. |
False
|
device_lfdi
|
str | None
|
LFDI of the EndDevice the MUP is posted under, put in
deviceLFDI. Defaults to |
None
|
declared
|
frozenset[ReadingIdentity] | None
|
The connector's |
None
|
Source code in src/py20305/telemetry/mup.py
create_meter_reading_list ¶
create_meter_reading_list(lfdi: str, readings: Sequence[Reading], timestamp: int | None = None, *, post_rate: int = 300, next_update_time: int | None = None, stale: bool = False, profile: ReadingProfile = ReadingProfile.DEFAULT, registered: Mapping[bytes, RegisteredReading] | None = None, power_direction: PowerDirection = PowerDirection.DEFAULT, role: DeviceRole = DeviceRole.DER, declared: frozenset[ReadingIdentity] | None = None) -> MirrorMeterReadingList
Create a MirrorMeterReadingList with this cycle's readings.
Used when POSTing readings to an existing MUP. Only the readings the
connector supplied are posted, so an unmeasured quantity never shows up as
a misleading 0. Posting a subset of the registered MirrorMeterReadings
is valid per IEEE 2030.5 §10.11.3, and each mRID is fixed by the reading's
identity, so a quantity that resumes reporting matches its registered
ReadingType (Rule h.1). The ReadingType itself is not included (Rule n).
timestamp is the instant the values were acquired. It becomes
timePeriod.start and lastUpdateTime. next_update_time is when
this MirrorMeterReading will next be posted, so a server can detect a
stalled feed without waiting out the 72-hour MUP timeout; None when the
caller cannot say.
stale marks the sample older than its consumers asked for, or from an
unreachable device (see :func:_quality_flags).
registered, when given, limits the list to readings the MUP has
registered, so a reading whose registration has not succeeded yet is held
back rather than met with Rule h.3. profile, power_direction,
role and declared must be the ones the MUP was created with; under
SIGNED_AS_REPORTED only declared readings are posted.
An interval reading (Average, Maximum, Minimum) covers a window that
CSIP-AUS requires to match the MUP postRate, so its duration is
post_rate; an instantaneous reading is a point in time, duration 0.
Under SIGNED_LOAD_CONVENTION every reading is an instantaneous sample.
Source code in src/py20305/telemetry/mup.py
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 | |
py20305.telemetry.checkpoint ¶
Serialize the readings a MirrorUsagePoint registered, so a restart can repeat them.
IEEE 2030.5-2023 section 10.10.3 rule n) says that once created, the ReadingType of a MirrorMeterReading SHALL NOT be modified. Under the default reading profile the flowDirection of a power reading comes from the sign of its value when the reading is registered. A client that forgets its registrations at a restart registers again from whatever sign the value has then, which can change the ReadingType the server holds. This module turns the registrations into plain data a caller can store, and back.
reading_to_dict ¶
Return a registered reading as JSON-safe data.
Source code in src/py20305/telemetry/checkpoint.py
reading_from_dict ¶
Return the registered reading data describes.
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in src/py20305/telemetry/checkpoint.py
load_checkpoint ¶
Return the data stored at path, or None when there is none or it is unreadable.
Source code in src/py20305/telemetry/checkpoint.py
save_checkpoint ¶
Write data to path through a temporary file, so a crash leaves the old file.
Raises:
| Type | Description |
|---|---|
OSError
|
the directory or file cannot be written. |
Source code in src/py20305/telemetry/checkpoint.py
py20305.telemetry.der_resource_manager ¶
DerResourceManager for periodic PUT of DER resources.
Manages the lifecycle of DERCapability, DERSettings, and DERStatus PUT operations for each device. Follows the TelemetryManager composition pattern: owns a PollScheduler, accepts client + connector resolver.
DeviceDerState
dataclass
¶
Per-device DER resource tracking state.
Source code in src/py20305/telemetry/der_resource_manager.py
DerResourceManager ¶
Manages periodic PUT of DER resources for all devices.
Handles three resource types: - DERCapability (nameplate ratings from connector) - DERSettings (configuration from connector) - DERStatus (operational status from connector)
Each resource is PUT on its own poll cycle. Errors are logged but never propagate (the poll loop must not crash).
Source code in src/py20305/telemetry/der_resource_manager.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 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 | |
active_devices
property
¶
Return list of LFDIs with active DER resource cycles.
start_device ¶
start_device(lfdi: str, capability_href: str | None, settings_href: str | None, status_href: str | None, *, capability_poll_rate: int = 86400, settings_poll_rate: int = 60, status_poll_rate: int = 300) -> None
Start periodic DER resource PUTs for a device.
Only schedules cycles for non-None hrefs. Each resource type runs at its own poll rate. DERCapability and DERSettings use change detection to skip PUTs when the data hasn't changed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lfdi
|
str
|
Device LFDI. |
required |
capability_href
|
str | None
|
Server path for DERCapability PUT. |
required |
settings_href
|
str | None
|
Server path for DERSettings PUT. |
required |
status_href
|
str | None
|
Server path for DERStatus PUT. |
required |
capability_poll_rate
|
int
|
Interval for DERCapability PUTs (default 24h). |
86400
|
settings_poll_rate
|
int
|
Interval for DERSettings PUTs (default 1min). |
60
|
status_poll_rate
|
int
|
Interval for DERStatus PUTs (default 300s). |
300
|
Source code in src/py20305/telemetry/der_resource_manager.py
stop_device ¶
Stop the DER resource PUTs for one device.
Drops the device's state, which is what the cycles read -- each becomes
a no-op immediately, and the scheduler's tasks are cleaned up by
shutdown. Mirrors TelemetryManager.stop_metering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lfdi
|
str
|
Device LFDI. |
required |
Source code in src/py20305/telemetry/der_resource_manager.py
forget_sent ¶
Treat every DERCapability and DERSettings as unsent, so each is PUT again.
For when the server may no longer hold what was sent, such as after a
sustained loss of contact. Only affects the on_change policy; under
periodic every capability cycle PUTs anyway.
Source code in src/py20305/telemetry/der_resource_manager.py
shutdown
async
¶
Stop all scheduled DER resource tasks.
py20305.readings ¶
Measurement vocabulary, and the source interface that supplies it.
One acquisition of a device's monitoring data becomes one :class:DeviceSnapshot
holding a :class:PointEntry per reading, keyed by
:func:~py20305.connectors.reading.reading_key. Entries are immutable: an
acquisition replaces a device's snapshot rather than mutating it, so a reader
that holds a snapshot always sees a coherent set of points from a single device
read.
:class:MeasurementSource is where a consumer gets those snapshots. It exists so
the telemetry path states what it needs -- a reading for this device, no older
than this -- without naming who satisfies it. :class:DirectConnectorSource is
the answer for a deployment with one consumer: read the connector, cache nothing.
A deployment serving several upstream interfaces over one device model supplies a
caching, demand-coalescing implementation instead, and nothing in the telemetry
path changes.
Quality ¶
Bases: Enum
The store's own health model for a value.
Deliberately not a protocol quality value. IEEE 2030.5 qualityFlags
is a separate bitfield the connector supplies and the MirrorUsagePoint path
posts; it rides along on :attr:PointEntry.protocol_quality rather than
being mapped onto this enum. The two answer different questions -- "did the
read succeed" versus "is this value still current".
Source code in src/py20305/readings.py
PointEntry
dataclass
¶
One reading and when it was acquired.
Source code in src/py20305/readings.py
DeviceSnapshot
dataclass
¶
A device's points as of one acquisition.
age is deliberately absent: it depends on a clock, and the store has
none. Callers compute it from :attr:last_success against whatever clock
they already hold.
Source code in src/py20305/readings.py
MeasurementSource ¶
Bases: Protocol
Where the telemetry path gets a device's measurements.
Three operations, because a consumer's interest in a device has a lifetime:
it announces what freshness it needs, reads repeatedly, and eventually stops
caring. An implementation that coalesces demand across several consumers
needs the first and last to do its job; one serving a single consumer can
ignore them, which is exactly what :class:DirectConnectorSource does.
Source code in src/py20305/readings.py
declare ¶
release ¶
read
async
¶
Return the best available snapshot of device, judged against max_age.
max_age is the freshness the caller wants, not a guarantee it gets:
a source may return an older sample marked STALE, or a COMM_LOST
one carrying the last known values. What it will not do is return a
stale sample looking fresh -- the verdict is already applied, so callers
do not call :func:with_freshness themselves. None means the caller
accepts whatever the source considers current.
Source code in src/py20305/readings.py
DirectConnectorSource ¶
Reads the connector on every request; never serves one from cache.
The single-consumer answer. With one upstream interface there is no second
reader to share a cached value with and no competing cadence to coalesce, so
caching a read would add staleness without removing a device read.
declare and release are deliberately inert: freshness is whatever the
read just returned.
It does retain the last successful snapshot per device. That is history, not a cache -- it is never returned in place of a read, only used so a failed read can report comm-lost against the last known values instead of an empty set, matching what the store-backed path does.
Source code in src/py20305/readings.py
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 | |
declare ¶
release ¶
read
async
¶
Read device through its connector, now.
Source code in src/py20305/readings.py
index_readings ¶
Return a connector's readings keyed by :func:reading_key.
A connector is third-party code and may return anything. A value that is not
a list or tuple raises TypeError; an entry that is not a valid
:class:Reading, or repeats an earlier reading's identity, is dropped with
a warning (see :func:~py20305.telemetry.mup.valid_readings). Identity
includes the multiplier, so two readings that differ only in multiplier are
both kept: the second is keyed by its reading_key plus :m<multiplier>.
Every path that turns a fetch_monitoring response into entries applies
this, so the snapshots agree.
Source code in src/py20305/readings.py
typed_declaration ¶
A connector's declared_readings() as a set of identities, or None if malformed.
The value comes from third-party code, and a declaration narrows what the
MirrorUsagePoint registers, so anything other than a collection of
:class:~py20305.connectors.reading.ReadingIdentity or
:class:~py20305.connectors.reading.Reading is treated as no declaration
rather than guessed at. A Reading stands for its identity; its value is
ignored.
Source code in src/py20305/readings.py
declared_readings_of ¶
connector.declared_readings(), typed; None when absent or broken.
Optional on the connector contract, so a connector that predates it, or does not subclass BaseConnector, declares nothing. A declaration that raises is no declaration: it must not turn a good read of the values into a failed one.
Source code in src/py20305/readings.py
with_freshness ¶
Downgrade a snapshot's GOOD entries to STALE once they exceed max_age.
Kept out of the store because staleness is not a property of the data: the same sample is fresh to a consumer wanting minute-old values and stale to one wanting second-old values. The store records when a value was acquired; what counts as too old belongs to whoever declared the demand.
COMM_LOST is left alone -- it already says something stronger than stale, and a value from an unreachable device is not merely late.