Connectors¶
Talking to the device underneath.
py20305.connectors.base ¶
Base connector class with async no-op defaults for all DER control modes.
Connectors inherit from BaseConnector and selectively override the methods they support. Unsupported modes are silent no-ops, matching the physical reality that not every device supports every IEEE 2030.5 control mode.
ConnectorConnectionError ¶
Bases: ConnectorError
Raised when the connector cannot reach the target device.
The optional permanent flag signals that the failure won't change
on retry without operator intervention -- e.g. Modbus protocol
exception codes 1-4 (illegal function/address/value, server failure),
which typically mean the configured device is missing models the
connector was told to scan for.
Source code in src/py20305/connectors/errors.py
ConnectorError ¶
ConnectorTimeoutError ¶
Bases: ConnectorError
Raised when a connector operation exceeds its deadline.
ConnectorValueError ¶
Bases: ConnectorError
Raised when a control parameter is outside the range the profile allows.
Distinct from :class:ConnectorWriteError: nothing was attempted. The
parameter itself is invalid, so no device could have accepted it and a retry
with the same value cannot succeed. The register is left untouched, including
any mode-enable point -- a lever must not be raised for a write that will not
happen.
Reported to the head-end as IEEE 2030.5 Table 31 status 253 (Invalid), because the fault is in the event's data rather than in what the device can do. Adapters translate accordingly at their own boundary.
Source code in src/py20305/connectors/errors.py
ConnectorWriteError ¶
Bases: ConnectorError
Raised when a control write fails or is rejected by the device.
ScheduleNotification
dataclass
¶
A relayed, forward-looking schedule event for a connector.
Pushed by the core on every change to a relayed schedule -- a control,
baseline, DOE or price -- so a downstream optimizer stays current without
polling for it. Informational only: it does not apply setpoints, which
remains the job of the update_* methods.
Source code in src/py20305/connectors/base.py
ReadingOverride
dataclass
¶
Per-quantity overrides for a connector's MirrorMeterReadings.
Returned (keyed by monitoring key, e.g. "W", "VL2") from
:meth:BaseConnector.reading_overrides to tailor ReadingType metadata and
the default qualityFlags to a connector's use case -- e.g. report a
quantity as a Maximum (data_qualifier=8) or a Summation
(accumulation_behaviour=9), or mark its readings derived.
Every field is optional; None leaves the client default in place, so
a connector only states the deltas it cares about. The ReadingType fields map
onto ReadingTypeSpec. quality_flags is a 16-bit value applied to the
Reading (not the ReadingType). flow_direction is intentionally not
overridable -- it stays derived from the value's sign.
Source code in src/py20305/connectors/base.py
BaseConnector ¶
Base connector with async no-op defaults for all DER methods.
Subclasses override only the methods their device supports. All methods are async to allow blocking I/O to be wrapped in executors.
Source code in src/py20305/connectors/base.py
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 | |
fetch_monitoring
async
¶
Return raw, unscaled power telemetry.
Signs are referenced to the DER and are a requirement, not a hint:
W SHALL be positive for generation and negative for absorption, and
Var positive for reactive power injection (over-excited) and negative
for absorption (under-excited). This is the SunSpec model 701 convention.
The SIGNED_LOAD_CONVENTION reading profile negates both, so a
connector reporting another convention posts the wrong sign.
Beyond the keys below, a connector may supply per-line keys (WL1,
VarL2, ...), ACType (SunSpec 701 enum), phase-to-phase voltages
(VL1L2, VL2L3, VL3L1) and State of Energy in Wh
(WHAvail). Absent or None means not measured.
Source code in src/py20305/connectors/base.py
reading_overrides ¶
Optional per-quantity ReadingType / qualityFlags overrides.
Keyed by the same monitoring key as fetch_monitoring ("W",
"VL2", ...). Return None (the default) to use the standard
ReadingType metadata and qualityFlags=valid for every reading. A
connector overrides only the deltas it needs; see :class:ReadingOverride.
For a static per-key qualityFlags default, set it here. For a
per-cycle value that varies with each sample (e.g. questionable on a
stale read), put it in fetch_monitoring under "<key>__quality"
(e.g. {"W": 1500, "W__quality": 0x10}); it takes precedence over the
static default for that cycle.
Source code in src/py20305/connectors/base.py
fetch_nameplate
async
¶
Return DER nameplate ratings.
Source code in src/py20305/connectors/base.py
fetch_configuration
async
¶
Return DER configuration settings.
Source code in src/py20305/connectors/base.py
fetch_availability
async
¶
Return DER availability / reserve status.
Source code in src/py20305/connectors/base.py
fetch_status
async
¶
Return DER operational status.
Source code in src/py20305/connectors/base.py
update_qv
async
¶
update_pv
async
¶
update_qp
async
¶
update_p_lim
async
¶
update_p_lim_inj
async
¶
update_p_lim_abs
async
¶
update_freq_watt
async
¶
update_pf
async
¶
update_const_q
async
¶
update_const_pf
async
¶
update_ov
async
¶
update_uv
async
¶
update_ov_mc
async
¶
update_uv_mc
async
¶
update_of
async
¶
update_uf
async
¶
update_fixed_w
async
¶
update_p_ramp
async
¶
update_es_permit_service
async
¶
update_connect
async
¶
update_max_lim_pct_va_absorb
async
¶
update_max_lim_pct_va_inject
async
¶
update_max_lim_pct_var_absorb
async
¶
update_max_lim_pct_var_inject
async
¶
update_max_lim_pct_w_absorb
async
¶
update_max_lim_var_absorb
async
¶
update_max_lim_var_inject
async
¶
update_target_v
async
¶
update_target_var
async
¶
update_target_w
async
¶
update_delta_w
async
¶
update_delta_var
async
¶
update_fixed_v
async
¶
update_grid_connect_permit
async
¶
update_island_permit
async
¶
update_exp_lim
async
¶
update_imp_lim
async
¶
update_gen_lim
async
¶
update_load_lim
async
¶
update_pricing_mode
async
¶
on_schedule_notification
async
¶
Single transport for all relayed schedule streams.
Called by the core on every change to a control/baseline affecting this
connector, so downstream logic has current schedule state without
polling. The default fans out to the per-stream notification_*
convenience methods; override either this transport or the specific
stream methods. Informational only -- exceptions are logged and
swallowed by the core, never affecting dispatch.
Source code in src/py20305/connectors/base.py
notification_control
async
¶
notification_default_baseline
async
¶
notification_doe
async
¶
notification_price
async
¶
The active pricing interval (TimeTariffInterval) changed. Relay-only: the connector decides whether to act on the price.
notification_drlc
async
¶
notification_flow_reservation
async
¶
py20305.connectors.config ¶
Typed configuration for the devices a connector talks to.
One model per connector type, discriminated on type, so a configuration
file naming a connector gets that connector's fields validated and nothing
else. :data:DeviceConfig is the union to annotate with;
:class:~py20305.connectors.registry.ConnectorConfigRegistry
consumes it.
To add a connector type, subclass :class:_DeviceConfigBase with a literal
type and add it to the union below and to the registry's class map.
SunSpecDeviceConfig ¶
Bases: _DeviceConfigBase
SunSpec Modbus device configuration.
Covers the three transports the connector speaks: plain Modbus TCP, Modbus RTU over a serial port, and Modbus TCP wrapped in TLS. Fields for the transports not in use are ignored, so one shape covers all three.
Source code in src/py20305/connectors/config.py
PrintDemoDeviceConfig ¶
Bases: _DeviceConfigBase
A device that logs what it would have done instead of doing it.
Needs no hardware, which makes it the connector to point at when trying the client against a utility server for the first time.
Source code in src/py20305/connectors/config.py
CustomDeviceConfig ¶
Bases: _DeviceConfigBase
A connector supplied by import path.
The escape hatch for a device this package has no connector for: point
class_path at your own
:class:~py20305.connectors.base.BaseConnector subclass and it
is constructed with init_kwargs.
Source code in src/py20305/connectors/config.py
py20305.connectors.registry ¶
Connector configuration registry with lazy instantiation.
Loads connector definitions from typed DeviceConfig objects and materializes them lazily on first access. Supports case-insensitive LFDI lookup.
ConnectorRegistryError ¶
LazyConnectorProxy ¶
Defers connector construction until the first attribute access.
Source code in src/py20305/connectors/registry.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
resolve ¶
Return the underlying connector, creating it on demand.
Synchronous: blocks the calling thread for the duration of the
factory (which for ConnectorSunSpec includes a Modbus scan
with retries). Use aresolve from the async hot paths so the
event loop can keep handling other requests during construction.
Permanent construction failures (factory raised
ConnectorConnectionError(permanent=True)) are cached for
_PERMANENT_FAILURE_TTL_SECONDS and re-raised without
re-running the factory.
Source code in src/py20305/connectors/registry.py
aresolve
async
¶
Async resolver: runs resolve on a worker thread.
First-touch construction of a real Modbus connector takes seconds
(TCP handshake + scan + readiness retries). Calling it from an
async def route on the client's event loop blocks every
other coroutine for that whole window. This wrapper offloads the
work via asyncio.to_thread so the loop stays responsive.
Once constructed, returns the cached instance with no thread hop,
so subsequent calls cost the same as resolve.
The lock-protected double-check around the to_thread guarantees
the factory runs at most once per proxy even when N coroutines
race for first-touch construction. Without it, the per-device
4 cycle types (metering / capability / settings / status) firing
close together at startup could each spawn their own
ConnectorSunSpec.__init__ and open duplicate Modbus
connections -- the exact fan-out this wrapper exists to make
safe. Note: asyncio.to_thread itself
uses the default ThreadPoolExecutor (size
min(32, cpu_count + 4)), so concurrent first-touch awaits
across different proxies can still queue behind the pool;
wall-clock for first dashboard load with N >> pool_size devices
is bounded by ceil(N / pool_size) * scan_time.
Source code in src/py20305/connectors/registry.py
ConnectorConfigRegistry ¶
Resolves a device LFDI to its connector, constructing it on first use.
Holds typed device configurations and hands out a
:class:LazyConnectorProxy per device. Nothing opens a socket or scans a
device until something asks for that device's connector, so a
configuration naming an offline device costs nothing until it is used.
LFDI lookup is case-insensitive: certificate tooling differs on hex case and a device should resolve either way.
An application with device types of its own supplies a factory_resolver
rather than subclassing. That covers the cases class_path cannot: a
connector that needs shared runtime state, one reached over a transport
this package knows nothing about, or one whose configuration is a model
defined downstream.
Source code in src/py20305/connectors/registry.py
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 | |
get_connector ¶
Return a proxy for the device connector mapped to lfdi.
LFDI comparison is case-insensitive, and the proxy is cached under the configured spelling so it is returned whichever spelling is asked for. Caching under the caller's spelling instead would mean a caller using a different case never hits the cache -- rebuilding the proxy and the connector on every lookup, which for a Modbus device is a fresh connection and scan each time, and which defeats the proxy's own failure cache and single-flight lock.
Source code in src/py20305/connectors/registry.py
iter_device_specs ¶
py20305.connectors.dispatcher ¶
ConnectorDispatcher: implements ControlDispatcher backed by connectors.
Bridges the event processing system to the connector system. Translates DERControl Pydantic models into connector method calls via the modes translation layer.
ConnectorDispatcher ¶
Implements ControlDispatcher protocol using the connector system.
Resolves device_href to a connector via the registry and an LFDI resolver callback, then translates control models to connector calls.
Source code in src/py20305/connectors/dispatcher.py
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 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 | |
telemetry
property
¶
The southbound telemetry emitter, if one was injected.
The metering cycle reports through the same emitter as the control path, so both halves of a device's traffic land on one channel with one configuration behind them.
registry
property
¶
The registry this dispatcher resolves through.
Exposed so a caller wiring a second consumer -- the metering cycle, which reads the same devices this writes to -- resolves through the same registry. Constructing a second one would build a second connector per device and open duplicate connections to it.
apply_control
async
¶
apply_control(device_href: str, derc: Dercontrol1, curves: list[Dercurve1], *, origin: str = CommandOrigin.IEEE2030_5) -> None
Apply a DERControl's settings to a device.
Source code in src/py20305/connectors/dispatcher.py
apply_control_by_lfdi
async
¶
apply_control_by_lfdi(lfdi: str, derc: Dercontrol1, curves: list[Dercurve1], *, origin: str = CommandOrigin.IEEE2030_5) -> None
Apply a DERControl directly to a device identified by LFDI.
Source code in src/py20305/connectors/dispatcher.py
apply_operation
async
¶
Apply one named control to one device by LFDI, and record it.
The write funnel for callers that already know which control they want, rather than a DERControl to be translated -- a Modbus master writing a register, for instance. Everything an event-driven write gets applies: the command is recorded with its origin, a failure is recorded as rejected and re-raised.
Raises:
| Type | Description |
|---|---|
ConnectorError
|
no connector is registered for |
CommandNotPermittedError
|
a gate refused this origin authority over this device. Raised rather than reported because this caller named the control and has somewhere to put the answer -- a protocol server owes its own client the distinction between a write that failed and one that was not permitted. |
Source code in src/py20305/connectors/dispatcher.py
apply_default_control
async
¶
apply_default_control(device_href: str, dderc: DefaultDercontrol, curves: list[Dercurve1], *, origin: str = CommandOrigin.DDERC_REAPPLY, cause_mrid: bytes | None = None) -> None
Apply default DER control (DDERC fallback) to a device.
cause_mrid names the event whose end brought the default back, for
the audit trail. None when no single event caused it.
Source code in src/py20305/connectors/dispatcher.py
apply_default_control_by_lfdi
async
¶
apply_default_control_by_lfdi(lfdi: str, dderc: DefaultDercontrol, curves: list[Dercurve1], *, origin: str = CommandOrigin.DDERC_REAPPLY, cause_mrid: bytes | None = None) -> None
Apply default DER control directly to a device identified by LFDI.
Source code in src/py20305/connectors/dispatcher.py
relay_schedule_notification
async
¶
Relay a schedule notification to each connector owning an affected LFDI.
Resolves each LFDI to its connector (the same registry.get_connector
path dispatch uses), de-duplicates so a connector that owns several affected
LFDIs is notified once, and isolates per-connector errors -- a
throwing/slow connector here must never affect event processing or the
other connectors.
De-dup is keyed by connector.relay_group when present. A connector
fronting several devices over one connection sets it to that
connection's name, so N per-LFDI instances collapse to a single
notification -- which is correct, because the notification already
carries every affected LFDI. Connectors that don't set it fall back to
instance identity.
The de-duped connectors are notified concurrently so one slow connector can't delay delivery to the others; each call is error-isolated.
Source code in src/py20305/connectors/dispatcher.py
clear_control
async
¶
Clear active control from a device by sending disable params.
Prefers the connector's own clear_control when it has one. A
connector talking to a remote device should implement it as a single
round-trip rather than paying for the per-mode fan-out below; the
bundled connectors talk to the device directly, so they don't
override it and take the fan-out.
Source code in src/py20305/connectors/dispatcher.py
clear_control_by_lfdi
async
¶
Clear active control from a device identified by LFDI.
The by-LFDI counterpart of clear_control (the comms-loss
safe-default when dispatching by LFDI). Skips the href->LFDI
resolution step.
Source code in src/py20305/connectors/dispatcher.py
disable_modes
async
¶
Disable the named control modes on a device.
modes are DERControlBase field names (op_mod_fixed_w) or the
CSIP-AUS limit element names (opModExpLimW), as the event processor
tracks them. Called at event end for the modes the ended event set and
the DefaultDERControl does not carry.
Source code in src/py20305/connectors/dispatcher.py
disable_modes_by_lfdi
async
¶
The by-LFDI counterpart of disable_modes.
Source code in src/py20305/connectors/dispatcher.py
py20305.connectors.errors ¶
Errors a connector raises when talking to a device.
Transport-neutral: a connector speaking Modbus, MQTT, SQL or anything else
raises these same types, so the code above it -- the dispatcher, the event
engine, the API -- reasons about failure without knowing the protocol
underneath. :mod:py20305.connectors.control_errors covers the
other half: a control the device declined rather than a transport that broke.
ConnectorError ¶
ConnectorConnectionError ¶
Bases: ConnectorError
Raised when the connector cannot reach the target device.
The optional permanent flag signals that the failure won't change
on retry without operator intervention -- e.g. Modbus protocol
exception codes 1-4 (illegal function/address/value, server failure),
which typically mean the configured device is missing models the
connector was told to scan for.
Source code in src/py20305/connectors/errors.py
ConnectorTimeoutError ¶
Bases: ConnectorError
Raised when a connector operation exceeds its deadline.
ConnectorWriteError ¶
Bases: ConnectorError
Raised when a control write fails or is rejected by the device.
ConnectorValueError ¶
Bases: ConnectorError
Raised when a control parameter is outside the range the profile allows.
Distinct from :class:ConnectorWriteError: nothing was attempted. The
parameter itself is invalid, so no device could have accepted it and a retry
with the same value cannot succeed. The register is left untouched, including
any mode-enable point -- a lever must not be raised for a write that will not
happen.
Reported to the head-end as IEEE 2030.5 Table 31 status 253 (Invalid), because the fault is in the event's data rather than in what the device can do. Adapters translate accordingly at their own boundary.
Source code in src/py20305/connectors/errors.py
py20305.connectors.control_errors ¶
Errors a connector raises when it will not perform a control.
Distinct from :mod:py20305.connectors.errors, which covers a
transport that broke. These say the transport was fine and the control still
did not happen -- the device is offline, the mode is unsupported, the value is
out of range, or the site declined on the customer's behalf.
The distinction is load-bearing because IEEE 2030.5 makes the head-end care
about it. Each type below carries the retry behavior the caller should apply
and the Table 31 response status the head-end should see; see
:func:py20305.events.response.response_code_for_dispatch_error
for the mapping.
ControlError ¶
DeviceOfflineTransientError ¶
Bases: ControlError
The device is unreachable, but may return on its own.
Caller logs and retries on the next polling cycle.
DeviceOfflinePermanentError ¶
Bases: ControlError
The device is unreachable and will stay that way without intervention.
Caller suppresses further attempts for this device rather than retrying every cycle.
DeviceNotConfiguredError ¶
Bases: ControlError
The connector has no configuration for the addressed device.
Caller re-sends its device configuration once and retries.
ModeNotSupportedError ¶
Bases: ControlError
The device cannot perform the requested control mode.
Permanent for this device and mode. Callers that pre-filter by a device's advertised modes should never see this; if one does, the advertised set and the device disagree.
Source code in src/py20305/connectors/control_errors.py
OptOutError ¶
Bases: ControlError
The control was declined on the customer's behalf.
Reports a decision, not a failure, and is surfaced to the head-end as IEEE 2030.5 Table 31 status 4 rather than a capability-limit code.
Source code in src/py20305/connectors/control_errors.py
InvalidControlValueError ¶
Bases: ControlError
A control parameter is outside the range the IEEE 2030.5 profile allows.
Like :class:OptOutError this is not a device fault, but unlike it the
event is not performed: surfaced to the head-end as Table 31 status 253
(Invalid) rather than a capability-limit code.
Callers must not latch this against the device and mode. A corrected value arriving on the next event has to be allowed through -- the value is at fault, not the pairing of device and mode.
Source code in src/py20305/connectors/control_errors.py
py20305.connectors.translation ¶
Pure SunSpec point-path translation connector.
Translates intermediate control parameters to SunSpec Modbus point paths. No I/O, no external dependencies. Returns dicts like: {'DERVoltVar[0].Ena': 1, 'DERVoltVar[0].Crv[1].Pt[0].V': 240}
Also includes translate_mup() for MirrorUsagePoint -> SunSpec point mapping.
Synchronous API¶
All translation logic is pure computation. The translate_to_sunspec()
function provides synchronous access for callers that cannot use await
(e.g. a threaded host application). It accepts the same
(method_name, params) tuples returned by translate_controls().
ConnectorTranslation ¶
Bases: BaseConnector
Translates intermediate parameters to SunSpec Modbus point paths.
Source code in src/py20305/connectors/translation.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 | |
translate_to_sunspec ¶
Synchronously translate control params to SunSpec point paths.
Accepts the same (method_name, params) tuples returned by
translate_controls() and translate_default_controls().
Returns a dict of SunSpec point paths, or None if the method
is not a recognized translation method (e.g. methods only defined
on BaseConnector with no translation logic).
Source code in src/py20305/connectors/translation.py
translate_mup ¶
Translate MirrorUsagePoint meter readings to SunSpec points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mup_readings
|
list[dict[str, Any]]
|
List of reading dicts, each with: - uom: IEEE 2030.5 unit of measure code - value: The reading value - multiplier: Power-of-ten multiplier (default 0) |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict of SunSpec point paths to converted values. |
Source code in src/py20305/connectors/translation.py
py20305.commands ¶
Command vocabulary, and the observer interface that records it.
A control reaching a device is one :class:CommandRecord: what was commanded, by
which interface, when, and whether the device has confirmed it. Monitoring
adapters read that state so a master can see what the command interface is doing
without being able to interfere, and an operator can tell why a setpoint moved.
:class:CommandObserver exists so the write path can say "this was commanded"
without naming who keeps the record. The write funnels are published client code
and the plane that stores the records is not, so the dependency has to point
down: the funnels depend on this Protocol, and the host application injects the
implementation. :class:NullCommandObserver is the default, which is what lets
an embedded consumer run the same write path with no plane at all.
Reflection is deliberately not modeled here as a value the device reports. A device may clamp a setpoint, ramp toward it, or reject it, so commanded and achieved routinely differ; the record says what was asked for and how far the confirmation has got, and never pretends the two are the same.
CommandOrigin ¶
Bases: StrEnum
The origins this package produces itself.
An origin says where a command entered the system, and it is a label: any
string. Everything that takes one -- the dispatcher, :class:CommandGate,
:class:CommandObserver, :class:CommandRecord -- carries it through
without interpreting it. So an application that puts another interface in
front of the same devices names that interface's origin itself, and passes
the string. Nothing here has to learn the name first, and which interfaces
an application has is not something this package should have to list.
These three are the exception, because the writes are made here: an IEEE 2030.5 control, and the two cases where the client reasserts state it already owns. Those two are not external commands at all, but they change the device just as visibly, and leaving them unrecorded is what makes a setpoint appear to move on its own. The members are strings, so a gate or an observer compares and stores them like any other origin.
Source code in src/py20305/commands.py
CommandStatus ¶
Bases: StrEnum
How far a command has got.
UNCONFIRMED is the honest default and often the terminal state: the
connector contract exposes no general setpoint readback, so most controls
have nothing to confirm against. It means "we asked and the write returned
without error", not "the device is doing it".
Source code in src/py20305/commands.py
CommandRecord
dataclass
¶
One control applied to one device.
Source code in src/py20305/commands.py
CommandObserver ¶
Bases: Protocol
Where the write path reports what it did.
Two operations, because confirmation arrives separately from the command and usually from a different code path: the write funnel knows what was asked for, and whoever polls the device later knows what it says about itself.
Source code in src/py20305/commands.py
record_command ¶
record_command(device: str, control: str, params: Mapping[str, Any], *, origin: str, at: float, error: str | None = None) -> None
Record that control was applied to device, or failed to be.
Source code in src/py20305/commands.py
record_readback ¶
Offer a device's self-reported state as confirmation evidence.
read_started_at is when the read that produced observed began,
not when it completed. An observation that started before a command was
issued cannot reflect it, however recent its arrival, and is what the
implementation uses to keep an in-flight poll from clearing a command it
never saw.
Source code in src/py20305/commands.py
NullCommandObserver ¶
Discards everything. The default where no plane is wired.
Published write paths run unchanged in a deployment that keeps no commanded state -- an embedded single-upstream consumer, or any test that cares about the write rather than the record.
Source code in src/py20305/commands.py
record_command ¶
CommandGate ¶
Bases: Protocol
Whether an origin may command a device.
A deployment may serve several command interfaces while intending only one of them to command any given device. Deciding that in configuration alone leaves it unenforced at the write: every interface still reaches the dispatcher, so one interface's events and another's setpoints overwrite each other while the configuration reads as though a single one were in charge.
Injected rather than imported, for the same reason :class:CommandObserver
is. Which interface holds authority over a device is the consuming
application's concern, and the dispatcher is client code, so the dependency
points that way.
Source code in src/py20305/commands.py
may_command ¶
Whether origin holds the command role for device.
Deny an origin you do not recognize. An origin is a string the caller names, so nothing upstream of this method rejects one that no interface owns: a mistyped name, or a write path added without one, arrives here looking like any other. An implementation that answers only for the origins it knows, and refuses the rest, is what makes that a refused write. One that permits by default makes it a command.
Source code in src/py20305/commands.py
AllowAllCommands ¶
Permits everything. The default where no authority is wired.
A consumer with a single command interface, or a test concerned with the write rather than with who was allowed to make it, behaves exactly as it did before the gate existed.
Everything includes an origin nothing claims. With this gate a mistyped origin commands like a correct one, and the only trace is the name in the audit record. That is the right trade for one interface, where there is no second commander for a wrong name to be mistaken for. An application with more than one should wire a gate of its own, and leaving this one in place is then a decision to check nothing.
Source code in src/py20305/commands.py
CommandNotPermittedError ¶
Bases: Exception
A gate refused this origin authority over this device.
Distinct from a connector error because the cause and the remedy are different: nothing is wrong with the device or the transport, and the caller cannot retry its way out of it. A caller serving a protocol client needs the distinction to answer that client honestly -- refused is not the same answer as failed.
Raised only by the entry points whose caller has somewhere to put it. A control arriving from an event engine is reported and dropped instead, since an interface posting to a device another one commands is a configuration being honored rather than a fault.