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.
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
|
Source code in src/py20305/telemetry/coordinator.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
telemetry
property
¶
The metering manager, or None when the server mirrors nothing.
der_resources
property
¶
The DER resource manager, once setup has run.
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
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
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 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 | |
start_metering ¶
start_metering(lfdi: str, post_rate: int, log_event_list_href: str | None = None, der_availability_href: 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
|
Source code in src/py20305/telemetry/manager.py
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
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
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 | |
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.
Creates MUP resources with system-wide MirrorMeterReadings (7 specs: W/Var/Hz/V/PF/VA/A) and, on multi-phase devices, an additional set of per-line readings for each phase advertised by the inverter (W/Var/V/PF/ VA/A per line; Hz is grid-wide and stays system-only).
ReadingTypeSpec
dataclass
¶
Specification for a MirrorMeterReading's ReadingType.
Source code in src/py20305/telemetry/mup.py
ReadingProfile ¶
Bases: StrEnum
How a device's MirrorMeterReadings are encoded.
DEFAULT is the historical encoding. SIGNED_LOAD_CONVENTION carries
the sign on every value (flowDirection 0) using the load convention --
active power negative on export, reactive power negative when the DER
injects -- with commodity, dataQualifier and kind left Not Applicable, and
adds line-to-line voltage and State of Energy readings when the device
supplies them.
Source code in src/py20305/telemetry/mup.py
ac_type_of ¶
The SunSpec 701 ACType in monitoring data, or None if absent or not an int.
Source code in src/py20305/telemetry/mup.py
registration_slots ¶
registration_slots(monitoring_data: dict[str, Any], profile: ReadingProfile, registered: frozenset[int] = frozenset()) -> frozenset[int]
The mRID slots a MUP built now would register.
Under SIGNED_LOAD_CONVENTION the set grows when an optional reading first appears, which is the signal to re-POST the MUP so the new mRID arrives with its ReadingType (Rule h.2) instead of meeting Rule h.3.
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
create_mup ¶
create_mup(lfdi: str, monitoring_data: dict[str, Any], post_rate: int, overrides: dict[str, ReadingOverride] | None = None, *, profile: ReadingProfile = ReadingProfile.DEFAULT, registered: frozenset[int] = frozenset()) -> MirrorUsagePoint
Create a MirrorUsagePoint with system + per-line MirrorMeterReadings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lfdi
|
str
|
Device LFDI (will be normalized to lowercase internally, stored as uppercase in deviceLFDI per spec) |
required |
monitoring_data
|
dict[str, Any]
|
Raw monitoring values from connector.fetch_monitoring().
May include |
required |
post_rate
|
int
|
Posting rate in seconds |
required |
overrides
|
dict[str, ReadingOverride] | None
|
Optional per-key ReadingType overrides from the connector
(see |
None
|
profile
|
ReadingProfile
|
How the readings are encoded (see :class: |
DEFAULT
|
registered
|
frozenset[int]
|
Slots registered by an earlier POST of this MUP. Under
SIGNED_LOAD_CONVENTION their optional readings are kept even
when absent from |
frozenset()
|
Returns:
| Type | Description |
|---|---|
MirrorUsagePoint
|
MirrorUsagePoint with system + per-line meter readings. |
Source code in src/py20305/telemetry/mup.py
create_meter_reading_list ¶
create_meter_reading_list(lfdi: str, monitoring_data: dict[str, Any], timestamp: int | None = None, overrides: dict[str, ReadingOverride] | None = None, *, post_rate: int = 300, next_update_time: int | None = None, stale: bool = False, profile: ReadingProfile = ReadingProfile.DEFAULT, registered: frozenset[int] | None = None) -> MirrorMeterReadingList
Create a MirrorMeterReadingList with current readings.
This is used when POSTing updated readings to an existing MUP. We post a
reading only for quantities the connector actually supplied this cycle: a
spec whose key is absent or None in monitoring_data is omitted
rather than zero-filled, so an un-measured quantity doesn't show up as a
misleading 0 (e.g. 0 V) on the server.
overrides (see BaseConnector.reading_overrides) supplies a per-key
qualityFlags default; unset keys use the standard valid flag.
timestamp is the instant the values were acquired, which since the
poll planner is no longer the instant they are posted. It becomes
timePeriod.start and lastUpdateTime; per METER.001 the interval runs
forward from start, so the existing duration semantics are unchanged and
only the clock supplying start differs.
next_update_time is when this MirrorMeterReading will next be posted,
not when the device will next be read, letting a server detect a stalled
feed without waiting out the 72-hour MUP timeout. Post cadence rather than
acquisition cadence because the two differ once the poll planner owns
acquisition, and only the former is reliably knowable: a device in backoff
has no predictable next read. None when the caller cannot say.
stale marks the sample older than its consumers asked for, or from an
unreachable device. It ORs the questionable bit onto whatever quality the
connector reported rather than replacing it, so a connector saying valid
cannot mask staleness the client knows about.
This is a subset of what create_mup registered -- create_mup always
registers the full ReadingType set for the device, so every omitted reading's
ReadingType is still registered. Posting a subset of registered
MirrorMeterReadings is valid per IEEE 2030.5 §10.11.3 (MirrorMeterReadings are
optional in the MUP and updates), and mRIDs are deterministic from
(lfdi, slot_index, pen) so a quantity that resumes reporting later matches
its registered ReadingType (Rule h.1).
Under SIGNED_LOAD_CONVENTION every reading is an instantaneous sample, so
its duration is 0 whatever the dataQualifier, and its value is scaled from the
effective multiplier (see _signed_load_value). registered, when given,
limits it to slots the MUP has registered, so a reading whose registration
has not succeeded yet is held back rather than met with Rule h.3.
Source code in src/py20305/telemetry/mup.py
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 | |
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
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |
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
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 monitoring 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 monitoring key's value and everything acquired alongside it.
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
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 | |
declare ¶
release ¶
read
async
¶
Read device through its connector, now.
Source code in src/py20305/readings.py
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 | |
split_quality ¶
Separate measured keys from their "<key>__quality" companions.
Lives with the vocabulary rather than with any store because it encodes the
connector convention itself, and every path that turns a raw
fetch_monitoring response into entries has to apply it identically. A
second copy would drift.
Source code in src/py20305/readings.py
typed_overrides ¶
Keep only well-formed :class:ReadingOverride values from a connector's dict.
Here for the same reason as :func:split_quality: it encodes the connector
contract, and every path that turns a raw reading_overrides() response
into a snapshot has to apply it identically or the snapshots disagree.
:attr:DeviceSnapshot.reading_overrides is typed
Mapping[str, ReadingOverride], and the values arrive from third-party
code through an Any, so nothing but this check keeps the annotation
honest.
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.