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.
Reading
dataclass
¶
One measured value and the IEEE 2030.5 ReadingType that describes it.
value is in engineering units (W, var, VA, V, A, Hz, Wh, or a power
factor between -1 and 1). Real and reactive power are signed in the frame of
the device's role:
- A DER and a DER meter report positive real power for power the DER delivers and negative for power it absorbs; positive reactive power for reactive power it injects (over-excited) and negative for reactive power it absorbs (under-excited).
- A site meter reports positive real and reactive power for import, from the area EPS to the premises, which IEEE 2030.5 FlowDirectionType calls Forward.
A power factor carries the sign of its reactive power. Every other quantity is posted as a magnitude.
The remaining fields are IEEE 2030.5 ReadingType codes:
uom: UomType, for example 38 W, 63 var, 61 VA, 29 V, 5 A, 33 Hz, 65 cos(theta), 72 Wh.phase: PhaseCode, for example 0 not applicable, 128 A, 129 AN, 132 AB, 224 ABC.kind: KindType, 37 power, 12 energy, 0 not applicable.data_qualifier: DataQualifierType, 12 normal, 2 average, 8 maximum, 9 minimum.accumulation_behaviour: 12 instantaneous, 9 summation.flow_direction: set only when the reading is direction-specific, such as an energy total delivered forward (1) or in reverse (19). None lets the reading profile choose (seepy20305.telemetry.mup).multiplier: the powerOfTenMultiplier to post with. None takes the library default for the unit.quality_flags: this sample's qualityFlags (16 bits). None postsvalid.
Source code in src/py20305/connectors/reading.py
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
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
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 | |
fetch_monitoring
async
¶
Return the device's measurements, one :class:Reading each.
Each reading states its IEEE 2030.5 ReadingType (uom, phase,
kind, data_qualifier, ...) and its value in engineering units.
Real and reactive power are signed in the frame of the device's role
(see :class:~py20305.connectors.reading.Reading); a reading profile
that posts another convention converts them. A quantity the device does
not measure is left out. Give each reading a distinct ReadingType,
multiplier included: a second reading with the same one is dropped and
a warning is logged.
Source code in src/py20305/connectors/base.py
supported_modes2 ¶
Optional: the DERControlType2 bits this device can apply.
DERCapability modesSupported2 and DERControlResponse
modesResponded2 report these, limited to what the server profile
permits. Return None (the default) to derive them from the controls
the connector implements: update_op_mod_max_lim_w_absorb sets bit 7,
update_op_mod_max_lim_w_inject bit 8, and so on. Return an integer
for a connector that implements a control method it cannot honor on this
device, so the device never advertises a mode it cannot apply.
Source code in src/py20305/connectors/base.py
declared_readings ¶
Optional: the readings this device provides, fixed for its life.
Each is a :class:~py20305.connectors.reading.ReadingIdentity (uom,
phase, kind, data qualifier, accumulation behaviour, flow direction and
multiplier), or a :class:~py20305.connectors.reading.Reading standing
for its identity. Under the SIGNED_AS_REPORTED reading profile the
MirrorUsagePoint registers exactly these readings, from the first
cycle, even one with no values (a charger with no vehicle plugged in),
so it is posted once and never re-posted for a reading that appears
later. A reading returned by fetch_monitoring but not declared is
not posted. Return None (the default) to register the readings as
they appear. Other profiles ignore it.
Source code in src/py20305/connectors/base.py
fetch_nameplate
async
¶
Return DER ratings keyed by IEEE 2030.5 DERCapability element name.
A value is a number, {"value": ..., "multiplier": ...}, or for a
power factor {"displacement": ..., "multiplier": ...}. rtgMaxW
is required. modesSupported is the DERControlType bitmap;
doeModesSupported is the CSIP-AUS extension bitmap and defaults to
all four limits. An absent or None key is not reported; an explicit
0 is.
Source code in src/py20305/connectors/base.py
fetch_configuration
async
¶
Return DER settings keyed by IEEE 2030.5 DERSettings element name.
Values take the shapes :meth:fetch_nameplate describes. setMaxW
is required. modesEnabled is the DERControlType bitmap;
doeModesEnabled is the CSIP-AUS extension bitmap and defaults to
the export and import limits.
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_op_mod_connect
async
¶
update_op_mod_energize
async
¶
update_op_mod_delta_var
async
¶
update_op_mod_delta_w
async
¶
update_op_mod_fixed_pf_absorb_w
async
¶
update_op_mod_fixed_pf_inject_w
async
¶
update_op_mod_fixed_v
async
¶
update_op_mod_fixed_var
async
¶
update_op_mod_fixed_w
async
¶
update_op_mod_freq_droop
async
¶
update_op_mod_freq_watt
async
¶
update_op_mod_grid_connect_permit
async
¶
update_op_mod_hfrt_may_trip
async
¶
update_op_mod_hfrt_must_trip
async
¶
update_op_mod_hvrt_may_trip
async
¶
update_op_mod_hvrt_momentary_cessation
async
¶
update_op_mod_hvrt_must_trip
async
¶
update_op_mod_island_permit
async
¶
update_op_mod_lfrt_may_trip
async
¶
update_op_mod_lfrt_must_trip
async
¶
update_op_mod_lvrt_may_trip
async
¶
update_op_mod_lvrt_momentary_cessation
async
¶
update_op_mod_lvrt_must_trip
async
¶
update_op_mod_max_lim_pct_va_absorb
async
¶
update_op_mod_max_lim_pct_va_inject
async
¶
update_op_mod_max_lim_pct_var_absorb
async
¶
update_op_mod_max_lim_pct_var_inject
async
¶
update_op_mod_max_lim_pct_w_absorb
async
¶
update_op_mod_max_lim_var_absorb
async
¶
update_op_mod_max_lim_var_inject
async
¶
update_op_mod_max_lim_w
async
¶
update_op_mod_max_lim_w_absorb
async
¶
update_op_mod_max_lim_w_inject
async
¶
update_op_mod_target_v
async
¶
update_op_mod_target_var
async
¶
update_op_mod_target_w
async
¶
update_op_mod_volt_var
async
¶
update_op_mod_volt_watt
async
¶
update_op_mod_watt_pf
async
¶
update_op_mod_watt_var
async
¶
update_op_mod_exp_lim_w
async
¶
update_op_mod_imp_lim_w
async
¶
update_op_mod_gen_lim_w
async
¶
update_op_mod_load_lim_w
async
¶
update_set_es_delay
async
¶
Apply setESDelay. IEEE 2030.5 updates the setting; it is never withdrawn.
update_set_es_high_freq
async
¶
Apply setESHighFreq. IEEE 2030.5 updates the setting; it is never withdrawn.
update_set_es_high_volt
async
¶
Apply setESHighVolt. IEEE 2030.5 updates the setting; it is never withdrawn.
update_set_es_low_freq
async
¶
Apply setESLowFreq. IEEE 2030.5 updates the setting; it is never withdrawn.
update_set_es_low_volt
async
¶
Apply setESLowVolt. IEEE 2030.5 updates the setting; it is never withdrawn.
update_set_es_ramp_tms
async
¶
Apply setESRampTms. IEEE 2030.5 updates the setting; it is never withdrawn.
update_set_es_random_delay
async
¶
Apply setESRandomDelay. IEEE 2030.5 updates the setting; it is never withdrawn.
update_set_grad_w
async
¶
update_set_soft_grad_w
async
¶
Apply setSoftGradW. IEEE 2030.5 updates the setting; it is never withdrawn.
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.
Transition active carries the new interval's prices. Transition
completed or cancelled reports that the active interval ended
with no interval after it; its payload is the ended interval's.
Source code in src/py20305/connectors/base.py
notification_drlc
async
¶
notification_flow_reservation
async
¶
py20305.connectors.reading ¶
The reading a connector returns from fetch_monitoring.
A :class:Reading is one measured value with the IEEE 2030.5 ReadingType that
describes it. The library posts each reading as a MirrorMeterReading and derives
its mRID from the reading's identity (see :func:reading_identity), so a reading
whose ReadingType differs from another's always gets a different mRID
(IEEE 2030.5-2023 §10.11.3 Rule n).
The module imports nothing from the rest of the package, so a connector can import it without loading the client.
Reading
dataclass
¶
One measured value and the IEEE 2030.5 ReadingType that describes it.
value is in engineering units (W, var, VA, V, A, Hz, Wh, or a power
factor between -1 and 1). Real and reactive power are signed in the frame of
the device's role:
- A DER and a DER meter report positive real power for power the DER delivers and negative for power it absorbs; positive reactive power for reactive power it injects (over-excited) and negative for reactive power it absorbs (under-excited).
- A site meter reports positive real and reactive power for import, from the area EPS to the premises, which IEEE 2030.5 FlowDirectionType calls Forward.
A power factor carries the sign of its reactive power. Every other quantity is posted as a magnitude.
The remaining fields are IEEE 2030.5 ReadingType codes:
uom: UomType, for example 38 W, 63 var, 61 VA, 29 V, 5 A, 33 Hz, 65 cos(theta), 72 Wh.phase: PhaseCode, for example 0 not applicable, 128 A, 129 AN, 132 AB, 224 ABC.kind: KindType, 37 power, 12 energy, 0 not applicable.data_qualifier: DataQualifierType, 12 normal, 2 average, 8 maximum, 9 minimum.accumulation_behaviour: 12 instantaneous, 9 summation.flow_direction: set only when the reading is direction-specific, such as an energy total delivered forward (1) or in reverse (19). None lets the reading profile choose (seepy20305.telemetry.mup).multiplier: the powerOfTenMultiplier to post with. None takes the library default for the unit.quality_flags: this sample's qualityFlags (16 bits). None postsvalid.
Source code in src/py20305/connectors/reading.py
ReadingIdentity ¶
Bases: NamedTuple
The ReadingType fields that identify a reading.
Two readings with the same identity are the same measurement. multiplier
is the effective powerOfTenMultiplier, after the library default is applied,
because it is part of the ReadingType too.
Source code in src/py20305/connectors/reading.py
effective_multiplier ¶
Return the powerOfTenMultiplier a reading posts with.
Source code in src/py20305/connectors/reading.py
reading_identity ¶
Return the identity of reading with its effective multiplier.
Source code in src/py20305/connectors/reading.py
reading_key ¶
Return a stable text key for a reading's identity, for keying stores and logs.
The multiplier is left out: a store keys a measurement, and the multiplier only says how the value is posted.
Source code in src/py20305/connectors/reading.py
is_valid_reading ¶
Return True when reading is a :class:Reading the library can post.
The ReadingType codes must be ints in 0..255 (each is a UInt8 in the IEEE 2030.5 schema), the multiplier in -9..9, the quality flags 16 bits, and the value a finite number. A bool is not accepted where an int or a number is expected.
Source code in src/py20305/connectors/reading.py
py20305.connectors.modes ¶
Control dispatch table: DERControlBase elements to connector methods.
Each IEEE 2030.5 control element has one connector method, update_<element>,
named after the element in snake case (opModVoltVar ->
update_op_mod_volt_var). The method receives one parameter dict:
enabled: True when the control sets the element, False when the element is no longer commanded and the device should return to its own default for that function.value: the element's value as IEEE 2030.5 defines it, present whenenabledis True. Keys are the IEEE 2030.5 element names. A curve link is resolved to the DERCurve it references (curveType,xMultiplier,yMultiplier,yRefType,CurveDataand the rest). A PerCent or SignedPerCent is the integer in hundredths of a percent. A power is{"value": ..., "multiplier": ...}. A boolean is a bool.rampTms: the DERControlBaserampTms, in hundredths of a second, when the control sets it.
The table covers every DERControlBase element, the CSIP-AUS dynamic operating envelope limits and the DefaultDERControl settings.
ControlElement
dataclass
¶
One IEEE 2030.5 control element and the connector method that receives it.
Source code in src/py20305/connectors/modes.py
snake_case ¶
Return an IEEE 2030.5 element name in snake case.
A run of capitals is one word: opModHVRTMustTrip ->
op_mod_hvrt_must_trip, opModFixedPFInjectW ->
op_mod_fixed_pf_inject_w.
Source code in src/py20305/connectors/modes.py
element_value ¶
Return a parsed IEEE 2030.5 value as plain data keyed by element name.
A model whose only content is value (a PerCent, an enumeration, a
multiplier) becomes that value. Bytes become upper-case hex. None
fields are left out.
Source code in src/py20305/connectors/modes.py
translate_controls ¶
translate_controls(base: DercontrolBase, curves: list[Dercurve1]) -> list[tuple[str, dict[str, Any]]]
Return (method, params) for every element base sets.
An absent element is skipped. An element marked disabled="true" is
withdrawn ({"enabled": False}), as is a curve element whose curve the
client does not hold. rampTms, when set, is added to every call that
applies an element.
Source code in src/py20305/connectors/modes.py
translate_default_controls ¶
translate_default_controls(dderc: DefaultDercontrol1, curves: list[Dercurve1]) -> list[tuple[str, dict[str, Any]]]
Return (method, params) for a DefaultDERControl.
The DERControlBase elements as :func:translate_controls returns them,
then each DefaultDERControl setting it carries (setGradW,
setSoftGradW and the enter-service settings).
Source code in src/py20305/connectors/modes.py
modes_supported2 ¶
Return the DERControlType2 bits for the controls connector can apply.
A connector that defines supported_modes2() and returns an integer
states the bitmap itself: for a connector that implements a control method
but cannot honor it on this device. Otherwise a control counts as supported
when the connector implements its update_<element> method. The base
class declares every one as a no-op, so inheriting it is not support.
Source code in src/py20305/connectors/modes.py
implemented_modes2 ¶
Return the DERControlType2 bits of the update_<element> methods connector has.
The base class declares every method as a no-op, so inheriting it is not
support. A connector's own supported_modes2() can start from this and
clear the bits its device cannot apply.
Source code in src/py20305/connectors/modes.py
implemented_doe_modes ¶
Return the CSIP-AUS DOE control bitmap of the limits connector implements.
Bit 0 is opModExpLimW, bit 1 opModImpLimW, bit 2 opModGenLimW and bit 3
opModLoadLimW (the DOEControlType bitmap in csipaus-ext.xsd). A limit
counts when the dispatcher would deliver it to the connector, so inheriting
the base class's no-op is not support, and a plugin-backed connector counts
the limits its live offer carries.
Source code in src/py20305/connectors/modes.py
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/sunspec/config.py
connector_kwargs ¶
Return the connector's keyword arguments, with the role it reads the device as.
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.sunspec.connector ¶
The SunSpec Modbus connector, on the IEEE 2030.5 connector contract.
:class:SunSpecConnector drives a SunSpec device over Modbus TCP, Modbus RTU
or Modbus TCP with TLS through the Modbus core, and converts what it reads and
writes in :mod:py20305.connectors.sunspec._ieee2030_5. Nothing SunSpec
leaves this package: monitoring is a list of readings, ratings and settings
use the DERCapability and DERSettings element names, status uses the
DERStatus types, and controls arrive as update_<element> calls.
A DER is read through models 701 to 705 (and 706, 712 and 713 where the
device has them), and its state of charge through model 713, 802 or 124. A
meter is read through models 201 to 204, 211 to 214 or 220; set its role
to site_meter or der_meter, and power_sign when the meter's sign of
real power is known.
Needs the sunspec extra (pip install py20305[sunspec]).
SunSpecConnector ¶
Bases: BaseConnector
A SunSpec Modbus device, presented with the IEEE 2030.5 connector contract.
Takes the keyword arguments of
:class:~py20305.connectors.sunspec.config.SunSpecDeviceConfig's
connector_kwargs(). Construction connects to the device and scans its
models; a device that refuses the scan raises
:class:~py20305.connectors.errors.ConnectorConnectionError.
Elements the device has no write for keep the base class's no-op, so the dispatcher reports them as unsupported by design.
Source code in src/py20305/connectors/sunspec/connector.py
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 | |
supported_modes2 ¶
Return the DERControlType2 bits this device can apply.
The connector implements opModMaxLimWAbsorb for every device, but a device with no charge-rate limit applies nothing for it, so bit 7 is left out for that device. The other bits follow the controls the connector implements.
Source code in src/py20305/connectors/sunspec/connector.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 182 183 184 185 186 | |
resolve ¶
Return the underlying connector, creating it on demand.
Synchronous: blocks the calling thread for the duration of the
factory (which may connect to and scan the device, 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
constructed ¶
Return the connector if it has been constructed, else None.
Never constructs it, so a caller that must not wait on a device can ask.
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 construct their own
connector and open duplicate device 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
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 | |
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
role_of ¶
Return the configured role of lfdi, or "der" for an unknown device.
An unknown device keeps the behavior every device had before roles existed, so a caller asking about it is not told it is a meter.
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
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 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 | |
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.
attach_write_history ¶
Keep every write this dispatcher issues in history, or stop with None.
takes_controls ¶
Return whether the device takes controls. A meter does not.
Only a device configured with a meter role is refused. A device the registry does not know, a control with no LFDI, and a registry that keeps no roles all take controls, as every device did before roles existed.
Source code in src/py20305/connectors/dispatcher.py
supported_modes2
async
¶
Return the DERControlType2 bits the device with lfdi can apply.
None when the device has no connector, or its connector has not been constructed yet. Nothing is reported for a missing connector, since a response may be posted for a device the client does not drive.
This runs on the response path, so it never constructs a connector: construction can connect to and scan the device with retries, and the acknowledgment and the activation timer wait on the response.
Source code in src/py20305/connectors/dispatcher.py
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.
Raises:
| Type | Description |
|---|---|
CommandNotPermittedError
|
the gate refused at least one mode, so the
device did not receive the control as sent. The event processor
reports the device as rejected rather than started (IEEE
2030.5-2023 Table 31). With a gate that answers the same for a
device and origin throughout, as :class: |
DeviceNotConfiguredError
|
the device is configured as a meter. |
ModeNotSupportedError
|
the control translates to at least one mode and the connector implements none of them, so nothing was applied. A control that applies at least one mode is not refused for the modes the connector leaves out. The event processor reports the device as rejected with Table 31 status 251 (252 for a 2018 server) rather than as started. |
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.
Raises:
| Type | Description |
|---|---|
CommandNotPermittedError
|
as for :meth: |
DeviceNotConfiguredError
|
the device is configured as a meter. |
ModeNotSupportedError
|
as for :meth: |
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. |
DeviceNotConfiguredError
|
the device is configured as a meter. |
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. A meter is
skipped: a default control carries no response to refuse it with.
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.
A meter is skipped, as in :meth:apply_default_control.
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. Each connector receives a stream's notifications one at a time, in the order they were relayed: a delivery starts only after the previous delivery of that stream to the same connector finished. Without this, an older notification still in delivery could finish after a newer one and leave the connector on stale schedule data.
The order is taken when the relay starts, before its connectors are resolved. Before a relay queues its deliveries, it waits for every older relay of the stream to resolve its connectors, which is immediate once a connector is resolved, and then for each older relay that shares one of its relay groups to queue its own. A slow resolution of an older relay therefore cannot let a newer one reach a shared connector first, even for a different device. Delivery to other relay groups never waits.
Source code in src/py20305/connectors/dispatcher.py
control_support
staticmethod
¶
control_support(connector: object, method_name: str) -> tuple[Callable[[dict[str, Any]], Any] | None, str | None]
Return (bound method, reason). reason is None when implemented.
BaseConnector declares every update_* method as a concrete method that
return None, so getattr finds one whether or not the connector
implements it. Reading that as support makes a connector look like it
accepted a command it never carried out: the dispatch succeeds, the
commanded plane records it, and a Modbus master is acknowledged for a
write that reached no device.
The two ways a mode can be unsupported need telling apart, because only one of them is anybody's mistake:
BY_DESIGN
The connector inherits the base no-op, as a connector does for every
mode its device has no way to carry out -- the base defaults exist
for exactly that. Expected, and not something an operator can act on.
OFFER_MISSING
No implementation resolves at all. For a plugin-backed connector,
whose modes arrive through __getattr__ from a live offer, that
means the offer lacks a mode it should carry -- typically a plugin
built against an older SDK. Actionable, and what the unimplemented
diagnostic was written for.
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. A meter is skipped.
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
unused_update_methods ¶
Return the update_* methods a connector class defines that the client never calls.
The client calls one update_<element> method per control element
(METHOD_BY_ELEMENT). A class written for an earlier contract may still
define methods named for its own control vocabulary; they are never called.
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.commands ¶
Command vocabulary, the observer interface that records it, and the write-path seams.
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.
Answer the same for the same device and origin while one control is being applied. The dispatcher asks once per mode, so a gate whose answer changes partway through can let some modes reach the device while the server is told the control was rejected.
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
InterceptedWrite
dataclass
¶
One translated write, offered to a :class:CommandIntercept before the connector.
The fields are the values the dispatcher would otherwise pass to the connector and keep in the write history.
Source code in src/py20305/commands.py
CommandIntercept ¶
Bases: Protocol
Takes a translated write before it reaches the connector.
A host application can route some writes somewhere other than the device's
connector, for example to logic that decides the final setpoint itself. The
dispatcher offers each write to the intercept after the :class:CommandGate
has permitted it, and only when the write names a device by LFDI. Only modes
the connector implements are offered, so the intercept sees the same writes
the connector would.
Injected rather than imported, for the same reason :class:CommandGate is.
Omitted, every write goes to the connector.
Source code in src/py20305/commands.py
intercept
async
¶
Return True to take write, or False to let the connector apply it.
A taken write is not applied to the connector. The dispatcher keeps it
in the write history with outcome intercepted, records no command
with the :class:CommandObserver, reports no device write to the
telemetry emitter, and returns success to its caller. Taking a write
makes the intercept responsible for it.
An exception is kept in the write history as a failed write and raised to the dispatcher's caller, as a connector failure is.
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 by the entry points whose caller has somewhere to put it: a named control, and a DERControl applied for an event, which the event processor reports to the server as a rejection (IEEE 2030.5-2023 Table 31, status 252). A default control and a clear are reported and dropped instead, since they send no response.