diff --git a/.deps-installed b/.deps-installed deleted file mode 100644 index e69de29b..00000000 diff --git a/.gitignore b/.gitignore index cf89f56b..57adb759 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ xnotes/* .env .envrc .venv +.deps-installed .vscode/settings.json # mypy diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6d819e5b..9afb51a9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,6 +5,8 @@ repos: hooks: # `packages/schema-1/spec/` holds byte copies of the eBus specification, # verified by byte comparison in tests/test_schema_one_conformance.py, and + # `tests/fixtures/captures/` holds byte copies of upstream reference captures + # and their LICENSE, pinned by SHA-256 in tests/test_captures_unchanged.py, and # the two MAIN 32 captures in tests/fixtures/ are byte copies of upstream with # that repository's LICENSE beside them, pinned by SHA-256 in # tests/adapter_fidelity/test_main32_fidelity.py. Any hook that rewrites a file @@ -12,9 +14,9 @@ repos: # makes the copies trustworthy. Non-mutating checks (check-json) deliberately # still run, since a corrupt copy should fail. - id: trailing-whitespace - exclude: '^src/span_panel_api/generated_client/.*|^packages/schema-1/spec/.*|^tests/fixtures/(main32(_r202639)?-tree-v1\.json|distribution-enclosure-simulator\.LICENSE)$|\..*_cache/.*|dist/.*|venv/.*|\.venv/.*' + exclude: '^src/span_panel_api/generated_client/.*|^packages/schema-1/spec/.*|^tests/fixtures/(captures/(.*\.json|LICENSE)|main32(_r202639)?-tree-v1\.json|distribution-enclosure-simulator\.LICENSE)$|\..*_cache/.*|dist/.*|venv/.*|\.venv/.*' - id: end-of-file-fixer - exclude: '^src/span_panel_api/generated_client/.*|^packages/schema-1/spec/.*|^tests/fixtures/(main32(_r202639)?-tree-v1\.json|distribution-enclosure-simulator\.LICENSE)$|\..*_cache/.*|dist/.*|venv/.*|\.venv/.*' + exclude: '^src/span_panel_api/generated_client/.*|^packages/schema-1/spec/.*|^tests/fixtures/(captures/(.*\.json|LICENSE)|main32(_r202639)?-tree-v1\.json|distribution-enclosure-simulator\.LICENSE)$|\..*_cache/.*|dist/.*|venv/.*|\.venv/.*' - id: check-yaml exclude: '^src/span_panel_api/generated_client/.*|\..*_cache/.*|dist/.*|venv/.*|\.venv/.*' - id: check-toml @@ -28,7 +30,7 @@ repos: exclude: '^src/span_panel_api/generated_client/.*|generate_client\.py|scripts/.*|tests/.*|\..*_cache/.*|dist/.*|venv/.*|\.venv/.*|^examples/.*' - id: mixed-line-ending args: ['--fix=lf'] - exclude: '^src/span_panel_api/generated_client/.*|^packages/schema-1/spec/.*|^tests/fixtures/(main32(_r202639)?-tree-v1\.json|distribution-enclosure-simulator\.LICENSE)$|\..*_cache/.*|dist/.*|venv/.*|\.venv/.*' + exclude: '^src/span_panel_api/generated_client/.*|^packages/schema-1/spec/.*|^tests/fixtures/(captures/(.*\.json|LICENSE)|main32(_r202639)?-tree-v1\.json|distribution-enclosure-simulator\.LICENSE)$|\..*_cache/.*|dist/.*|venv/.*|\.venv/.*' # Ruff for formatting and linting - repo: https://github.com/astral-sh/ruff-pre-commit diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 00000000..28ddd2cb --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,99 @@ +# Working on span-panel-api + +Guidance for anyone changing this repository, person or coding agent. It lists what has to be kept up when the code changes; the procedures themselves live in [DEVELOPMENT.md](DEVELOPMENT.md) (setup, tests, captures, conformance) and +[RELEASE.md](RELEASE.md) (versions, floors, tags, pre-releases). Read those before changing a capture, a dependency floor or a version. + +## No AI Attribution + +Do not attribute work to Claude, Copilot or any other AI agent anywhere in this repository's history or on GitHub. Work belongs to the human who directs it. + +- No `Co-Authored-By` or other AI co-author trailer in a commit message. +- No "Generated with" / "Generated by" footer, and no AI session link, in a commit message, pull request description, issue, comment or release note. +- No mention of AI tools in code, comments, documentation or the changelog. + +This rule takes precedence over any default tool behaviour that would add attribution. + +## Worktrees + +Create worktrees with `scripts/new-worktree.sh`, never with `git worktree add` or an agent's built-in worktree tool: + +```bash +./scripts/new-worktree.sh [] # defaults to feat/ +``` + +It creates `../span-panel-api-` beside the primary checkout from a freshly fetched `origin/main`, prepares it with `setup-hooks.sh`, and links `.env`. That location is the one the integration's developer notes expect when installing a library +worktree into its environment. [DEVELOPMENT.md](DEVELOPMENT.md#worktrees) has the details. + +- **Never share a virtual environment between checkouts.** This repository installs its own distributions in editable mode, each recording one checkout's source path, so a shared `.venv` imports whichever checkout synced last and tests pass against the + wrong code without an error. +- **Install the pre-commit hook from the primary checkout.** Hooks are shared by every worktree and record the interpreter that installed them. `new-worktree.sh` installs the hook from the primary checkout when it is missing or bound elsewhere, and refuses + to create the worktree if that fails. `setup-hooks.sh` in a worktree checks the shared hook rather than rebinding it to an environment that is deleted with the worktree. + +## The rule every field follows + +A value the panel did not publish is `None` (or unknown), never a constant. A `0.0`, `False`, `""` or empty collection in a snapshot field is a reading the panel published, or an answer the library can derive from what the panel declared, and the docstring +of the field says which. Where a field is not yet optional, the adapter fidelity harness records its absence value as an explicit, reasoned exception rather than letting it pass unnoticed. + +## When you add, rename or change a snapshot field or an adapter read + +Every read the schema-1 adapter makes is accounted for in more than one place, and each place fails the suite if it is left behind: + +- **Field metadata and discovery** (`packages/schema-1/src/span_panel_api_schema_1/field_metadata.py`). A reading with a unit gets a `_PROPERTY_FIELD_MAP` row, or a row in a lugs table; a property read into the snapshot without one goes in + `_CONSUMED_WITHOUT_A_ROW`. Otherwise it is reported as discovered and becomes an extension reading. `tests/test_schema_one_discovery.py` proves each entry by perturbing it against the reference tree; an entry the tree does not declare goes in + `_ABSENT_FROM_THE_CAPTURE` with a synthetic experiment of its own. +- **Conformance** (`tests/test_schema_one_conformance.py`). A property no vendored catalog defines goes in `_SPAN_EXTENSIONS`, and one the pinned emitter's reference tree never declares goes in `_NOT_EXERCISED_BY_THE_EMITTER`, each with its reason. +- **Public API** (`tests/test_public_api_unchanged.py`). A new export is added to `__all__` and to the expected set, with a dated note. +- **The adapter fidelity harness** (`tests/adapter_fidelity/`), below. + +## The adapter fidelity harness + +`harness.py` replays a captured device tree through the real adapter, perturbs every declared property, and classifies each one: mapped, an extension reading, intentionally dropped by code that says why, or silently dropped. It then holds every value to a +documented rule: + +- **Transforms** (`rules.TRANSFORMS`): for each row (a device role and a `node/property`) and each snapshot field it moves, how the field follows from the wire value: identity, negation, integer, literal, boolean, or a derivation with the rule stated where + it is simple. Every cell shares them, and `test_every_mapped_field_has_a_documented_transform` requires one for every field-metadata row. Change the transform when you change a read, and give a device whose frame differs its own role rather than bending + a shared row. +- **Derivations**: a field that holds a value no published property moves on its own, such as one decided by a declaration, or a documented elimination. Each cell carries only the derivations its captures need. `test_every_derivation_is_needed` refuses one + that no cell uses, because an unused justification is how a list of reasons becomes an allowlist. `rules.py` holds the derivations for the two captures in `tests/fixtures/`, and `rules_captured.py` holds those for the reference captures. +- **Drops** (`DropReason`): the three kinds of intentional drop, each citing the code. A cell pins every row it drops _with a value_, each with a reviewed reason (`dropped_with_a_value` in `test_main32_fidelity.py`, `DROPPED_WITH_A_VALUE` in + `test_capture_fidelity.py`), so a drop rule that newly covers a published property waits for review. Rows the library drops today but should not are listed in `deferred` with the reason, and a deferral that no longer holds fails like a new silent drop. + +`test_capture_fidelity.py` measures every capture in `tests/fixtures/captures/` and pins by row, never by capture, so a capture added to that directory is covered without editing the tests. `test_harness.py` plants each kind of defect and checks the +harness names it. + +## The expected-failure registry + +`tests/expected_failures.py` lists, by `::`, the acceptance tests this line does not pass yet. `tests/conftest.py` marks each one `xfail(strict=True)`, so: + +- a `PENDING` row is behaviour a later change brings, and that change deletes the row: a listed test that starts passing fails the run until it is; +- a `DIVERGENT` row is behaviour this library deliberately does not have, and stays until the test or the decision changes; +- a row naming a file that does not exist, or a test function that file does not define (at module level or on a `Test` class), stops the run. The check reads the files rather than the tests a run collected, so a partial run (`-k`, one file) judges every + row exactly as a full run does, and a renamed or deleted test file cannot orphan its rows. + +Ported acceptance tests are never edited. A strict xfail stops at its first failing line, so a companion file (`*_companions.py`) asserts what each divergent test checks after its divergent line. + +## Vendored captures + +Captures are byte copies and must stay that way: + +- `tests/fixtures/captures/` holds the reference captures with their upstream `LICENSE` and a `README.md` naming the upstream repository, path and commit; `SHA256SUMS` pins each capture and the `LICENSE` by SHA-256. `tests/test_captures_unchanged.py` + checks every pin, requires a pin for every capture and the directory to hold nothing but the pinned files, `README.md` and `SHA256SUMS`; those two are this repository's records and are not pinned. The two captures in `tests/fixtures/` are pinned the same + way by `tests/adapter_fidelity/test_main32_fidelity.py`. +- `.pre-commit-config.yaml` excludes them from every hook that rewrites files. Keep any new capture path in those excludes. +- A capture is replaced only by copying it again from its upstream commit and updating the pins, never by editing it. + +The schema-1 reference tree (`packages/schema-1/src/span_panel_api_schema_1/reference/parent_child_tree.json`) is package data, produced by `scripts/capture_parent_child_reference.py` from `scripts/reference_panel.yaml` with the pinned emitter; +DEVELOPMENT.md, "Regenerating a vendored capture", has the procedure. Change the manifest, never the output, and keep every circuit inside the position range `PANEL_POSITIONS_BY_MODEL` gives the panel's model: the adapter reports the table's range and +warns once for a panel whose circuits fall outside it. A changed capture is a release of the adapter that ships it (RELEASE.md). + +## Lessons from review + +What a change must do is decided before it is written; these are the checks made while writing and verifying it. Each was a defect that review has already caught at least once, in this repository or in the emitter it is tested against. + +- **Prove a test or a guard by breaking what it guards.** Revert the fix or mutate the code and confirm the test fails; a guard that survives every mutation guards nothing. Assert what a consumer can observe, the snapshot value or the published outcome, + not an internal step. +- **A test that keeps documentation runnable reads the documentation.** A hand-copied recipe pins the sequence but lets the document rot. +- **Check the changelog as it will ship.** Check where each entry lands, since a new heading inserted above an entry re-files it with no deletion in the diff, and re-derive every count or list against the source at the tag. +- **Read data as published.** A `null` or empty value in a capture means unpublished, never zero. A predicate that reads declared metadata refuses what it cannot interpret instead of guessing. +- **One capture is not the firmware.** Check a change against every capture available; panels on the same firmware release do not always publish a value in the same form. +- **Measure claims.** A statement about a real panel, broker or built artifact is checked there, and a result is reported only after it has actually been run. diff --git a/CHANGELOG.md b/CHANGELOG.md index 09036d16..923b93ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,32 +7,39 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), Pre-releases are not listed separately. A beta is a step towards the next public version, so its changes are folded into that version's entry as they land and are described against the **last public release**, never against the beta before it. What one beta corrected in an earlier beta does not appear at all: from the point of view of somebody upgrading between released versions, it never happened. -## [Unreleased] +## [3.8.0] -Snapshot fields that held a fabricated constant can now be unknown, and with `span-panel-api-schema-0` and `span-panel-api-schema-1` 1.3.0 or newer the parsers report them as unknown and stop synthesising unoccupied positions. +Snapshot fields that held a fabricated constant can now be unknown, and with `span-panel-api-schema-0` 1.3.0 and `span-panel-api-schema-1` 1.4.0 or newer the parsers report them as unknown and stop synthesising unoccupied positions. ### Added +- **spanos3/r202639/03 batch 2: reads more of the data this firmware publishes.** +- **`SpanMqttClient.masked_tree()` returns the panel's device tree with identifiers and site details masked**, for a consumer's diagnostics; `None` on a flat panel. - **`V2StatusInfo.hardware_version` reports the hardware version string from `GET /api/v2/status`.** +- **`SpanEvseSnapshot.charge_current_limit_minimum_a` and `charge_current_limit_maximum_a` report the range a SPAN Drive declares for its charge-current limit**, `None` where undeclared. ### Changed -- **BREAKING FOR CONSUMERS: `SpanPanelSnapshot.proximity_proven` becomes `bool | None`**, and with `span-panel-api-schema-0` and `span-panel-api-schema-1` 1.3.0 or newer it is always `None`, where it was effectively a constant `True`, because neither MQTT - schema publishes a proximity property and the panel's own answer is `V2StatusInfo.proximity_proven`. +- **BREAKING FOR CONSUMERS: `SpanPanelSnapshot.proximity_proven` becomes `bool | None`**, and with `span-panel-api-schema-0` 1.3.0 and `span-panel-api-schema-1` 1.4.0 or newer it is always `None`, where it was effectively a constant `True`, because neither + MQTT schema publishes a proximity property and the panel's own answer is `V2StatusInfo.proximity_proven`. - **BREAKING FOR CONSUMERS: `SpanPanelSnapshot.uptime_s` becomes `int | None`**, and with those parsers it is `None` on a parent/child panel and before a flat panel first reports ready, where it was a constant `0`. - **BREAKING FOR CONSUMERS: `SpanCircuitSnapshot.instant_power_update_time_s` and `energy_accum_update_time_s` become `int | None` and default to `None`**, and with those parsers they are `None` until the reading has arrived and always on a parent/child panel, where they were `0`. -- **The `schema-0` and `schema-1` extras require `span-panel-api-schema-0` and `span-panel-api-schema-1` 1.3.0 or newer**, the adapters that report these values as unknown. +- **BREAKING FOR CONSUMERS: `SpanCircuitSnapshot.is_240v` becomes `bool | None`**, and with `span-panel-api-schema-1` 1.4.0 or newer it is `None` where the pole count is unpublished. +- **BREAKING FOR CONSUMERS: `SpanPanelSnapshot.lugs_at_service_entrance` becomes `bool | None`**, and with `span-panel-api-schema-1` 1.4.0 or newer it is `None` while the upstream lugs declare their feed but leave it unpublished. +- **The `schema-0` extra requires `span-panel-api-schema-0` 1.3.0 or newer and the `schema-1` extra requires `span-panel-api-schema-1` 1.4.0 or newer**, the adapters that report these values as unknown; schema-1 1.4.0 also fills the snapshot fields this + release adds. ### Removed -- **BREAKING: with `span-panel-api-schema-0` and `span-panel-api-schema-1` 1.3.0 or newer, snapshots no longer include synthesised `unmapped_tab_N` entries for unoccupied breaker positions, which carried no measured data**, so `SpanPanelSnapshot.circuits` - holds only real circuits and `panel_size` alone states the panel's total positions. +- **BREAKING: with `span-panel-api-schema-0` 1.3.0 and `span-panel-api-schema-1` 1.4.0 or newer, snapshots no longer include synthesised `unmapped_tab_N` entries for unoccupied breaker positions, which carried no measured data**, so + `SpanPanelSnapshot.circuits` holds only real circuits and `panel_size` alone states the panel's total positions. ### Fixed - **`V2HomieSchema.types_schema_hash` on data model 1.0 is the panel's published `deviceClassesSchemaHash`, or a hash of `deviceClasses` when none is published, where it was one constant for every such panel**; a flat panel's value is unchanged, and a value stored from 3.6.x differs once on a data model 1.0 panel. +- **A property the panel clears reads as unpublished** on a parent/child panel, where it read as an empty value until the panel published it again. ## [3.6.2] diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 00000000..43c994c2 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1 @@ +@AGENTS.md diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 1a9e72c7..0563c856 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -165,6 +165,21 @@ report, and a smaller report looks exactly like a panel with nothing new on it. a snapshot field, and every reported property moves none. `_CONSUMED_OFF_SNAPSHOT` holds the three declarations consumed by a route no snapshot field can show (tier-1 dispatch, the shadowed islanding tier, the unreached feedthrough branch); each names the code that reads it, and each fails the day its property does move a field. +### A masked tree for diagnostics + +Discovery rows never carry a value, so they can be forwarded as they stand. `MaskedTree` is the opposite trade: it carries the whole tree, every declared property with the value the panel published, so a consumer can attach a panel's real shape to a report +and a maintainer can replay it through the same loader, adapter and fidelity harness the vendored captures use. It can carry values because it is safe by construction: `SchemaOneAdapter.export_masked_tree` runs the tree through +`span_panel_api_schema_1.tree_export`, which masks by rule, so a consumer forwards the result whole and decides nothing about what is sensitive. + +The masks match the site properties (`utility-meter-serial-number`, `wifi-ssid`, `postal-code`, `address-lines`, `locality`, `region`, `latitude`, `longitude`, `time-zone` as `UTC`, `country-code` as `ZZ`) and `serial-number` by property id on any node, +and the panel's `info/name` and its `$description` `name`; `name` on any other node or device is kept. Device ids become placeholders that start `masked-`, and a final sweep replaces any device id, and any serial that reads as an identifier (six characters +or more with a digit; a placeholder such as `0` or `N/A` is masked at its own property only), still present in any wire string. It decodes JSON string literals to do so, to a bound of four nested levels, and in the plain text between them a JSON-style +escape written out (`\n`, `\u00b0`) is a boundary before an identifier, as a backslash alone is. A `$description` is read as parsed to a looser bound of thirty-two containers, after which a subtree is masked whole only if something in it would be swept. +The module and `_Sweep` docstrings in `tree_export.py` hold the rules; change them there. + +It is optional, like the discovery rows: `TreeExportingAdapter` is a separate `runtime_checkable` protocol, not a `SchemaAdapter` member, so no `ADAPTER_CONTRACT` bump and no adapter distribution is rejected. `SpanMqttClient.masked_tree()` returns `None` +for an adapter that does not offer it, which includes the flat adapter, and before the root device has described itself. + ## Devices this library models nothing for `TreeRoles` sorts a v1.0 tree into the roles a snapshot needs. Anything matching none of them used to fall off the end silently — a panel publishing a device type nobody modelled produced no field, no metadata row and no sign it was there. The eBus schema @@ -197,6 +212,7 @@ The two answer opposite questions and are separate types so that conflating them | Type | Question | Destination | Carries a value | | -------------------- | -------------------------------------------- | --------------------------------- | --------------- | | `DiscoveredMetadata` | "we model this device and read nothing here" | consumer diagnostics, which leave | **no** | +| `MaskedTree` | "the whole tree, safe to forward" | consumer diagnostics, which leave | **yes, masked** | | `AdoptedProperty` | "nothing here models this device at all" | an entity on the same machine | **yes** | `AdoptedProperty` also carries the declared `format` and `settable` flag, which together are the value domain a consumer needs to build a control rather than a reading. @@ -280,7 +296,20 @@ To install pre-commit hooks: ./setup-hooks.sh ``` -This installs dependencies (if needed) and configures git pre-commit hooks. +This syncs dependencies and, in the primary checkout, installs the git pre-commit hook. Run from a worktree, it syncs that worktree's own environment and checks the shared hook instead of reinstalling it: hooks are shared by every worktree and record the +interpreter that installed them, so a hook installed from a worktree stops working when that worktree is removed. `./setup-hooks.sh --check-hook` only checks the shared hook, and exits non-zero when it is missing or not bound to the primary checkout. + +## Worktrees + +Create worktrees with the script rather than `git worktree add`: + +```bash +./scripts/new-worktree.sh [] # defaults to feat/ +``` + +It fetches `origin`, fast-forwards `main` where that is safe, installs the shared pre-commit hook from the primary checkout if it is missing or bound elsewhere, creates `../span-panel-api-` on a branch that does not track a remote, links `.env` from +the primary checkout, and runs `setup-hooks.sh` inside it. The worktree gets a virtual environment of its own rather than a link to the primary checkout's: editable installs record one checkout's source path, so a shared environment would import whichever +checkout synced last. ## Workspace layout diff --git a/README.md b/README.md index a2b5e7ae..fdd546ff 100644 --- a/README.md +++ b/README.md @@ -129,35 +129,42 @@ The library defines structural subtyping protocols (PEP 544). All are `runtime_c | `CircuitControlProtocol` | Relay and shed-priority control: `set_circuit_relay`, `set_circuit_priority` | | `PanelControlProtocol` | Panel-level control: `set_dominant_power_source` | | `EvseControlProtocol` | Per-charger control: `set_evse_charge_limit(node_id, amps)` | +| `EvseLockControlProtocol` | Per-charger connector lock: `set_evse_lock(node_id, locked)` | | `AdoptedControlProtocol` | Write to a settable property of a device this library models nothing for | | `ControlInterceptionProtocol` | Install one veto-and-observe point for every control command: `set_control_interceptor` | | `StreamingCapableProtocol` | Push-based updates: `register_snapshot_callback`, `start_streaming`, `stop_streaming` | -The first five differ in subject, not just in name. `EvseControlProtocol` is separate from `PanelControlProtocol` because several chargers may be commissioned at once and every call names which one. `AdoptedControlProtocol` differs in kind: the curated -setters name a control this library understands and translate or bound the value on the way out, while this one names a property by its wire address and passes the value through, because the declaration is all anybody here knows about it. That write is -authorised by the snapshot rather than by its arguments — the transport resolves the property against the current `adopted_devices` and refuses anything it does not find carrying a set topic, so a device this library _does_ model cannot be addressed -through it. +The first six differ in subject, not just in name. `EvseControlProtocol` is separate from `PanelControlProtocol` because several chargers may be commissioned at once and every call names which one. `EvseLockControlProtocol` is separate from +`EvseControlProtocol` so that protocol's implementers are unchanged, and its write is authorised by the snapshot: only a charger whose `SpanEvseSnapshot.lock_control` is set can be addressed, and only with a value its `lock_state_options` lists. +`AdoptedControlProtocol` differs in kind: the curated setters name a control this library understands and translate or bound the value on the way out, while this one names a property by its wire address and passes the value through, because the declaration +is all anybody here knows about it. That write is authorised by the snapshot rather than by its arguments — the transport resolves the property against the current `adopted_devices` and refuses anything it does not find carrying a set topic, so a device +this library _does_ model cannot be addressed through it. -`ControlInterceptionProtocol` is separate from the four control protocols rather than a member of them because adding it there would break every implementer of those protocols a second time in one release, and separate from `StreamingCapableProtocol` -because a transport could reasonably offer one and not the other. +`ControlInterceptionProtocol` is separate from the control protocols rather than a member of them because adding it there would break every implementer of those protocols a second time in one release, and separate from `StreamingCapableProtocol` because a +transport could reasonably offer one and not the other. One further protocol, `SchemaAdapter`, is the bootstrap-to-parser contract rather than a consumer-facing one; it is what an adapter distribution implements and what discovery checks. Integration code programs against the protocols above, not against transport-specific classes. +`TreeExportingAdapter` sits beside `SchemaAdapter` as an optional protocol, not one every adapter must implement: an adapter that offers `export_masked_tree()` lets `SpanMqttClient.masked_tree()` return the panel's device tree with serials, device ids and +site details masked, and `None` otherwise. + ### Snapshots All panel state is represented as immutable, frozen dataclasses: - **`SpanPanelSnapshot`**: complete panel state. Identity (serial, firmware, vendor, model, hardware version), panel size, main breaker rating, main relay, door state, connection uptime on a flat panel, network links with the Wi-Fi SSID and vendor cloud, - grid and feedthrough power and energy, grid/DSM state, run configuration, dominant power source, grid islandability, per-leg voltages, power flows, lugs current and whether the lugs are the service entrance, shed policy and forecast. It holds `circuits`, - `battery`, `pv`, `pv_inverters`, `evse`, `mid`, `pcs`, `adopted_devices` and `extension_properties`. + grid and feedthrough power and energy, grid/DSM state, run configuration, dominant power source, grid islandability, per-leg voltages, power flows, lugs current and whether the lugs are the service entrance, busbar current, line frequency, the rating of + the protection ahead of the upstream lugs, the first and last breaker positions, whether any circuit declares what it feeds, shed policy and forecast. It holds `circuits`, `battery`, `pv`, `pv_inverters`, `evse`, `mid`, `pcs`, `adopted_devices` and + `extension_properties`. - **`SpanCircuitSnapshot`**: one circuit. Id, name, relay state and requester, power, energy and their update times, tabs, 240 V, breaker rating, current, priority, user controllability, sheddable / never-backup / always-on flags, device type, relative - position, PCS management and priority, and the `$target` pending state for relay and priority. -- **`SpanBatterySnapshot`**: the BESS. SoE percentage and kWh, its own meter reading, communication state, link health, vendor / `model` / `part_number` / serial / version, nameplate capacity. + position, PCS management and priority, the `$target` pending state for relay and priority, nominal voltage, the breaker's protection functions, the role it declares for what it feeds, the other circuits its meter or relay is shared with, and whether it + is a meter outside the panel, which has no breaker space, relay or shed priority and reads import-positive. +- **`SpanBatterySnapshot`**: the BESS. Whether the panel declares one, SoE percentage and kWh, its own meter reading, communication state, link health, the circuit that feeds it, vendor / `model` / `part_number` / serial / version, nameplate capacity. - **`SpanPVSnapshot`**: one PV inverter. Link health, vendor / `model` / serial / version, nameplate capacity (the array's DC size), feeding circuit, relative position, its wire `device_id` and its `node_id`, which is its key in `pv_inverters`. `SpanPanelSnapshot.pv` is the lone inverter, or describes several together. -- **`SpanEvseSnapshot`**: one EV charger. `node_id`, feeding circuit, status, lock state, advertised current, link health, vendor / `model` / `part_number` / serial / version, charge-current limit, ceiling, pending target and settability, and the effective - limit it applies. +- **`SpanEvseSnapshot`**: one EV charger. `node_id`, feeding circuit, status, lock state, advertised current, link health, vendor / `model` / `part_number` / serial / version, charge-current limit, ceiling, pending target and settability, the effective + limit it applies, the range it declares for that limit, and where its connector lock is commanded with the values it accepts. - **`SpanMidSnapshot`**: the Microgrid Interconnect Device. `node_id`, islanding state, grid state, grid-forming entity and its device name, vendor / `model` / serial / software and hardware version. - **`SpanPcsSnapshot`**: the Power Control System. Enabled and active, the enforced import limit and its binding constraint, and each import constraint's limit, enablement and active state (feed, operator, off-grid, requested). - **`AdoptedDevice`**: a device type this library models nothing for, carried whole. Identity (id, type, name, vendor, model, serial, versions), its declared parent, whether a peer proxies it, and its readings. @@ -171,6 +178,10 @@ see the changelog, because `battery.model` changes value for existing flat users `uptime_s` and a circuit's update times are the reverse: only the flat parser measures them, and they are `None` under the parent/child schema. Neither schema publishes proximity, so `SpanPanelSnapshot.proximity_proven` is always `None`; the panel's own answer is `V2StatusInfo.proximity_proven`, from `GET /api/v2/status`. +Two booleans can be unknown under the parent/child schema: `SpanCircuitSnapshot.is_240v` is `None` where no pole count is published, and `SpanPanelSnapshot.lugs_at_service_entrance` is `None` while the upstream lugs declare their feed and have not +published it, so a consumer tests both against `None` before reading them as a boolean. `SpanPanelSnapshot.circuits` holds only circuits the panel publishes: no entry stands in for an unoccupied breaker position, and `panel_size`, with `first_position` and +`last_position` under the parent/child schema, says which positions exist. + ## Usage ### Factory Pattern (Recommended) @@ -195,8 +206,11 @@ async def main(): # The upstream lugs' own meter. That is grid flow only where the lugs are # the utility connection point; a BESS wired ahead of them, or a panel fed # by another panel, makes it this panel's feed instead. `power_flow_grid` - # is the site-level figure in every topology. - if snapshot.lugs_at_service_entrance: + # is the site-level figure in every topology. `None` means the lugs have + # not yet published what feeds them, so neither reading is known. + if snapshot.lugs_at_service_entrance is None: + print(f"Grid power: {snapshot.power_flow_grid}W") + elif snapshot.lugs_at_service_entrance: print(f"Grid power: {snapshot.instant_grid_power_w}W") else: print(f"Panel feed: {snapshot.instant_grid_power_w}W") @@ -358,8 +372,9 @@ deliver it minutes later. `CONFIRMED` is strong evidence rather than proof: the idempotent in its physical effect. **A control the panel declares non-commandable raises rather than returning an outcome**, because there is no topic to publish to and so nothing to report on. `SpanPanelServerError` is raised for a relay on a circuit commissioned always-on, for the shed -priority of a circuit commissioned never-backup, and for a charger with no settable charge-current limit. The same facts are on the snapshot ahead of the call — `SpanCircuitSnapshot.is_user_controllable` and `.is_never_backup` — so a consumer that offers -the control only where the panel offers it will not meet this; it is the backstop for the case a setup-time gate cannot see, since re-commissioning a circuit in place changes its settability while an entity built from the earlier snapshot is still alive. +priority of a circuit commissioned never-backup, and for a charger with no settable charge-current limit or connector lock. The same facts are on the snapshot ahead of the call — `SpanCircuitSnapshot.is_user_controllable` and `.is_never_backup` — so a +consumer that offers the control only where the panel offers it will not meet this; it is the backstop for the case a setup-time gate cannot see, since re-commissioning a circuit in place changes its settability while an entity built from the earlier +snapshot is still alive. ### Control Interception @@ -505,6 +520,7 @@ All exceptions inherit from `SpanPanelError`: | `SpanPanelValidationError` | Data validation failure | | `SpanPanelAPIError` | Unexpected HTTP response from v2 endpoints | | `SpanPanelServerError` | Panel answered 5xx, or answered `200` with a body that cannot be used — "not ready yet" | +| `SpanPanelRateLimitError` | Panel refused a registration with HTTP 429; `retry_after_s` carries the wait it asked for | Three more are specific to the hot-loading model, and they are separate because the remedy differs: @@ -584,6 +600,7 @@ One repository, three distributions. The bootstrap is at the root; each parser i src/span_panel_api/ # distribution: span-panel-api (no parser) ├── __init__.py # Public API exports ├── _http.py # Shared httpx plumbing / client ownership rules +├── _ssl.py # The panel's trust anchor: SSL context, CA fingerprint, leaf-name probe ├── adapters.py # installed_adapter_keys(), resolve_adapter() — metadata, then lazy import ├── auth.py # v2 HTTP provisioning (register, cert, schema, passphrase) ├── const.py # Panel state constants (DSM, relay) @@ -601,6 +618,7 @@ src/span_panel_api/ # distribution: span-panel-api (no parser) ├── client.py # SpanMqttClient (transport + control protocols) ├── connection.py # AsyncMqttBridge (event-loop-driven, no threads) ├── const.py # MQTT/Homie constants + UUID helpers + ├── control.py # PublishOutcome, ControlCommand, ControlInterceptor └── models.py # MqttClientConfig, MqttTransport packages/schema-0/ # distribution: span-panel-api-schema-0 diff --git a/packages/schema-0/CHANGELOG.md b/packages/schema-0/CHANGELOG.md index 54dcfe25..2556bbe9 100644 --- a/packages/schema-0/CHANGELOG.md +++ b/packages/schema-0/CHANGELOG.md @@ -9,9 +9,9 @@ rather than by this version number. A release here means this parser changed, ne Pre-releases are not listed separately. A beta is a step towards the next public version, so its changes are folded into that version's entry as they land and are described against the last public release, never against the beta before it. -## [Unreleased] +## [1.3.0] -Requires `span-panel-api` **3.7.0 or newer**, whose snapshot fields accept the unknown values this parser now reports. +Requires `span-panel-api` **3.8.0 or newer**, whose snapshot fields accept the unknown values this parser now reports. ### Changed diff --git a/packages/schema-0/pyproject.toml b/packages/schema-0/pyproject.toml index cae9aed3..f563c730 100644 --- a/packages/schema-0/pyproject.toml +++ b/packages/schema-0/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "span-panel-api-schema-0" -version = "1.3.0b1" +version = "1.3.0" description = "Flat-schema (data-model-version absent) parser for span-panel-api" authors = [ {name = "SpanPanel"} @@ -19,9 +19,9 @@ dependencies = [ # Raised to 3.6.0, the first bootstrap whose snapshot carries `pv_inverters` # and the inverter's `device_id` and `node_id`, which this parser fills. # Against an earlier one, building a snapshot fails on those arguments. - # Raised to 3.7.0b1, whose snapshot fields accept the unknown values this + # Raised to 3.8.0, whose snapshot fields accept the unknown values this # parser now reports, where an earlier one types them as never unknown. - "span-panel-api>=3.7.0b1,<4.0", + "span-panel-api>=3.8.0,<4.0", ] [project.urls] diff --git a/packages/schema-1/CHANGELOG.md b/packages/schema-1/CHANGELOG.md index 81849b7d..6b92b683 100644 --- a/packages/schema-1/CHANGELOG.md +++ b/packages/schema-1/CHANGELOG.md @@ -9,25 +9,37 @@ number. A release here means this parser changed, never that the panel did. Pre-releases are not listed separately. A beta is a step towards the next public version, so its changes are folded into that version's entry as they land and are described against the last public release, never against the beta before it. -## [Unreleased] +## [1.4.0] -Requires `span-panel-api` **3.7.0 or newer**, whose snapshot fields accept the unknown values this parser now reports. +Requires `span-panel-api` **3.8.0 or newer**, whose snapshot fields accept the unknown values this parser now reports and carry the fields it now fills. + +### Added + +- **spanos3/r202639/03 batch 2: reads more of the data this firmware publishes.** +- **`SchemaOneAdapter` exports the tree it holds, masked**, for `SpanMqttClient.masked_tree()`. +- **Each SPAN Drive's declared charge-current limit range is reported.** ### Changed +- The shipped reference tree is recaptured with `ebus-panel-sim` 0.9.0: every circuit inside the panel's breaker positions, firmware r202639's discharge-positive battery meter, and no user charge limit until one is set. - **`proximity_proven` is `None`**, where it was a hard-coded `True`, because the tree publishes no proximity property. - **`uptime_s` is `None`**, where it was always `0`, because no device publishes an uptime and this parser keeps no readiness clock to measure one. ### Removed - **BREAKING FOR CONSUMERS: `snapshot.build_snapshot()` no longer takes the `ready_since` argument**, which no caller in this repository passed, so a call that passes it by keyword or position now raises `TypeError`. - - **BREAKING: snapshots no longer include synthesised `unmapped_tab_N` entries for unoccupied breaker positions, which carried no measured data**, and `panel.build_unmapped_tabs` and `const.UNMAPPED_TAB_PREFIX` are gone with them. ### Fixed - **A circuit whose shed priority is `UNKNOWN` is no longer reported as sheddable.** - **The grid-forming device name falls back to vendor and model instead of showing a device id.** +- **A panel with no MID reports `dsm_state` `DSM_ON_GRID` and `current_run_config` `PANEL_ON_GRID` whenever it is publishing**, where both dropped to `UNKNOWN` each time `power-flows/grid` read within 1 W of zero + ([#215](https://github.com/SpanPanel/span-panel-api/issues/215)). +- **Each MQTT message costs the same few microseconds however many devices the panel declares**, where routing and readiness checks grew with the tree ([#223](https://github.com/SpanPanel/span-panel-api/issues/223)). +- **A property the panel clears reads as unpublished**, where it read as an empty value until the panel published it again. +- **A charge-current limit outside the range a SPAN Drive declares is refused** instead of published. +- **A device typed as a subtype of a class (`energy.ebus.device.bess.`) is read as that class**, where it was dropped from the snapshot, adoption and discovery ([#228](https://github.com/SpanPanel/span-panel-api/issues/228)). ## [1.2.2] diff --git a/packages/schema-1/README.md b/packages/schema-1/README.md index 56f2e577..32fffecd 100644 --- a/packages/schema-1/README.md +++ b/packages/schema-1/README.md @@ -32,6 +32,8 @@ pip install "span-panel-api[schema-0,schema-1]" - **Adopted devices** (`SpanPanelSnapshot.adopted_devices`). A device type this parser models nothing for is reported whole — identity and readings — rather than dropped. The schema is explicitly vendor-extensible, so an unmodelled device is an expected arrival rather than a hypothetical one. - **Extension properties** (`SpanPanelSnapshot.extension_properties`). A vendor property on a device this parser _does_ model, carried with its value and the snapshot subject it hangs off. +- **Meters outside the panel** (`SpanCircuitSnapshot.measures_outside_panel`). A circuit device that declares no breaker space is reported as a meter with no relay, breaker or shed priority, its power import-positive. +- **The masked device tree** (`SchemaOneAdapter.export_masked_tree()`). The tree the adapter holds with serials, device ids and site details masked, which `SpanMqttClient.masked_tree()` returns for a consumer's diagnostics. Devices are sorted by declared device type, never by device id. Field metadata comes from each device's own `$description` rather than from a schema document, because the same capability exposes different properties on different device classes — `meter` is voltage on the panel, power and energy on a circuit, and both currents on the lugs. diff --git a/packages/schema-1/pyproject.toml b/packages/schema-1/pyproject.toml index 57294b18..ed267930 100644 --- a/packages/schema-1/pyproject.toml +++ b/packages/schema-1/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "span-panel-api-schema-1" -version = "1.3.0b1" +version = "1.4.0" description = "Parent/child schema (data-model-version 1.x) parser for span-panel-api" authors = [ {name = "SpanPanel"} @@ -28,10 +28,13 @@ dependencies = [ # Raised to 3.6.1, whose SpanPanelSnapshot.pv documents what this parser builds. # Raised to 3.6.2, which waits on this parser's missing labels after a bridge # rebuild as well as on connect; the fix spans both, so the pair moves together. - # Raised to 3.7.0b1, whose snapshot fields accept the unknown values this + # Raised to 3.8.0, whose snapshot fields accept the unknown values this # parser now reports: against an earlier one, the update times it leaves - # unset read as a constant 0. - "span-panel-api>=3.7.0b1,<4.0", + # unset read as a constant 0. This parser also fills snapshot fields new in + # it, imports `device_id_order` from its models, implements the masked-tree + # protocol and types new in it, and relies on its client reading a cleared + # value as unpublished. + "span-panel-api>=3.8.0,<4.0", # Only this distribution depends on the eBus SDK. The bootstrap and # schema-0 stay clean, so a flat-panel install never pulls it in — which is # what bounds the release coupling this dependency introduces to panels on diff --git a/packages/schema-1/src/span_panel_api_schema_1/adapter.py b/packages/schema-1/src/span_panel_api_schema_1/adapter.py index fa0b8d7a..22577aa8 100644 --- a/packages/schema-1/src/span_panel_api_schema_1/adapter.py +++ b/packages/schema-1/src/span_panel_api_schema_1/adapter.py @@ -17,9 +17,10 @@ from __future__ import annotations +from importlib.metadata import PackageNotFoundError, version import logging import time -from typing import TYPE_CHECKING, Final +from typing import TYPE_CHECKING, Final, NamedTuple from ebus_sdk import Controller @@ -45,31 +46,92 @@ STATE_READY, TYPE_CIRCUIT, ) -from span_panel_api_schema_1.description import declared_settable, device_type, node_properties +from span_panel_api_schema_1.description import declared_settable, declares_class, device_type, node_properties from span_panel_api_schema_1.devices import feed_circuit_ids from span_panel_api_schema_1.field_metadata import build_field_metadata -from span_panel_api_schema_1.panel import integer, text +from span_panel_api_schema_1.panel import integer, positions_outside_model, text from span_panel_api_schema_1.snapshot import TreeRoles, build_snapshot, harmonised_evse_keys -from span_panel_api_schema_1.transport import ControllerRoutes +from span_panel_api_schema_1.transport import ControllerRoutes, control_target +from span_panel_api_schema_1.tree_export import export_masked_tree if TYPE_CHECKING: from collections.abc import Callable from ebus_sdk.homie import DiscoveredDevice - from span_panel_api.models import FieldMetadata, SpanPanelSnapshot, V2HomieSchema + from span_panel_api.models import FieldMetadata, MaskedTree, SpanPanelSnapshot, V2HomieSchema _LOGGER = logging.getLogger(__name__) +_DISTRIBUTION: Final = "span-panel-api-schema-1" + + +def _producer() -> str: + """The distribution and version that wrote an export, or ``unknown`` where this code runs without its dist-info. + + A checkout put on ``sys.path`` has no installed metadata, and an export must + not fail for the lack of a version string. + """ + try: + return f"{_DISTRIBUTION} {version(_DISTRIBUTION)}" + except PackageNotFoundError: + return f"{_DISTRIBUTION} unknown" + + FEED_GRACE_S: Final = 2.0 -"""How long an inverter's feed may stay unvalued once everything else has arrived. +"""How long an inverter's feed or a DER's model may stay unvalued once every name has arrived. -A retained `connection/feeds-device-id` lands in the same burst as its circuit's -name. One still missing this long after the rest of the tree's labels is taken -as absent: a DER may be published with no connection record at all. +A retained `connection/feeds-device-id` or `info/model` lands in the same burst +as the rest of the tree's labels. One still missing this long after every name +and firmware version is taken as absent: a DER may be published with no +connection record at all, and a declared model may never be valued. """ +class _ValueTopic(NamedTuple): + """One device's `node/property`, and whether the topic carries its value or its `$target`.""" + + device_id: str + node_id: str + property_id: str + target: bool + + +def _value_topic(topic: str) -> _ValueTopic | None: + """The value or `$target` a topic addresses, or None for any other topic. + + The two shapes `Controller` stores a payload under, read as it reads them: + `/5///` is a value unless the property id + starts with `$`, and `/5////$target` is a + target. `$state`, `$description` and every other shape are not values. + """ + parts = topic.split("/") + if parts[:2] != [HOMIE_DOMAIN, HOMIE_VERSION]: + return None + if len(parts) == 5 and not parts[4].startswith("$"): + return _ValueTopic(parts[2], parts[3], parts[4], target=False) + if len(parts) == 6 and parts[5] == "$target": + return _ValueTopic(parts[2], parts[3], parts[4], target=True) + return None + + +def _forget(by_node: object, node_id: str, property_id: str) -> bool: + """Remove one value from an SDK `{node: {property: value}}` map; whether there was one. + + A node left with no values is removed with its last one, so the map holds + what the broker retains and nothing more. + """ + if not isinstance(by_node, dict): + return False + by_property: object = by_node.get(node_id) + if not isinstance(by_property, dict) or property_id not in by_property: + return False + del by_property[property_id] + if not by_property: + del by_node[node_id] + return True + + def _unvalued_feeds_for_unplaced_pvs(roles: TreeRoles) -> list[str]: """Circuits whose feed has not arrived, while an inverter has no known source. @@ -110,13 +172,21 @@ def __init__( self._serial_number = serial_number self._schema = schema self._clock = clock - self._feed_wait_since: float | None = None - self._feed_wait_reported = False + self._grace_since: dict[str, float] = {} + self._grace_reported: set[str] = set() + self._positions_reported = False self._routes = ControllerRoutes() self._controller = Controller(root_device_id=serial_number, mqttc=self._routes) self._property_callbacks: list[Callable[[str, str, str, str | None], None]] = [] self._awaiting: tuple[str, ...] = () + # Readiness as last computed, or None once the tree has changed since. + self._ready: bool | None = None self._controller.set_on_property_changed_callback(self._on_property_changed) + # Every event that can change what `is_ready()` answers; see there. + self._controller.set_on_device_discovered_callback(self._tree_changed) + self._controller.set_on_device_state_changed_callback(self._tree_changed) + self._controller.set_on_device_removed_callback(self._tree_changed) + self._controller.set_on_description_received_callback(self._tree_changed) # Records the subscriptions the tree walk needs; nothing reaches the # wire, because this object has no connection to reach it with. self._controller.start_discovery() @@ -136,8 +206,48 @@ def topics_to_subscribe(self) -> list[str]: return [f"{HOMIE_DOMAIN}/{HOMIE_VERSION}/#"] def handle_message(self, topic: str, payload: str) -> None: + """Route one message to the SDK callback that asked for it, keeping a clear a clear. + + A zero-length payload deletes a retained message, and Homie 5 spells an + empty string differently, as one `0x00` byte, so that the two stay + apart. The SDK decodes both to `""` and stores it, which would leave a + property the panel cleared reading as one it published empty. So a + clear of a value or `$target` the tree holds is applied here: the + stored value goes, exactly as an unpublished one is absent, and + property observers hear `None`. A clear of `$state` (the SDK's device + removal) or `$description` still goes to the SDK, as does anything + else. A `$description` cleared on its own makes the SDK log + `descriptionParseError` at ERROR and keep the stale description; that + is normally silent only because Homie clears `$state` first, after + which the SDK no longer holds the device and ignores the rest. + """ + if not payload and self._clear(topic): + return self._routes.dispatch(topic, payload) + def _clear(self, topic: str) -> bool: + """Apply a clear of a value or target; False where the topic addresses none the tree holds. + + Only a device the controller holds is touched, the same test the SDK + applies before storing a value. Any other clear goes on to dispatch, + where a route the SDK still records for a device it dropped ignores it, + and an unrouted one takes back what is held for its topic. + + A clear of a value that was never published changes nothing and is not + reported. A cleared value is reported as a change, so it forgets the + remembered readiness where a new value would; a cleared target is not, + as no target change is. + """ + address = _value_topic(topic) + device = None if address is None else self._controller.get_device(address.device_id) + if address is None or device is None: + return False + if address.target: + _forget(device.property_targets, address.node_id, address.property_id) + elif _forget(device.properties, address.node_id, address.property_id): + self._notify(address.device_id, address.node_id, address.property_id, None) + return True + def is_ready(self) -> bool: """Ready when the whole declared tree has described itself. @@ -171,7 +281,22 @@ def is_ready(self) -> bool: panel's positions with none to lay out. Asking only for what the panel itself promised keeps a firmware that omits the property connectable — it falls back to the drift warning in `panel_size_from_model`. + + **The answer is remembered until the tree changes.** The transport asks + before and after every message, and walking the tree each time cost + more than routing the message did (#223). Only the Controller's own + events can move it: a device's first `$state`, a change of state, a + removal, a `$description`, and the root's `info/model` value. Each + forgets the answer and the next call works it out again. The events + never work it out themselves, because a description is announced before + the SDK has reconciled the children it declares. """ + if self._ready is None: + self._ready = self._tree_ready() + return self._ready + + def _tree_ready(self) -> bool: + """What `is_ready()` answers, worked out from the tree as it stands.""" root = self._controller.get_root(self._serial_number) if root is None or root.state != STATE_READY or not root.description: return False @@ -186,7 +311,34 @@ def is_ready(self) -> bool: def build_snapshot(self) -> SpanPanelSnapshot: root = self._require_root() - return build_snapshot(root, self._children()) + snapshot = build_snapshot(root, self._children()) + self._report_positions_outside_model(snapshot) + return snapshot + + def _report_positions_outside_model(self, snapshot: SpanPanelSnapshot) -> None: + """Warn once per panel when its circuits occupy spaces outside its model's range. + + The snapshot keeps reporting the model's range, so such a circuit lies + outside the positions a consumer lays out until the table is corrected. + """ + if self._positions_reported: + return + outside = positions_outside_model( + snapshot.model, (tab for circuit in snapshot.circuits.values() for tab in circuit.tabs) + ) + if outside is None: + return + (first, last), (lowest, highest) = outside + _LOGGER.warning( + "Panel model %s has breaker positions %d-%d, but its circuits occupy spaces %d-%d; " + "the snapshot reports the model's positions", + snapshot.model, + first, + last, + lowest, + highest, + ) + self._positions_reported = True def build_field_metadata(self) -> dict[str, FieldMetadata]: root = self._controller.get_root(self._serial_number) @@ -212,6 +364,12 @@ def circuit_nodes_missing_names(self) -> list[str]: the same exposure, so a DER missing the model it declared is reported alongside a circuit missing its name. + Only a declared label is waited for. A circuit-typed device whose + description declares no `info/name` -- a meter outside the panel + declares no `info` node at all -- has no name coming, and waiting for + one would hold every connect and every tree rebuild to the full + timeout. + An inverter's feeding circuit is waited on too, because it decides the inverter's `pv_inverters` key, and a key that moved after the first snapshot would move every entity built on it. A circuit feeding nothing @@ -223,52 +381,66 @@ def circuit_nodes_missing_names(self) -> list[str]: The panel itself is reported while a declared BESS waits on the panel's declared firmware version, which decides the BESS meter's frame. - The feed wait is bounded by `FEED_GRACE_S`. A DER may be published with - no connection record pointing at it, and then no value is coming; a - retained feed lands in the same burst as its circuit's name, so once - every name, model and firmware version has arrived, a feed still - unvalued after the grace is taken as absent. The inverter is then keyed - by its device id, reported once at INFO rather than the transport - warning after the full name timeout. The grace restarts whenever - anything else is missing again, and once every inverter is placed, so - an inverter that appears after another's feed has arrived, within the - same wait, gets a whole grace of its own. + The feed and model waits are bounded by `FEED_GRACE_S`. A DER may be + published with no connection record pointing at it, and a declared + model may never be valued; then no value is coming. Both land in the + same burst as the circuits' names, so once every name and firmware + version has arrived, a feed or model still unvalued after the grace is + taken as absent and reported once per device at INFO, rather than the + transport warning after the full name timeout. An inverter whose feed + was taken as absent is keyed by its device id; a model fills device + metadata only, so one that lands later moves nothing. Each device's + grace starts when it is first waited on alone and restarts whenever a + name or firmware version is missing again, so a device that appears + after another's grace has run gets a whole grace of its own. """ roles = TreeRoles(self._children()) - missing = [circuit.device_id for circuit in roles.circuits if not circuit.get_property(NODE_INFO, PROP_NAME)] + missing = [ + circuit.device_id + for circuit in roles.circuits + if PROP_NAME in circuit.get_node_properties(NODE_INFO) and not circuit.get_property(NODE_INFO, PROP_NAME) + ] + missing.extend(self._firmware_version_pending(roles)) ders = (roles.bess, *roles.pvs, *roles.evse) - missing.extend( - device.device_id + graced = { + device.device_id: f"{NODE_INFO}/{PROP_MODEL}" for device in ders if device is not None and PROP_MODEL in device.get_node_properties(NODE_INFO) and device.get_property(NODE_INFO, PROP_MODEL) is None + } + graced.update( + (circuit_id, f"{NODE_CONNECTION}/{PROP_FEEDS_DEVICE_ID}") + for circuit_id in _unvalued_feeds_for_unplaced_pvs(roles) ) - missing.extend(self._firmware_version_pending(roles)) - feeds = _unvalued_feeds_for_unplaced_pvs(roles) - if feeds and not missing: - now = self._clock() - if self._feed_wait_since is None: - self._feed_wait_since = now - if now - self._feed_wait_since >= FEED_GRACE_S: - if not self._feed_wait_reported: - _LOGGER.info( - "No connection record names %d circuit(s) as an inverter's feed; " - "inverters without one are keyed by device id", - len(feeds), - ) - self._feed_wait_reported = True - feeds = [] - else: - # No feed is being waited out on its own: something else is still - # missing, or every inverter is placed. Either way a later feed wait - # is a new one and gets the whole grace. - self._feed_wait_since = None - if not feeds: - self._feed_wait_reported = False - missing.extend(feeds) + missing.extend(self._within_grace(graced, held=bool(missing))) return missing + def _within_grace(self, pending: dict[str, str], *, held: bool) -> list[str]: + """The devices of `pending` whose grace has not run out. + + `pending` maps each device to the declared `node/property` it has not + valued. While `held`, something without a grace is still missing, so + every device is waited on and no grace runs. A device whose grace runs + out is reported once, and stops being waited on until its value arrives + or a hold starts its grace again. + """ + for device_id in self._grace_since.keys() - pending.keys(): + del self._grace_since[device_id] + self._grace_reported &= pending.keys() + if held: + self._grace_since.clear() + return list(pending) + now = self._clock() + waiting: list[str] = [] + for device_id, path in pending.items(): + if now - self._grace_since.setdefault(device_id, now) < FEED_GRACE_S: + waiting.append(device_id) + elif device_id not in self._grace_reported: + _LOGGER.info("%s declares %s and has not published it; taking it as absent", device_id, path) + self._grace_reported.add(device_id) + return waiting + def _firmware_version_pending(self, roles: TreeRoles) -> list[str]: """The panel itself, while a declared BESS waits on the panel's firmware version. @@ -289,13 +461,15 @@ def _firmware_version_pending(self, roles: TreeRoles) -> list[str]: return [] def find_node_by_type(self, type_str: str) -> str | None: - """Return the id of the first device declaring `type_str`. + """Return the id of the first device declaring `type_str` or a subtype of it. Named for the flat schema's nodes; under parent/child the same question - is asked of devices, and the answer is a device id. + is asked of devices, and the answer is a device id. A device typed + ``…device.bess.hybrid`` is a ``…device.bess`` (`declares_class`), the + same device the snapshot reads as the battery. """ for device in self._children(): - if device_type(device) == type_str: + if declares_class(device_type(device), type_str): return device.device_id return None @@ -308,7 +482,7 @@ def set_circuit_relay_target(self, circuit_id: str) -> ControlTarget | None: """Where this circuit's relay is commanded, or None if it may not be. **None where the panel declares the relay non-commandable**, by either of - the two signals `relay_is_settable` reads. `_target` is pure string + the two signals `relay_is_settable` reads. `control_target` is pure string formatting from a device id, so building the topic unconditionally aimed a write at a circuit the panel commissioned as always-on — every part of the refusal was already in the tree, and nothing consulted it. @@ -325,7 +499,7 @@ def set_circuit_relay_target(self, circuit_id: str) -> ControlTarget | None: device = self._child(circuit_id) if device is None or not relay_is_settable(device): return None - return self._target(circuit_id, NODE_SWITCH, PROP_RELAY) + return control_target(circuit_id, NODE_SWITCH, PROP_RELAY) def set_circuit_priority_target(self, circuit_id: str) -> ControlTarget | None: """Where this circuit's shed priority is written, or None if it may not be. @@ -342,7 +516,7 @@ def set_circuit_priority_target(self, circuit_id: str) -> ControlTarget | None: device = self._child(circuit_id) if device is None or not priority_is_settable(device): return None - return self._target(circuit_id, NODE_LOAD_SHED, PROP_PRIORITY) + return control_target(circuit_id, NODE_LOAD_SHED, PROP_PRIORITY) def has_circuit(self, circuit_id: str) -> bool: """Whether the tree carries a circuit under this id. @@ -351,7 +525,9 @@ def has_circuit(self, circuit_id: str) -> bool: is addressable by id — the BESS, the MID, the lugs, a charger — and none of them is a circuit, so answering on membership alone would report a BESS as a circuit whose relay the panel declares non-commandable. It - declares no relay at all. + declares no relay at all. The class is the answer rather than the exact + type, so a subtyped circuit the snapshot reads into `circuits` is a + circuit here too. A child that has not described itself yet reads as absent, because it has declared nothing: type, nodes and properties all arrive together in @@ -364,7 +540,7 @@ def has_circuit(self, circuit_id: str) -> bool: would put a second, weaker rule where the authorisation lives. """ device = self._child(circuit_id) - return device is not None and device_type(device) == TYPE_CIRCUIT + return device is not None and declares_class(device_type(device), TYPE_CIRCUIT) def set_dominant_power_source_target(self) -> ControlTarget | None: """The settable successor: `shed/asserted-islanding-state` on the panel. @@ -398,7 +574,7 @@ def set_dominant_power_source_target(self) -> ControlTarget | None: root = self._controller.get_root(self._serial_number) if not declared_settable(node_properties(root, NODE_SHED).get(PROP_ASSERTED_ISLANDING_STATE)): return None - return self._target(self._serial_number, NODE_SHED, PROP_ASSERTED_ISLANDING_STATE) + return control_target(self._serial_number, NODE_SHED, PROP_ASSERTED_ISLANDING_STATE) def dominant_power_source_payload(self, value: str) -> str | None: """Translate a flat `dominant-power-source` value into an assertion. @@ -447,7 +623,7 @@ def set_evse_charge_limit_target(self, node_id: str) -> ControlTarget | None: if writable is None: return None device, surface, limit = writable - return self._target(device.device_id, surface.node, limit.property_id) + return control_target(device.device_id, surface.node, limit.property_id) def evse_charge_limit_payload(self, node_id: str, amps: int) -> str | None: """The payload to publish for `amps`, or None if it may not be published. @@ -463,22 +639,39 @@ def evse_charge_limit_payload(self, node_id: str, amps: int) -> str | None: charge-only EVSE cannot be told to export by lowering a ceiling, so a negative value is not a smaller limit but a malformed one. + **Refuses outside the range the limit declares.** Firmware r202639 + publishes `:` as the limit's `$format` + (`6:32`), so a value under the minimum is refused here instead of being + published for the panel to reject or misapply. A declared maximum + tighter than the ceiling applies too. A format that is absent, or that + cannot be read as an integer range, bounds nothing extra and the + ceiling rule above still holds. + A charger that declares no ceiling is not second-guessed — the catalog - makes `installer-max` a SHOULD, and the value that bounds the write is - the one the panel published, not one this library invents. + makes `installer-max` a SHOULD, and the values that bound the write are + the ones the panel published, not ones this library invents. With no + ceiling, a maximum declared in the limit's `$format` still bounds the + write; with neither, nothing does. """ writable = self._writable_charge_limit(node_id) if writable is None or amps < 0: return None - device, surface, _limit = writable + device, surface, limit = writable ceiling = surface.ceiling commissioned = None if ceiling is None else integer(device, surface.node, ceiling.property_id) if commissioned is not None and amps > commissioned: return None + if limit.bounds is not None: + minimum, maximum = limit.bounds + if (minimum is not None and amps < minimum) or (maximum is not None and amps > maximum): + return None return str(amps) def register_property_callback(self, callback: Callable[[str, str, str, str | None], None]) -> Callable[[], None]: - """Subscribe to per-property updates: `(device_id, node_id, property_id, value)`.""" + """Subscribe to per-property updates: `(device_id, node_id, property_id, value)`. + + `value` is `None` when the panel clears a value it had published. + """ self._property_callbacks.append(callback) def _unregister() -> None: @@ -514,23 +707,21 @@ def _writable_charge_limit( return device, surface, surface.limit return None - def _target(self, device_id: str, node: str, prop: str) -> ControlTarget: - """One device/node/property address as both a set topic and an observation key. - - The triple is returned alongside the topic rather than left for the - transport to parse back out of it: the transport is the one component - that is supposed to know nothing about this schema's topic grammar, and - under parent/child the device is a peer of the panel rather than a node - beneath it, so the grammar is not even the flat one. + def export_masked_tree(self) -> MaskedTree | None: + """The device tree the adapter holds, masked, or None before the root has described itself. - The spelling here is the spelling `_on_property_changed` reports under, - because a write is verified by matching one against the other. + Computed at call time and not gated on `is_ready()`: a tree that has not + finished arriving is exactly when a diagnostic is wanted, and + `metadata["tree_complete"]` says whether this one is whole. """ - return ControlTarget( - topic=f"{HOMIE_DOMAIN}/{HOMIE_VERSION}/{device_id}/{node}/{prop}/set", - device_id=device_id, - node_id=node, - property_id=prop, + root = self._controller.get_root(self._serial_number) + if root is None or root.description is None: + return None + return export_masked_tree( + root, + self._children(), + producer=_producer(), + tree_complete=self._controller.is_tree_complete(self._serial_number), ) def _require_root(self) -> DiscoveredDevice: @@ -596,5 +787,16 @@ def _on_property_changed(self, device_id: str, node_id: str, property_id: str, v protocol has no place for the previous value, and consumers that need one keep it themselves. """ + self._notify(device_id, node_id, property_id, value) + + def _notify(self, device_id: str, node_id: str, property_id: str, value: str | None) -> None: + """Report one property's new value, `None` once cleared, after forgetting what it invalidates.""" + # The one value readiness waits on. + if (device_id, node_id, property_id) == (self._serial_number, NODE_INFO, PROP_MODEL): + self._ready = None for callback in list(self._property_callbacks): callback(device_id, node_id, property_id, value) + + def _tree_changed(self, *_event: object) -> None: + """Forget the remembered readiness. Accepts any of the Controller's tree events.""" + self._ready = None diff --git a/packages/schema-1/src/span_panel_api_schema_1/adoption.py b/packages/schema-1/src/span_panel_api_schema_1/adoption.py index 715990a5..3ee56726 100644 --- a/packages/schema-1/src/span_panel_api_schema_1/adoption.py +++ b/packages/schema-1/src/span_panel_api_schema_1/adoption.py @@ -25,6 +25,7 @@ from span_panel_api_schema_1.const import ( HOMIE_DOMAIN, HOMIE_VERSION, + SITE_PROPERTIES, TYPE_BESS, TYPE_CIRCUIT, TYPE_EVSE, @@ -34,7 +35,14 @@ TYPE_PANEL, TYPE_PV, ) -from span_panel_api_schema_1.description import declared_settable, device_type, nodes, optional_str, properties +from span_panel_api_schema_1.description import ( + declared_settable, + declares_class, + device_type, + nodes, + optional_str, + properties, +) if TYPE_CHECKING: from ebus_sdk.homie import DiscoveredDevice @@ -71,10 +79,11 @@ def is_modelled(declared: str) -> bool: Subtype-aware, because firmware may declare either a base type or a subtype of it -- ``…device.lugs`` with a ``direction`` property, or ``…device.lugs.upstream``. A subtype of something modelled is modelled: the - snapshot builder matches lugs by prefix for exactly this reason, and a - subtype arriving must not be adopted behind the builder's back. + snapshot builder sorts each class with the same `declares_class`, so the + two agree about which devices a class covers, and a subtype the builder + reads is never adopted behind its back. """ - return any(declared == known or declared.startswith(f"{known}.") for known in MODELLED_TYPES) + return any(declares_class(declared, known) for known in MODELLED_TYPES) def build_adopted_devices(children: list[DiscoveredDevice]) -> tuple[AdoptedDevice, ...]: @@ -132,7 +141,7 @@ def card(property_id: str) -> str | None: def _readings(device: DiscoveredDevice, declared_nodes: dict[str, dict[str, object]]) -> tuple[AdoptedProperty, ...]: - """Every declared property outside the identity and topology nodes. + """Every declared property outside the identity and topology nodes, and no site property. Those two are excluded by *node*, which is what the eBus vocabulary defines, rather than by property name. The catalogs carry no marker for "this string @@ -146,6 +155,8 @@ def _readings(device: DiscoveredDevice, declared_nodes: dict[str, dict[str, obje if node_id in (ADOPTION_IDENTITY_NODE, ADOPTION_TOPOLOGY_NODE): continue for property_id, definition in properties(node).items(): + if property_id in SITE_PROPERTIES: + continue raw = device.get_property(node_id, property_id) # The same reading the curated controls get: this one gates a set # topic on an uncurated device, so a declaration that has not said diff --git a/packages/schema-1/src/span_panel_api_schema_1/charge_limit.py b/packages/schema-1/src/span_panel_api_schema_1/charge_limit.py index 9a120c66..42e0d281 100644 --- a/packages/schema-1/src/span_panel_api_schema_1/charge_limit.py +++ b/packages/schema-1/src/span_panel_api_schema_1/charge_limit.py @@ -39,6 +39,7 @@ from __future__ import annotations from dataclasses import dataclass +import re from typing import TYPE_CHECKING from span_panel_api_schema_1.description import declared_settable, nodes, optional_str, properties @@ -81,6 +82,42 @@ class ChargeLimitSpelling: """ +_PLAIN_INTEGER = re.compile(r"-?[0-9]+", re.ASCII) + +IntegerBounds = tuple[int | None, int | None] +"""A declared integer range, `(minimum, maximum)`; None on a side the format leaves open.""" + + +def declared_integer_bounds(datatype: str, declared: object) -> IntegerBounds | None: + """The range an `integer` property's `$format` declares, or None. + + Homie 5 spells it `:` and allows either side to be empty. Anything + else is not interpreted: a format that is not a string, a datatype that is + not `integer`, a missing colon, extra segments, or a bound that is not a + plain integer (an optional minus sign and ASCII digits, so `1_0`, `+6` and + non-ASCII digits are refused) or a minimum above the maximum all yield None, + which bounds nothing. Guessing a range from a format we cannot read would + refuse a write the panel might accept, and the commissioned ceiling still + applies either way. + + A property declared `float` is not bounded by its range: only `integer` + ranges are read. + """ + if datatype != "integer" or not isinstance(declared, str): + return None + parts = declared.split(":") + if len(parts) != 2: + return None + low, high = parts[0].strip(), parts[1].strip() + if any(text and _PLAIN_INTEGER.fullmatch(text) is None for text in (low, high)): + return None + minimum = int(low) if low else None + maximum = int(high) if high else None + if minimum is not None and maximum is not None and minimum > maximum: + return None + return minimum, maximum + + @dataclass(frozen=True, slots=True) class ChargeLimitProperty: """One declared property of the resolved surface. @@ -95,6 +132,8 @@ class ChargeLimitProperty: unit: str | None datatype: str settable: bool + bounds: IntegerBounds | None = None + """The `:` range the declaration's `$format` states, or None where it states none we can read.""" @dataclass(frozen=True, slots=True) @@ -144,9 +183,11 @@ def resolve_charge_limit(device: DiscoveredDevice | None) -> ChargeLimitSurface def _property(property_id: str, definition: dict[str, object] | None) -> ChargeLimitProperty | None: if definition is None: return None + datatype = str(definition.get("datatype") or "string") return ChargeLimitProperty( property_id=property_id, unit=optional_str(definition.get("unit")), - datatype=str(definition.get("datatype") or "string"), + datatype=datatype, settable=declared_settable(definition), + bounds=declared_integer_bounds(datatype, definition.get("format")), ) diff --git a/packages/schema-1/src/span_panel_api_schema_1/circuits.py b/packages/schema-1/src/span_panel_api_schema_1/circuits.py index 7a10f791..ddfde7ae 100644 --- a/packages/schema-1/src/span_panel_api_schema_1/circuits.py +++ b/packages/schema-1/src/span_panel_api_schema_1/circuits.py @@ -8,7 +8,7 @@ ====================== =========================================================== Flat property v1.0 source ====================== =========================================================== -``always-on`` ``switch/relay-controllable``, inverted +``always-on`` ``switch/relay-controllable``, inverted, where a relay is declared ``never-backup`` ``$settable`` on ``load-shed/priority``, inverted ``sheddable`` computed: a shed priority and ``relay-controllable`` ====================== =========================================================== @@ -24,15 +24,31 @@ ``exported-energy`` (the panel exported it *to* the circuit). The snapshot reports consumption as positive, so power is negated and the two energy accumulators are swapped. + +**A circuit-typed device that declares no breaker space is a meter outside the +panel**, and none of that applies to it. Its ``active-power`` is already +import-positive (positive = flowing into the panel), so it is reported as +published, with ``imported-energy`` as consumed and ``exported-energy`` as +produced: consumed minus produced is net import. The classification reads the +declaration, never a value, so a meter that has not reported is already outside +the panel and a hosted circuit that has not reported is still hosted. """ from __future__ import annotations from typing import TYPE_CHECKING, Final -from span_panel_api.models import SpanCircuitSnapshot +from span_panel_api.models import ( + FEEDS_ROLES, + PROTECTION_FUNCTIONS, + FeedsRole, + ProtectionFunction, + SpanCircuitSnapshot, + device_id_order, +) from span_panel_api_schema_1.const import ( NODE_BREAKER, + NODE_CONNECTION, NODE_INFO, NODE_LOAD_SHED, NODE_METER, @@ -43,21 +59,28 @@ PROP_ACTIVE_POWER, PROP_CURRENT, PROP_EXPORTED_ENERGY, + PROP_FEEDS_ROLE, PROP_IMPORTED_ENERGY, PROP_MANAGED, PROP_NAME, + PROP_NOMINAL_VOLTAGE, PROP_POLES, PROP_PRIORITY, + PROP_PROTECTION_FUNCTIONS, PROP_RATING, PROP_RELAY, PROP_RELAY_CONTROLLABLE, PROP_RELAY_REQUESTER, + PROP_SHARED_WITH_DEVICE_IDS, PROP_SPACES, UNKNOWN, ) from span_panel_api_schema_1.description import declared_settable, node_properties +from span_panel_api_schema_1.panel import declares_node if TYPE_CHECKING: + from collections.abc import Collection + from ebus_sdk.homie import DiscoveredDevice _SHED_PRIORITIES: Final = frozenset({PRIORITY_OFF_GRID, PRIORITY_SOC_THRESHOLD}) @@ -88,10 +111,11 @@ def _number(device: DiscoveredDevice, node: str, prop: str) -> float | None: def _flag(device: DiscoveredDevice, node: str, prop: str, *, default: bool) -> bool: """Read a Homie boolean. Absent means `default`, which is not always False. - `relay-controllable` absent has to mean *controllable*, because the - property exists to mark the exception (an always-on circuit). Defaulting it - to False would silently make every circuit uncontrollable on a panel that - omits it. + `relay-controllable` absent has to mean *controllable* on a device that + declares a relay, because the property exists to mark the exception (an + always-on circuit). Defaulting it to False would silently make every circuit + uncontrollable on a panel that omits it. See `_relay_controllable` for a + device that declares no relay. """ raw = device.get_property(node, prop) if raw is None or raw == "": @@ -125,6 +149,28 @@ def _optional_integer(device: DiscoveredDevice, node: str, prop: str) -> int | N return None if raw is None else int(raw) +def declares_spaces(device: DiscoveredDevice) -> bool: + """Whether the device's `$description` declares ``info/spaces``. + + The hosted-or-outside question, asked of the declaration because a value + cannot answer it: a hosted circuit whose spaces have not arrived yet and a + meter that has none read the same until the values land, and a consumer + that keyed the sign of a reading on that gap would book the first readings + of every hosted circuit backwards. + """ + return PROP_SPACES in node_properties(device, NODE_INFO) + + +def _relay_controllable(device: DiscoveredDevice) -> bool: + """``switch/relay-controllable``, defaulting to whether a relay is declared at all. + + A device that declares no ``switch`` node has no relay to command, so it is + not controllable whatever it leaves unpublished; one that declares the node + and leaves the property unvalued is, for the reason `_flag` gives. + """ + return _flag(device, NODE_SWITCH, PROP_RELAY_CONTROLLABLE, default=declares_node(device, NODE_SWITCH)) + + def _tabs(device: DiscoveredDevice) -> list[int]: """Breaker spaces from ``info/spaces``. @@ -235,21 +281,68 @@ def relay_is_settable(device: DiscoveredDevice) -> bool: specification's rule showing up in hardware. The vendored capture carries the same pattern on its five. """ - return _settable(device, NODE_SWITCH, PROP_RELAY) and _flag(device, NODE_SWITCH, PROP_RELAY_CONTROLLABLE, default=True) + return _settable(device, NODE_SWITCH, PROP_RELAY) and _relay_controllable(device) + + +def _feeds_role(device: DiscoveredDevice) -> FeedsRole | None: + """The declared `connection/feeds-role`, or None when unpublished or outside the role set.""" + published = _text(device, NODE_CONNECTION, PROP_FEEDS_ROLE) + return next((role for role in FEEDS_ROLES if role == published), None) + + +def _protection_functions(device: DiscoveredDevice) -> tuple[ProtectionFunction, ...] | None: + """The published `breaker/protection-functions`, in order, or None when unpublished. + + A comma-separated list of the enum's members; a value outside + `PROTECTION_FUNCTIONS` is dropped rather than passed on. + """ + published = device.get_property(NODE_BREAKER, PROP_PROTECTION_FUNCTIONS) + if published is None: + return None + listed = [part.strip() for part in str(published).split(",")] + return tuple(function for part in listed for function in PROTECTION_FUNCTIONS if function == part) + + +def _shared_with(device: DiscoveredDevice, node: str, circuit_ids: Collection[str]) -> tuple[str, ...] | None: + """One node's `shared-with-device-ids`, resolved to the other circuits of the snapshot. + + A circuit's snapshot key is its device id, so resolving keeps the listed ids + that name another circuit, in `device_id_order`. `None` while the list is + undeclared or unpublished; an empty tuple where it names no known circuit. + """ + published = device.get_property(node, PROP_SHARED_WITH_DEVICE_IDS) + if published is None: + return None + listed = {part.strip() for part in str(published).split(",")} + return tuple(sorted((listed & set(circuit_ids)) - {device.device_id}, key=device_id_order)) def build_circuit( - device: DiscoveredDevice, device_type: str = "circuit", relative_position: str = "" + device: DiscoveredDevice, + device_type: str = "circuit", + relative_position: str = "", + circuit_ids: Collection[str] = frozenset(), ) -> SpanCircuitSnapshot: - """Build one circuit snapshot from its v1.0 device.""" - raw_power = _number(device, NODE_METER, PROP_ACTIVE_POWER) - # Negate so positive means consumption. The guard keeps -0.0 out of the - # snapshot, where it would compare equal to 0.0 but format as "-0.0". - # A meter that has not reported stays `None` rather than becoming 0.0 W — - # see `SpanCircuitSnapshot` for why absent and zero must not collapse. - instant_power_w = None if raw_power is None else (0.0 if raw_power == 0.0 else -raw_power) + """Build one circuit snapshot from its v1.0 device. - relay_controllable = _flag(device, NODE_SWITCH, PROP_RELAY_CONTROLLABLE, default=True) + `circuit_ids` is every circuit device id in the tree, against which the + circuit's shared-with lists are resolved. + """ + outside = not declares_spaces(device) + raw_power = _number(device, NODE_METER, PROP_ACTIVE_POWER) + # A hosted circuit is negated so positive means consumption; a meter outside + # the panel is already import-positive and is reported as published. The + # guard keeps -0.0 out of the snapshot, where it would compare equal to 0.0 + # but format as "-0.0". A meter that has not reported stays `None` rather + # than becoming 0.0 W — see `SpanCircuitSnapshot` for why absent and zero + # must not collapse. + frame = 1.0 if outside else -1.0 + instant_power_w = None if raw_power is None else (0.0 if raw_power == 0.0 else frame * raw_power) + imported_wh = _number(device, NODE_METER, PROP_IMPORTED_ENERGY) + exported_wh = _number(device, NODE_METER, PROP_EXPORTED_ENERGY) + poles = _number(device, NODE_BREAKER, PROP_POLES) + + relay_controllable = _relay_controllable(device) priority = _text(device, NODE_LOAD_SHED, PROP_PRIORITY, UNKNOWN) priority_settable = priority_is_settable(device) @@ -258,11 +351,12 @@ def build_circuit( name=_text(device, NODE_INFO, PROP_NAME), relay_state=_text(device, NODE_SWITCH, PROP_RELAY, UNKNOWN), instant_power_w=instant_power_w, - # The panel *imported* this energy from the circuit, so the circuit - # produced it. Named from the panel's perspective, reported from the - # circuit's. - produced_energy_wh=_number(device, NODE_METER, PROP_IMPORTED_ENERGY), - consumed_energy_wh=_number(device, NODE_METER, PROP_EXPORTED_ENERGY), + # On a hosted circuit the panel *imported* this energy from the + # circuit, so the circuit produced it: named from the panel's + # perspective, reported from the circuit's. A meter outside the panel + # measures the panel's own import, so its imported energy is consumed. + produced_energy_wh=exported_wh if outside else imported_wh, + consumed_energy_wh=imported_wh if outside else exported_wh, tabs=_tabs(device), priority=priority, # `always-on` is `not relay-controllable`, and the flat schema derived @@ -273,10 +367,18 @@ def build_circuit( is_never_backup=not priority_settable, device_type=device_type, relative_position=relative_position, - is_240v=(_number(device, NODE_BREAKER, PROP_POLES) or 1) >= 2, + nominal_voltage_v=_number(device, NODE_INFO, PROP_NOMINAL_VOLTAGE), + protection_functions=_protection_functions(device), + feeds_role=_feeds_role(device), + meter_shared_with=_shared_with(device, NODE_METER, circuit_ids), + relay_shared_with=_shared_with(device, NODE_SWITCH, circuit_ids), + # Unknown without a pole count: a meter outside the panel has no + # breaker, and a breaker whose count has not arrived has not said. + is_240v=None if poles is None else poles >= 2, current_a=_number(device, NODE_METER, PROP_CURRENT), breaker_rating_a=_number(device, NODE_BREAKER, PROP_RATING), - always_on=not relay_controllable, + # A relay locked closed. A device with no relay is not "on" at all. + always_on=declares_node(device, NODE_SWITCH) and not relay_controllable, relay_requester=_text(device, NODE_SWITCH, PROP_RELAY_REQUESTER, UNKNOWN), relay_state_target=device.get_property_target(NODE_SWITCH, PROP_RELAY), priority_target=device.get_property_target(NODE_LOAD_SHED, PROP_PRIORITY), @@ -291,4 +393,5 @@ def build_circuit( # policy, both, or neither, so they are read separately and named apart. pcs_managed=_optional_flag(device, NODE_PCS, PROP_MANAGED), pcs_priority=_optional_integer(device, NODE_PCS, PROP_PRIORITY), + measures_outside_panel=outside, ) diff --git a/packages/schema-1/src/span_panel_api_schema_1/const.py b/packages/schema-1/src/span_panel_api_schema_1/const.py index ba758bb2..41b61787 100644 --- a/packages/schema-1/src/span_panel_api_schema_1/const.py +++ b/packages/schema-1/src/span_panel_api_schema_1/const.py @@ -8,6 +8,9 @@ from __future__ import annotations +from collections.abc import Mapping +from typing import Final + # -- Device classes --------------------------------------------------------- DEVICE_TYPE_PREFIX = "energy.ebus.device." @@ -41,6 +44,32 @@ # imports `panel` -- so the constant has to live below both of them. PROP_FEEDS_DEVICE_ID = "feeds-device-id" PROP_FEEDS_DEVICE_STATUS = "feeds-device-status" +PROP_FEEDS_ROLE = "feeds-role" +PROP_SHARED_WITH_DEVICE_IDS = "shared-with-device-ids" +PROP_OVERCURRENT_PROTECTION = "overcurrent-protection" +PROP_BUSBAR_CURRENT = "busbar-current" +PROP_FREQUENCY = "frequency" +PROP_NOMINAL_VOLTAGE = "nominal-voltage" +PROP_PROTECTION_FUNCTIONS = "protection-functions" + +SITE_PROPERTIES: Final[frozenset[str]] = frozenset( + { + "address-lines", + "locality", + "region", + "country-code", + "latitude", + "longitude", + "utility-meter-serial-number", + } +) +"""Property ids that say where a panel is installed, which never become a reading. + +Skipped by `extension` and `adoption` on whatever node a device declares them. +Where the panel declares them, under `info` beside the site's `info/name`, the +identity node is skipped as a whole already; this holds if a device declares +them anywhere else. They stay discovery rows, which carry no values. +""" PROP_FED_BY_DEVICE_ID = "fed-by-device-id" PROP_FED_BY_DEVICE_STATUS = "fed-by-device-status" NODE_DOOR = "door" @@ -194,6 +223,17 @@ "MLO_48": 48, } +# The first and last breaker position for each model. Keyed like +# `PANEL_SIZE_BY_MODEL`, and like it the numbers are ours: the panel publishes +# only which positions are occupied. +PANEL_POSITIONS_BY_MODEL: Final[Mapping[str, tuple[int, int]]] = { + "MAIN_16": (9, 24), + "MLO_24": (1, 24), + "MAIN_32": (1, 32), + "MAIN_40": (9, 48), + "MLO_48": (1, 48), +} + # The Homie attribute that carries what the flat schema published as the # `never-backup` boolean. v1.0 retires the property and expresses it as # mutability: a circuit commissioned never-backup has its priority locked, and diff --git a/packages/schema-1/src/span_panel_api_schema_1/description.py b/packages/schema-1/src/span_panel_api_schema_1/description.py index b2873278..b65303ec 100644 --- a/packages/schema-1/src/span_panel_api_schema_1/description.py +++ b/packages/schema-1/src/span_panel_api_schema_1/description.py @@ -36,6 +36,21 @@ def device_type(device: DiscoveredDevice) -> str: return str(declared) if declared else "" +def declares_class(declared: str, known: str) -> bool: + """Whether a declared device type is the class `known` or a subtype of it. + + eBus device types are hierarchical and a subtype carries its parent's + class, so a device typed ``…device.bess.hybrid`` is a ``…device.bess``. + The boundary is the dot: ``…device.lugsfoo`` merely begins with + ``…device.lugs`` and names a different class. + + The one answer to the question for every reader of a type -- the snapshot + roles, adoption, field metadata and discovery -- so that no two of them can + disagree about which class a device belongs to. + """ + return declared == known or declared.startswith(f"{known}.") + + def nodes(description: dict[str, object]) -> dict[str, dict[str, object]]: """The capability nodes a description declares, by node id.""" declared = description.get("nodes") diff --git a/packages/schema-1/src/span_panel_api_schema_1/devices.py b/packages/schema-1/src/span_panel_api_schema_1/devices.py index 27b268bb..edf357c9 100644 --- a/packages/schema-1/src/span_panel_api_schema_1/devices.py +++ b/packages/schema-1/src/span_panel_api_schema_1/devices.py @@ -36,12 +36,13 @@ The frame is chosen from the enclosure's release build number (``firmware.release_build``), never from the respin suffix after it. Where the version does not parse, the two wire properties decide instead: one nonzero sign -on both is the old frame, opposite signs the new one. Where either is zero or +on both is the old frame, opposite signs the new one. The reference capture +(``ebus-panel-sim`` 0.9.0) publishes no SPAN version string and is read this way: +it carries r202639's frame, told by its opposite signs. Where either is zero or absent the old frame is assumed, because that is what every earlier release of -this package applied and what the reference capture (``ebus-panel-sim`` 0.8.0, -which publishes no SPAN version string) carries. A battery at rest reads zero in -both frames, so the assumption only decides a nonzero BESS meter beside a missing -or zero flow figure. +this package applied. A battery at rest reads zero in both frames, so the +assumption only decides a nonzero BESS meter beside a missing or zero flow +figure. On either firmware ``panel.power_flow_battery`` (passed through untouched, and charge-positive) and ``battery.power_w`` end up as each other's mirror, so a @@ -53,7 +54,7 @@ from typing import TYPE_CHECKING from span_panel_api.models import SpanBatterySnapshot, SpanEvseSnapshot, SpanMidSnapshot, SpanPVSnapshot -from span_panel_api_schema_1.charge_limit import ChargeLimitProperty, ChargeLimitSurface, resolve_charge_limit +from span_panel_api_schema_1.charge_limit import ChargeLimitProperty, ChargeLimitSurface, IntegerBounds, resolve_charge_limit from span_panel_api_schema_1.const import ( NODE_CONNECTION, NODE_GRID, @@ -75,8 +76,10 @@ PROP_VENDOR_NAME, UNKNOWN, ) +from span_panel_api_schema_1.description import declared_settable, node_properties from span_panel_api_schema_1.firmware import release_build from span_panel_api_schema_1.panel import integer, number, resolve_grid_forming_device_name, text +from span_panel_api_schema_1.transport import control_target if TYPE_CHECKING: from collections.abc import Mapping @@ -241,19 +244,30 @@ def build_battery( bess: DiscoveredDevice | None, owners: list[DiscoveredDevice], *, + feeds: Mapping[str, str] | None = None, + feed_statuses: Mapping[str, str] | None = None, firmware_version: str | None = None, power_flow_battery: float | None = None, ) -> SpanBatterySnapshot: - """Build the battery snapshot. An uncommissioned panel yields the empty one. + """Build the battery snapshot. A tree with no battery yields the empty one, marked absent. `firmware_version` is the enclosure's ``info/firmware-version`` and `power_flow_battery` its ``power-flows/battery``; together they pick the BESS meter's wire frame. Omitted, they leave the old frame assumed. + + The link status is the owner's ``fed-by-*`` record where a device claims + the battery that way, as the upstream lugs do for a battery ahead of them. + Otherwise it is the record of the circuit that feeds the battery, from + `feeds` and `feed_statuses` (``feed_circuit_ids`` and + ``feed_connection_statuses``), as it is for an inverter or a charger. """ if bess is None: - return SpanBatterySnapshot() + return SpanBatterySnapshot(present=False) + feed_circuit_id = (feeds or {}).get(bess.device_id) status = connection_status_for(bess.device_id, owners) + if status is None: + status = (feed_statuses or {}).get(bess.device_id) raw_power_w = number(bess, NODE_METER, PROP_ACTIVE_POWER) charge_positive_on_wire = _bess_meter_is_charge_positive(firmware_version, raw_power_w, power_flow_battery) @@ -279,6 +293,8 @@ def build_battery( # than collapsed to a bool: DEGRADED is neither OK nor LOST, and a bool # would have to pick one. communication_state=_optional(text(bess, NODE_STATUS, PROP_COMMUNICATION_STATE)), + present=True, + feed_circuit_id=feed_circuit_id, ) @@ -326,6 +342,15 @@ def build_pv( ) +def _declared_format(device: DiscoveredDevice, node: str, prop: str) -> tuple[str, ...] | None: + """The members an enum property's declaration lists in `$format`, or None where it lists none.""" + declaration = node_properties(device, node).get(prop) + listed = None if declaration is None else declaration.get("format") + if not isinstance(listed, str) or not listed: + return None + return tuple(member.strip() for member in listed.split(",") if member.strip()) + + def build_evse( evse: DiscoveredDevice, feeds: dict[str, str], *, node_id: str, feed_statuses: dict[str, str] ) -> SpanEvseSnapshot: @@ -344,15 +369,24 @@ def build_evse( The charge-current pair is read through `resolve_charge_limit` rather than from named constants, because which node and properties carry it is a question only this charger's `$description` can answer. See - `span_panel_api_schema_1.charge_limit`. + `span_panel_api_schema_1.charge_limit`. The limit's declared range comes from + the same resolution, so the range a control offers and the range + `SchemaOneAdapter.evse_charge_limit_payload` enforces cannot disagree. """ limit = resolve_charge_limit(evse) + minimum, maximum = _limit_bounds(limit) return SpanEvseSnapshot( node_id=node_id, feed_circuit_id=feeds.get(evse.device_id, ""), connected=_connected(feed_statuses.get(evse.device_id)), status=text(evse, NODE_STATUS, PROP_STATUS, UNKNOWN), lock_state=text(evse, NODE_SWITCH, PROP_LOCK_STATE, UNKNOWN), + lock_control=( + control_target(evse.device_id, NODE_SWITCH, PROP_LOCK_STATE) + if declared_settable(node_properties(evse, NODE_SWITCH).get(PROP_LOCK_STATE)) + else None + ), + lock_state_options=_declared_format(evse, NODE_SWITCH, PROP_LOCK_STATE), advertised_current_a=number(evse, NODE_METER, PROP_ADVERTISED_CURRENT), vendor_name=_optional(text(evse, NODE_INFO, PROP_VENDOR_NAME)), model=_optional(text(evse, NODE_INFO, PROP_MODEL)), @@ -363,9 +397,23 @@ def build_evse( charge_current_ceiling_a=_limit_value(evse, limit, limit.ceiling) if limit else None, charge_current_limit_target_a=_limit_target(evse, limit), charge_current_limit_settable=limit is not None and limit.limit is not None and limit.limit.settable, + charge_current_limit_minimum_a=minimum, + charge_current_limit_maximum_a=maximum, ) +def _limit_bounds(surface: ChargeLimitSurface | None) -> IntegerBounds: + """The range the resolved limit declares, `None` on a side it leaves open or cannot be read. + + `ChargeLimitProperty.bounds` is already None for a format + `declared_integer_bounds` will not interpret, so a declaration that bounds + nothing on the write path reports no range here either. + """ + if surface is None or surface.limit is None or surface.limit.bounds is None: + return None, None + return surface.limit.bounds + + def _limit_value(evse: DiscoveredDevice, surface: ChargeLimitSurface, declaration: ChargeLimitProperty | None) -> int | None: """One half of the resolved charge-limit pair, or None where it is not declared.""" if declaration is None: @@ -389,7 +437,7 @@ def _limit_target(evse: DiscoveredDevice, surface: ChargeLimitSurface | None) -> return None try: return int(float(raw)) - except (TypeError, ValueError): + except TypeError, ValueError: return None diff --git a/packages/schema-1/src/span_panel_api_schema_1/extension.py b/packages/schema-1/src/span_panel_api_schema_1/extension.py index 4a203584..cae2291a 100644 --- a/packages/schema-1/src/span_panel_api_schema_1/extension.py +++ b/packages/schema-1/src/span_panel_api_schema_1/extension.py @@ -33,6 +33,7 @@ from typing import TYPE_CHECKING from span_panel_api.models import ADOPTION_IDENTITY_NODE, ADOPTION_TOPOLOGY_NODE, ExtensionProperty, ExtensionSubject +from span_panel_api_schema_1.const import SITE_PROPERTIES from span_panel_api_schema_1.description import declared_settable, nodes, optional_str, properties from span_panel_api_schema_1.field_metadata import is_addressed @@ -69,12 +70,19 @@ def build_extension_properties( if node_id in (ADOPTION_IDENTITY_NODE, ADOPTION_TOPOLOGY_NODE): continue declarations = properties(node) + # A site property never becomes a reading, but it still counts as + # an unaddressed sibling below: it is not one this adapter reads. unaddressed = { property_id: definition for property_id, definition in declarations.items() if not is_addressed(addressed, declared, node_id, property_id) } - if not unaddressed: + readable = { + property_id: definition + for property_id, definition in unaddressed.items() + if property_id not in SITE_PROPERTIES + } + if not readable: continue # True when the node carries at least one property this adapter does # read. One bit rather than the node-to-field map: a vendor @@ -82,7 +90,7 @@ def build_extension_properties( # a consumer can act on. Exporting which fields would freeze this # adapter's internals as API for a signal the design ranks last. has_curated_siblings = len(unaddressed) < len(declarations) - for property_id, definition in unaddressed.items(): + for property_id, definition in readable.items(): raw = device.get_property(node_id, property_id) found.append( ExtensionProperty( diff --git a/packages/schema-1/src/span_panel_api_schema_1/field_metadata.py b/packages/schema-1/src/span_panel_api_schema_1/field_metadata.py index a0ebd9e7..d92b39a9 100644 --- a/packages/schema-1/src/span_panel_api_schema_1/field_metadata.py +++ b/packages/schema-1/src/span_panel_api_schema_1/field_metadata.py @@ -44,6 +44,7 @@ PROP_ACTIVE_POWER, PROP_EXPORTED_ENERGY, PROP_IMPORTED_ENERGY, + PROP_OVERCURRENT_PROTECTION, TYPE_BESS, TYPE_CIRCUIT, TYPE_EVSE, @@ -53,6 +54,7 @@ TYPE_PV, ) from span_panel_api_schema_1.description import ( + declares_class, device_type as declared_type, nodes as declared_nodes, optional_str, @@ -85,6 +87,8 @@ (TYPE_PANEL, NODE_STATUS, "cloud-connection", "panel.vendor_cloud"), (TYPE_PANEL, NODE_METER, "voltage-a", "panel.l1_voltage"), (TYPE_PANEL, NODE_METER, "voltage-b", "panel.l2_voltage"), + (TYPE_PANEL, NODE_METER, "busbar-current", "panel.busbar_current_a"), + (TYPE_PANEL, NODE_METER, "frequency", "panel.frequency_hz"), (TYPE_PANEL, NODE_BREAKER, "rating", "panel.main_breaker_rating_a"), (TYPE_PANEL, NODE_POWER_FLOWS, "pv", "panel.power_flow_pv"), (TYPE_PANEL, NODE_POWER_FLOWS, "battery", "panel.power_flow_battery"), @@ -131,6 +135,8 @@ (TYPE_CIRCUIT, NODE_METER, "exported-energy", "circuit.consumed_energy_wh"), (TYPE_CIRCUIT, NODE_BREAKER, "rating", "circuit.breaker_rating_a"), (TYPE_CIRCUIT, NODE_BREAKER, "poles", "circuit.is_240v"), + (TYPE_CIRCUIT, NODE_BREAKER, "protection-functions", "circuit.protection_functions"), + (TYPE_CIRCUIT, NODE_INFO, "nominal-voltage", "circuit.nominal_voltage_v"), # --- Circuit `connection` -> the DER the circuit feeds --------------------- # The one place a row's device type and its field path deliberately disagree. # v1.0 states the enclosure/DER relationship on the *circuit*, so the panel's @@ -179,6 +185,23 @@ ) +_OPTIONAL_PROPERTIES: frozenset[str] = frozenset( + { + "panel.busbar_current_a", + "panel.frequency_hz", + "panel.upstream_protection_rating_a", + "circuit.nominal_voltage_v", + "circuit.protection_functions", + } +) +"""Rows whose property a device may leave out of a node it does declare. + +A device that declares the node without the property yields no entry for these, +rather than `resolved=False`: the property is optional on that node, so its +absence is not a gap. +""" + + def build_field_metadata(devices: list[DiscoveredDevice]) -> dict[str, FieldMetadata]: """Collect metadata for every mapped field the tree actually declares. @@ -199,7 +222,7 @@ def build_field_metadata(devices: list[DiscoveredDevice]) -> dict[str, FieldMeta present_type_nodes: set[tuple[str, str]] = set() for device in devices: description: dict[str, object] = device.description or {} - device_type = str(description.get("type") or "") + device_type = declared_type(device) if not device_type: continue for node_id, node in declared_nodes(description).items(): @@ -216,12 +239,13 @@ def build_field_metadata(devices: list[DiscoveredDevice]) -> dict[str, FieldMeta if found is not None: unit, datatype = found metadata[field_path] = FieldMetadata(unit=unit, datatype=datatype) - elif _node_declared(present_type_nodes, device_type, node_id): + elif field_path not in _OPTIONAL_PROPERTIES and _node_declared(present_type_nodes, device_type, node_id): # The node is here and does not declare the property: a real gap, # distinct from the hardware simply not being installed. metadata[field_path] = FieldMetadata(unit=None, datatype="unknown", resolved=False) metadata.update(_lugs_metadata(devices, upstream=True, fields=_UPSTREAM_LUGS_FIELDS)) metadata.update(_lugs_metadata(devices, upstream=False, fields=_DOWNSTREAM_LUGS_FIELDS)) + metadata.update(_lugs_metadata(devices, upstream=True, fields=_UPSTREAM_LUGS_CONNECTION_FIELDS, node_id=NODE_CONNECTION)) metadata.update(_charge_limit_metadata(devices)) # Namespaced, so a consumer partitions them out before it reads the map as # an inventory of produced fields. See `build_discovery`. @@ -251,7 +275,7 @@ def _charge_limit_metadata(devices: list[DiscoveredDevice]) -> dict[str, FieldMe rather than absent hardware. """ for device in devices: - if not declared_type(device).startswith(TYPE_EVSE): + if not declares_class(declared_type(device), TYPE_EVSE): continue surface = resolve_charge_limit(device) if surface is None: @@ -270,16 +294,16 @@ def _charge_limit_entry(declaration: ChargeLimitProperty | None) -> FieldMetadat def _node_declared(present_type_nodes: set[tuple[str, str]], device_type: str, node_id: str) -> bool: - """Whether any present device of this type declares this node. + """Whether any present device of this type, or a subtype of it, declares this node. - Mirrors `_lookup`'s subtype rule, and has to: presence and lookup must - agree about which devices answer for a row, or a subtyped device that + Asks `declares_class`, as `_lookup` does, and has to: presence and lookup + must agree about which devices answer for a row, or a subtyped device that dropped a property would resolve through one and misclassify through the other. Both are now exercised on non-lugs types, lugs having moved to a direction-resolved lookup of their own. """ return any( - node == node_id and (declared_device_type == device_type or declared_device_type.startswith(f"{device_type}.")) + node == node_id and declares_class(declared_device_type, device_type) for declared_device_type, node in present_type_nodes ) @@ -323,9 +347,19 @@ def _node_declared(present_type_nodes: set[tuple[str, str]], device_type: str, n (PROP_CURRENT_B, "panel.downstream_l2_current_a"), ) +# The protection ahead of the upstream lugs, from their `connection` node rather +# than their meter, and resolved by direction for the same reason. +_UPSTREAM_LUGS_CONNECTION_FIELDS: tuple[tuple[str, str], ...] = ( + (PROP_OVERCURRENT_PROTECTION, "panel.upstream_protection_rating_a"), +) + def _lugs_metadata( - devices: list[DiscoveredDevice], *, upstream: bool, fields: tuple[tuple[str, str], ...] + devices: list[DiscoveredDevice], + *, + upstream: bool, + fields: tuple[tuple[str, str], ...], + node_id: str = NODE_METER, ) -> dict[str, FieldMetadata]: """Metadata for one lugs device, resolved by direction rather than by type. @@ -333,29 +367,31 @@ def _lugs_metadata( value can never disagree about which device is which. Carries the same three-way contract as the table-driven loop, on the same - (device, node) granularity: no lugs device in this direction, or no `meter` - node on it, means no entry, while a `meter` node that omits a property is a - declared gap. Both directions run through here so the two halves of - `panel.*` cannot drift into answering to different rules. + (device, node) granularity: no lugs device in this direction, or no + `node_id` node on it, means no entry, while a node that omits a property is + a declared gap unless the property is optional (`_OPTIONAL_PROPERTIES`). + Both directions run through here so the two halves of `panel.*` cannot + drift into answering to different rules. A lugs device that publishes no `info/direction` is invisible to `find_lugs` and so yields no entry, which is deliberate: the mapper reads its values through the same call, so nothing would populate those fields either. """ - lugs = find_lugs([d for d in devices if declared_type(d).startswith(TYPE_LUGS)], upstream=upstream) + lugs = find_lugs([d for d in devices if declares_class(declared_type(d), TYPE_LUGS)], upstream=upstream) if lugs is None: return {} - meter = declared_nodes(lugs.description or {}).get(NODE_METER) - if meter is None: + node = declared_nodes(lugs.description or {}).get(node_id) + if node is None: return {} - declared = declared_properties(meter) + declared = declared_properties(node) found: dict[str, FieldMetadata] = {} for property_id, field_path in fields: definition = declared.get(property_id) if definition is None: - found[field_path] = FieldMetadata(unit=None, datatype="unknown", resolved=False) + if field_path not in _OPTIONAL_PROPERTIES: + found[field_path] = FieldMetadata(unit=None, datatype="unknown", resolved=False) continue found[field_path] = FieldMetadata( unit=optional_str(definition.get("unit")), @@ -370,7 +406,8 @@ def _lookup( """Find a declaration, allowing a device type to be a subtype of the mapped one. eBus device types are hierarchical and a subtype carries its parent's - properties, so a device typed `X.Y` satisfies a row written for `X`. + properties, so a device typed `X.Y` satisfies a row written for `X` + (`declares_class`), and one typed `Xfoo` does not. Lugs were the observed instance — `…device.lugs` versus a subtyped `…device.lugs.upstream` — and they no longer come through here, because @@ -384,7 +421,7 @@ def _lookup( return exact suffix = f"|{node_id}|{property_id}" for key, value in declared.items(): - if key.endswith(suffix) and key[: -len(suffix)].startswith(device_type): + if key.endswith(suffix) and declares_class(key[: -len(suffix)], device_type): return value return None @@ -432,6 +469,10 @@ def _lookup( (TYPE_PANEL, NODE_SHED_FORECAST, "full-charge-total-time-remaining"), # --- Circuit topology and PCS membership -------------------------------- (TYPE_CIRCUIT, NODE_CONNECTION, "feeds-device-id"), + (TYPE_CIRCUIT, NODE_CONNECTION, "feeds-role"), + # Device references, resolved to the circuit ids of the snapshot. + (TYPE_CIRCUIT, NODE_METER, "shared-with-device-ids"), + (TYPE_CIRCUIT, NODE_SWITCH, "shared-with-device-ids"), (TYPE_CIRCUIT, NODE_PCS, "managed"), (TYPE_CIRCUIT, NODE_PCS, "priority"), # --- Lugs direction and the upstream device's link ----------------------- @@ -500,6 +541,7 @@ def _lookup( | frozenset( (TYPE_LUGS, NODE_METER, property_id) for property_id, _ in (*_UPSTREAM_LUGS_FIELDS, *_DOWNSTREAM_LUGS_FIELDS) ) + | frozenset((TYPE_LUGS, NODE_CONNECTION, property_id) for property_id, _ in _UPSTREAM_LUGS_CONNECTION_FIELDS) | frozenset(_CONSUMED_WITHOUT_A_ROW) | frozenset(_CONSUMED_OFF_SNAPSHOT) ) @@ -530,7 +572,7 @@ def addressed_rows(devices: list[DiscoveredDevice]) -> set[tuple[str, str, str]] addressed = set(_ADDRESSED) for device in devices: evse_type = declared_type(device) - if not evse_type.startswith(TYPE_EVSE): + if not declares_class(evse_type, TYPE_EVSE): continue surface = resolve_charge_limit(device) if surface is None: @@ -603,14 +645,14 @@ def _short_type(device_type: str) -> str: def is_addressed(addressed: set[tuple[str, str, str]], device_type: str, node_id: str, property_id: str) -> bool: """Whether any addressed row covers this declaration, subtypes included. - Carries `_lookup`'s subtype rule for the same reason it exists there: eBus - device types are hierarchical and a subtype carries its parent's properties, - so a device typed ``X.Y`` is served by a row written for ``X``. Without it a + Asks `declares_class`, as `_lookup` does, for the same reason: eBus device + types are hierarchical and a subtype carries its parent's properties, so a + device typed ``X.Y`` is served by a row written for ``X``. Without it a panel that subtypes its lugs devices would report every mapped lugs property as newly discovered — which is the false positive that would teach a maintainer to stop reading this. """ return any( - node == node_id and prop == property_id and (device_type == mapped_type or device_type.startswith(f"{mapped_type}.")) + node == node_id and prop == property_id and declares_class(device_type, mapped_type) for mapped_type, node, prop in addressed ) diff --git a/packages/schema-1/src/span_panel_api_schema_1/panel.py b/packages/schema-1/src/span_panel_api_schema_1/panel.py index 2131a037..b039d4f5 100644 --- a/packages/schema-1/src/span_panel_api_schema_1/panel.py +++ b/packages/schema-1/src/span_panel_api_schema_1/panel.py @@ -50,6 +50,7 @@ NODE_SHED, NODE_SHED_FORECAST, NODE_STATUS, + PANEL_POSITIONS_BY_MODEL, PANEL_SIZE_BY_MODEL, PCS_ACTIVE_SUFFIX, PCS_ENABLEMENT_SUFFIX, @@ -58,6 +59,7 @@ PROP_ACTIVE_POWER, PROP_ASSERTED_ISLANDING_STATE, PROP_BINDING_CONSTRAINT, + PROP_BUSBAR_CURRENT, PROP_CAPABLE, PROP_CLOUD_CONNECTION, PROP_CONFIDENCE, @@ -66,6 +68,7 @@ PROP_EXPORTED_ENERGY, PROP_FED_BY_DEVICE_ID, PROP_FIRMWARE_VERSION, + PROP_FREQUENCY, PROP_FULL_CHARGE_TIME_TO_PRIORITY_SHED, PROP_FULL_CHARGE_TOTAL_TIME_REMAINING, PROP_GRID_FORMING_ENTITY, @@ -73,6 +76,7 @@ PROP_IMPORT_LIMIT, PROP_IMPORTED_ENERGY, PROP_MODEL, + PROP_OVERCURRENT_PROTECTION, PROP_POLICY, PROP_RATING, PROP_RELAY, @@ -90,9 +94,10 @@ TYPE_PV, UNKNOWN, ) +from span_panel_api_schema_1.description import declares_class if TYPE_CHECKING: - from collections.abc import Mapping, Sequence + from collections.abc import Iterable, Mapping, Sequence from ebus_sdk.homie import DiscoveredDevice @@ -206,11 +211,13 @@ def panel_size_from_model(model: str) -> int: Unknown models return 0 and log, because inventing a size is worse than reporting none: a wrong total lays out positions that are not there, or - hides real ones. + hides real ones. `UNKNOWN` is a member of the model enum that names no + model, so it returns 0 without logging on every snapshot. """ - size = PANEL_SIZE_BY_MODEL.get(model.strip().upper()) + normalized = model.strip().upper() + size = PANEL_SIZE_BY_MODEL.get(normalized) if size is None: - if model: + if model and normalized != UNKNOWN: _LOGGER.warning( "Unknown panel model %r; panel size unavailable. Known models: %s", model, @@ -220,6 +227,45 @@ def panel_size_from_model(model: str) -> int: return size +def panel_positions(model: str | None, occupied: Iterable[int]) -> tuple[int | None, int | None]: + """The panel's first and last breaker positions. + + The reported model's range, exactly as `PANEL_POSITIONS_BY_MODEL` gives it, + where the table knows the model; an occupied space outside that range does + not move it (`positions_outside_model` says when one does). With no known + model, the lowest and highest occupied spaces, and `(None, None)` when none + is occupied. Only the range: nothing is filled in over it. + """ + known = _model_positions(model) + if known is not None: + return known + spaces = set(occupied) + if not spaces: + return None, None + return min(spaces), max(spaces) + + +def positions_outside_model(model: str | None, occupied: Iterable[int]) -> tuple[tuple[int, int], tuple[int, int]] | None: + """The model's position range and the occupied extremes, where a space lies outside the range. + + `None` where the table does not know the model, or every occupied space lies + inside its range. A panel that answers otherwise disagrees with the table, + which is ours to correct; the range reported stays the table's. + """ + known = _model_positions(model) + spaces = set(occupied) + if known is None or not spaces: + return None + extremes = (min(spaces), max(spaces)) + if known[0] <= extremes[0] and extremes[1] <= known[1]: + return None + return known, extremes + + +def _model_positions(model: str | None) -> tuple[int, int] | None: + return PANEL_POSITIONS_BY_MODEL.get(model.strip().upper()) if model else None + + def panel_model_drift(panel: DiscoveredDevice) -> tuple[str, ...]: """Models the panel says are valid that we have no size for. @@ -239,10 +285,11 @@ def panel_model_drift(panel: DiscoveredDevice) -> tuple[str, ...]: advertised = str(definition.get("format", "")) if not advertised: return () + # `UNKNOWN` is a member that names no model, so there is no size to miss. unknown = [ value.strip() for value in advertised.split(",") - if value.strip() and value.strip().upper() not in PANEL_SIZE_BY_MODEL + if value.strip() and value.strip().upper() not in {*PANEL_SIZE_BY_MODEL, UNKNOWN} ] if unknown: _LOGGER.warning( @@ -346,6 +393,24 @@ def _percent(value: object) -> int | None: return None +def lugs_at_service_entrance(upstream_lugs: DiscoveredDevice | None) -> bool | None: + """Whether nothing sits between the utility and the upstream lugs, or None if not yet said. + + Read from the lugs' own `connection/fed-by-device-id`, the mechanism + `power-flows` 0.3 names when it qualifies the `grid` row of its negation + table. A device id there means something feeds the lugs: `False`. No such + property declared, or one published empty, is the ordinary case: `True`. + Declared and not yet valued, the lugs have not said, and either answer + would be a guess: `None`. + """ + if upstream_lugs is None or PROP_FED_BY_DEVICE_ID not in upstream_lugs.get_node_properties(NODE_CONNECTION): + return True + fed_by = upstream_lugs.get_property(NODE_CONNECTION, PROP_FED_BY_DEVICE_ID) + if fed_by is None: + return None + return not str(fed_by) + + class PanelFields: """Panel-level values gathered from the tree, ready for the snapshot. @@ -368,7 +433,10 @@ def __init__( # one: the consumer owns the fallback text it has always shown, and a # default invented here would replace it with a different invention. self.vendor_name = text(panel, NODE_INFO, PROP_VENDOR_NAME) or None - self.model = text(panel, NODE_INFO, PROP_MODEL) or None + # `UNKNOWN` is a member of the model enum that names no model, so it + # reads as absent and the consumer keeps its own fallback. + model = text(panel, NODE_INFO, PROP_MODEL) + self.model = model if model and model.strip().upper() != UNKNOWN else None self.hardware_version = text(panel, NODE_INFO, PROP_HARDWARE_VERSION) or None self.main_relay_state = text(panel, NODE_STATUS, PROP_RELAY, UNKNOWN) self.door_state = text(panel, NODE_DOOR, PROP_STATE, UNKNOWN) @@ -381,6 +449,9 @@ def __init__( # the entity does not change meaning between adapters. self.wwan_link = self.vendor_cloud == CLOUD_CONNECTED + self.busbar_current_a = number(panel, NODE_METER, PROP_BUSBAR_CURRENT) + self.frequency_hz = number(panel, NODE_METER, PROP_FREQUENCY) + self.upstream_protection_rating_a = integer(upstream_lugs, NODE_CONNECTION, PROP_OVERCURRENT_PROTECTION) self.l1_voltage = number(panel, NODE_METER, PROP_VOLTAGE_A) self.l2_voltage = number(panel, NODE_METER, PROP_VOLTAGE_B) rating = number(panel, NODE_BREAKER, PROP_RATING) @@ -393,12 +464,8 @@ def __init__( # Whether the upstream lugs are the utility connection point, which is not # a given: a BESS wired ahead of the main lugs, or a panel fed by another - # panel, puts a device between the utility and this meter. Read from the - # lugs' own `connection/fed-by-device-id`, the mechanism `power-flows` 0.3 - # names when it qualifies the `grid` row of its negation table. Empty - # string is the absence -- `text` defaults to it -- and absence is the - # ordinary case. - self.lugs_at_service_entrance = not text(upstream_lugs, NODE_CONNECTION, PROP_FED_BY_DEVICE_ID) + # panel, puts a device between the utility and this meter. + self.lugs_at_service_entrance = lugs_at_service_entrance(upstream_lugs) # No sign flip: the enclosure frame already reports import-positive, which # is what consumption means here. @@ -557,11 +624,6 @@ def build_pcs(panel: DiscoveredDevice) -> SpanPcsSnapshot | None: ) -# Matches `schema_0`'s epsilon so the no-MID heuristic answers identically on the two -# adapters — the tier exists precisely for panels where nothing authoritative is -# published, and disagreeing about the threshold would make it schema-dependent. -_GRID_POWER_EPSILON_W = 1.0 - ISLANDING_ON_GRID = "ON_GRID" ISLANDING_OFF_GRID = "OFF_GRID" @@ -573,8 +635,8 @@ def resolve_islanding_state(mid: DiscoveredDevice | None, panel: DiscoveredDevic | --- | --- | --- | | 1 | `shed/asserted-islanding-state` is `ON_GRID` or `OFF_GRID` | asserted | | 2 | MID `$state` is `ready` and `islanding-state` present | sensed | - | 3 | no MID at all | `power-flows/grid` heuristic | - | 4 | none of the above | unknown | + | 3 | no MID at all | on-grid, by elimination | + | 4 | a MID that has not answered | unknown | **An assertion in force is the effective state, so it outranks the MID.** When the panel's link to the battery is not healthy (the battery's `status/communication-state` @@ -585,12 +647,25 @@ def resolve_islanding_state(mid: DiscoveredDevice | None, panel: DiscoveredDevic different one. The assertion clears itself back to `NONE` once the battery link recovers, so the MID's answer returns without anything here having to expire it. - **Tier 3 never answers `OFF_GRID`, and never asserts on-grid from a missing MID.** An - earlier draft reasoned that no MID means no islanding authority means on-grid. That is - wrong: a missing MID means *SPAN* is not the islanding authority, and says nothing - about whether the site is islanded — a generator-fed island is the plain - counterexample. Grid power flowing is positive evidence of being on-grid; its absence - is not evidence of the opposite. + **No MID at all means on-grid, and tier 3 never answers `OFF_GRID`.** A commissioned + MID is what a SPAN panel islands with, so a panel without one cannot separate from + whatever feeds it, and what feeds it is what SPAN treats as the grid. This is the + elimination `resolve_dominant_power_source` makes, and the two now agree on every + tree. A panel that loses that feed loses power and stops publishing, so the answer + is withdrawn with the panel rather than left standing. + + Tier 3 read `power-flows/grid` before, and answered on-grid only above 1 W, on the + reasoning that a missing MID says nothing about whether the site is islanded — a + generator-fed island being the counterexample. The threshold never defended that + case: a generator-fed panel carrying any load reads far above it and was reported + on-grid all the same. What it did was withdraw the answer each time the reading + touched zero, which a sub-panel with a small net draw does many times a day, and a + consumer saw each return as the grid coming back. How much power is flowing says + nothing about where it comes from, so the reading no longer takes part. + + `mid is None` means no MID is declared, not that one has yet to be discovered: the + adapter builds no snapshot until every device the tree declares has described + itself. A MID that exists and has not answered is tier 4, and stays unknown. """ asserted = text(panel, NODE_SHED, PROP_ASSERTED_ISLANDING_STATE) if asserted in (ISLANDING_ON_GRID, ISLANDING_OFF_GRID): @@ -603,10 +678,7 @@ def resolve_islanding_state(mid: DiscoveredDevice | None, panel: DiscoveredDevic return sensed return None - grid_power = number(panel, NODE_POWER_FLOWS, "grid") - if grid_power is not None and abs(grid_power) > _GRID_POWER_EPSILON_W: - return ISLANDING_ON_GRID - return None + return ISLANDING_ON_GRID def resolve_dsm_state(islanding: str | None) -> str: @@ -634,7 +706,7 @@ def resolve_run_config( | condition | result | | --- | --- | | `grid-forming-entity == "GRID"` | `PANEL_ON_GRID` | - | resolves to a device of class `bess` | `PANEL_BACKUP` | + | resolves to a device of class `bess`, or a subtype of it | `PANEL_BACKUP` | | resolves to any other device | `PANEL_OFF_GRID` | | absent, empty, or unresolvable | falls through below | @@ -652,10 +724,8 @@ class is recoverable from the tree, so the distinction becomes authoritative. if forming.upper() == "GRID": return "PANEL_ON_GRID" resolved = device_types.get(forming) - if resolved == TYPE_BESS: - return "PANEL_BACKUP" if resolved is not None: - return "PANEL_OFF_GRID" + return "PANEL_BACKUP" if declares_class(resolved, TYPE_BESS) else "PANEL_OFF_GRID" if islanding == ISLANDING_ON_GRID: return "PANEL_ON_GRID" @@ -686,10 +756,11 @@ def resolve_grid_islandable(inverters: Sequence[DiscoveredDevice]) -> bool | Non # Flat's `dominant-power-source` enum, keyed by the device class v1.0 names instead. +# A class covers its subtypes (`declares_class`), so this is searched rather than indexed. # `GENERATOR` has no row because the device-type registry has no generator: flat's value # came from the panel computing a source class, v1.0 names an actual device, and there is # no generator device to name yet. One row when there is. -_POWER_SOURCE_BY_TYPE: dict[str, str] = { +_POWER_SOURCE_BY_CLASS: dict[str, str] = { TYPE_BESS: "BATTERY", TYPE_PV: "PV", } @@ -734,12 +805,11 @@ def resolve_dominant_power_source( A site genuinely running off-grid without storage is not a counterexample; it goes dark at sunset. - This deliberately does **not** follow `resolve_islanding_state`, which refuses the - same shortcut. The two answer different questions and the counterexample that defeats - it there is the one that supports it here: a generator-fed island is islanded — so - inferring on-grid from a missing MID would be wrong — while its grid-forming entity - really is what SPAN calls the grid. Islanding is a safety fact about separation; this - is a class of source. + `resolve_islanding_state` rests on the same elimination and answers on-grid for the + same trees. It refused the shortcut at first, on the grounds that a generator-fed + island is islanded, and read grid power instead — which reported that same island + on-grid whenever it carried load. A source with no MID interface is the grid as far + as SPAN can tell, and both fields now say so. It is also no worse than flat, which is the bar. Flat could not see an uninterfaced generator either and published `GRID` regardless; a panel upgrading to v1.0 keeps the @@ -756,7 +826,8 @@ def resolve_dominant_power_source( return None if forming.upper() == "GRID": return "GRID" - return _POWER_SOURCE_BY_TYPE.get(device_types.get(forming, ""), UNKNOWN) + resolved = device_types.get(forming, "") + return next((source for known, source in _POWER_SOURCE_BY_CLASS.items() if declares_class(resolved, known)), UNKNOWN) def device_display_name(device: DiscoveredDevice) -> str | None: diff --git a/packages/schema-1/src/span_panel_api_schema_1/reference/parent_child_tree.json b/packages/schema-1/src/span_panel_api_schema_1/reference/parent_child_tree.json index 4408e2bf..9a3a8235 100644 --- a/packages/schema-1/src/span_panel_api_schema_1/reference/parent_child_tree.json +++ b/packages/schema-1/src/span_panel_api_schema_1/reference/parent_child_tree.json @@ -1,11 +1,11 @@ { "0ab966b95f92a6a51ec548485aa85f54": { - "$description": "{\"homie\": \"5.0\", \"version\": 1787880675280, \"type\": \"energy.ebus.device.circuit\", \"name\": \"Kitchen Lights\", \"nodes\": {\"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"relay\": {\"name\": \"Circuit relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\", \"settable\": true}, \"relay-requester\": {\"name\": \"Actor requesting the relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,NONE,LOAD_SHED,USER,PCS,CONFIGURATION,FAULT\"}, \"relay-controllable\": {\"name\": \"Can the circuit's relay be commanded by the user?\", \"datatype\": \"boolean\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Circuit breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"poles\": {\"name\": \"Number of breaker poles\", \"datatype\": \"integer\", \"format\": \"1:4:1\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}, \"load-shed\": {\"name\": \"load-shed\", \"type\": \"energy.ebus.capability.load-shed\", \"properties\": {\"priority\": {\"name\": \"Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER\", \"settable\": true}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"managed\": {\"name\": \"Is circuit managed by PCS?\", \"datatype\": \"boolean\"}, \"priority\": {\"name\": \"Circuit PCS priority ranking\", \"datatype\": \"integer\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this circuit\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}}}, \"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"name\": {\"name\": \"Circuit name\", \"datatype\": \"string\"}, \"spaces\": {\"name\": \"Circuit breaker space number(s) within the load center (comma-separated for multi-pole)\", \"datatype\": \"string\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", + "$description": "{\"homie\": \"5.0\", \"version\": 1793478308268, \"type\": \"energy.ebus.device.circuit\", \"name\": \"Kitchen Lights\", \"nodes\": {\"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"relay\": {\"name\": \"Circuit relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\", \"settable\": true}, \"relay-requester\": {\"name\": \"Actor requesting the relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,NONE,LOAD_SHED,USER,PCS,CONFIGURATION,FAULT\"}, \"relay-controllable\": {\"name\": \"Can the circuit's relay be commanded by the user?\", \"datatype\": \"boolean\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Circuit breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"poles\": {\"name\": \"Number of breaker poles\", \"datatype\": \"integer\", \"format\": \"1:4:1\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}, \"load-shed\": {\"name\": \"load-shed\", \"type\": \"energy.ebus.capability.load-shed\", \"properties\": {\"priority\": {\"name\": \"Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER\", \"settable\": true}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"managed\": {\"name\": \"Is circuit managed by PCS?\", \"datatype\": \"boolean\"}, \"priority\": {\"name\": \"Circuit PCS priority ranking\", \"datatype\": \"integer\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this circuit\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}}}, \"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"name\": {\"name\": \"Circuit name\", \"datatype\": \"string\"}, \"spaces\": {\"name\": \"Circuit breaker space number(s) within the load center (comma-separated for multi-pole)\", \"datatype\": \"string\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", "$state": "ready", "breaker/poles": "1", "breaker/rating": "15", "info/name": "Kitchen Lights", - "info/spaces": "1", + "info/spaces": "9", "load-shed/priority": "SOC_THRESHOLD", "meter/active-power": "-121.0", "meter/current": "1.0083333333333333", @@ -18,7 +18,7 @@ "switch/relay-requester": "NONE" }, "573066aaddd7b75114c4563ce3af18c4": { - "$description": "{\"homie\": \"5.0\", \"version\": 1787880675280, \"type\": \"energy.ebus.device.circuit\", \"name\": \"Solar Inverter\", \"nodes\": {\"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"relay\": {\"name\": \"Circuit relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\"}, \"relay-requester\": {\"name\": \"Actor requesting the relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,NONE,LOAD_SHED,USER,PCS,CONFIGURATION,FAULT\"}, \"relay-controllable\": {\"name\": \"Can the circuit's relay be commanded by the user?\", \"datatype\": \"boolean\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Circuit breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"poles\": {\"name\": \"Number of breaker poles\", \"datatype\": \"integer\", \"format\": \"1:4:1\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}, \"load-shed\": {\"name\": \"load-shed\", \"type\": \"energy.ebus.capability.load-shed\", \"properties\": {\"priority\": {\"name\": \"Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER\", \"settable\": true}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"managed\": {\"name\": \"Is circuit managed by PCS?\", \"datatype\": \"boolean\"}, \"priority\": {\"name\": \"Circuit PCS priority ranking\", \"datatype\": \"integer\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this circuit\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}}}, \"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"name\": {\"name\": \"Circuit name\", \"datatype\": \"string\"}, \"spaces\": {\"name\": \"Circuit breaker space number(s) within the load center (comma-separated for multi-pole)\", \"datatype\": \"string\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", + "$description": "{\"homie\": \"5.0\", \"version\": 1793478308269, \"type\": \"energy.ebus.device.circuit\", \"name\": \"Solar Inverter\", \"nodes\": {\"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"relay\": {\"name\": \"Circuit relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\"}, \"relay-requester\": {\"name\": \"Actor requesting the relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,NONE,LOAD_SHED,USER,PCS,CONFIGURATION,FAULT\"}, \"relay-controllable\": {\"name\": \"Can the circuit's relay be commanded by the user?\", \"datatype\": \"boolean\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Circuit breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"poles\": {\"name\": \"Number of breaker poles\", \"datatype\": \"integer\", \"format\": \"1:4:1\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}, \"load-shed\": {\"name\": \"load-shed\", \"type\": \"energy.ebus.capability.load-shed\", \"properties\": {\"priority\": {\"name\": \"Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER\", \"settable\": true}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"managed\": {\"name\": \"Is circuit managed by PCS?\", \"datatype\": \"boolean\"}, \"priority\": {\"name\": \"Circuit PCS priority ranking\", \"datatype\": \"integer\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this circuit\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}}}, \"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"name\": {\"name\": \"Circuit name\", \"datatype\": \"string\"}, \"spaces\": {\"name\": \"Circuit breaker space number(s) within the load center (comma-separated for multi-pole)\", \"datatype\": \"string\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", "$state": "ready", "breaker/poles": "2", "breaker/rating": "30", @@ -39,7 +39,7 @@ "switch/relay-requester": "CONFIGURATION" }, "62d0e03897b337b57101aae82f1e9ba2": { - "$description": "{\"homie\": \"5.0\", \"version\": 1787880675280, \"type\": \"energy.ebus.device.circuit\", \"name\": \"SPAN Drive - Garage\", \"nodes\": {\"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"relay\": {\"name\": \"Circuit relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\", \"settable\": true}, \"relay-requester\": {\"name\": \"Actor requesting the relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,NONE,LOAD_SHED,USER,PCS,CONFIGURATION,FAULT\"}, \"relay-controllable\": {\"name\": \"Can the circuit's relay be commanded by the user?\", \"datatype\": \"boolean\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Circuit breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"poles\": {\"name\": \"Number of breaker poles\", \"datatype\": \"integer\", \"format\": \"1:4:1\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}, \"load-shed\": {\"name\": \"load-shed\", \"type\": \"energy.ebus.capability.load-shed\", \"properties\": {\"priority\": {\"name\": \"Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER\", \"settable\": true}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"managed\": {\"name\": \"Is circuit managed by PCS?\", \"datatype\": \"boolean\"}, \"priority\": {\"name\": \"Circuit PCS priority ranking\", \"datatype\": \"integer\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this circuit\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}}}, \"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"name\": {\"name\": \"Circuit name\", \"datatype\": \"string\"}, \"spaces\": {\"name\": \"Circuit breaker space number(s) within the load center (comma-separated for multi-pole)\", \"datatype\": \"string\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", + "$description": "{\"homie\": \"5.0\", \"version\": 1793478308268, \"type\": \"energy.ebus.device.circuit\", \"name\": \"SPAN Drive - Garage\", \"nodes\": {\"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"relay\": {\"name\": \"Circuit relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\", \"settable\": true}, \"relay-requester\": {\"name\": \"Actor requesting the relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,NONE,LOAD_SHED,USER,PCS,CONFIGURATION,FAULT\"}, \"relay-controllable\": {\"name\": \"Can the circuit's relay be commanded by the user?\", \"datatype\": \"boolean\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Circuit breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"poles\": {\"name\": \"Number of breaker poles\", \"datatype\": \"integer\", \"format\": \"1:4:1\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}, \"load-shed\": {\"name\": \"load-shed\", \"type\": \"energy.ebus.capability.load-shed\", \"properties\": {\"priority\": {\"name\": \"Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER\", \"settable\": true}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"managed\": {\"name\": \"Is circuit managed by PCS?\", \"datatype\": \"boolean\"}, \"priority\": {\"name\": \"Circuit PCS priority ranking\", \"datatype\": \"integer\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this circuit\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}}}, \"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"name\": {\"name\": \"Circuit name\", \"datatype\": \"string\"}, \"spaces\": {\"name\": \"Circuit breaker space number(s) within the load center (comma-separated for multi-pole)\", \"datatype\": \"string\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", "$state": "ready", "breaker/poles": "2", "breaker/rating": "50", @@ -60,12 +60,12 @@ "switch/relay-requester": "NONE" }, "acf35888f35522c721501d35e66503e6": { - "$description": "{\"homie\": \"5.0\", \"version\": 1787880675280, \"type\": \"energy.ebus.device.circuit\", \"name\": \"Pool Pump\", \"nodes\": {\"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"relay\": {\"name\": \"Circuit relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\", \"settable\": true}, \"relay-requester\": {\"name\": \"Actor requesting the relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,NONE,LOAD_SHED,USER,PCS,CONFIGURATION,FAULT\"}, \"relay-controllable\": {\"name\": \"Can the circuit's relay be commanded by the user?\", \"datatype\": \"boolean\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Circuit breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"poles\": {\"name\": \"Number of breaker poles\", \"datatype\": \"integer\", \"format\": \"1:4:1\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}, \"load-shed\": {\"name\": \"load-shed\", \"type\": \"energy.ebus.capability.load-shed\", \"properties\": {\"priority\": {\"name\": \"Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER\"}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"managed\": {\"name\": \"Is circuit managed by PCS?\", \"datatype\": \"boolean\"}, \"priority\": {\"name\": \"Circuit PCS priority ranking\", \"datatype\": \"integer\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this circuit\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}}}, \"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"name\": {\"name\": \"Circuit name\", \"datatype\": \"string\"}, \"spaces\": {\"name\": \"Circuit breaker space number(s) within the load center (comma-separated for multi-pole)\", \"datatype\": \"string\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", + "$description": "{\"homie\": \"5.0\", \"version\": 1793478308268, \"type\": \"energy.ebus.device.circuit\", \"name\": \"Pool Pump\", \"nodes\": {\"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"relay\": {\"name\": \"Circuit relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\", \"settable\": true}, \"relay-requester\": {\"name\": \"Actor requesting the relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,NONE,LOAD_SHED,USER,PCS,CONFIGURATION,FAULT\"}, \"relay-controllable\": {\"name\": \"Can the circuit's relay be commanded by the user?\", \"datatype\": \"boolean\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Circuit breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"poles\": {\"name\": \"Number of breaker poles\", \"datatype\": \"integer\", \"format\": \"1:4:1\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}, \"load-shed\": {\"name\": \"load-shed\", \"type\": \"energy.ebus.capability.load-shed\", \"properties\": {\"priority\": {\"name\": \"Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER\"}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"managed\": {\"name\": \"Is circuit managed by PCS?\", \"datatype\": \"boolean\"}, \"priority\": {\"name\": \"Circuit PCS priority ranking\", \"datatype\": \"integer\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this circuit\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}}}, \"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"name\": {\"name\": \"Circuit name\", \"datatype\": \"string\"}, \"spaces\": {\"name\": \"Circuit breaker space number(s) within the load center (comma-separated for multi-pole)\", \"datatype\": \"string\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", "$state": "ready", "breaker/poles": "1", "breaker/rating": "20", "info/name": "Pool Pump", - "info/spaces": "3", + "info/spaces": "11", "load-shed/priority": "OFF_GRID", "meter/active-power": "-1230.0", "meter/current": "10.25", @@ -78,7 +78,7 @@ "switch/relay-requester": "NONE" }, "bess": { - "$description": "{\"homie\": \"5.0\", \"version\": 1787880675281, \"type\": \"energy.ebus.device.bess\", \"name\": \"Battery\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"vendor-name\": {\"name\": \"Vendor name\", \"datatype\": \"string\"}, \"model\": {\"name\": \"Model\", \"datatype\": \"string\"}, \"part-number\": {\"name\": \"Part number\", \"datatype\": \"string\"}, \"serial-number\": {\"name\": \"Serial number\", \"datatype\": \"string\"}, \"firmware-version\": {\"name\": \"Firmware version\", \"datatype\": \"string\"}, \"nameplate-capacity\": {\"name\": \"Nameplate capacity\", \"datatype\": \"float\", \"unit\": \"kWh\"}}}, \"soc\": {\"name\": \"soc\", \"type\": \"energy.ebus.capability.soc\", \"properties\": {\"soc\": {\"name\": \"State of charge\", \"datatype\": \"float\", \"unit\": \"%\"}, \"soe\": {\"name\": \"State of energy\", \"datatype\": \"float\", \"unit\": \"kWh\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"active-power\": {\"name\": \"Active power\", \"datatype\": \"float\", \"unit\": \"W\"}}}, \"status\": {\"name\": \"status\", \"type\": \"energy.ebus.capability.status\", \"properties\": {\"communication-state\": {\"name\": \"Communication state\", \"datatype\": \"enum\", \"format\": \"OK,DEGRADED,LOST,UNKNOWN\"}}}}, \"children\": [\"bess-mid\"], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", + "$description": "{\"homie\": \"5.0\", \"version\": 1793478308269, \"type\": \"energy.ebus.device.bess\", \"name\": \"Battery\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"vendor-name\": {\"name\": \"Vendor name\", \"datatype\": \"string\"}, \"model\": {\"name\": \"Model\", \"datatype\": \"string\"}, \"part-number\": {\"name\": \"Part number\", \"datatype\": \"string\"}, \"serial-number\": {\"name\": \"Serial number\", \"datatype\": \"string\"}, \"firmware-version\": {\"name\": \"Firmware version\", \"datatype\": \"string\"}, \"nameplate-capacity\": {\"name\": \"Nameplate capacity\", \"datatype\": \"float\", \"unit\": \"kWh\"}}}, \"soc\": {\"name\": \"soc\", \"type\": \"energy.ebus.capability.soc\", \"properties\": {\"soc\": {\"name\": \"State of charge\", \"datatype\": \"float\", \"unit\": \"%\"}, \"soe\": {\"name\": \"State of energy\", \"datatype\": \"float\", \"unit\": \"kWh\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"active-power\": {\"name\": \"Active power\", \"datatype\": \"float\", \"unit\": \"W\"}}}, \"status\": {\"name\": \"status\", \"type\": \"energy.ebus.capability.status\", \"properties\": {\"communication-state\": {\"name\": \"Communication state\", \"datatype\": \"enum\", \"format\": \"OK,DEGRADED,LOST,UNKNOWN\"}}}}, \"children\": [\"bess-mid\"], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", "$state": "ready", "info/firmware-version": "example-bess/v0.1.0", "info/model": "Example BESS", @@ -86,13 +86,13 @@ "info/part-number": "SPN-BESS-001", "info/serial-number": "EXAMPLE-BESS-40T-001", "info/vendor-name": "Span", - "meter/active-power": "3500.0", + "meter/active-power": "-3500.0", "soc/soc": "50.410493827160494", "soc/soe": "6.805416666666667", "status/communication-state": "OK" }, "bess-mid": { - "$description": "{\"homie\": \"5.0\", \"version\": 1787880675281, \"type\": \"energy.ebus.device.mid\", \"name\": \"Microgrid Interconnect Device\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"vendor-name\": {\"name\": \"Vendor name\", \"datatype\": \"string\"}, \"serial-number\": {\"name\": \"Serial number\", \"datatype\": \"string\"}, \"model\": {\"name\": \"Model\", \"datatype\": \"string\"}, \"firmware-version\": {\"name\": \"Firmware version\", \"datatype\": \"string\"}, \"hardware-version\": {\"name\": \"Hardware version\", \"datatype\": \"string\"}}}, \"grid\": {\"name\": \"grid\", \"type\": \"energy.ebus.capability.grid\", \"properties\": {\"islanding-state\": {\"name\": \"Islanding state of the BESS-integrated grid-forming device\", \"datatype\": \"enum\", \"format\": \"ON_GRID,OFF_GRID,UNKNOWN\"}, \"grid-state\": {\"name\": \"Sensed grid condition\", \"datatype\": \"enum\", \"format\": \"UP,DOWN,DEGRADED,UNKNOWN\"}, \"grid-forming-entity\": {\"name\": \"Identity of the currently grid-forming entity\", \"datatype\": \"string\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"bess\", \"extensions\": []}", + "$description": "{\"homie\": \"5.0\", \"version\": 1793478308270, \"type\": \"energy.ebus.device.mid\", \"name\": \"Microgrid Interconnect Device\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"vendor-name\": {\"name\": \"Vendor name\", \"datatype\": \"string\"}, \"serial-number\": {\"name\": \"Serial number\", \"datatype\": \"string\"}, \"model\": {\"name\": \"Model\", \"datatype\": \"string\"}, \"firmware-version\": {\"name\": \"Firmware version\", \"datatype\": \"string\"}, \"hardware-version\": {\"name\": \"Hardware version\", \"datatype\": \"string\"}}}, \"grid\": {\"name\": \"grid\", \"type\": \"energy.ebus.capability.grid\", \"properties\": {\"islanding-state\": {\"name\": \"Islanding state of the BESS-integrated grid-forming device\", \"datatype\": \"enum\", \"format\": \"ON_GRID,OFF_GRID,UNKNOWN\"}, \"grid-state\": {\"name\": \"Sensed grid condition\", \"datatype\": \"enum\", \"format\": \"UP,DOWN,DEGRADED,UNKNOWN\"}, \"grid-forming-entity\": {\"name\": \"Identity of the currently grid-forming entity\", \"datatype\": \"string\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"bess\", \"extensions\": []}", "$state": "ready", "grid/grid-forming-entity": "GRID", "grid/grid-state": "UP", @@ -104,12 +104,12 @@ "info/vendor-name": "Span" }, "d3724e0d660ba506aa79c1cafe5d1181": { - "$description": "{\"homie\": \"5.0\", \"version\": 1787880675280, \"type\": \"energy.ebus.device.circuit\", \"name\": \"Garage Outlet\", \"nodes\": {\"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"relay\": {\"name\": \"Circuit relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\", \"settable\": true}, \"relay-requester\": {\"name\": \"Actor requesting the relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,NONE,LOAD_SHED,USER,PCS,CONFIGURATION,FAULT\"}, \"relay-controllable\": {\"name\": \"Can the circuit's relay be commanded by the user?\", \"datatype\": \"boolean\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Circuit breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"poles\": {\"name\": \"Number of breaker poles\", \"datatype\": \"integer\", \"format\": \"1:4:1\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}, \"load-shed\": {\"name\": \"load-shed\", \"type\": \"energy.ebus.capability.load-shed\", \"properties\": {\"priority\": {\"name\": \"Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER\", \"settable\": true}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"managed\": {\"name\": \"Is circuit managed by PCS?\", \"datatype\": \"boolean\"}, \"priority\": {\"name\": \"Circuit PCS priority ranking\", \"datatype\": \"integer\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this circuit\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}}}, \"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"name\": {\"name\": \"Circuit name\", \"datatype\": \"string\"}, \"spaces\": {\"name\": \"Circuit breaker space number(s) within the load center (comma-separated for multi-pole)\", \"datatype\": \"string\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", + "$description": "{\"homie\": \"5.0\", \"version\": 1793478308268, \"type\": \"energy.ebus.device.circuit\", \"name\": \"Garage Outlet\", \"nodes\": {\"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"relay\": {\"name\": \"Circuit relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\", \"settable\": true}, \"relay-requester\": {\"name\": \"Actor requesting the relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,NONE,LOAD_SHED,USER,PCS,CONFIGURATION,FAULT\"}, \"relay-controllable\": {\"name\": \"Can the circuit's relay be commanded by the user?\", \"datatype\": \"boolean\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Circuit breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"poles\": {\"name\": \"Number of breaker poles\", \"datatype\": \"integer\", \"format\": \"1:4:1\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}, \"load-shed\": {\"name\": \"load-shed\", \"type\": \"energy.ebus.capability.load-shed\", \"properties\": {\"priority\": {\"name\": \"Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER\", \"settable\": true}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"managed\": {\"name\": \"Is circuit managed by PCS?\", \"datatype\": \"boolean\"}, \"priority\": {\"name\": \"Circuit PCS priority ranking\", \"datatype\": \"integer\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this circuit\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}}}, \"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"name\": {\"name\": \"Circuit name\", \"datatype\": \"string\"}, \"spaces\": {\"name\": \"Circuit breaker space number(s) within the load center (comma-separated for multi-pole)\", \"datatype\": \"string\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", "$state": "ready", "breaker/poles": "1", "breaker/rating": "20", "info/name": "Garage Outlet", - "info/spaces": "2", + "info/spaces": "10", "load-shed/priority": "SOC_THRESHOLD", "meter/active-power": "-122.0", "meter/current": "1.0166666666666666", @@ -122,10 +122,9 @@ "switch/relay-requester": "NONE" }, "evse": { - "$description": "{\"homie\": \"5.0\", \"version\": 1787880675281, \"type\": \"energy.ebus.device.evse\", \"name\": \"SPAN Drive - Garage\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"vendor-name\": {\"name\": \"Vendor name\", \"datatype\": \"string\"}, \"model\": {\"name\": \"Model\", \"datatype\": \"string\"}, \"part-number\": {\"name\": \"Part number\", \"datatype\": \"string\"}, \"serial-number\": {\"name\": \"Serial number\", \"datatype\": \"string\"}, \"firmware-version\": {\"name\": \"Firmware version\", \"datatype\": \"string\"}}}, \"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"lock-state\": {\"name\": \"Lock state\", \"datatype\": \"enum\", \"format\": \"UNLOCKED,LOCKED\"}}}, \"status\": {\"name\": \"status\", \"type\": \"energy.ebus.capability.status\", \"properties\": {\"status\": {\"name\": \"Status\", \"datatype\": \"enum\", \"format\": \"AVAILABLE,PREPARING,CHARGING,UNAVAILABLE\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"advertised-current\": {\"name\": \"Current EVSE is advertising to the EV\", \"datatype\": \"float\", \"unit\": \"A\"}}}, \"config\": {\"name\": \"config\", \"type\": \"energy.ebus.capability.config\", \"properties\": {\"user-max-charge-current\": {\"name\": \"User-configured maximum EVSE charge current (ceiling)\", \"datatype\": \"integer\", \"settable\": true, \"unit\": \"A\"}, \"max-charge-current\": {\"name\": \"Commissioned maximum EVSE charge current (installer-configured)\", \"datatype\": \"integer\", \"unit\": \"A\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", + "$description": "{\"homie\": \"5.0\", \"version\": 1793478308269, \"type\": \"energy.ebus.device.evse\", \"name\": \"SPAN Drive - Garage\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"vendor-name\": {\"name\": \"Vendor name\", \"datatype\": \"string\"}, \"model\": {\"name\": \"Model\", \"datatype\": \"string\"}, \"part-number\": {\"name\": \"Part number\", \"datatype\": \"string\"}, \"serial-number\": {\"name\": \"Serial number\", \"datatype\": \"string\"}, \"firmware-version\": {\"name\": \"Firmware version\", \"datatype\": \"string\"}}}, \"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"lock-state\": {\"name\": \"Lock state\", \"datatype\": \"enum\", \"format\": \"UNLOCKED,LOCKED\"}}}, \"status\": {\"name\": \"status\", \"type\": \"energy.ebus.capability.status\", \"properties\": {\"status\": {\"name\": \"Status\", \"datatype\": \"enum\", \"format\": \"AVAILABLE,PREPARING,CHARGING,UNAVAILABLE\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"advertised-current\": {\"name\": \"Current EVSE is advertising to the EV\", \"datatype\": \"float\", \"unit\": \"A\"}}}, \"config\": {\"name\": \"config\", \"type\": \"energy.ebus.capability.config\", \"properties\": {\"user-max-charge-current\": {\"name\": \"User-configured maximum EVSE charge current (ceiling)\", \"datatype\": \"integer\", \"format\": \"6:32\", \"settable\": true, \"unit\": \"A\"}, \"max-charge-current\": {\"name\": \"Commissioned maximum EVSE charge current (installer-configured)\", \"datatype\": \"integer\", \"unit\": \"A\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", "$state": "ready", "config/max-charge-current": "32", - "config/user-max-charge-current": "32", "info/firmware-version": "example/v0.1.0", "info/model": "SPAN Drive", "info/part-number": "SPN-DRV-001", @@ -136,10 +135,9 @@ "switch/lock-state": "LOCKED" }, "evse-2": { - "$description": "{\"homie\": \"5.0\", \"version\": 1787880675281, \"type\": \"energy.ebus.device.evse\", \"name\": \"SPAN Drive - Driveway\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"vendor-name\": {\"name\": \"Vendor name\", \"datatype\": \"string\"}, \"model\": {\"name\": \"Model\", \"datatype\": \"string\"}, \"part-number\": {\"name\": \"Part number\", \"datatype\": \"string\"}, \"serial-number\": {\"name\": \"Serial number\", \"datatype\": \"string\"}, \"firmware-version\": {\"name\": \"Firmware version\", \"datatype\": \"string\"}}}, \"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"lock-state\": {\"name\": \"Lock state\", \"datatype\": \"enum\", \"format\": \"UNLOCKED,LOCKED\"}}}, \"status\": {\"name\": \"status\", \"type\": \"energy.ebus.capability.status\", \"properties\": {\"status\": {\"name\": \"Status\", \"datatype\": \"enum\", \"format\": \"AVAILABLE,PREPARING,CHARGING,UNAVAILABLE\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"advertised-current\": {\"name\": \"Current EVSE is advertising to the EV\", \"datatype\": \"float\", \"unit\": \"A\"}}}, \"config\": {\"name\": \"config\", \"type\": \"energy.ebus.capability.config\", \"properties\": {\"user-max-charge-current\": {\"name\": \"User-configured maximum EVSE charge current (ceiling)\", \"datatype\": \"integer\", \"settable\": true, \"unit\": \"A\"}, \"max-charge-current\": {\"name\": \"Commissioned maximum EVSE charge current (installer-configured)\", \"datatype\": \"integer\", \"unit\": \"A\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", + "$description": "{\"homie\": \"5.0\", \"version\": 1793478308269, \"type\": \"energy.ebus.device.evse\", \"name\": \"SPAN Drive - Driveway\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"vendor-name\": {\"name\": \"Vendor name\", \"datatype\": \"string\"}, \"model\": {\"name\": \"Model\", \"datatype\": \"string\"}, \"part-number\": {\"name\": \"Part number\", \"datatype\": \"string\"}, \"serial-number\": {\"name\": \"Serial number\", \"datatype\": \"string\"}, \"firmware-version\": {\"name\": \"Firmware version\", \"datatype\": \"string\"}}}, \"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"lock-state\": {\"name\": \"Lock state\", \"datatype\": \"enum\", \"format\": \"UNLOCKED,LOCKED\"}}}, \"status\": {\"name\": \"status\", \"type\": \"energy.ebus.capability.status\", \"properties\": {\"status\": {\"name\": \"Status\", \"datatype\": \"enum\", \"format\": \"AVAILABLE,PREPARING,CHARGING,UNAVAILABLE\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"advertised-current\": {\"name\": \"Current EVSE is advertising to the EV\", \"datatype\": \"float\", \"unit\": \"A\"}}}, \"config\": {\"name\": \"config\", \"type\": \"energy.ebus.capability.config\", \"properties\": {\"user-max-charge-current\": {\"name\": \"User-configured maximum EVSE charge current (ceiling)\", \"datatype\": \"integer\", \"format\": \"6:32\", \"settable\": true, \"unit\": \"A\"}, \"max-charge-current\": {\"name\": \"Commissioned maximum EVSE charge current (installer-configured)\", \"datatype\": \"integer\", \"unit\": \"A\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", "$state": "ready", "config/max-charge-current": "32", - "config/user-max-charge-current": "32", "info/firmware-version": "example/v0.1.0", "info/model": "SPAN Drive", "info/part-number": "SPN-DRV-001", @@ -150,7 +148,7 @@ "switch/lock-state": "UNLOCKED" }, "example-40t-001": { - "$description": "{\"homie\": \"5.0\", \"version\": 1787880675281, \"type\": \"energy.ebus.device.distribution-enclosure\", \"name\": \"Example 40-tab Panel\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"vendor-name\": {\"name\": \"Vendor name\", \"datatype\": \"string\"}, \"model\": {\"name\": \"Model\", \"datatype\": \"enum\", \"format\": \"MAIN_16,MLO_24,MAIN_32,MAIN_40,MLO_48\"}, \"serial-number\": {\"name\": \"Serial number\", \"datatype\": \"string\"}, \"hardware-version\": {\"name\": \"Hardware version\", \"datatype\": \"string\"}, \"firmware-version\": {\"name\": \"Firmware version\", \"datatype\": \"string\"}, \"data-model-version\": {\"name\": \"eBus data-model version (parent/child schema discriminator)\", \"datatype\": \"string\"}}}, \"door\": {\"name\": \"door\", \"type\": \"energy.ebus.capability.door\", \"properties\": {\"state\": {\"name\": \"Door state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"voltage-a\": {\"name\": \"L1 voltage\", \"datatype\": \"float\", \"unit\": \"V\"}, \"voltage-b\": {\"name\": \"L2 voltage\", \"datatype\": \"float\", \"unit\": \"V\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Main breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"enabled\": {\"name\": \"PCS system enabled\", \"datatype\": \"boolean\"}, \"active\": {\"name\": \"PCS system actively controlling one (or more) loads\", \"datatype\": \"boolean\"}, \"import-limit\": {\"name\": \"The power import limit currently being managed to\", \"datatype\": \"float\", \"unit\": \"A\"}, \"binding-constraint\": {\"name\": \"Which constraint class currently sets the import limit\", \"datatype\": \"enum\", \"format\": \"FSR,DOE,VOLTAGE,OFF_GRID,REQUESTED,OPERATOR,NONE,UNKNOWN\"}, \"feed-import-limit\": {\"name\": \"Limit of maximum power feeding the distribution enclosure\", \"datatype\": \"float\", \"unit\": \"A\"}, \"feed-import-limit-enablement\": {\"name\": \"Enablement status of the feed-import-limit\", \"datatype\": \"enum\", \"format\": \"UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED\"}, \"feed-import-limit-active\": {\"name\": \"Is feed-import-limit currently being enforced?\", \"datatype\": \"boolean\"}, \"operator-import-limit\": {\"name\": \"Operator-imposed maximum import limit\", \"datatype\": \"float\", \"unit\": \"A\"}, \"operator-import-limit-enablement\": {\"name\": \"Enablement status of the operator-import-limit\", \"datatype\": \"enum\", \"format\": \"UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED\"}, \"operator-import-limit-active\": {\"name\": \"Is operator-import-limit currently being enforced?\", \"datatype\": \"boolean\"}, \"off-grid-import-limit\": {\"name\": \"Off-Grid limit maximum import power\", \"datatype\": \"float\", \"unit\": \"A\"}, \"off-grid-import-limit-enablement\": {\"name\": \"Enablement status of the off-grid-import-limit\", \"datatype\": \"enum\", \"format\": \"UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED\"}, \"off-grid-import-limit-active\": {\"name\": \"Is off-grid-import-limit currently being enforced?\", \"datatype\": \"boolean\"}, \"requested-import-limit\": {\"name\": \"Requested limit maximum import power\", \"datatype\": \"float\", \"unit\": \"A\"}, \"requested-import-limit-enablement\": {\"name\": \"Enablement status of the requested-import-limit\", \"datatype\": \"enum\", \"format\": \"UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED\"}, \"requested-import-limit-active\": {\"name\": \"Is requested-import-limit currently being enforced?\", \"datatype\": \"boolean\"}}}, \"shed-forecast\": {\"name\": \"shed-forecast\", \"type\": \"energy.ebus.capability.shed-forecast\", \"properties\": {\"total-time-remaining\": {\"name\": \"Estimated total time before all sheddable circuits are shed (off-grid runtime)\", \"datatype\": \"integer\", \"unit\": \"min\"}, \"time-to-priority-shed\": {\"name\": \"Estimated time before the next priority tier is shed\", \"datatype\": \"integer\", \"unit\": \"min\"}, \"full-charge-total-time-remaining\": {\"name\": \"Estimated total time assuming BESS starts at full charge\", \"datatype\": \"integer\", \"unit\": \"min\"}, \"full-charge-time-to-priority-shed\": {\"name\": \"Estimated time to next priority shed assuming BESS starts at full charge\", \"datatype\": \"integer\", \"unit\": \"min\"}, \"confidence\": {\"name\": \"Confidence of the shed-forecast estimate\", \"datatype\": \"enum\", \"format\": \"LOW,MEDIUM,HIGH\"}}}, \"shed\": {\"name\": \"shed\", \"type\": \"energy.ebus.capability.shed\", \"properties\": {\"asserted-islanding-state\": {\"name\": \"Consumer-asserted islanding-state (grid-state override during MID/BESS comm-loss)\", \"datatype\": \"enum\", \"format\": \"NONE,ON_GRID,OFF_GRID\", \"settable\": true}, \"policy\": {\"name\": \"Shed policy (algorithm and parameters)\", \"datatype\": \"json\", \"format\": \"{\\\"$id\\\":\\\"soc-priority.v1\\\",\\\"type\\\":\\\"object\\\",\\\"required\\\":[\\\"algorithm\\\",\\\"parameters\\\"],\\\"additionalProperties\\\":false,\\\"properties\\\":{\\\"algorithm\\\":{\\\"const\\\":\\\"soc-priority.v1\\\"},\\\"parameters\\\":{\\\"type\\\":\\\"object\\\",\\\"required\\\":[\\\"soc-threshold-shed\\\",\\\"soc-threshold-release\\\"],\\\"additionalProperties\\\":false,\\\"properties\\\":{\\\"soc-threshold-shed\\\":{\\\"type\\\":\\\"integer\\\",\\\"minimum\\\":0,\\\"maximum\\\":100,\\\"description\\\":\\\"SoC percent below which SOC_THRESHOLD circuits shed\\\"},\\\"soc-threshold-release\\\":{\\\"type\\\":\\\"integer\\\",\\\"minimum\\\":0,\\\"maximum\\\":100,\\\"description\\\":\\\"SoC percent above which shed SOC_THRESHOLD circuits restore\\\"}}}}}\"}}}, \"power-flows\": {\"name\": \"power-flows\", \"type\": \"energy.ebus.capability.power-flows\", \"properties\": {\"pv\": {\"name\": \"PV power flow\", \"datatype\": \"float\", \"unit\": \"W\"}, \"battery\": {\"name\": \"Battery/BESS power flow\", \"datatype\": \"float\", \"unit\": \"W\"}, \"grid\": {\"name\": \"Grid power flow\", \"datatype\": \"float\", \"unit\": \"W\"}, \"site\": {\"name\": \"Site power flow\", \"datatype\": \"float\", \"unit\": \"W\"}}}, \"status\": {\"name\": \"status\", \"type\": \"energy.ebus.capability.status\", \"properties\": {\"relay\": {\"name\": \"Main relay\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\"}, \"ethernet\": {\"name\": \"Is Ethernet network interface operational?\", \"datatype\": \"boolean\"}, \"wifi\": {\"name\": \"Is Wi-Fi network interface operational?\", \"datatype\": \"boolean\"}, \"wifi-ssid\": {\"name\": \"SSID to which Wi-Fi network interface is connected\", \"datatype\": \"string\"}, \"cloud-connection\": {\"name\": \"Device connected to vendor cloud?\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,UNCONNECTED,CONNECTED\"}, \"postal-code\": {\"name\": \"Postal (Zip) code\", \"datatype\": \"string\"}, \"time-zone\": {\"name\": \"Time zone\", \"datatype\": \"string\"}}}}, \"children\": [\"bess\", \"0ab966b95f92a6a51ec548485aa85f54\", \"d3724e0d660ba506aa79c1cafe5d1181\", \"62d0e03897b337b57101aae82f1e9ba2\", \"fe8b85c15bc9610c1b8b4ebc6f82488d\", \"acf35888f35522c721501d35e66503e6\", \"573066aaddd7b75114c4563ce3af18c4\", \"evse\", \"evse-2\", \"lugs-upstream\", \"lugs-downstream\", \"pv\"], \"extensions\": []}", + "$description": "{\"homie\": \"5.0\", \"version\": 1793478308269, \"type\": \"energy.ebus.device.distribution-enclosure\", \"name\": \"Example 40-tab Panel\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"vendor-name\": {\"name\": \"Vendor name\", \"datatype\": \"string\"}, \"model\": {\"name\": \"Model\", \"datatype\": \"enum\", \"format\": \"MAIN_16,MLO_24,MAIN_32,MAIN_40,MLO_48\"}, \"serial-number\": {\"name\": \"Serial number\", \"datatype\": \"string\"}, \"hardware-version\": {\"name\": \"Hardware version\", \"datatype\": \"string\"}, \"firmware-version\": {\"name\": \"Firmware version\", \"datatype\": \"string\"}, \"data-model-version\": {\"name\": \"eBus data-model version (parent/child schema discriminator)\", \"datatype\": \"string\"}}}, \"door\": {\"name\": \"door\", \"type\": \"energy.ebus.capability.door\", \"properties\": {\"state\": {\"name\": \"Door state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"voltage-a\": {\"name\": \"L1 voltage\", \"datatype\": \"float\", \"unit\": \"V\"}, \"voltage-b\": {\"name\": \"L2 voltage\", \"datatype\": \"float\", \"unit\": \"V\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Main breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"enabled\": {\"name\": \"PCS system enabled\", \"datatype\": \"boolean\"}, \"active\": {\"name\": \"PCS system actively controlling one (or more) loads\", \"datatype\": \"boolean\"}, \"import-limit\": {\"name\": \"The power import limit currently being managed to\", \"datatype\": \"float\", \"unit\": \"A\"}, \"binding-constraint\": {\"name\": \"Which constraint class currently sets the import limit\", \"datatype\": \"enum\", \"format\": \"FSR,DOE,VOLTAGE,OFF_GRID,REQUESTED,OPERATOR,NONE,UNKNOWN\"}, \"feed-import-limit\": {\"name\": \"Limit of maximum power feeding the distribution enclosure\", \"datatype\": \"float\", \"unit\": \"A\"}, \"feed-import-limit-enablement\": {\"name\": \"Enablement status of the feed-import-limit\", \"datatype\": \"enum\", \"format\": \"UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED\"}, \"feed-import-limit-active\": {\"name\": \"Is feed-import-limit currently being enforced?\", \"datatype\": \"boolean\"}, \"operator-import-limit\": {\"name\": \"Operator-imposed maximum import limit\", \"datatype\": \"float\", \"unit\": \"A\"}, \"operator-import-limit-enablement\": {\"name\": \"Enablement status of the operator-import-limit\", \"datatype\": \"enum\", \"format\": \"UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED\"}, \"operator-import-limit-active\": {\"name\": \"Is operator-import-limit currently being enforced?\", \"datatype\": \"boolean\"}, \"off-grid-import-limit\": {\"name\": \"Off-Grid limit maximum import power\", \"datatype\": \"float\", \"unit\": \"A\"}, \"off-grid-import-limit-enablement\": {\"name\": \"Enablement status of the off-grid-import-limit\", \"datatype\": \"enum\", \"format\": \"UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED\"}, \"off-grid-import-limit-active\": {\"name\": \"Is off-grid-import-limit currently being enforced?\", \"datatype\": \"boolean\"}, \"requested-import-limit\": {\"name\": \"Requested limit maximum import power\", \"datatype\": \"float\", \"unit\": \"A\"}, \"requested-import-limit-enablement\": {\"name\": \"Enablement status of the requested-import-limit\", \"datatype\": \"enum\", \"format\": \"UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED\"}, \"requested-import-limit-active\": {\"name\": \"Is requested-import-limit currently being enforced?\", \"datatype\": \"boolean\"}}}, \"shed-forecast\": {\"name\": \"shed-forecast\", \"type\": \"energy.ebus.capability.shed-forecast\", \"properties\": {\"total-time-remaining\": {\"name\": \"Estimated total time before all sheddable circuits are shed (off-grid runtime)\", \"datatype\": \"integer\", \"unit\": \"min\"}, \"time-to-priority-shed\": {\"name\": \"Estimated time before the next priority tier is shed\", \"datatype\": \"integer\", \"unit\": \"min\"}, \"full-charge-total-time-remaining\": {\"name\": \"Estimated total time assuming BESS starts at full charge\", \"datatype\": \"integer\", \"unit\": \"min\"}, \"full-charge-time-to-priority-shed\": {\"name\": \"Estimated time to next priority shed assuming BESS starts at full charge\", \"datatype\": \"integer\", \"unit\": \"min\"}, \"confidence\": {\"name\": \"Confidence of the shed-forecast estimate\", \"datatype\": \"enum\", \"format\": \"LOW,MEDIUM,HIGH\"}}}, \"shed\": {\"name\": \"shed\", \"type\": \"energy.ebus.capability.shed\", \"properties\": {\"asserted-islanding-state\": {\"name\": \"Consumer-asserted islanding-state (grid-state override during MID/BESS comm-loss)\", \"datatype\": \"enum\", \"format\": \"NONE,ON_GRID,OFF_GRID\", \"settable\": true}, \"policy\": {\"name\": \"Shed policy (algorithm and parameters)\", \"datatype\": \"json\", \"format\": \"{\\\"$id\\\":\\\"soc-priority.v1\\\",\\\"type\\\":\\\"object\\\",\\\"required\\\":[\\\"algorithm\\\",\\\"parameters\\\"],\\\"additionalProperties\\\":false,\\\"properties\\\":{\\\"algorithm\\\":{\\\"const\\\":\\\"soc-priority.v1\\\"},\\\"parameters\\\":{\\\"type\\\":\\\"object\\\",\\\"required\\\":[\\\"soc-threshold-shed\\\",\\\"soc-threshold-release\\\"],\\\"additionalProperties\\\":false,\\\"properties\\\":{\\\"soc-threshold-shed\\\":{\\\"type\\\":\\\"integer\\\",\\\"minimum\\\":0,\\\"maximum\\\":100,\\\"description\\\":\\\"SoC percent below which SOC_THRESHOLD circuits shed\\\"},\\\"soc-threshold-release\\\":{\\\"type\\\":\\\"integer\\\",\\\"minimum\\\":0,\\\"maximum\\\":100,\\\"description\\\":\\\"SoC percent above which shed SOC_THRESHOLD circuits restore\\\"}}}}}\"}}}, \"power-flows\": {\"name\": \"power-flows\", \"type\": \"energy.ebus.capability.power-flows\", \"properties\": {\"pv\": {\"name\": \"PV power flow\", \"datatype\": \"float\", \"unit\": \"W\"}, \"battery\": {\"name\": \"Battery/BESS power flow\", \"datatype\": \"float\", \"unit\": \"W\"}, \"grid\": {\"name\": \"Grid power flow\", \"datatype\": \"float\", \"unit\": \"W\"}, \"site\": {\"name\": \"Site power flow\", \"datatype\": \"float\", \"unit\": \"W\"}}}, \"status\": {\"name\": \"status\", \"type\": \"energy.ebus.capability.status\", \"properties\": {\"relay\": {\"name\": \"Main relay\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\"}, \"ethernet\": {\"name\": \"Is Ethernet network interface operational?\", \"datatype\": \"boolean\"}, \"wifi\": {\"name\": \"Is Wi-Fi network interface operational?\", \"datatype\": \"boolean\"}, \"wifi-ssid\": {\"name\": \"SSID to which Wi-Fi network interface is connected\", \"datatype\": \"string\"}, \"cloud-connection\": {\"name\": \"Device connected to vendor cloud?\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,UNCONNECTED,CONNECTED\"}, \"postal-code\": {\"name\": \"Postal (Zip) code\", \"datatype\": \"string\"}, \"time-zone\": {\"name\": \"Time zone\", \"datatype\": \"string\"}}}}, \"children\": [\"bess\", \"0ab966b95f92a6a51ec548485aa85f54\", \"d3724e0d660ba506aa79c1cafe5d1181\", \"62d0e03897b337b57101aae82f1e9ba2\", \"fe8b85c15bc9610c1b8b4ebc6f82488d\", \"acf35888f35522c721501d35e66503e6\", \"573066aaddd7b75114c4563ce3af18c4\", \"evse\", \"evse-2\", \"lugs-upstream\", \"lugs-downstream\", \"pv\"], \"extensions\": []}", "$state": "ready", "breaker/rating": "200", "door/state": "CLOSED", @@ -198,7 +196,7 @@ "status/wifi-ssid": "example-wifi" }, "fe8b85c15bc9610c1b8b4ebc6f82488d": { - "$description": "{\"homie\": \"5.0\", \"version\": 1787880675280, \"type\": \"energy.ebus.device.circuit\", \"name\": \"SPAN Drive - Driveway\", \"nodes\": {\"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"relay\": {\"name\": \"Circuit relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\", \"settable\": true}, \"relay-requester\": {\"name\": \"Actor requesting the relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,NONE,LOAD_SHED,USER,PCS,CONFIGURATION,FAULT\"}, \"relay-controllable\": {\"name\": \"Can the circuit's relay be commanded by the user?\", \"datatype\": \"boolean\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Circuit breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"poles\": {\"name\": \"Number of breaker poles\", \"datatype\": \"integer\", \"format\": \"1:4:1\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}, \"load-shed\": {\"name\": \"load-shed\", \"type\": \"energy.ebus.capability.load-shed\", \"properties\": {\"priority\": {\"name\": \"Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER\", \"settable\": true}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"managed\": {\"name\": \"Is circuit managed by PCS?\", \"datatype\": \"boolean\"}, \"priority\": {\"name\": \"Circuit PCS priority ranking\", \"datatype\": \"integer\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this circuit\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}}}, \"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"name\": {\"name\": \"Circuit name\", \"datatype\": \"string\"}, \"spaces\": {\"name\": \"Circuit breaker space number(s) within the load center (comma-separated for multi-pole)\", \"datatype\": \"string\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", + "$description": "{\"homie\": \"5.0\", \"version\": 1793478308268, \"type\": \"energy.ebus.device.circuit\", \"name\": \"SPAN Drive - Driveway\", \"nodes\": {\"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"relay\": {\"name\": \"Circuit relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\", \"settable\": true}, \"relay-requester\": {\"name\": \"Actor requesting the relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,NONE,LOAD_SHED,USER,PCS,CONFIGURATION,FAULT\"}, \"relay-controllable\": {\"name\": \"Can the circuit's relay be commanded by the user?\", \"datatype\": \"boolean\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Circuit breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"poles\": {\"name\": \"Number of breaker poles\", \"datatype\": \"integer\", \"format\": \"1:4:1\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}, \"load-shed\": {\"name\": \"load-shed\", \"type\": \"energy.ebus.capability.load-shed\", \"properties\": {\"priority\": {\"name\": \"Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER\", \"settable\": true}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"managed\": {\"name\": \"Is circuit managed by PCS?\", \"datatype\": \"boolean\"}, \"priority\": {\"name\": \"Circuit PCS priority ranking\", \"datatype\": \"integer\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this circuit\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}}}, \"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"name\": {\"name\": \"Circuit name\", \"datatype\": \"string\"}, \"spaces\": {\"name\": \"Circuit breaker space number(s) within the load center (comma-separated for multi-pole)\", \"datatype\": \"string\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", "$state": "ready", "breaker/poles": "2", "breaker/rating": "50", @@ -219,7 +217,7 @@ "switch/relay-requester": "NONE" }, "lugs-downstream": { - "$description": "{\"homie\": \"5.0\", \"version\": 1787880675281, \"type\": \"energy.ebus.device.lugs\", \"name\": \"Downstream lugs\", \"nodes\": {\"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current-a\": {\"name\": \"L1 current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"current-b\": {\"name\": \"L2 current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Imported energy\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Exported energy\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"fed-by-device-id\": {\"name\": \"Homie device-id of the upstream device feeding this lugs\", \"datatype\": \"string\"}, \"fed-by-device-type\": {\"name\": \"Homie $type of the upstream device\", \"datatype\": \"string\"}, \"fed-by-device-status\": {\"name\": \"Panel's view of comm health to the upstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this lugs\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}}}, \"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"direction\": {\"name\": \"Lugs feed direction: upstream or downstream\", \"datatype\": \"enum\", \"format\": \"UPSTREAM,DOWNSTREAM\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", + "$description": "{\"homie\": \"5.0\", \"version\": 1793478308269, \"type\": \"energy.ebus.device.lugs\", \"name\": \"Downstream lugs\", \"nodes\": {\"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current-a\": {\"name\": \"L1 current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"current-b\": {\"name\": \"L2 current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Imported energy\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Exported energy\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"fed-by-device-id\": {\"name\": \"Homie device-id of the upstream device feeding this lugs\", \"datatype\": \"string\"}, \"fed-by-device-type\": {\"name\": \"Homie $type of the upstream device\", \"datatype\": \"string\"}, \"fed-by-device-status\": {\"name\": \"Panel's view of comm health to the upstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this lugs\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}}}, \"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"direction\": {\"name\": \"Lugs feed direction: upstream or downstream\", \"datatype\": \"enum\", \"format\": \"UPSTREAM,DOWNSTREAM\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", "$state": "ready", "info/direction": "DOWNSTREAM", "meter/active-power": "-4617.0", @@ -229,7 +227,7 @@ "meter/imported-energy": "64.55" }, "lugs-upstream": { - "$description": "{\"homie\": \"5.0\", \"version\": 1787880675281, \"type\": \"energy.ebus.device.lugs\", \"name\": \"Upstream lugs\", \"nodes\": {\"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current-a\": {\"name\": \"L1 current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"current-b\": {\"name\": \"L2 current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Imported energy\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Exported energy\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"fed-by-device-id\": {\"name\": \"Homie device-id of the upstream device feeding this lugs\", \"datatype\": \"string\"}, \"fed-by-device-type\": {\"name\": \"Homie $type of the upstream device\", \"datatype\": \"string\"}, \"fed-by-device-status\": {\"name\": \"Panel's view of comm health to the upstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this lugs\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}}}, \"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"direction\": {\"name\": \"Lugs feed direction: upstream or downstream\", \"datatype\": \"enum\", \"format\": \"UPSTREAM,DOWNSTREAM\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", + "$description": "{\"homie\": \"5.0\", \"version\": 1793478308269, \"type\": \"energy.ebus.device.lugs\", \"name\": \"Upstream lugs\", \"nodes\": {\"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current-a\": {\"name\": \"L1 current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"current-b\": {\"name\": \"L2 current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Imported energy\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Exported energy\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"fed-by-device-id\": {\"name\": \"Homie device-id of the upstream device feeding this lugs\", \"datatype\": \"string\"}, \"fed-by-device-type\": {\"name\": \"Homie $type of the upstream device\", \"datatype\": \"string\"}, \"fed-by-device-status\": {\"name\": \"Panel's view of comm health to the upstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this lugs\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}}}, \"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"direction\": {\"name\": \"Lugs feed direction: upstream or downstream\", \"datatype\": \"enum\", \"format\": \"UPSTREAM,DOWNSTREAM\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", "$state": "ready", "connection/fed-by-device-id": "bess", "connection/fed-by-device-status": "OK", @@ -242,7 +240,7 @@ "meter/imported-energy": "64.55" }, "pv": { - "$description": "{\"homie\": \"5.0\", \"version\": 1787880675281, \"type\": \"energy.ebus.device.pv\", \"name\": \"Solar\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"vendor-name\": {\"name\": \"Vendor name\", \"datatype\": \"string\"}, \"model\": {\"name\": \"Model\", \"datatype\": \"string\"}, \"serial-number\": {\"name\": \"Serial number\", \"datatype\": \"string\"}, \"firmware-version\": {\"name\": \"Firmware version\", \"datatype\": \"string\"}, \"nominal-power\": {\"name\": \"Nominal power\", \"datatype\": \"float\", \"unit\": \"W\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", + "$description": "{\"homie\": \"5.0\", \"version\": 1793478308269, \"type\": \"energy.ebus.device.pv\", \"name\": \"Solar\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"vendor-name\": {\"name\": \"Vendor name\", \"datatype\": \"string\"}, \"model\": {\"name\": \"Model\", \"datatype\": \"string\"}, \"serial-number\": {\"name\": \"Serial number\", \"datatype\": \"string\"}, \"firmware-version\": {\"name\": \"Firmware version\", \"datatype\": \"string\"}, \"nominal-power\": {\"name\": \"Nominal power\", \"datatype\": \"float\", \"unit\": \"W\"}}}}, \"children\": [], \"root\": \"example-40t-001\", \"parent\": \"example-40t-001\", \"extensions\": []}", "$state": "ready", "info/firmware-version": "example-pv/v0.1.0", "info/model": "IQ8PLUS-72-2-US", diff --git a/packages/schema-1/src/span_panel_api_schema_1/snapshot.py b/packages/schema-1/src/span_panel_api_schema_1/snapshot.py index fafebc98..99f8ed9b 100644 --- a/packages/schema-1/src/span_panel_api_schema_1/snapshot.py +++ b/packages/schema-1/src/span_panel_api_schema_1/snapshot.py @@ -17,6 +17,7 @@ NODE_CONNECTION, NODE_INFO, PROP_FEEDS_DEVICE_ID, + PROP_FEEDS_ROLE, PROP_MODEL, PROP_SERIAL_NUMBER, TYPE_BESS, @@ -27,7 +28,7 @@ TYPE_MID, TYPE_PV, ) -from span_panel_api_schema_1.description import device_type +from span_panel_api_schema_1.description import declares_class, device_type, node_properties from span_panel_api_schema_1.devices import ( build_battery, build_evse, @@ -44,6 +45,7 @@ build_pcs, device_display_name, find_lugs, + panel_positions, panel_size_from_model, resolve_dominant_power_source, resolve_dsm_state, @@ -62,10 +64,13 @@ class TreeRoles: """The tree sorted into the roles a snapshot needs. - Matching is prefix-based for lugs, because firmware may declare either the - base ``…device.lugs`` type with a ``direction`` property or a subtyped - ``…device.lugs.upstream`` — the flat adapter already had to handle both - conventions, and there is no reason to assume v1.0 settled it. + Each role takes its class and every subtype of it (`declares_class`), + because firmware may declare either the base ``…device.lugs`` type with a + ``direction`` property or a subtyped ``…device.lugs.upstream`` — the flat + adapter already had to handle both conventions for lugs, and the same + hierarchy applies to every class here. Matching the others by exact type + left a subtype read by no role, while adoption, which honours the + hierarchy, declined it as modelled (#228). """ def __init__(self, devices: list[DiscoveredDevice]) -> None: @@ -81,17 +86,17 @@ def __init__(self, devices: list[DiscoveredDevice]) -> None: for device in devices: declared = device_type(device) - if declared == TYPE_CIRCUIT: + if declares_class(declared, TYPE_CIRCUIT): self.circuits.append(device) - elif declared.startswith(TYPE_LUGS): + elif declares_class(declared, TYPE_LUGS): self.lugs.append(device) - elif declared == TYPE_EVSE: + elif declares_class(declared, TYPE_EVSE): self.evse.append(device) - elif declared == TYPE_BESS and self.bess is None: + elif declares_class(declared, TYPE_BESS) and self.bess is None: self.bess = device - elif declared == TYPE_PV: + elif declares_class(declared, TYPE_PV): self.pvs.append(device) - elif declared == TYPE_MID and self.mid is None: + elif declares_class(declared, TYPE_MID) and self.mid is None: self.mid = device @@ -159,13 +164,19 @@ def build_snapshot(panel: DiscoveredDevice, children: list[DiscoveredDevice]) -> # uses, and this loop is where a circuit's is decided -- deriving it a # second time downstream would be a second implementation free to drift. circuit_subjects: list[tuple[DiscoveredDevice, ExtensionSubject]] = [] + circuit_ids = frozenset(circuit.device_id for circuit in roles.circuits) for circuit in roles.circuits: - snapshot = build_circuit(circuit, device_type=der_type_by_circuit.get(circuit.device_id, "circuit")) + snapshot = build_circuit( + circuit, device_type=der_type_by_circuit.get(circuit.device_id, "circuit"), circuit_ids=circuit_ids + ) circuits[snapshot.circuit_id] = snapshot circuit_subjects.append((circuit, ExtensionSubject(kind="circuit", instance_key=snapshot.circuit_id))) # An unknown model yields size 0 rather than a guessed total. panel_size = panel_size_from_model(text(panel, NODE_INFO, PROP_MODEL)) + first_position, last_position = panel_positions( + fields.model, (tab for circuit in circuits.values() for tab in circuit.tabs) + ) # Owners are every device that can claim a DER through a `connection` node. owners = [*roles.lugs, *roles.circuits, panel] @@ -176,7 +187,7 @@ def build_snapshot(panel: DiscoveredDevice, children: list[DiscoveredDevice]) -> # instead of guessed from a power source the way flat had to. device_types = {device.device_id: device_type(device) for device in children} device_names = {device.device_id: name for device in children if (name := device_display_name(device)) is not None} - inverters = [device for device in children if device_type(device) == TYPE_INVERTER] + inverters = [device for device in children if declares_class(device_type(device), TYPE_INVERTER)] islanding = resolve_islanding_state(roles.mid, panel) # Vendor extensions on devices this adapter *does* model. The pairing is @@ -244,8 +255,8 @@ def build_snapshot(panel: DiscoveredDevice, children: list[DiscoveredDevice]) -> feedthrough_energy_produced_wh=fields.feedthrough_energy_produced_wh, # Read, not derived. Flat had to infer both from `dominant-power-source` # plus grid power because nothing stated them; v1.0 states them on the MID, - # so the multi-signal heuristic is gone and only the no-MID tier remains a - # heuristic. The user-visible value set is unchanged. + # so the multi-signal heuristic is gone, and a panel with no MID is on-grid + # by elimination. The user-visible value set is unchanged. dsm_state=resolve_dsm_state(islanding), current_run_config=resolve_run_config(roles.mid, islanding, device_types), door_state=fields.door_state, @@ -270,6 +281,14 @@ def build_snapshot(panel: DiscoveredDevice, children: list[DiscoveredDevice]) -> vendor_name=fields.vendor_name, model=fields.model, hardware_version=fields.hardware_version, + busbar_current_a=fields.busbar_current_a, + frequency_hz=fields.frequency_hz, + upstream_protection_rating_a=fields.upstream_protection_rating_a, + first_position=first_position, + last_position=last_position, + publishes_solar_roles=any( + PROP_FEEDS_ROLE in node_properties(circuit, NODE_CONNECTION) for circuit in roles.circuits + ), shed_policy=fields.shed_policy, shed_policy_algorithm=fields.shed_policy_algorithm, shed_soc_threshold_shed_percent=fields.shed_soc_threshold_shed_percent, @@ -291,6 +310,8 @@ def build_snapshot(panel: DiscoveredDevice, children: list[DiscoveredDevice]) -> battery=build_battery( roles.bess, owners, + feeds=feeds, + feed_statuses=feed_statuses, firmware_version=fields.firmware_version, power_flow_battery=fields.power_flow_battery, ), diff --git a/packages/schema-1/src/span_panel_api_schema_1/transport.py b/packages/schema-1/src/span_panel_api_schema_1/transport.py index 812e3d11..3040cbe5 100644 --- a/packages/schema-1/src/span_panel_api_schema_1/transport.py +++ b/packages/schema-1/src/span_panel_api_schema_1/transport.py @@ -33,21 +33,48 @@ the SDK would have got that value as a retained message at subscribe time, so holding it reproduces what it would otherwise have seen rather than inventing anything. Dropping it instead is silent and total: an entire panel parses as -zero circuits. +zero circuits. By the same rule a clear, which deletes a retained message, is +not held: it takes back what is held for its topic, because the broker would +have replayed nothing there. """ from __future__ import annotations +import itertools import logging -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING, Any, NamedTuple -from paho.mqtt.client import topic_matches_sub +from paho.mqtt.matcher import MQTTMatcher + +from span_panel_api.models import ControlTarget +from span_panel_api_schema_1.const import HOMIE_DOMAIN, HOMIE_VERSION if TYPE_CHECKING: from collections.abc import Callable _LOGGER = logging.getLogger(__name__) + +def control_target(device_id: str, node: str, prop: str) -> ControlTarget: + """One device/node/property address as both a set topic and an observation key. + + The triple is returned alongside the topic rather than left for the + transport to parse back out of it: the transport is the one component + that is supposed to know nothing about this schema's topic grammar, and + under parent/child the device is a peer of the panel rather than a node + beneath it, so the grammar is not even the flat one. + + The spelling here is the spelling the adapter's property callbacks report + under, because a write is verified by matching one against the other. + """ + return ControlTarget( + topic=f"{HOMIE_DOMAIN}/{HOMIE_VERSION}/{device_id}/{node}/{prop}/set", + device_id=device_id, + node_id=node, + property_id=prop, + ) + + # Ceiling on messages held for a route that has not appeared. Sized well past a # full panel — a 48-space enclosure with every DER runs to a few thousand # topics — so reaching it means messages are arriving for a subtree the SDK @@ -56,6 +83,13 @@ MAX_HELD_MESSAGES = 4096 +class _Route(NamedTuple): + """A recorded callback, and when it was recorded, which decides an overlap.""" + + recorded: int + callback: Callable[[str, bytes], None] + + class ControllerRoutes: """Record `Controller`'s subscriptions and route messages back to them. @@ -64,8 +98,11 @@ class ControllerRoutes: """ def __init__(self) -> None: - # Insertion-ordered; dispatch walks it in reverse — see dispatch(). - self._routes: dict[str, Callable[[str, bytes], None]] = {} + self._routes: dict[str, _Route] = {} + # The same patterns, indexed for matching: each maps to itself, and + # dispatch resolves the patterns that match through `_routes`. + self._matcher = MQTTMatcher() + self._recordings = itertools.count() # Last payload per topic that matched no route yet, keyed by topic so a # newer value supersedes an older one — the same last-value-wins rule # the broker applies to the retained message this stands in for. @@ -108,27 +145,35 @@ def subscribe(self, sub: str, param: Any, qos: int = 1) -> None: # pylint: disa the adapter's behalf, not of a route recorded in a dict. """ # Pop before insert: assigning an existing key updates the value but - # keeps the key's original position, which would leave a re-registered - # pattern behind whatever was added after it in dispatch's match order. + # keeps the key's original position, and `routes` lists most recent last. self._routes.pop(sub, None) - self._routes[sub] = param + self._routes[sub] = _Route(next(self._recordings), param) + self._matcher[sub] = sub self._release(sub, param) def unsubscribe(self, sub: str) -> None: """Forget the callback for `sub`. The broad wire subscription stays. Messages for a device the SDK has - dropped simply stop matching a route, and dispatch discards them. + dropped simply stop matching a route, and dispatch holds them. """ - self._routes.pop(sub, None) + # Guarded because the matcher raises for a pattern it never held, and + # forgetting one that was never recorded is harmless. + if self._routes.pop(sub, None) is not None: + del self._matcher[sub] # -- our side ---------------------------------------------------------- def dispatch(self, topic: str, payload: str) -> None: """Deliver one message to the callback of the route that matches. - Walked most-recent-first, which is defensive rather than currently - required. Tree-rooted discovery subscribes four **device-scoped** + Matched through a prefix tree of the recorded patterns, so the cost + follows the topic's depth rather than the number of routes. Every + message takes this path, and a linear scan grew with each device the + panel declares, at four routes per device (#223). + + The most recently recorded match wins, which is defensive rather than + currently required. Tree-rooted discovery subscribes four **device-scoped** patterns per device — `$state`, `$description`, `+/+`, `+/+/$target` (`Controller._subscribe_device_topics`) — which cannot overlap each other or another device's, so today exactly one route matches any topic. @@ -144,18 +189,34 @@ def dispatch(self, topic: str, payload: str) -> None: route it belongs to may simply not exist yet — see the module docstring. The wire subscription is broader than the SDK's interest by construction, so some held messages are never claimed; the ceiling - keeps that from growing without bound. + keeps that from growing without bound. A clear (a zero-length payload) + is never held; see `_hold`. The SDK hands callbacks `bytes`; the transport hands us `str`. """ - for sub in reversed(self._routes): - if topic_matches_sub(sub, topic): - self._routes[sub](topic, payload.encode()) - return - self._hold(topic, payload) + # The matcher is untyped and yields what it was given, the pattern + # string; `_routes` turns each back into a typed route. The list is + # complete before any callback runs, so a callback that subscribes + # changes a matcher nothing is still walking. + matched = [self._routes[sub] for sub in self._matcher.iter_match(topic)] + if not matched: + self._hold(topic, payload) + return + max(matched, key=lambda route: route.recorded).callback(topic, payload.encode()) def _hold(self, topic: str, payload: str) -> None: - """Keep a message for a route that has not been registered yet.""" + """Keep a message for a route that has not been registered yet. + + A zero-length payload is not kept. It deletes the topic's retained + message, so a subscription made after it would be replayed nothing for + the topic: the clear takes back whatever is held for it instead. + Releasing the older value would bring back a reading the panel + withdrew, and releasing the clear would hand the SDK an empty payload, + which it stores as an empty value. + """ + if not payload: + self._held.pop(topic, None) + return if topic not in self._held and len(self._held) >= MAX_HELD_MESSAGES: self._discarded += 1 if self._discarded == 1: @@ -177,8 +238,13 @@ def _release(self, sub: str, callback: Callable[[str, bytes], None]) -> None: in turn, so a whole tree unfolds from one root subscription. The candidate list is therefore taken up front and each entry re-checked, since a nested release may have claimed it already. + + The pattern is indexed once and matched against every held topic, + rather than indexed afresh for each of them. """ - for topic in [held for held in self._held if topic_matches_sub(sub, held)]: + pattern = MQTTMatcher() + pattern[sub] = sub + for topic in [held for held in self._held if next(pattern.iter_match(held), None) is not None]: payload = self._held.pop(topic, None) if payload is not None: callback(topic, payload.encode()) diff --git a/packages/schema-1/src/span_panel_api_schema_1/tree_export.py b/packages/schema-1/src/span_panel_api_schema_1/tree_export.py new file mode 100644 index 00000000..3c1c67c0 --- /dev/null +++ b/packages/schema-1/src/span_panel_api_schema_1/tree_export.py @@ -0,0 +1,924 @@ +"""The masked device-tree export: the panel's whole tree, safe to share. + +``export_masked_tree`` writes the tree in the ``tree-v1`` form of the reference +captures, so an attached export replays through the same loader, adapter and +fidelity harness they do. Every retained value is carried as the wire string +the panel published; a declared property that was never valued, or whose +value the panel has since cleared, has no key, so the three states of a +property (valued, valued empty, unvalued) stay apart. + +A masked export replaces every device id with a placeholder that starts +``masked-``, so it can never equal a real id. The placeholder follows the +device rather than the shape of its id: SPAN treats ids as opaque and has said +they can change, so circuits are numbered by the breaker space they occupy and +lugs take their direction. Exports taken before and after such a change then +compare device by device. + +Values are masked by their property id on any node: a serial, and the site's +address, location, postal code and network; the panel's ``info/name``, the +site's name, is masked too. Every value that names a +device is passed through the same placeholders, so a reference still resolves; +one that names no device in the tree becomes ``masked-missing-`` and stays +visibly dangling. + +Last, every string the panel published that the rules keep is swept for the +tree's original device ids, for its serial numbers that read as identifiers, +the utility meter's among them, and for every dangling id that does, which +reads as its own ``masked-missing-`` wherever it appears: a property the +library has never seen, a device named by an id, an identifier inside a +``json`` value, as a string literal or a number, after a backslash or an +escape written out in plain text, through JSON nested in strings a few levels +deep; a string nested deeper than real values go is masked whole where it may +hide one, and a description subtree nested far deeper than real descriptions +go is masked whole where anything in it would be. The sweep reads only what +came off the wire, never the placeholders and masks the rules wrote, so it +cannot rewrite them. +""" + +from __future__ import annotations + +from collections.abc import Iterable, Mapping, Sequence +import json +import re +from types import MappingProxyType +from typing import TYPE_CHECKING, Final + +from span_panel_api.models import MaskedTree, MaskedTreeDevice, UndescribedDevice +from span_panel_api_schema_1.const import DEVICE_TYPE_PREFIX, TYPE_CIRCUIT, TYPE_LUGS +from span_panel_api_schema_1.description import declares_class, device_type, nodes, properties + +if TYPE_CHECKING: + from ebus_sdk.homie import DiscoveredDevice + +_PREFIX = "masked-" +_PANEL = f"{_PREFIX}panel" +_UNDESCRIBED = "undescribed" +_UNTYPED = "untyped" +_LUGS = "lugs" +_CIRCUIT = "circuit" +_DIRECTIONS = {"UPSTREAM": "upstream", "DOWNSTREAM": "downstream"} +_MISSING = "missing" +_ESCAPED_TYPE = "type-" +_RESERVED_SHORT_TYPES: Final = frozenset({_MISSING, _UNDESCRIBED}) +"""Placeholder names that are not a device type; a type spelt like one is numbered as ``type-``. + +``masked-missing-`` is a reference to no device in the tree and +``masked-undescribed-`` a device that has not described itself. A described +device whose short type is one of those words becomes ``masked-type-missing-1`` +or ``masked-type-undescribed-1``, so it can be read as neither. + +That keeps every placeholder distinct by construction. Each numbered one is +``masked--`` with one counter per name, and ````, the digits after +the last ``-``, cannot contain a ``-``, so two different names or numbers never +spell the same placeholder. A device whose short type really is +``type-missing`` shares that name and its counter, and the two differ by +number. The unnumbered ``masked-panel`` and ``masked-lugs-upstream`` / +``-downstream`` do not end in digits. +""" + +_SCHEMA: Final = "tree-v1" +_NUMERIC_DATATYPES: Final = frozenset({"integer", "float"}) + +_SERIAL_NUMBER: Final = "serial-number" +_METER_SERIAL_NUMBER: Final = "utility-meter-serial-number" +_NAME: Final = "info/name" +_MASKED_PANEL_NAME: Final = "Masked Panel" +_SITE_MASKS: Final[Mapping[str, str]] = MappingProxyType( + { + _METER_SERIAL_NUMBER: "MASKED-METER", + "wifi-ssid": "masked-ssid", + "postal-code": "00000", + "address-lines": "Masked Address", + "locality": "Masked City", + "region": "Masked Region", + "latitude": "0.0", + "longitude": "0.0", + "time-zone": "UTC", + "country-code": "ZZ", + } +) +"""Site values replaced whole, by property id on whichever node publishes them. + +The panel declares them under ``info`` and ``status``, but nothing in the +specification ties a site property to a node, which is why ``SITE_PROPERTIES`` +(``const.py``) is read the same way. ``time-zone`` and ``country-code`` are masked +to ``UTC`` and ``ZZ``, valid values a consumer that parses the export still reads. +The serial number is matched by property id too; the site's name is not, since +``name`` is every device's label and only the panel's ``info/name`` is masked. +""" + +_ID_PROPERTIES: Final = frozenset({"connection/feeds-device-id", "connection/fed-by-device-id"}) +_GRID_FORMING_ENTITY: Final = "grid/grid-forming-entity" +_GRID: Final = "GRID" +_ID_LIST_PROPERTY: Final = "shared-with-device-ids" +_REFERENCE_KEYS: Final = ("parent", "root") +_CHILDREN: Final = "children" +_DESCRIPTION_NAME: Final = "name" + +_DIGIT_RUNS = re.compile(r"([0-9]+)") +_MIN_EMBEDDED: Final = 6 +"""An identifier shorter than this is swept only where it is a whole value, never inside one.""" +_BOUNDARY_BEFORE: Final = r"(?:(?/properties``, whose fields are +scalars; a vendor's definition may nest a level or two deeper. Nothing in a +description is written again, so the bound guards the interpreter's stack +alone: ``parsed`` costs about three frames per level, and thirty-two levels +stay far inside the default limit. +""" +_NESTED_VALUE_MASK: Final = f"{_PREFIX}nested-value" +_DESCRIPTION_COPY_LIMIT: Final = 64 +"""How deep a kept description subtree may reach: a consumer writes the export indented, which a deep one makes raise.""" +_JSON_NUMBER: Final = re.compile(r"(-?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?)") +"""A JSON number token, captured so ``split`` returns the tokens at the odd indices. + +Between the string literals of text that parses as a JSON object or array there +are only numbers, ``true``, ``false``, ``null``, punctuation and whitespace, so +an identifier found there lies in a number. +""" +_DIGIT: Final = re.compile(r"[0-9]") + +type NaturalKey = tuple[tuple[int, str | int], ...] +type Order = tuple[NaturalKey, str] + + +def natural_key(text: str) -> NaturalKey: + """Sort key that compares runs of ASCII digits as integers and the rest case-folded.""" + return tuple( + (1, int(part)) if part.isascii() and part.isdigit() else (0, part.casefold()) + for part in _DIGIT_RUNS.split(text) + if part + ) + + +def _order(device_id: str) -> Order: + """Total order on ids: natural order, with the raw id breaking a tie. + + Distinct ids can share a natural key (`g-01` and `g-1`, or ids differing only + in case); without the tie-breaker their order is the input order, and the + same tree would not always give the same document. + """ + return (natural_key(device_id), device_id) + + +def placeholder_ids(root: DiscoveredDevice, descendants: Sequence[DiscoveredDevice]) -> dict[str, str]: + """Every device id in the tree, mapped to its distinct ``masked-`` placeholder. + + The root is ``masked-panel``. Circuits are numbered by their lowest breaker + space, then by natural id order for those that share a space or declare + none (the remote CT). Circuits and lugs are recognised by class, so a + subtyped one (`declares_class`) is placed exactly as its class is. Lugs + take ``masked-lugs-upstream`` / ``-downstream`` + from ``info/direction``; a lugs device whose direction is absent, not one of + the two, or already taken is numbered ``masked-lugs-``. Any other + described device is numbered per short type in natural id order, and a device + that has not described itself, or whose description is not a JSON object, + is ``masked-undescribed-``. + """ + ids: dict[str, str] = {root.device_id: _PANEL} + counters: dict[str, int] = {} + + def numbered(name: str) -> str: + counters[name] = counters.get(name, 0) + 1 + return f"{_PREFIX}{name}-{counters[name]}" + + ordered = sorted(descendants, key=lambda device: _order(device.device_id)) + circuits = [device for device in ordered if _is_described(device) and declares_class(device_type(device), TYPE_CIRCUIT)] + for device in sorted(circuits, key=_circuit_order): + ids[device.device_id] = numbered(_CIRCUIT) + + taken: set[str] = set() + for device in ordered: + if not _is_described(device) or not declares_class(device_type(device), TYPE_LUGS): + continue + direction = _DIRECTIONS.get(_text(device, "info", "direction")) + if direction is None or direction in taken: + ids[device.device_id] = numbered(_LUGS) + else: + taken.add(direction) + ids[device.device_id] = f"{_PREFIX}{_LUGS}-{direction}" + + for device in ordered: + if device.device_id in ids: + continue + ids[device.device_id] = numbered(_short_type(device) if _is_described(device) else _UNDESCRIBED) + return ids + + +def _is_described(device: DiscoveredDevice) -> bool: + """Whether the device has described itself with a ``$description`` that is a JSON object. + + The SDK stores whatever JSON the topic carried. A description that parsed + to a list or a string declares nothing, so the device is treated as one + that has not described itself, by the placeholders and the document alike. + """ + description: object = device.description + return isinstance(description, dict) + + +def _short_type(device: DiscoveredDevice) -> str: + declared = device_type(device).removeprefix(DEVICE_TYPE_PREFIX) or _UNTYPED + return f"{_ESCAPED_TYPE}{declared}" if declared in _RESERVED_SHORT_TYPES else declared + + +def _text(device: DiscoveredDevice, node: str, prop: str) -> str: + value = device.properties.get(node, {}).get(prop) + return "" if value is None else str(value).strip() + + +def _circuit_order(device: DiscoveredDevice) -> tuple[int, int, Order]: + """Hosted circuits by lowest breaker space first, the rest after, ties by natural id.""" + spaces = [int(part) for part in re.findall(r"[0-9]+", _text(device, "info", "spaces"))] + if not spaces: + return (1, 0, _order(device.device_id)) + return (0, min(spaces), _order(device.device_id)) + + +def export_masked_tree( + root: DiscoveredDevice, descendants: Sequence[DiscoveredDevice], *, producer: str, tree_complete: bool +) -> MaskedTree: + """The tree as a ``tree-v1`` document, with device ids, serials and site values masked. + + A described device goes under ``devices``: its ``$description`` with + ``parent``, ``root`` and ``children`` mapped to placeholders, every declared + value split by its declared ``datatype`` (``integer`` and ``float`` into + ``numeric_properties``, the rest into ``properties``), every value its + description does not declare in ``undeclared_properties``, its ``$target`` + values, and its ``$state`` when one arrived. A device its parent declared + but that has not described itself, or whose description is not a JSON + object, goes under ``undescribed_devices`` with its values unsplit, since + nothing says what they are. + + The masks apply to a value by its property id on any node, wherever it is + published, declared or not, and to targets as to values. A valued-empty + ``""`` stays empty under every rule: it carries no identity, and replacing + it would turn an empty reading into a value. Everything else the panel + published is swept (``_Sweep``): the values and targets no rule replaces, + their ``node/property`` keys, ``$state``, and every key, string and number + of a description but the references and the panel's name the rules map. + + Devices are written in placeholder order and each device's values in key + order, so the same tree always gives the same document. A dangling id is + numbered ``masked-missing-`` in the order it is first met: devices in + placeholder order, and within one its values, then its targets, then its + description's references; the sweep replaces the same id with the same + placeholder wherever else the panel published it. The SDK's objects are + only read; a description is copied before anything in it is replaced. + """ + ids = placeholder_ids(root, descendants) + in_order = sorted([root, *descendants], key=lambda device: _order(ids[device.device_id])) + references = _References(ids) + for device in in_order: + references.register(device) + masker = _Masker(references, root.device_id, _Sweep(_identifiers(ids, in_order, references.dangling()))) + devices: dict[str, MaskedTreeDevice] = {} + undescribed: dict[str, UndescribedDevice] = {} + for device in in_order: + placeholder = ids[device.device_id] + values = masker.values(device.device_id, _flattened(device.properties)) + targets = masker.values(device.device_id, _flattened(device.property_targets)) + state = None if device.state is None else masker.published(str(device.state)) + description: object = device.description + if isinstance(description, dict): # `_is_described`, inline so the description narrows + devices[placeholder] = _described(masker.description(device.device_id, description), values, targets, state) + else: + undescribed[placeholder] = _undescribed(values, targets, state) + return { + "metadata": {"schema": _SCHEMA, "masked": True, "producer": producer, "tree_complete": tree_complete}, + "devices": devices, + "undescribed_devices": undescribed, + } + + +def _identifiers( + ids: Mapping[str, str], in_order: Sequence[DiscoveredDevice], dangling: Sequence[tuple[str, str]] +) -> list[tuple[str, str]]: + """Every device id, and every id-like dangling id and serial, with what the sweep replaces it by, highest priority first. + + An id is replaced by its device's placeholder and a serial by its device's + masked serial, the placeholder in upper case. Ids come first, so on a panel + whose serial is its id the text is read as the id; then the dangling ids + that read as ids (``_is_id_like``), each with the ``masked-missing-`` its + reference was given, so such an id reads the same at a reference and + anywhere else, even one spelt like a serial; + then serials, so a serial that is also an id is read as that id. Within + each, devices come in placeholder order, so a serial two devices publish (a + MID and its BESS) is the first owner's wherever it is found. The utility + meter's serial comes last and is replaced by its own mask, + ``MASKED-METER``: it is a serial number, not free text, though it names the + premises rather than a device. A serial that does not read as an id + (``0``, ``N/A``, ``unknown``) is a placeholder the panel published for a + serial it does not have: its own property is masked by the rule all the + same, but it is not swept, since every equal value would go with it. + """ + identifiers = [(device.device_id, ids[device.device_id]) for device in in_order] + identifiers.extend((device_id, missing) for device_id, missing in dangling if _is_id_like(device_id)) + for device in in_order: + identifiers.extend( + (serial, ids[device.device_id].upper()) for serial in _serials(device, _SERIAL_NUMBER) if _is_id_like(serial) + ) + meter_mask = _SITE_MASKS[_METER_SERIAL_NUMBER] + for device in in_order: + identifiers.extend((serial, meter_mask) for serial in _serials(device, _METER_SERIAL_NUMBER) if _is_id_like(serial)) + return identifiers + + +def _is_id_like(value: str) -> bool: + """Whether a dangling reference or a serial reads as an identifier, not a word: six characters or more, with a digit. + + A reference names no device for one of two reasons: the device is absent, + or the panel published a word there (``UNKNOWN``, ``NONE``, ``BACKUP``). + Such a word is mapped where it is published like any dangling id, but it is + also a reading and an enum member, so it is not swept anywhere else. A + serial of ``0`` or ``N/A`` stands in for one the panel does not have, and + is likewise masked where it is published and swept nowhere else. + """ + return len(value) >= _MIN_EMBEDDED and _DIGIT.search(value) is not None + + +def _serials(device: DiscoveredDevice, property_id: str) -> list[str]: + """The values a device publishes for ``property_id``, on any node, as values or targets, without surrounding space.""" + serials: list[str] = [] + for published in (_flattened(device.properties), _flattened(device.property_targets)): + serials.extend(published[topic].strip() for topic in sorted(published) if topic.partition("/")[2] == property_id) + return [serial for serial in serials if serial] + + +class _Sweep: + """Replaces every device id, and every id-like dangling id and serial number, found in text the panel published. + + The matching rules keep it from rewriting unrelated text. Only identifiers + are swept: device ids, dangling references that read as ids, and serial + numbers, the utility meter's included. Any other site value is free text or + a short code, so a region of ``OK`` swept as a whole would rewrite every + status of ``OK``, and the property rules mask those alone. + + An identifier matches case-insensitively and only where no ASCII letter or + digit adjoins it, so ``circuit-1`` is not found inside ``circuit-12``; any + other character, a ``-`` or a backslash among them, is a boundary, and so + is a JSON-style escape written out in plain text (``\\n``, ``\\u00b0``), + whose letter or last hex digit would otherwise adjoin the identifier. A + ``-`` must be one, because device ids are serials and suffixes joined by + ``-``, and a serial embedded in an id the tree does not hold must still be + found. For an identifier made only of digits a decimal point that joins it + to another digit is no boundary either, so a meter serial is not found + inside a decimal reading. Identifiers are tried longest first, so + ``-lugs-up`` maps to the lugs' placeholder rather than the panel's + with a suffix. One shorter than six characters is matched only as a whole + string, never inside a longer string or in a key, where ``pv`` is also a + property id. A serial is swept only where it reads as an identifier + (``_is_id_like``); its own property is masked by rule whatever it says. + + Every string is swept the same way (``value``), whatever it was declared + as. Each JSON string literal in it is decoded, since in the raw text an + escape's own letter would adjoin an identifier or spell part of one + (``\\u006e``), and its content is swept as a string of its own by this same + rule, so JSON carried inside a string is reached; a literal followed by + ``:`` is an object key and is swept as a key. A quote that never closes + opens a literal all the same, whose content is the rest of the text less a + lone backslash at the end; it is written again without a closing quote. + The literal is decoded leniently, a raw control character allowed and a + backslash that starts no JSON escape read as a backslash, so that a valid + escape beside such a flaw cannot hide an identifier. Only a literal that + changed is written again, with standard escapes, and escaped where UTF-8 + cannot carry a character of it. The text between the literals, and a + literal that still does not decode, is swept as plain text. A number equal + to an identifier is replaced there like any other text, and where the whole + text parses as a JSON object or array the number token is written as a + JSON string, so the value still parses. Every other byte stays as + published. + + The decoding stops at ``_NESTING_BOUND``: every level written again doubles + the escapes of the levels inside it and costs a stack frame, so unbounded + nesting is exponential output and a ``RecursionError``. A literal decoded + at the bound is not swept inside; it is replaced whole by + ``masked-nested-value`` if its content holds an identifier under the plain + rule, or a quote, which may open a literal the sweep will not read, and is + kept as published otherwise. A description's containers (``parsed``) are + already decoded and are written again nowhere, so they are read by + recursion to the looser ``_DESCRIPTION_NESTING_BOUND`` and a container at + it is walked with an explicit stack instead: it is replaced whole by + ``masked-nested-value`` if any key, string or number in it would be swept + by the rules above the bound, and copied as published otherwise. + + Where identifiers that differ only in case match, the one spelt as found + wins, then the one of higher priority (``_identifiers``). + """ + + def __init__(self, identifiers: Sequence[tuple[str, str]]) -> None: + self._replacements: dict[str, str] = {} + for identifier, replacement in identifiers: + if identifier: + self._replacements.setdefault(identifier, replacement) + embedded = sorted((ident for ident in self._replacements if len(ident) >= _MIN_EMBEDDED), key=len, reverse=True) + whole = [ident for ident in self._replacements if len(ident) < _MIN_EMBEDDED] + self._embedded = _alternation( + ([ident for ident in embedded if not _is_digits(ident)], _BOUNDARY_BEFORE, _BOUNDARY_AFTER), + ([ident for ident in embedded if _is_digits(ident)], _DIGITS_BOUNDARY_BEFORE, _DIGITS_BOUNDARY_AFTER), + ) + self._whole = _alternation((whole, "", "")) + + def value(self, text: str) -> str: + """A published string with every identifier in it replaced, a short one only where it is the whole string.""" + return self._swept(text, whole=True) + + def key(self, text: str) -> str: + """A key with every identifier of six characters or more in it replaced.""" + return self._swept(text, whole=False) + + def topic(self, topic: str) -> str: + """A ``node/property`` key, swept as its node and property ids are in the description that declares them.""" + node_id, separator, property_id = topic.partition("/") + return f"{self.key(node_id)}{separator}{self.key(property_id)}" + + def parsed(self, value: object, depth: int = 0) -> object: + """A copy of parsed JSON (a description): each key swept as a key, each string as a string, each number as its text. + + ``depth`` is how many containers enclose the value below the + description's own keys. A container at ``_DESCRIPTION_NESTING_BOUND`` + is not walked by recursion: ``_bounded`` decides for it whole, on the + same leaf rules, with a stack of its own. + """ + if isinstance(value, str): + return self.value(value) + if isinstance(value, int | float) and not isinstance(value, bool): + return self._number(value) + if isinstance(value, dict | list) and depth >= _DESCRIPTION_NESTING_BOUND: + return self._bounded(value, depth) + if isinstance(value, dict): + return _first_per_key((self.key(str(key)), self.parsed(item, depth + 1)) for key, item in value.items()) + if isinstance(value, list): + return [self.parsed(item, depth + 1) for item in value] + return value + + def _number(self, value: int | float) -> object: + """A number whose text holds an identifier, as that text swept; any other number is itself. + + A serial published as a JSON number in a description (``45123987``) is + the text of one published in a ``json`` value and reads the same mask, + as a string; a sign stays, inside the string. + """ + text = str(value) + swept = self._swept_flat(text, whole=True) + return value if swept == text else swept + + def _bounded(self, value: dict[object, object] | list[object], depth: int) -> object: + """A container at the description bound: a copy, or ``masked-nested-value`` if it would change or reaches too deep. + + The subtree is walked with a stack of its own, not the interpreter's, + so a description nested to any depth costs no stack frames. Each key + is held to the key rule and each string and number leaf to the rule + ``parsed`` applies above the bound; a boolean or null is never an + identifier. If any of them would change, the container is masked + whole, because nothing below the bound is swept in place, and so is + one whose containers reach past ``_DESCRIPTION_COPY_LIMIT`` from the + description's root, which the export must not carry; otherwise the + copy keeps the document from sharing an object with the SDK's tree. + """ + copied: dict[object, object] | list[object] = {} if isinstance(value, dict) else [] + pending = [(value, copied, depth)] + while pending: + source, target, at = pending.pop() + pairs: Iterable[tuple[object, object]] = source.items() if isinstance(source, dict) else enumerate(source) + for key, item in pairs: + if isinstance(key, str) and self.key(key) != key: + return _NESTED_VALUE_MASK + leaf: object = item + if isinstance(item, dict | list): + if at + 1 > _DESCRIPTION_COPY_LIMIT: + return _NESTED_VALUE_MASK + child: dict[object, object] | list[object] = {} if isinstance(item, dict) else [] + pending.append((item, child, at + 1)) + leaf = child + elif self._leaf_changes(item): + return _NESTED_VALUE_MASK + if isinstance(target, dict): + target[key] = leaf + else: + target.append(leaf) + return copied + + def _leaf_changes(self, leaf: object) -> bool: + """Whether ``parsed`` would replace a scalar: a string the sweep changes, or a number whose text holds one.""" + if isinstance(leaf, str): + return self.value(leaf) != leaf + if isinstance(leaf, int | float) and not isinstance(leaf, bool): + return isinstance(self._number(leaf), str) + return False + + def _swept(self, text: str, *, whole: bool, depth: int = 0) -> str: + """The text with its string literals swept each as a string and the text between them as plain text. + + ``whole`` allows a short identifier to match the entire text. ``depth`` + is how many literals the text was decoded from: the wire string is 0. + The plain text is swept again with its numbers written as strings when + an identifier was found in it and the text parses as a JSON object or + array: a number is then in a value position, and a bare word there + would stop the value parsing. A quote that never closes ends the plain + text; it and the rest are one unclosed literal. + """ + if whole and self._whole is not None and self._whole.fullmatch(text): + return self._replacement(text) + literals: list[re.Match[str]] = [] + spans: list[str] = [] + position = 0 + unclosed: re.Match[str] | None = None + for match in _JSON_STRING.finditer(text): + if match.group(1) is None: + unclosed = match + break + literals.append(match) + spans.append(text[position : match.start()]) + position = match.end() + spans.append(text[position : len(text) if unclosed is None else unclosed.start()]) + swept = [self._plain(span) for span in spans] + if swept != spans and _is_json_container(text): + swept = [self._numbers_quoted(span) for span in spans] + pieces = [ + piece for span, match in zip(swept[:-1], literals, strict=True) for piece in (span, self._literal(match, depth)) + ] + tail = "" if unclosed is None else self._unclosed(unclosed, depth) + return "".join([*pieces, swept[-1], tail]) + + def _plain(self, text: str) -> str: + """Plain text with every identifier of six characters or more in it replaced.""" + if self._embedded is None: + return text + return self._embedded.sub(lambda match: self._replacement(match.group()), text) + + def _numbers_quoted(self, span: str) -> str: + """Plain text from a JSON object or array, swept, with a number that held an identifier written as a JSON string.""" + parts = _JSON_NUMBER.split(span) + for index, part in enumerate(parts): + swept = self._plain(part) + parts[index] = json.dumps(swept) if index % 2 and swept != part else swept + return "".join(parts) + + def _literal(self, match: re.Match[str], depth: int) -> str: + """One string literal, its content swept as a string (as a key before a colon), written again only if it changed. + + A literal that does not decode is swept as the plain text it is. + """ + literal, colon = match.group(1), match.group(2) + swept = self._literal_swept(literal, whole=colon is None, depth=depth) + return self._plain(match.group()) if swept is None else swept + (colon or "") + + def _unclosed(self, match: re.Match[str], depth: int) -> str: + """A quote that never closes, with the rest of the text: swept as a literal, written again without a closing quote. + + The content is the text after the quote less a lone backslash at the + end (``_JSON_STRING`` group 3), which stays as it was; swept as plain + text, an escape's letter in it would adjoin an identifier. Content + that does not decode is swept as plain text, and content that did not + change keeps its bytes. + """ + text, trailing = match.group(), match.group(3) + swept = self._literal_swept(f'"{text[1 : len(text) - len(trailing)]}"', whole=True, depth=depth) + return self._plain(text) if swept is None else f'"{swept[1:-1]}{trailing}' + + def _literal_swept(self, literal: str, *, whole: bool, depth: int) -> str | None: + """A string literal with its content swept as a string: itself where nothing changed, None where it does not decode. + + The content is decoded leniently (``_JSON_ESCAPE``, ``strict=False``). + Content decoded at ``_NESTING_BOUND`` is not swept inside: the literal + becomes ``masked-nested-value`` where the content may hide an + identifier, and is kept otherwise. + """ + try: + decoded: object = json.loads(_JSON_ESCAPE.sub(_defined_escape, literal), strict=False) + except ValueError: + return None + if not isinstance(decoded, str): + return literal + if depth + 1 >= _NESTING_BOUND: + return _dumped(_NESTED_VALUE_MASK) if self._hides_an_identifier(decoded, whole=whole) else literal + swept = self._swept(decoded, whole=whole, depth=depth + 1) + return literal if swept == decoded else _dumped(swept) + + def _hides_an_identifier(self, text: str, *, whole: bool) -> bool: + """Whether text the sweep will not read inside may hold an identifier. + + It holds one under the plain rule (``_swept_flat``), or a quote, which + may open a literal the sweep will not read. + """ + return '"' in text or self._swept_flat(text, whole=whole) != text + + def _swept_flat(self, text: str, *, whole: bool) -> str: + """The text swept by the plain rule alone, a short identifier only as the whole of it; no literal is read.""" + if whole and self._whole is not None and self._whole.fullmatch(text): + return self._replacement(text) + return self._plain(text) + + def _replacement(self, found: str) -> str: + exact = self._replacements.get(found) + if exact is not None: + return exact + return next( + replacement + for identifier, replacement in self._replacements.items() + if re.fullmatch(re.escape(identifier), found, re.IGNORECASE) + ) + + +def _defined_escape(match: re.Match[str]) -> str: + """A ``_JSON_ESCAPE`` match as JSON defines it: an escape as written, a stray backslash doubled.""" + return "\\\\" if match.group(1) else match.group() + + +def _is_json_container(text: str) -> bool: + """Whether a published value parses as a JSON object or array, whatever its declared datatype. + + It decides only whether a swept number is written as a JSON string + (``_Sweep``). JSON text that opens with ``{`` or ``[`` is an object or array + if it parses at all, so a scalar (``"bess"``, ``12``) never gets past the + first check: a bare number equal to an identifier is a whole value and is + replaced as text. Nesting too deep to parse is read as not parsing, so the + export stays total. + """ + if not text.lstrip().startswith(("{", "[")): + return False + try: + json.loads(text) + except ValueError, RecursionError: + return False + return True + + +def _dumped(text: str) -> str: + """A string as a JSON literal, its characters written as they are, or escaped where UTF-8 cannot carry one. + + A lone surrogate, which the escape ``\\ud800`` decodes to, has no UTF-8 + encoding and would stop the export being written; it goes back as an escape. + """ + literal = json.dumps(text, ensure_ascii=False) + try: + literal.encode("utf-8") + except UnicodeEncodeError: + return json.dumps(text) + return literal + + +def _is_digits(identifier: str) -> bool: + """Whether an identifier is made only of ASCII digits, so a decimal point may join it to a number.""" + return identifier.isascii() and identifier.isdigit() + + +def _alternation(*groups: tuple[Sequence[str], str, str]) -> re.Pattern[str] | None: + """One case-insensitive pattern trying each group's identifiers in turn between its two boundaries; None for none. + + No identifiers gives None, never an empty pattern, which would match at + every position. Each group's boundaries are shared, outside its + alternation: an identifier that fails the boundary after it still + backtracks into the next, so the matches are those of a boundary around + each, and the boundary before is tested once per position rather than once + per identifier. The groups are tried in order at each position, which + costs no longer match: identifiers from two groups can both match at one + position only where one is a prefix of the other, so a group whose + identifiers may be prefixes of another's comes after it. + """ + sources = [ + f"{before}(?:{'|'.join(re.escape(ident) for ident in identifiers)}){after}" + for identifiers, before, after in groups + if identifiers + ] + if not sources: + return None + return re.compile("|".join(sources), re.IGNORECASE) + + +def _first_per_key[T](pairs: Iterable[tuple[str, T]]) -> dict[str, T]: + """Pairs as a map; where sweeping made two keys one, the first in order is kept.""" + merged: dict[str, T] = {} + for key, item in pairs: + merged.setdefault(key, item) + return merged + + +def _named_ids(topic: str, value: str) -> list[str] | None: + """The ids a value names where its property carries device ids; None where it names none. + + ``connection/feeds-device-id`` and ``fed-by-device-id`` name one, + ``*/shared-with-device-ids`` a comma-separated list with each element + trimmed, and the MID's ``grid/grid-forming-entity`` one unless it is the grid + itself, read as the adapter reads it. + """ + if topic in _ID_PROPERTIES: + return [value] + if topic == _GRID_FORMING_ENTITY: + return None if value.strip().upper() == _GRID else [value] + if topic.partition("/")[2] == _ID_LIST_PROPERTY: + return [part.strip() for part in value.split(",") if part.strip()] + return None + + +def _description_ids(description: Mapping[object, object]) -> list[str]: + """The ids a description names: its ``parent``, its ``root``, then each of its ``children``.""" + named = [reference for key in _REFERENCE_KEYS if isinstance(reference := description.get(key), str)] + children = description.get(_CHILDREN) + if isinstance(children, list): + named.extend(child for child in children if isinstance(child, str)) + return named + + +class _References: + """Device ids mapped to placeholders, and each dangling id to its own ``masked-missing-``.""" + + def __init__(self, ids: Mapping[str, str]) -> None: + self._ids = ids + self._missing: dict[str, str] = {} + + def placeholder(self, device_id: str) -> str: + """The placeholder of a device in the tree.""" + return self._ids[device_id] + + def map(self, device_id: str) -> str: + """The placeholder of the device an id names, or the dangling id's own ``masked-missing-``.""" + placeholder = self._ids.get(device_id) + if placeholder is not None: + return placeholder + if device_id not in self._missing: + self._missing[device_id] = f"{_PREFIX}{_MISSING}-{len(self._missing) + 1}" + return self._missing[device_id] + + def register(self, device: DiscoveredDevice) -> None: + """Number every dangling id a device names, in the order the masking meets them. + + Its values, then its targets, each in key order, then its description's + references; a valued-empty ``""`` names nothing. Registering every + device in placeholder order before any is masked numbers each dangling + id as the masking would, so the sweep can replace it everywhere else. + """ + for published in (_flattened(device.properties), _flattened(device.property_targets)): + for topic in sorted(published): + named = _named_ids(topic, published[topic]) if published[topic] else None + for device_id in named or (): + self.map(device_id) + description: object = device.description + if isinstance(description, dict): + for device_id in _description_ids(description): + self.map(device_id) + + def dangling(self) -> list[tuple[str, str]]: + """Each dangling id met so far, with its ``masked-missing-``, in the order met.""" + return list(self._missing.items()) + + +class _Masker: + """The masking rules and the sweep, sharing one map of references.""" + + def __init__(self, references: _References, panel_id: str, sweep: _Sweep) -> None: + self._references = references + self._panel_id = panel_id + self._sweep = sweep + + def published(self, text: str) -> str: + """A string the panel published and no rule replaces, swept.""" + return self._sweep.value(text) + + def values(self, owner: str, values: Mapping[str, str]) -> dict[str, str]: + """One device's ``node/property`` values with every rule applied, keys swept, in key order. + + The rules read each value under its published key, in that key's order, + so dangling ids are numbered the same whatever the sweep makes of a key. + """ + masked = _first_per_key( + (self._sweep.topic(topic), self.value(owner, topic, values[topic])) for topic in sorted(values) + ) + return {topic: masked[topic] for topic in sorted(masked)} + + def value(self, owner: str, topic: str, value: str) -> str: + if value == "": + return value + masked = self._fixed_mask(owner, topic) + return self._referenced(topic, value) if masked is None else masked + + def _fixed_mask(self, owner: str, topic: str) -> str | None: + """The replacement for an identifying or site value, or None where the name carries neither.""" + if topic == _NAME and owner == self._panel_id: + return _MASKED_PANEL_NAME + property_id = topic.partition("/")[2] + if property_id == _SERIAL_NUMBER: + return self._references.placeholder(owner).upper() + return _SITE_MASKS.get(property_id) + + def _referenced(self, topic: str, value: str) -> str: + """The value with every device id it names mapped; a value that names none, swept.""" + named = _named_ids(topic, value) + if named is None: + return self.published(value) + return ",".join(self._references.map(device_id) for device_id in named) + + def description(self, owner: str, description: Mapping[object, object]) -> dict[str, object]: + """A copy of a ``$description`` with its device references mapped, the panel's name masked, the rest swept. + + The references and the name are decided from the description as + published, before the sweep, and are not swept themselves. + """ + replaced: dict[str, object] = {} + for key in _REFERENCE_KEYS: + reference = description.get(key) + if isinstance(reference, str): + replaced[key] = self._references.map(reference) + children = description.get(_CHILDREN) + if isinstance(children, list): + replaced[_CHILDREN] = [ + self._references.map(child) if isinstance(child, str) else self._sweep.parsed(child) for child in children + ] + if owner == self._panel_id and _DESCRIPTION_NAME in description: + replaced[_DESCRIPTION_NAME] = _MASKED_PANEL_NAME + return _first_per_key( + (name, replaced[name]) if name in replaced else (self._sweep.key(name), self._sweep.parsed(value)) + for name, value in ((str(key), value) for key, value in description.items()) + ) + + +def _described( + description: dict[str, object], values: dict[str, str], targets: dict[str, str], state: str | None +) -> MaskedTreeDevice: + numeric = { + f"{node_id}/{property_id}": _is_numeric(definition) + for node_id, node in nodes(description).items() + for property_id, definition in properties(node).items() + } + entry: MaskedTreeDevice = { + "description": description, + "properties": {}, + "numeric_properties": {}, + "targets": targets, + "undeclared_properties": {}, + } + for topic, value in values.items(): + if topic not in numeric: + entry["undeclared_properties"][topic] = value + elif numeric[topic]: + entry["numeric_properties"][topic] = value + else: + entry["properties"][topic] = value + if state is not None: + entry["state"] = state + return entry + + +def _is_numeric(definition: Mapping[str, object]) -> bool: + """Whether a property's declared ``datatype`` puts its value in ``numeric_properties``.""" + datatype = definition.get("datatype") + return isinstance(datatype, str) and datatype in _NUMERIC_DATATYPES + + +def _undescribed(values: dict[str, str], targets: dict[str, str], state: str | None) -> UndescribedDevice: + entry: UndescribedDevice = {"values": values, "targets": targets} + if state is not None: + entry["state"] = state + return entry + + +def _flattened(by_node: object) -> dict[str, str]: + """The SDK's ``{node: {property: value}}`` map, keyed ``node/property``.""" + flat: dict[str, str] = {} + if not isinstance(by_node, dict): + return flat + for node_id, by_property in by_node.items(): + if isinstance(by_property, dict): + for property_id, value in by_property.items(): + flat[f"{node_id}/{property_id}"] = str(value) + return flat diff --git a/pyproject.toml b/pyproject.toml index f2af8a62..0d4f80ae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "span-panel-api" -version = "3.7.0b1" +version = "3.8.0" description = "A client library for SPAN Panel API" authors = [ {name = "SpanPanel"} @@ -62,14 +62,16 @@ dependencies = [ # so a 1.1.x adapter is still accepted, but it fills neither `pv_inverters` nor # the inverter identity fields 3.6.0 adds. Upgrading through the extra is what # brings the adapters that do. -# Raised to 1.3.0b1 for 3.7.0b1: that adapter reports the unknown values this +# Raised to 1.3.0 for 3.8.0: that adapter reports the unknown values this # bootstrap's snapshot fields now accept, and stops synthesising unoccupied positions. -schema-0 = ["span-panel-api-schema-0>=1.3.0b1"] +schema-0 = ["span-panel-api-schema-0>=1.3.0"] # Raised to 1.2.1 for 3.6.1: that adapter builds the `pv` that `SpanPanelSnapshot.pv` now documents. # Raised to 1.2.2 for 3.6.2: the readiness gate every snapshot passes asks that # adapter what is still missing, and 1.2.2 restarts its feed grace correctly. -# Raised to 1.3.0b1 for 3.7.0b1, for the same reason as schema-0's. -schema-1 = ["span-panel-api-schema-1>=1.3.0b1"] +# Raised to 1.4.0 for 3.8.0: for the same reason as schema-0's, and because that +# adapter fills the snapshot fields this bootstrap adds and exports the masked +# device tree. +schema-1 = ["span-panel-api-schema-1>=1.4.0"] [project.urls] Homepage = "https://github.com/SpanPanel/span-panel-api" @@ -93,7 +95,7 @@ dev = [ # known. Dependabot raises the bump on its own; the bump PR re-runs # `scripts/capture_parent_child_reference.py` and the suite then says whether # the wire moved. - "ebus-panel-sim==0.8.0", + "ebus-panel-sim==0.9.0", "pytest>=9.0.2", "pytest-asyncio>=1.3.0", "pytest-cov", @@ -253,6 +255,12 @@ explicit_package_bases = true # `tests/` on `sys.path`; the support packages the mypy hook checks resolve the same # way here. mypy_path = "src:tests" +# paho ships `py.typed` but leaves its topic matcher unannotated, so every call +# into it would be an untyped call. The schema-1 route table resolves what the +# matcher yields through a typed dict at once, which keeps its `Any` from going +# further; `warn_return_any` does not police that for you (a union or a +# `yield from` passes it), so keep it to that shape. +untyped_calls_exclude = ["paho.mqtt.matcher"] # Excluded by name for the reason `[tool.ruff]` gives above: the capture script is # checked like the library, and the hand-run tools written before that was expected # are not. diff --git a/pytest.ini b/pytest.ini index 2f4c80e3..59272703 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,5 @@ [pytest] asyncio_mode = auto +strict_markers = true +markers = + spec_only: pins a behaviour the eBus catalog defines that no reference payload publishes diff --git a/scripts/new-worktree.sh b/scripts/new-worktree.sh new file mode 100755 index 00000000..b75e4b6c --- /dev/null +++ b/scripts/new-worktree.sh @@ -0,0 +1,121 @@ +#!/bin/bash +# +# Create a worktree for a branch of work beside the primary checkout, and prepare +# it with setup-hooks.sh. +# +# Usage: scripts/new-worktree.sh [] +# +# The worktree is created at ../-, beside the primary +# checkout: the layout the integration's developer notes expect when +# installing a library worktree into its environment. +# The branch to create. Defaults to feat/. +# +# The branch starts from origin/main as just fetched and does not track it, so a +# bare `git push` can never land on main. Local main is fast-forwarded as well where +# that is safe, and the script refuses when local main holds commits origin/main +# lacks, because branching from origin/main would silently leave them out. +# +# The worktree gets a virtual environment of its own rather than a link to the +# primary checkout's. This repository installs its own distributions in editable +# mode, and each records the path of one checkout's sources, so a shared +# environment imports whichever checkout synced last and tests pass against the +# wrong code without an error. uv clones packages from its cache, so the second +# environment costs little. Local configuration that is not bound to a path, `.env`, +# is linked instead. +# +# The shared pre-commit hook is installed from the primary checkout first when it is +# missing or bound elsewhere, so no worktree starts out committing unchecked. + +set -euo pipefail + +usage() { + echo "Usage: $0 []" >&2 + exit 2 +} + +[[ $# -ge 1 && $# -le 2 ]] || usage +name=$1 +if [[ ! "$name" =~ ^[A-Za-z0-9._-]+$ ]]; then + echo "Worktree name '$name' may use only letters, digits, dots, underscores and hyphens." >&2 + exit 2 +fi +branch=${2:-feat/$name} + +script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +checkout=$(cd "$script_dir/.." && pwd) +common_dir=$(git -C "$checkout" rev-parse --path-format=absolute --git-common-dir) +primary_root=$(dirname "$common_dir") +target="$(dirname "$primary_root")/$(basename "$primary_root")-$name" + +if [[ -e "$target" ]]; then + echo "$target already exists." >&2 + exit 1 +fi +if git -C "$primary_root" show-ref --verify --quiet "refs/heads/$branch"; then + echo "Branch $branch already exists." >&2 + exit 1 +fi + +echo "Fetching origin..." +git -C "$primary_root" fetch origin + +if git -C "$primary_root" show-ref --verify --quiet refs/heads/main; then + ahead=$(git -C "$primary_root" rev-list --count origin/main..main) + if ((ahead > 0)); then + echo "Local main has $ahead commit(s) that origin/main does not. Reconcile main first;" >&2 + echo "branching from origin/main would silently leave them out." >&2 + exit 1 + fi + + # Where main is checked out, move it only if that checkout is clean. + main_checkout=$(git -C "$primary_root" worktree list --porcelain | + awk '/^worktree /{wt = substr($0, 10)} /^branch refs\/heads\/main$/{print wt}') + if [[ -z "$main_checkout" ]]; then + # update-ref rather than `branch --force`: that would also rewrite main's + # upstream to origin/main, silently re-pointing a main that tracks another + # remote. The old value guards against main moving since it was checked. + git -C "$primary_root" update-ref -m "new-worktree.sh: fast-forward main to origin/main" \ + refs/heads/main "$(git -C "$primary_root" rev-parse refs/remotes/origin/main)" \ + "$(git -C "$primary_root" rev-parse refs/heads/main)" + elif [[ -n "$(git -C "$main_checkout" status --porcelain --untracked-files=no)" ]]; then + echo "main is checked out with uncommitted changes at $main_checkout; leaving it as it is." + elif ! git -C "$main_checkout" merge --ff-only --quiet origin/main; then + # Untracked files are not counted as changes above, because a fast-forward + # refuses to overwrite one; this is where that refusal lands. + echo "Could not fast-forward main at $main_checkout; leaving it as it is." + fi +fi + +# Every worktree commits through the one hook in the common directory. Missing, its +# commits skip every check without a word; bound to an environment that is gone, +# they fail. The primary checkout is the one place it can be installed to last, so +# install it there before the worktree exists, and refuse if that does not take. +if ! (cd "$checkout" && bash ./setup-hooks.sh --check-hook >/dev/null); then + echo "Installing the shared pre-commit hook from the primary checkout..." + if ! (cd "$primary_root" && ./setup-hooks.sh); then + echo "Could not install the pre-commit hook from $primary_root; not creating the worktree." >&2 + exit 1 + fi + if ! (cd "$checkout" && bash ./setup-hooks.sh --check-hook); then + echo "The pre-commit hook is still not bound to $primary_root; not creating the worktree." >&2 + exit 1 + fi +fi + +echo "Creating $target on $branch from origin/main..." +git -C "$primary_root" worktree add --no-track -b "$branch" "$target" origin/main + +if [[ -f "$primary_root/.env" && ! -e "$target/.env" ]]; then + ln -s "$primary_root/.env" "$target/.env" + echo "Linked .env from the primary checkout." +fi + +# The setup script beside this one rather than the target's copy. The branch starts +# from origin/main, which can predate the worktree-aware setup, and running an older +# copy there would rebind the shared hook to the new worktree. +echo "Preparing the worktree..." +(cd "$target" && bash "$checkout/setup-hooks.sh") + +echo +echo "Worktree ready: $target" +echo "Branch: $branch, from $(git -C "$target" rev-parse --short HEAD), not tracking a remote" diff --git a/scripts/reference_panel.yaml b/scripts/reference_panel.yaml index 8a945033..7c8518a9 100644 --- a/scripts/reference_panel.yaml +++ b/scripts/reference_panel.yaml @@ -9,7 +9,7 @@ # # Laid out to mirror the emitter's own `examples/forty_tab_minimal.yaml` key for key, # so the two can be read side by side and `diff`ed. Every difference is deliberate and -# is marked ==> below. There are two kinds. +# is marked ==> below. There are three kinds. # # ==> DIVERGENCE 1: shed priorities. # The emitter's example commissions the two ordinary loads as `NICE_TO_HAVE`. That is @@ -31,6 +31,11 @@ # library tests injecting those values by hand, reading as coverage while asking # nothing about what a panel sends. Every value here is synthetic (`example-*`), # because these bytes ship inside a wheel. +# +# ==> DIVERGENCE 3: breaker positions. +# The example places three circuits on spaces 1-3, outside the position range +# `PANEL_POSITIONS_BY_MODEL` gives this panel's model. A reference capture should +# describe positions a panel of that model has, so they move to 9, 10 and 11. panel_config: serial_number: example-40t-001 @@ -109,11 +114,11 @@ circuits: - id: kitchen_lights name: Kitchen Lights template: lighting - tabs: [1] + tabs: [9] - id: garage_outlet name: Garage Outlet template: outlet - tabs: [2] + tabs: [10] - id: span_drive_garage name: SPAN Drive - Garage template: span_drive @@ -125,7 +130,7 @@ circuits: - id: pool_pump name: Pool Pump template: pool_pump - tabs: [3] + tabs: [11] - id: solar_inverter name: Solar Inverter template: solar diff --git a/setup-hooks.sh b/setup-hooks.sh index 3143a50b..25f87ab7 100755 --- a/setup-hooks.sh +++ b/setup-hooks.sh @@ -1,31 +1,114 @@ #!/bin/bash +# +# Prepare this checkout for development: install dependencies and make sure the +# git pre-commit hook is in place. +# +# Usage: ./setup-hooks.sh [--update | --check-hook] +# +# --update Upgrade the lockfile before syncing. +# --check-hook Only check the shared pre-commit hook, and exit non-zero when it +# is missing or not bound to the primary checkout. +# +# Safe to run from the primary checkout and from a linked worktree, which differ +# in the one respect that matters here. Git hooks live in the repository's common +# directory and every worktree shares them, and `pre-commit install` writes the +# interpreter that runs it into the hook. Installing from a worktree therefore +# binds every checkout's commits to that worktree's virtual environment -- which +# is deleted with the worktree, after which every commit fails with "`pre-commit` +# not found". So only the primary checkout installs the hook. A worktree checks +# that the shared hook is bound to the primary checkout and says how to fix it if +# not, and leaves it alone either way. -# Check if we should force update (pass --update flag) -FORCE_UPDATE=false -if [[ "$1" == "--update" ]]; then - FORCE_UPDATE=true -fi +usage() { + echo "Usage: $0 [--update | --check-hook]" >&2 + exit 2 +} + +mode=setup +case "${1:-}" in + "") ;; + --update) mode=update ;; + --check-hook) mode=check-hook ;; + *) usage ;; +esac +[[ $# -le 1 ]] || usage + +git_dir=$(git rev-parse --absolute-git-dir) || exit 1 +common_dir=$(git rev-parse --path-format=absolute --git-common-dir) || exit 1 +primary_root=$(dirname "$common_dir") -# Ensure dependencies are installed first -if [[ ! -f ".deps-installed" ]] || [[ "pyproject.toml" -nt ".deps-installed" ]] || [[ "uv.lock" -nt ".deps-installed" ]] || [[ "$FORCE_UPDATE" == "true" ]]; then - echo "Installing/updating dependencies..." +# Whether the shared hook exists and runs with the primary checkout's environment. +# Silent when it does; otherwise says what is wrong and how to fix it. +check_shared_hook() { + local hook install_python - if [[ "$FORCE_UPDATE" == "true" ]]; then - echo "Forcing update to latest versions..." - uv lock --upgrade - uv sync - else - uv sync + hook=$(git rev-parse --path-format=absolute --git-path hooks/pre-commit) + if [[ ! -f "$hook" ]]; then + echo "No pre-commit hook is installed for this repository yet, so commits skip every" + echo "check. Install it from the primary checkout, where it outlives every worktree:" + echo " (cd \"$primary_root\" && ./setup-hooks.sh)" + return 1 fi - if [[ $? -ne 0 ]]; then - echo "Failed to install dependencies. Please check the output above." + install_python=$(sed -n "s/^INSTALL_PYTHON=//p" "$hook") + install_python=${install_python#\'} + install_python=${install_python%\'} + + if [[ "$install_python" != "$primary_root"/.venv/* ]]; then + echo "The shared pre-commit hook runs with ${install_python:-an unknown interpreter}, not the" + echo "primary checkout's environment, so commits will fail once that environment is gone." + echo "Rebind it from the primary checkout:" + echo " (cd \"$primary_root\" && ./setup-hooks.sh)" + return 1 + fi + + if [[ ! -x "$install_python" ]]; then + echo "The shared pre-commit hook runs with $install_python, which no longer exists, so" + echo "commits will fail. Reinstall it from the primary checkout:" + echo " (cd \"$primary_root\" && ./setup-hooks.sh)" + return 1 + fi +} + +if [[ "$mode" == "check-hook" ]]; then + check_shared_hook || exit 1 + echo "Shared pre-commit hook is bound to the primary checkout." + exit 0 +fi + +if [[ "$mode" == "update" ]]; then + echo "Forcing update to latest versions..." + if ! uv lock --upgrade; then + echo "Failed to upgrade the lockfile. Please check the output above." exit 1 fi - touch .deps-installed fi -# Install pre-commit hooks -uv run pre-commit install +# Every run syncs. uv is idempotent and clones packages from its cache, so an +# environment that is already current costs little. This used to be gated on a +# stamp file that had been committed to the repository, which meant a fresh +# worktree checked the stamp out and whether it got an environment at all came +# down to the order in which checkout happened to write files. +echo "Installing/updating dependencies..." +if ! uv sync; then + echo "Failed to install dependencies. Please check the output above." + exit 1 +fi -echo "Git hooks installed successfully!" +if [[ "$git_dir" == "$common_dir" ]]; then + if ! uv run pre-commit install; then + echo "Failed to install the pre-commit hook. Please check the output above." + exit 1 + fi + if ! check_shared_hook; then + echo "Failed to bind the pre-commit hook to this checkout's environment." + exit 1 + fi + echo "Git hooks installed successfully!" + exit 0 +fi + +# A linked worktree from here on. +if check_shared_hook; then + echo "Shared pre-commit hook is bound to the primary checkout; leaving it alone." +fi diff --git a/src/span_panel_api/__init__.py b/src/span_panel_api/__init__.py index c5f77c16..c59b0657 100644 --- a/src/span_panel_api/__init__.py +++ b/src/span_panel_api/__init__.py @@ -29,6 +29,7 @@ SpanPanelError, SpanPanelInsufficientPrivilegeError, SpanPanelPassphraseUnavailableError, + SpanPanelRateLimitError, SpanPanelSchemaVersionError, SpanPanelServerError, SpanPanelStaleDataError, @@ -41,15 +42,22 @@ ADOPTION_IDENTITY_NODE, ADOPTION_TOPOLOGY_NODE, DISCOVERY_NAMESPACE, + FEEDS_ROLES, + PROTECTION_FUNCTIONS, AdoptedDevice, AdoptedProperty, ControlTarget, DiscoveredMetadata, ExtensionProperty, ExtensionSubject, + FeedsRole, FieldMetadata, HomieSchemaTypes, + MaskedTree, + MaskedTreeDevice, + MaskedTreeMetadata, PassphraseRotation, + ProtectionFunction, SpanBatterySnapshot, SpanCircuitSnapshot, SpanEvseSnapshot, @@ -57,10 +65,12 @@ SpanPanelSnapshot, SpanPcsSnapshot, SpanPVSnapshot, + UndescribedDevice, V2AuthResponse, V2HomieSchema, V2StatusInfo, is_discovery_path, + shared_meter_groups, ) from .mqtt import ( ControlCommand, @@ -84,10 +94,12 @@ CircuitControlProtocol, ControlInterceptionProtocol, EvseControlProtocol, + EvseLockControlProtocol, PanelCapability, PanelControlProtocol, SpanPanelClientProtocol, StreamingCapableProtocol, + TreeExportingAdapter, ) __version__ = _pkg_version("span-panel-api") @@ -106,6 +118,9 @@ # snapshot rather than by its arguments -- a device the adapter models # produces no AdoptedDevice and so cannot be addressed through it. "AdoptedControlProtocol", + # A charger's connector lock, authorised by `SpanEvseSnapshot.lock_control`. + # A protocol of its own so `EvseControlProtocol`'s implementers are unchanged. + "EvseLockControlProtocol", # Added 2026-08-25 (3.1.0): one veto/observe point for every control # command. A protocol of its own rather than a member on the four control # protocols, which would break their implementers a second time in one @@ -137,6 +152,15 @@ "ControlTarget", "ExtensionProperty", "ExtensionSubject", + # Added 2026-10-31: the masked device tree a consumer forwards in diagnostics, + # and the optional protocol an adapter offers it through. Deliberately not a + # SchemaAdapter member: the protocol derives its required set from itself, so a + # member there would invalidate every built adapter wheel. + "MaskedTree", + "MaskedTreeDevice", + "MaskedTreeMetadata", + "UndescribedDevice", + "TreeExportingAdapter", # Snapshots "SpanBatterySnapshot", "SpanCircuitSnapshot", @@ -145,6 +169,16 @@ "SpanPVSnapshot", "SpanPanelSnapshot", "SpanPcsSnapshot", + # What a circuit's `connection/feeds-role` declares, read into + # `SpanCircuitSnapshot.feeds_role`. + "FEEDS_ROLES", + "FeedsRole", + # What a circuit's `breaker/protection-functions` lists, read into + # `SpanCircuitSnapshot.protection_functions`. + "PROTECTION_FUNCTIONS", + "ProtectionFunction", + # The circuits one meter measures, from `SpanCircuitSnapshot.meter_shared_with`. + "shared_meter_groups", # Factory "create_span_client", # Detection @@ -216,6 +250,10 @@ # keep their meaning; deliberately not a SpanPanelAuthError, because the # passphrase the user supplied may be correct. "SpanPanelPassphraseUnavailableError", + # Registration refused with HTTP 429, carrying the panel's `Retry-After` in + # seconds. A subclass of SpanPanelAPIError, so existing except clauses keep + # their meaning; not a SpanPanelAuthError, because no credential was judged. + "SpanPanelRateLimitError", "SpanPanelServerError", "SpanPanelStaleDataError", # Added 2026-08-31 (3.4.0): a bootstrap REST call that failed verification diff --git a/src/span_panel_api/auth.py b/src/span_panel_api/auth.py index df8a1c1c..011c16af 100644 --- a/src/span_panel_api/auth.py +++ b/src/span_panel_api/auth.py @@ -10,9 +10,12 @@ import asyncio from collections.abc import Collection, Mapping +from datetime import UTC, datetime +from email.utils import parsedate_to_datetime import hashlib import json import logging +import math import ssl import uuid @@ -24,6 +27,7 @@ SpanPanelAuthError, SpanPanelInsufficientPrivilegeError, SpanPanelPassphraseUnavailableError, + SpanPanelRateLimitError, SpanPanelServerError, ) from .models import HomieSchemaTypes, PassphraseRotation, V2AuthResponse, V2HomieSchema, V2StatusInfo @@ -216,21 +220,37 @@ def _error_detail(response: httpx.Response) -> str | None: CA_CERT_BACKOFF_S = 1.5 -def _retry_delay(retry_after: str | None, attempt: int, backoff_s: float) -> float: - """Return how long to wait before retrying a rate-limited request. +def _retry_after_s(retry_after: str | None, now: datetime) -> float | None: + """The wait a ``Retry-After`` header asks for, in seconds, or None if it asks for none. - Prefers the panel's ``Retry-After`` header (delta-seconds form) and falls - back to exponential backoff. Malformed or negative values fall back too, - so a bad header can never stall or skip the retry. + Both forms RFC 9110 allows: delta-seconds, taken as given, and an HTTP-date, + taken as the seconds from `now` until then (0.0 once it has passed). A + negative, infinite or unparseable value is no answer, so a bad header can + never stall or skip a retry. """ - fallback = backoff_s * (2.0 ** (attempt - 1)) if retry_after is None: - return fallback + return None try: - parsed = float(retry_after) - except (TypeError, ValueError): - return fallback - return parsed if parsed >= 0 else fallback + seconds = float(retry_after) + except ValueError: + try: + until = parsedate_to_datetime(retry_after) + except (TypeError, ValueError): + return None + if until.tzinfo is None: + return None + return max((until - now).total_seconds(), 0.0) + return seconds if math.isfinite(seconds) and seconds >= 0 else None + + +def _retry_delay(retry_after: str | None, attempt: int, backoff_s: float) -> float: + """Return how long to wait before retrying a rate-limited request. + + Prefers the panel's ``Retry-After`` header and falls back to exponential + backoff where it gives no usable wait. + """ + parsed = _retry_after_s(retry_after, datetime.now(UTC)) + return backoff_s * (2.0 ** (attempt - 1)) if parsed is None else parsed async def register_v2( @@ -276,6 +296,7 @@ async def register_v2( Raises: SpanPanelAuthError: Invalid passphrase or auth failure SpanPanelPassphraseUnavailableError: The panel cannot read its own passphrase + SpanPanelRateLimitError: HTTP 429; the panel is limiting registrations. Not retried SpanPanelServerError: The panel is not ready to register clients (any 5xx, including the 503 it answers before its serial number is known); retryable SpanPanelConnectionError: Cannot reach panel @@ -314,6 +335,16 @@ async def register_v2( status_code=reply.status_code, ) + if reply.status_code == HTTP_TOO_MANY_REQUESTS: + # Not retried: the panel limits registrations per client address, and a + # retry here would spend the caller's next attempt on its behalf. + _log_auth_failure(reply.endpoint, reply.response, sent) + raise SpanPanelRateLimitError( + f"Panel is rate-limiting registration (HTTP {reply.status_code})", + status_code=reply.status_code, + retry_after_s=_retry_after_s(reply.headers.get("retry-after"), datetime.now(UTC)), + ) + if reply.status_code == 422 and _error_detail(reply.response) == REGISTRATION_UNAVAILABLE_DETAIL: # Checked before the general 422 below, which means "credential not # accepted". This one is the panel failing to read its own passphrase, @@ -613,8 +644,8 @@ async def rotate_passphrase( Raises: SpanPanelInsufficientPrivilegeError: HTTP 403; the token is reduced-privilege SpanPanelAuthError: HTTP 401 (token invalid or stale) or 412 (no bearer token) - SpanPanelServerError: HTTP 5xx. After a 500 the outcome is unknown: the - passphrase may or may not have changed. + SpanPanelServerError: HTTP 5xx. After a 500 or a 504 the outcome is unknown: + the passphrase may or may not have changed. SpanPanelConnectionError: Cannot reach panel SpanPanelTimeoutError: Request timed out SpanPanelAPIError: Unexpected response diff --git a/src/span_panel_api/exceptions.py b/src/span_panel_api/exceptions.py index 8bcf8ebf..84f63437 100644 --- a/src/span_panel_api/exceptions.py +++ b/src/span_panel_api/exceptions.py @@ -68,6 +68,25 @@ class SpanPanelServerError(SpanPanelAPIError): """ +class SpanPanelRateLimitError(SpanPanelAPIError): + """The panel is limiting the client's requests and refused this one (HTTP 429). + + Raised by ``register_v2``, which does not retry: the caller decides when to + try again. ``retry_after_s`` is the wait the panel asked for, in seconds, + from its ``Retry-After`` header: a delta-seconds value as given, an HTTP-date + as the seconds until that time. ``None`` when the header is absent or holds + neither. + + A `SpanPanelAPIError`, so an existing clause catching that class still + catches this, and not a `SpanPanelAuthError`: the credential was never + judged. + """ + + def __init__(self, message: str, status_code: int | None = None, retry_after_s: float | None = None) -> None: + super().__init__(message, status_code) + self.retry_after_s = retry_after_s + + class SpanPanelPassphraseUnavailableError(SpanPanelAPIError): """The panel cannot read its own passphrase, so it cannot issue broker credentials. diff --git a/src/span_panel_api/models.py b/src/span_panel_api/models.py index 07dc41fb..b544d4cc 100644 --- a/src/span_panel_api/models.py +++ b/src/span_panel_api/models.py @@ -11,11 +11,25 @@ from collections.abc import Mapping from dataclasses import dataclass, field +import re +from typing import Final, Literal, NotRequired, TypedDict # Homie schema type: {type_name: {property_name: {attribute: value}}} # Values are heterogeneous JSON (str, int, bool, nested dicts). type HomieSchemaTypes = dict[str, dict[str, object]] +type FeedsRole = Literal["LOADS", "SUBPANEL", "SOLAR", "STORAGE", "GENERATOR", "MIXED", "UNUSED"] +"""What a circuit feeds, as its `connection/feeds-role` declares it.""" + +FEEDS_ROLES: Final[tuple[FeedsRole, ...]] = ("LOADS", "SUBPANEL", "SOLAR", "STORAGE", "GENERATOR", "MIXED", "UNUSED") +"""Every `FeedsRole`, for reading a wire value into one.""" + +type ProtectionFunction = Literal["OVERCURRENT", "SHORT_CIRCUIT", "GROUND_FAULT", "ARC_FAULT"] +"""One protection a circuit's breaker provides, as `breaker/protection-functions` lists it.""" + +PROTECTION_FUNCTIONS: Final[tuple[ProtectionFunction, ...]] = ("OVERCURRENT", "SHORT_CIRCUIT", "GROUND_FAULT", "ARC_FAULT") +"""Every `ProtectionFunction`, for reading a wire value into one.""" + @dataclass(frozen=True, slots=True) class SpanCircuitSnapshot: @@ -33,9 +47,9 @@ class SpanCircuitSnapshot: # fabricated zero as a reset and books the whole counter as an offset # (`SpanPanel/span#259`). A new circuit legitimately reads `0.0`, and the # two must stay tellable apart. - instant_power_w: float | None # Positive = consumption - produced_energy_wh: float | None # Generation/backfeed (Wh) - consumed_energy_wh: float | None # Consumption (Wh) + instant_power_w: float | None # Positive = consumption; import where `measures_outside_panel` + produced_energy_wh: float | None # Generation/backfeed (Wh); export where `measures_outside_panel` + consumed_energy_wh: float | None # Consumption (Wh); import where `measures_outside_panel` tabs: list[int] priority: str # v1: MUST_HAVE | NICE_TO_HAVE | NON_ESSENTIAL | UNKNOWN # v2: NEVER | SOC_THRESHOLD | OFF_GRID | UNKNOWN @@ -44,7 +58,10 @@ class SpanCircuitSnapshot: is_never_backup: bool # v1: Circuit.isNeverBackup | v2: circuit/never-backup device_type: str = "circuit" # "circuit" | "pv" | "evse" relative_position: str = "" # PV/EVSE: "IN_PANEL" | "UPSTREAM" | "DOWNSTREAM" - is_240v: bool = False + # From the breaker's pole count. `None` where the circuit publishes no pole + # count: a meter outside the panel has no breaker, and a breaker whose count + # has not arrived has not said. + is_240v: bool | None = False current_a: float | None = None breaker_rating_a: float | None = None always_on: bool = False # v2 new: circuit/always-on @@ -75,6 +92,53 @@ class SpanCircuitSnapshot: pcs_managed: bool | None = None # v2: circuit pcs/managed pcs_priority: int | None = None # v2: circuit pcs/priority + measures_outside_panel: bool = False + """The device declares no breaker space: a meter outside the panel. + + Power is import-positive (positive = flowing into the panel); consumed is + imported energy and produced is exported energy, so consumed minus produced + is net import. Read from the device's declaration, never from its values, so + a meter that has not reported yet is already outside the panel. Such a meter + has no relay, no breaker and no shed priority, and occupies no position. + """ + + meter_shared_with: tuple[str, ...] | None = None + """The other circuits this circuit's meter also measures, by circuit id. + + From `meter/shared-with-device-ids`, without the circuit itself or an id + naming no circuit in the snapshot, ordered by `device_id_order`. `None` + where the circuit declares no such list or has not published it; `()` where + it lists no circuit the snapshot holds. The peers' readings are the same + meter's, so a consumer never adds them up; `shared_meter_groups` groups + them. + """ + relay_shared_with: tuple[str, ...] | None = None + """The other circuits this circuit's relay also switches, by circuit id. + + From `switch/shared-with-device-ids`, read as `meter_shared_with` is. + """ + + nominal_voltage_v: float | None = None + """The circuit's rated voltage, from `info/nominal-voltage`. + + `None` where the circuit declares none or has not published it. + """ + protection_functions: tuple[ProtectionFunction, ...] | None = None + """The protections the circuit's breaker provides, from `breaker/protection-functions`. + + In published order, without any value outside `PROTECTION_FUNCTIONS`. + `None` where the breaker declares none or has not published them. + """ + + feeds_role: FeedsRole | None = None + """What the circuit feeds, from its `connection/feeds-role`. + + `None` where the circuit declares no role, has not published it, or + publishes a value outside `FEEDS_ROLES`. Reported as declared and nothing + more: `device_type` stays as published, so a circuit whose role is solar is + still a circuit. The flat schema declares no roles. + """ + @dataclass(frozen=True, slots=True) class SpanPVSnapshot: @@ -401,6 +465,52 @@ class SpanEvseSnapshot: set topic when it is not. """ + charge_current_limit_minimum_a: int | None = None + """The lowest charge-current limit the charger declares a user may set, in amps. v1.0 only. + + The minimum of the `:` range the limit's declaration states in + `$format`, from the same resolution as `charge_current_limit_a`; firmware + r202639 declares `6:`. A write below it is refused + rather than published, so a control offers nothing under it. + + A declaration, not a reading: it is reported as soon as the charger + describes itself, and whether or not the limit is settable, which + `charge_current_limit_settable` answers. `None` where the charger declares + no limit, no `$format`, or the format leaves this side open, and where the + format cannot be read as an integer range (not `integer`, not `:`, + a bound that is not a plain integer, or a minimum above the maximum). `None` + on the flat schema, which declares no range. + """ + + charge_current_limit_maximum_a: int | None = None + """The highest charge-current limit the charger declares a user may set, in amps. v1.0 only. + + The maximum of the same declared range, `None` on the same terms. A write + above it is refused rather than published. + + **Not `charge_current_ceiling_a`.** That is the commissioned ceiling, a + published value; this is the declared range, part of the limit's + description. Every r202639 capture declares a maximum equal to the ceiling + it publishes, but they are separate facts, and a write must satisfy both: a + control's upper bound is the lower of the two where both are present. + """ + + lock_control: ControlTarget | None = None + """Where the charger's connector lock is commanded, and which property reports it. v1.0 only. + + Addresses `switch/lock-state` on the charger's own device, and is present + only where that declaration carries `$settable`: absence is refusal, so a + lock the charger reports but does not accept writes to has no target. The + value written is one of `lock_state_options`. `None` on the flat schema. + """ + + lock_state_options: tuple[str, ...] | None = None + """The values the charger's `switch/lock-state` declares in its `$format`. v1.0 only. + + What a lock command may write: a value outside them is refused rather than + published. `None` where the charger declares no lock or no `$format`. + """ + connected: bool | None = None """The enclosure's view of the link to this charger, v1.0 only. @@ -476,6 +586,20 @@ class SpanBatterySnapshot: # it, and the migration guide warns against conflating them. communication_state: str | None = None # v2: bess status/communication-state + # Whether the panel's device tree declares a battery, v1.0 only. True from the + # moment the battery describes itself, before any of its values arrive, so a + # battery whose state of charge is never published is still a battery. None + # on the flat schema, which has no battery device to declare and publishes + # its battery values whether or not one is installed. + present: bool | None = None + + # The circuit whose `connection/feeds-device-id` names this battery, v1.0 + # only. Where it is set and no device claims the battery through a + # `fed-by-*` record, `connected` is that circuit's `feeds-device-status`. + # None where no circuit feeds the battery, as when it sits ahead of the + # upstream lugs, and on the flat schema. + feed_circuit_id: str | None = None + @dataclass(frozen=True, slots=True) class FieldMetadata: @@ -540,6 +664,48 @@ class FieldMetadata: _DISCOVERY_PREFIX = f"{DISCOVERY_NAMESPACE}." +def device_id_order(device_id: str) -> tuple[str | int, ...]: + """Sort key for device ids under which digit runs compare as numbers. + + `circuit-9` sorts before `circuit-10`. Splitting on a captured digit run + leaves the runs at the odd positions and the text between them at the even + ones, so every position holds the same type in every key. + """ + parts = re.split(r"(\d+)", device_id) + return tuple(int(part) if index % 2 else part for index, part in enumerate(parts)) + + +def shared_meter_groups(circuits: Mapping[str, SpanCircuitSnapshot]) -> dict[str, tuple[str, ...]]: + """The circuits one meter measures, grouped and keyed by their first member. + + A group holds every circuit linked through `meter_shared_with`, in + `device_id_order`, and its key is the first of them. A circuit that names no + known peer and is named by none is in no group. Only membership: no reading + is combined, because every member already reports the one meter's values. + """ + links: dict[str, set[str]] = {} + for circuit_id, circuit in circuits.items(): + for peer in circuit.meter_shared_with or (): + if peer in circuits and peer != circuit_id: + links.setdefault(circuit_id, set()).add(peer) + links.setdefault(peer, set()).add(circuit_id) + groups: dict[str, tuple[str, ...]] = {} + seen: set[str] = set() + for start in sorted(links, key=device_id_order): + if start in seen: + continue + members = {start} + pending = [start] + while pending: + for peer in links[pending.pop()] - members: + members.add(peer) + pending.append(peer) + seen |= members + ordered = tuple(sorted(members, key=device_id_order)) + groups[ordered[0]] = ordered + return groups + + def discovery_path(device_type: str, node_id: str, property_id: str) -> str: """The namespaced field path for one declared-but-unaddressed property. @@ -1135,6 +1301,45 @@ class SpanPanelSnapshot: and `DeviceInfo(hw_version=...)` is the consumer's abbreviation, not ours. """ + busbar_current_a: float | None = None + """The panel's busbar current, from its `meter/busbar-current`. v1.0 only. + + `None` where the panel declares none or has not published it. + """ + frequency_hz: float | None = None + """The line frequency, from the panel's `meter/frequency`. v1.0 only. + + `None` where the panel declares none or has not published it. + """ + upstream_protection_rating_a: int | None = None + """The rating of the protection ahead of the upstream lugs, in amperes. v1.0 only. + + From the upstream lugs' `connection/overcurrent-protection`; `None` where + they declare none or have not published it. + """ + + first_position: int | None = None + """The panel's first breaker position. v1.0 only. + + The reported model's range as the adapter's model table gives it, where + the table knows the model, otherwise the lowest occupied space. An occupied + space outside a known model's range does not move it: the adapter warns + once for that panel instead. `None` on the flat schema and where neither is + known. Together with `last_position` it says which positions exist, + occupied or not; no circuit is made up for an empty one. + """ + last_position: int | None = None + """The panel's last breaker position. v1.0 only; see `first_position`.""" + + publishes_solar_roles: bool = False + """Whether any circuit declares `connection/feeds-role`. + + The declaration decides, not the value: a circuit that declares the role + before publishing it, or declares a role other than solar, still marks the + panel as one that says where its solar is. `False` on the flat schema, + which declares no roles. + """ + # `shed/policy`, v1.0 only: how the panel decides what to shed, and the two # SoC thresholds that make its behaviour predictable. The wire carries one # `json` document; these are the parsed answer plus the document itself. @@ -1285,7 +1490,7 @@ class SpanPanelSnapshot: apart — every limit in this capture is a legal `0.0`. """ - lugs_at_service_entrance: bool = True + lugs_at_service_entrance: bool | None = True """Whether this enclosure's upstream lugs *are* the utility connection point. `False` means something sits between the utility and the main lugs, so the @@ -1316,6 +1521,9 @@ class SpanPanelSnapshot: flat panel's lugs are its service entrance. schema_0 leaves it alone for that reason. + `None` while the lugs declare `connection/fed-by-device-id` and have not + published it: the feed may yet name a device, so neither answer is known. + A defaulted snapshot field rather than a `SchemaAdapter` member, for the reason `adopted_devices` gives above: the protocol derives its required members from itself, so a new member would be required of every adapter @@ -1328,3 +1536,65 @@ class SpanPanelSnapshot: the feeding device is another panel with its own tree, not a child of this one. """ + + +class MaskedTreeMetadata(TypedDict): + """What produced a `MaskedTree` and whether it can be trusted to be whole. + + `masked` is always `True`: the tree never carries a serial, a credential or + an address, and the marker lets whoever reads a forwarded diagnostic see that + without inspecting the values. `tree_complete` is `False` when the panel had + not finished publishing its tree, so what follows is a partial reading. + """ + + schema: Literal["tree-v1"] + masked: Literal[True] + producer: str + tree_complete: bool + + +class MaskedTreeDevice(TypedDict): + """One described device in a `MaskedTree`, as a consumer forwards it in diagnostics. + + Values are keyed `"/"` and kept as the wire strings the + panel published, masked where they identify the device or the site. + `numeric_properties` holds the values of declared `integer` and `float` + properties, `properties` the values of every other declared property, + `undeclared_properties` values the panel published that its own description + does not declare, and `targets` its `$target` values. A declared property + with no value has no key: never `None`, and never a `""` the panel did not + send, because a placeholder would read as a reading. A `""` the panel did + publish is kept as `""`. + """ + + description: dict[str, object] + properties: dict[str, str] + numeric_properties: dict[str, str] + targets: dict[str, str] + undeclared_properties: dict[str, str] + state: NotRequired[str] + + +class UndescribedDevice(TypedDict): + """A device the panel published values for but never described. + + With no `$description` there is nothing to say which node a property belongs + to, so `values` keeps each as `"/"` -> wire string, unsplit. + """ + + values: dict[str, str] + targets: dict[str, str] + state: NotRequired[str] + + +class MaskedTree(TypedDict): + """The masked device tree a consumer forwards in diagnostics. + + Produced by an adapter that offers `TreeExportingAdapter`. Described devices + and undescribed ones are kept apart so a reader never mistakes one for the + other. + """ + + metadata: MaskedTreeMetadata + devices: dict[str, MaskedTreeDevice] + undescribed_devices: dict[str, UndescribedDevice] diff --git a/src/span_panel_api/mqtt/client.py b/src/span_panel_api/mqtt/client.py index 17699a13..45a9a78b 100644 --- a/src/span_panel_api/mqtt/client.py +++ b/src/span_panel_api/mqtt/client.py @@ -36,8 +36,16 @@ SpanPanelTLSVerificationError, SpanPanelValidationError, ) -from ..models import AdoptedProperty, ControlTarget, FieldMetadata, HomieSchemaTypes, SpanPanelSnapshot, V2HomieSchema -from ..protocol import PanelCapability, SchemaAdapter +from ..models import ( + AdoptedProperty, + ControlTarget, + FieldMetadata, + HomieSchemaTypes, + MaskedTree, + SpanPanelSnapshot, + V2HomieSchema, +) +from ..protocol import PanelCapability, SchemaAdapter, TreeExportingAdapter from .connection import AsyncMqttBridge from .const import MQTT_READY_TIMEOUT_S from .control import ControlCommand, ControlDeadlines, ControlInterceptor, PublishOutcome, PublishState @@ -48,6 +56,11 @@ _LOGGER = logging.getLogger(__name__) +LOCK_STATE_LOCKED = "LOCKED" +"""The `switch/lock-state` value that locks a charger's connector, as the panel declares it.""" +LOCK_STATE_UNLOCKED = "UNLOCKED" +"""The `switch/lock-state` value that unlocks it.""" + # How long to wait for circuit name properties after device ready. # Retained messages typically arrive within 1-2s, but allow headroom. _CIRCUIT_NAMES_TIMEOUT_S = 10.0 @@ -415,6 +428,18 @@ def field_metadata(self) -> dict[str, FieldMetadata] | None: return None return adapter.build_field_metadata() + def masked_tree(self) -> MaskedTree | None: + """The panel's device tree with serials, device ids and site details masked. + + Computed from the adapter's current view at call time. None on a flat + panel, whose adapter does not export a tree, and before the root device + has described itself. + """ + adapter = self._adapter + if isinstance(adapter, TreeExportingAdapter): + return adapter.export_masked_tree() + return None + async def connect(self) -> None: """Connect to MQTT broker and wait for Homie device ready. @@ -949,6 +974,41 @@ async def set_evse_charge_limit(self, node_id: str, amps: int) -> PublishOutcome ) return await self._publish_control(target, payload, self._control_deadlines.evse_charge_limit) + # -- EvseLockControlProtocol ------------------------------------------- + + async def set_evse_lock(self, node_id: str, locked: bool) -> PublishOutcome: + """Lock or unlock one commissioned charger's connector. + + Args: + node_id: the key this charger has in `SpanPanelSnapshot.evse` + locked: True to lock, False to unlock + + **The snapshot is the authorisation**, as for an adopted property: the + charger's `lock_control` is the topic, and it is set only where the + charger declares `switch/lock-state` settable. The value must be one the + declaration's `$format` lists, so a charger that spells its states + differently is refused rather than sent a word it does not know. + """ + value = LOCK_STATE_LOCKED if locked else LOCK_STATE_UNLOCKED + charger = self._require_adapter().build_snapshot().evse.get(node_id) + target = None if charger is None else charger.lock_control + if charger is None or target is None: + await self._refuse_control( + device_id=node_id, + value=value, + detail="no such control", + message=f"No settable lock on EVSE {node_id!r}", + ) + if value not in (charger.lock_state_options or ()): + await self._refuse_control( + target=target, + device_id=target.device_id, + value=value, + detail="value not declared", + message=f"EVSE {node_id!r} does not declare the lock state {value}", + ) + return await self._publish_control(target, value, self._control_deadlines.evse_lock) + # -- AdoptedControlProtocol -------------------------------------------- async def set_adopted_property(self, device_id: str, node_id: str, property_id: str, value: str) -> PublishOutcome: @@ -1039,10 +1099,16 @@ def _observe(self, adapter: SchemaAdapter) -> None: self._unregister_property_observer = adapter.register_property_callback(self._on_property_value) def _on_property_value(self, device_id: str, node_id: str, property_id: str, value: str | None) -> None: - """Record one property's value and resolve any write waiting for it.""" + """Record one property's value and resolve any write waiting for it. + + `None` is a property with no value, such as one the panel cleared. Its + last value is forgotten, so a write of that value is not taken for a + no-op, and no write is confirmed by it. + """ + key = (device_id, node_id, property_id) if value is None: + self._observed_values.pop(key, None) return - key = (device_id, node_id, property_id) self._observed_values[key] = value for verification in list(self._verifications): if verification.key == key and verification.expected == value and not verification.observed.done(): diff --git a/src/span_panel_api/mqtt/control.py b/src/span_panel_api/mqtt/control.py index 64144023..d0e09027 100644 --- a/src/span_panel_api/mqtt/control.py +++ b/src/span_panel_api/mqtt/control.py @@ -105,6 +105,7 @@ class ControlDeadlines: priority: float = 2.0 dominant_power_source: float = 2.0 evse_charge_limit: float = 2.0 + evse_lock: float = 2.0 adopted_property: float = 2.0 diff --git a/src/span_panel_api/protocol.py b/src/span_panel_api/protocol.py index 24f4ed8c..8a60ac0b 100644 --- a/src/span_panel_api/protocol.py +++ b/src/span_panel_api/protocol.py @@ -14,7 +14,7 @@ if TYPE_CHECKING: from ._ssl import LeafNameMismatch from .exceptions import SpanPanelError - from .models import ControlTarget, FieldMetadata, SpanPanelSnapshot, V2HomieSchema + from .models import ControlTarget, FieldMetadata, MaskedTree, SpanPanelSnapshot, V2HomieSchema from .mqtt.control import ControlInterceptor, PublishOutcome @@ -124,6 +124,19 @@ class EvseControlProtocol(Protocol): async def set_evse_charge_limit(self, node_id: str, amps: int) -> PublishOutcome: ... +@runtime_checkable +class EvseLockControlProtocol(Protocol): + """Control protocol for a commissioned EV charger's connector lock. + + A protocol of its own rather than a member on `EvseControlProtocol`, which + would break that protocol's implementers. The write is authorised by the + snapshot: only a charger whose `SpanEvseSnapshot.lock_control` is set can be + addressed, and only with a value its `lock_state_options` lists. + """ + + async def set_evse_lock(self, node_id: str, locked: bool) -> PublishOutcome: ... + + @runtime_checkable class AdoptedControlProtocol(Protocol): """Control protocol for settable properties on a device nothing here models. @@ -373,3 +386,18 @@ def register_property_callback(self, callback: Callable[[str, str, str, str | No `device_id` is the panel serial rather than being omitted. Filling it in is what lets a consumer treat both schemas' streams as one shape. """ + + +@runtime_checkable +class TreeExportingAdapter(Protocol): + """Adapter that can export the device tree it holds, masked for diagnostics. + + A protocol of its own rather than a `SchemaAdapter` member: the required set + of that protocol is derived from itself, so a member added there would be + demanded of every built adapter and invalidate those already shipped. A + consumer asks `isinstance(adapter, TreeExportingAdapter)` and offers the + export only when it holds. + """ + + def export_masked_tree(self) -> MaskedTree | None: + """The masked tree, or None when the adapter holds no tree yet.""" diff --git a/tests/adapter_fidelity/harness.py b/tests/adapter_fidelity/harness.py index 10572311..b307d207 100644 --- a/tests/adapter_fidelity/harness.py +++ b/tests/adapter_fidelity/harness.py @@ -44,7 +44,7 @@ import re from typing import Final -from reference_payloads.schema_one import RetainedTopicTree, devices_from_tree +from reference_payloads.schema_one import RetainedTopicTree, devices_from_tree, retained_payload from span_panel_api.models import ( ADOPTION_IDENTITY_NODE, ADOPTION_TOPOLOGY_NODE, @@ -344,7 +344,7 @@ def _frozen_clock() -> float: def _replay(capture: _Capture) -> SchemaOneAdapter: - """A fresh adapter fed the capture as retained messages.""" + """A fresh adapter fed the capture as retained messages, an empty value as `0x00` (`retained_payload`).""" schema = V2HomieSchema( firmware_version=capture.firmware, types_schema_hash="sha256:capture", @@ -358,7 +358,7 @@ def _replay(capture: _Capture) -> SchemaOneAdapter: adapter.handle_message(f"{prefix}/$description", json.dumps(device.description)) adapter.handle_message(f"{prefix}/$state", "ready") for topic in sorted(device.values): - adapter.handle_message(f"{prefix}/{topic}", device.values[topic]) + adapter.handle_message(f"{prefix}/{topic}", retained_payload(device.values[topic])) return adapter @@ -542,10 +542,21 @@ class _Instance: deferred: bool = False +OUTSIDE_PANEL_ROLE: Final = "meter-outside-panel" +"""The role of a circuit-typed device that declares no breaker space: a meter outside the panel. + +Its own role, because the library reads it in the opposite frame from a hosted +circuit (`circuits.build_circuit` and `SpanCircuitSnapshot.measures_outside_panel`), +so one row could not document both. +""" + + def _role(capture: _Capture, device: _Device) -> str: if device.device_id == capture.root_id: return "panel" short = device.device_type.removeprefix(DEVICE_TYPE_PREFIX) + if device.device_type == TYPE_CIRCUIT and "info/spaces" not in device.declared: + return OUTSIDE_PANEL_ROLE if device.device_type.startswith(TYPE_LUGS): direction = device.values.get("info/direction", "").strip().lower() return f"lugs-{direction}" if direction else "lugs" @@ -598,13 +609,13 @@ def _measure(capture: _Capture, instances: list[_Instance], baseline: Mapping[st # as a later retained value does. target = session if instance.raw is not None else _replay(capture) for candidate in _candidates(instance.declaration, instance.raw, property_id, references): - target.handle_message(topic, candidate) + target.handle_message(topic, retained_payload(candidate)) leaves = _flatten(target) moved = _moved(baseline, leaves) instance.effect |= moved instance.perturbed.append((candidate, {leaf: leaves[leaf] for leaf in moved if leaf in leaves})) if instance.raw is not None: - session.handle_message(topic, instance.raw) + session.handle_message(topic, retained_payload(instance.raw)) unrestored = _moved(baseline, _flatten(session)) if unrestored: raise AssertionError(f"republishing the captured values did not restore the session: {sorted(unrestored)[:5]}") diff --git a/tests/adapter_fidelity/rules.py b/tests/adapter_fidelity/rules.py index 6a49bc06..0ad63dd4 100644 --- a/tests/adapter_fidelity/rules.py +++ b/tests/adapter_fidelity/rules.py @@ -5,7 +5,7 @@ the edit that moves the code. The transform table covers every row of the library's own `_PROPERTY_FIELD_MAP` -and both lugs tables, which `test_every_mapped_field_has_a_documented_transform` +and the three lugs tables, which `test_every_mapped_field_has_a_documented_transform` holds it to: a field the library starts mapping cannot reach a snapshot without a transform documented here. The derivations are only the ones these captures need, which `test_every_derivation_is_needed` holds them to: a justification no @@ -17,7 +17,10 @@ from collections.abc import Callable from typing import Final -from .harness import ANY_LEAF, CellRules, Derivation, DropReason, RowKey, Transform, TransformKind +from span_panel_api.models import FEEDS_ROLES, PROTECTION_FUNCTIONS +from span_panel_api_schema_1.const import PANEL_POSITIONS_BY_MODEL + +from .harness import ANY_LEAF, OUTSIDE_PANEL_ROLE, CellRules, Derivation, DropReason, RowKey, Transform, TransformKind _IDENTITY: Final = TransformKind.IDENTITY _NEGATE: Final = TransformKind.NEGATE @@ -65,6 +68,32 @@ def _listed_spaces(raw: str, value: object) -> bool: return value == tuple(spaces) +def _model_or_none(raw: str, value: object) -> bool: + """`UNKNOWN` (or nothing) names no model and reads as None; a named model reads as published.""" + return value == (None if raw.strip().upper() in ("", "UNKNOWN") else raw) + + +def _position(index: int) -> Callable[[str, object], bool]: + """The model's first (0) or last (1) position from the table; for a model it lacks, the occupied range decides.""" + + def holds(raw: str, value: object) -> bool: + known = PANEL_POSITIONS_BY_MODEL.get(raw.strip().upper()) + if known is None: + return value is None or isinstance(value, int) + return value == known[index] + + return holds + + +def _feeds_role(raw: str, value: object) -> bool: + return value == (raw if raw in FEEDS_ROLES else None) + + +def _protection_functions(raw: str, value: object) -> bool: + listed = [part.strip() for part in raw.split(",")] + return value == tuple(part for part in listed if part in PROTECTION_FUNCTIONS) + + def _transforms() -> dict[RowKey, dict[str, Transform]]: table: dict[RowKey, dict[str, Transform]] = {} @@ -89,8 +118,24 @@ def add( "devices.build_battery: the release build in the firmware version picks the BESS meter's frame", ) add("panel", "info/vendor-name", "panel.vendor_name", _LITERAL, panel_fields) - add("panel", "info/model", "panel.model", _LITERAL, panel_fields) + add( + "panel", + "info/model", + "panel.model", + _DERIVED, + f"{panel_fields}: an UNKNOWN model names no model and reads as None", + _model_or_none, + ) add("panel", "info/model", "panel.panel_size", _DERIVED, "panel.panel_size_from_model and const.PANEL_SIZE_BY_MODEL") + for index, position in enumerate(("first_position", "last_position")): + add( + "panel", + "info/model", + f"panel.{position}", + _DERIVED, + "panel.panel_positions and const.PANEL_POSITIONS_BY_MODEL; the occupied spaces where the table lacks the model", + _position(index), + ) add("panel", "info/hardware-version", "panel.hardware_version", _LITERAL, panel_fields) add("panel", "info/serial-number", "panel.serial_number", _LITERAL, panel_fields) add("panel", "status/relay", "panel.main_relay_state", _LITERAL, panel_fields) @@ -110,6 +155,8 @@ def add( add("panel", "meter/voltage-a", "panel.l1_voltage", _IDENTITY, panel_fields) add("panel", "meter/voltage-b", "panel.l2_voltage", _IDENTITY, panel_fields) add("panel", "breaker/rating", "panel.main_breaker_rating_a", _INT, panel_fields) + add("panel", "meter/busbar-current", "panel.busbar_current_a", _IDENTITY, panel_fields) + add("panel", "meter/frequency", "panel.frequency_hz", _IDENTITY, panel_fields) for flow in ("pv", "battery", "grid", "site"): add( "panel", @@ -125,13 +172,6 @@ def add( _DERIVED, "devices.build_battery: compared in sign with the BESS meter where the firmware names no release build", ) - add( - "panel", - "power-flows/grid", - ANY_LEAF, - _DERIVED, - "panel.resolve_islanding_state: grid power decides on-grid only where no MID is published", - ) add("panel", "shed/policy", "panel.shed_policy", _LITERAL, panel_fields) for policy_field in ("shed_policy_algorithm", "shed_soc_threshold_shed_percent", "shed_soc_threshold_release_percent"): add("panel", "shed/policy", f"panel.{policy_field}", _DERIVED, "panel._shed_policy parses the policy document") @@ -191,6 +231,39 @@ def add( add("circuit", "breaker/poles", "circuit.is_240v", _DERIVED, f"{circuit}: two poles or more", _two_poles_or_more) add("circuit", "info/name", "circuit.name", _LITERAL, circuit) add("circuit", "info/spaces", "circuit.tabs", _DERIVED, "circuits._tabs parses the list of spaces", _listed_spaces) + for position in ("first_position", "last_position"): + add( + "circuit", + "info/spaces", + f"panel.{position}", + _DERIVED, + "panel.panel_positions: the occupied spaces decide the range where the table lacks the model", + ) + add("circuit", "info/nominal-voltage", "circuit.nominal_voltage_v", _IDENTITY, circuit) + add( + "circuit", + "breaker/protection-functions", + "circuit.protection_functions", + _DERIVED, + "circuits._protection_functions: the listed members of PROTECTION_FUNCTIONS, in published order", + _protection_functions, + ) + add( + "circuit", + "connection/feeds-role", + "circuit.feeds_role", + _DERIVED, + "circuits._feeds_role: a member of FEEDS_ROLES as published, else None", + _feeds_role, + ) + for node, shared in (("meter", "circuit.meter_shared_with"), ("switch", "circuit.relay_shared_with")): + add( + "circuit", + f"{node}/shared-with-device-ids", + shared, + _DERIVED, + "circuits._shared_with: the listed ids naming another circuit of the snapshot, in device_id_order", + ) add("circuit", "switch/relay", "circuit.relay_state", _LITERAL, circuit) add("circuit", "switch/relay-requester", "circuit.relay_requester", _LITERAL, circuit) add("circuit", "switch/relay-controllable", "circuit.is_user_controllable", _BOOL, circuit) @@ -226,16 +299,43 @@ def add( _DERIVED, "snapshot.build_snapshot and devices.feed_circuit_ids: the circuit's label, and the fed DER's feeding circuit, key and position", ) - for der in ("evse", "pv", "pv_inverter"): + for der in ("battery", "evse", "pv", "pv_inverter"): add( "circuit", "connection/feeds-device-status", f"{der}.connected", _DERIVED, - "devices.feed_connection_statuses and devices._connected: OK is a working link", + "devices.feed_connection_statuses and devices._connected: OK is a working link " + "(for a battery, where no device claims it through a fed-by record)", _is_ok_link, ) + # --- a circuit-typed device with no breaker space ----------------------- + outside = "circuits.build_circuit: a meter outside the panel reads import-positive, as published" + add(OUTSIDE_PANEL_ROLE, "meter/active-power", "circuit.instant_power_w", _IDENTITY, outside) + add( + OUTSIDE_PANEL_ROLE, + "meter/imported-energy", + "circuit.consumed_energy_wh", + _IDENTITY, + f"{outside}: imported is consumed", + ) + add( + OUTSIDE_PANEL_ROLE, + "meter/exported-energy", + "circuit.produced_energy_wh", + _IDENTITY, + f"{outside}: exported is produced", + ) + add(OUTSIDE_PANEL_ROLE, "meter/current", "circuit.current_a", _IDENTITY, outside) + add( + OUTSIDE_PANEL_ROLE, + "meter/shared-with-device-ids", + "circuit.meter_shared_with", + _DERIVED, + "circuits._shared_with: the listed ids naming another circuit of the snapshot, in device_id_order", + ) + # --- lugs -------------------------------------------------------------- lugs_meter = "panel.PanelFields: the lugs read import-positive and pass through" for role, power, consumed, produced, current_a, current_b in ( @@ -284,6 +384,13 @@ def add( _DERIVED, "devices.resolve_relative_position: a DER fed through the feedthrough is in the panel", ) + add( + "lugs-upstream", + "connection/overcurrent-protection", + "panel.upstream_protection_rating_a", + _INT, + "panel.PanelFields: the upstream lugs' protection rating", + ) # --- BESS -------------------------------------------------------------- battery = "devices.build_battery" @@ -352,6 +459,14 @@ def add( "evse", "info/serial-number", ANY_LEAF, _DERIVED, "snapshot.harmonised_evse_keys: the charger is keyed by its serial" ) add("evse", "info/firmware-version", "evse.software_version", _LITERAL, evse) + # The charge-current pair, in either spelling the charger's description declares. + charge_limit = f"{evse} through charge_limit.resolve_charge_limit, read as an integer" + for node, ceiling, limit in ( + ("config", "max-charge-current", "user-max-charge-current"), + ("charge-limit", "installer-max", "owner-limit"), + ): + add("evse", f"{node}/{ceiling}", "evse.charge_current_ceiling_a", _INT, charge_limit) + add("evse", f"{node}/{limit}", "evse.charge_current_limit_a", _INT, charge_limit) return table @@ -380,6 +495,15 @@ def add( "ctl.dps_target", "adapter.SchemaOneAdapter.set_dominant_power_source_target: a topic, offered where the declaration is `$settable`", ), + Derivation("battery.present", "devices.build_battery: the tree declares a battery, before any of its values"), + Derivation( + "circuit.measures_outside_panel", + "circuits.declares_spaces: whether the description declares info/spaces, not a value", + ), + Derivation( + "panel.publishes_solar_roles", + "snapshot.build_snapshot: whether any circuit's description declares connection/feeds-role, not a value", + ), Derivation("pv.device_id", "devices.build_pv: the inverter's device id"), Derivation("pv.node_id", "devices.pv_inverter_key: the feeding circuit's id, else the inverter's device id"), Derivation("pv_inverter.device_id", "devices.build_pv: the inverter's device id"), @@ -404,4 +528,9 @@ def add( ), } -MAIN32_RULES: Final = CellRules(transforms=_transforms(), derivations=_DERIVATIONS, drops=_DROPS, deferred=_DEFERRED) +TRANSFORMS: Final = _transforms() +"""Every documented transform, shared by every cell: a transform states what the library does, whichever capture shows it.""" + +DROPS: Final = _DROPS + +MAIN32_RULES: Final = CellRules(transforms=TRANSFORMS, derivations=_DERIVATIONS, drops=_DROPS, deferred=_DEFERRED) diff --git a/tests/adapter_fidelity/rules_captured.py b/tests/adapter_fidelity/rules_captured.py new file mode 100644 index 00000000..0e34a8d3 --- /dev/null +++ b/tests/adapter_fidelity/rules_captured.py @@ -0,0 +1,85 @@ +"""What is right for the reference-capture cells, and the code that makes each entry so. + +The transforms and the drop reasons are the ones every cell shares +(`rules.TRANSFORMS`, `rules.DROPS`): a transform states what the library does, +whichever capture shows it. The derivations are only the ones these captures +need, as `test_every_derivation_is_needed` holds them to, so they are chosen +here rather than inherited. + +Four of them are exceptions rather than derivations, and say so: the snapshot +holds `"UNKNOWN"` in a `str` field where the panel publishes nothing for it. +That is the field's long-standing absence value, not a reading; whether those +fields become optional is a type question deferred past 3.8.0. +""" + +from __future__ import annotations + +from typing import Final + +from .harness import CellRules, Derivation +from .rules import DROPS, MAIN32_RULES, TRANSFORMS + +_SHARED: Final = frozenset( + { + "battery.present", + "circuit.circuit_id", + "circuit.device_type", + "circuit.is_never_backup", + "circuit.is_sheddable", + "circuit.measures_outside_panel", + "ctl.dps_target", + "ctl.priority_target", + "panel.publishes_solar_roles", + } +) +"""The MAIN 32 derivations these captures need as well.""" + +_NO_RELAY = ( + "circuits.build_circuit: a device that declares no switch node has no relay, " + "so it is not controllable, not sheddable and not always on" +) +_STR_SENTINEL = "pre-existing str sentinel; type question deferred past 3.8.0" + +_DERIVATIONS: Final = ( + *(derivation for derivation in MAIN32_RULES.derivations if derivation.family in _SHARED), + Derivation("circuit.is_user_controllable", _NO_RELAY, values=(False,)), + Derivation("circuit.is_sheddable", _NO_RELAY, values=(False,)), + Derivation("circuit.always_on", _NO_RELAY, values=(False,)), + Derivation( + "panel.dominant_power_source", + "panel.resolve_dominant_power_source: with no MID, GRID is an elimination, since nothing else can form the grid", + values=("GRID",), + ), + Derivation( + "panel.dsm_state", + "panel.resolve_islanding_state: with no MID, on-grid is the same elimination, since nothing can island the panel", + values=("DSM_ON_GRID",), + ), + Derivation( + "panel.current_run_config", + "panel.resolve_islanding_state: with no MID, on-grid is the same elimination, since nothing can island the panel", + values=("PANEL_ON_GRID",), + ), + Derivation( + "circuit.relay_state", + f"{_STR_SENTINEL}: circuits.build_circuit reads UNKNOWN where the device publishes no switch/relay", + values=("UNKNOWN",), + ), + Derivation( + "circuit.relay_requester", + f"{_STR_SENTINEL}: circuits.build_circuit reads UNKNOWN where the device publishes no switch/relay-requester", + values=("UNKNOWN",), + ), + Derivation( + "circuit.priority", + f"{_STR_SENTINEL}: circuits.build_circuit reads UNKNOWN where the device publishes no load-shed/priority", + values=("UNKNOWN",), + ), + Derivation( + "panel.main_relay_state", + f"{_STR_SENTINEL}: panel.PanelFields reads UNKNOWN while status/relay is unpublished", + values=("UNKNOWN",), + ), +) + +CAPTURED_RULES: Final = CellRules(transforms=TRANSFORMS, derivations=_DERIVATIONS, drops=DROPS, deferred={}) diff --git a/tests/adapter_fidelity/test_capture_fidelity.py b/tests/adapter_fidelity/test_capture_fidelity.py new file mode 100644 index 00000000..e33e0e43 --- /dev/null +++ b/tests/adapter_fidelity/test_capture_fidelity.py @@ -0,0 +1,153 @@ +"""Every property the r202639 reference captures declare reaches the snapshot, faithfully. + +The same measurement as the MAIN 32 cells, over each vendored reference capture +(`tests/fixtures/captures/`, pinned by `test_captures_unchanged.py`): each +declared property is perturbed to see what it moves, and every value is held to +the transform the rules document for it. A property that moves nothing and is +not dropped on purpose by code that says so is silently lost; a value with no +wire behind it is fabricated. + +What the cells pin is keyed by row, never by capture, so a capture added to the +directory is measured by every test here without an edit. +""" + +from __future__ import annotations + +from collections.abc import Mapping +from functools import cache +from typing import Final + +import pytest + +from reference_payloads.captures import CAPTURES, capture_path + +from .harness import DropReason, Fate, FidelityReport, RowKey, run_cell +from .rules_captured import CAPTURED_RULES + +_PEER_TYPE: Final = ( + "the declared type of the device the record names, which the library reads from that device's own " + "$description when it sorts the tree" +) +_DISPATCH: Final = "chooses which adapter parses the tree, so it is consumed before any snapshot exists" +_NODE_RULE: Final = ( + "an identity or topology property, which extension.build_extension_properties skips by node: " + "a label or a wiring fact, never a reading" +) +_SITE: Final = ( + "where the panel is installed: on the identity node, which is never a reading, and on " + "const.SITE_PROPERTIES wherever else a device declares it" +) + +DROPPED_WITH_A_VALUE: Final[Mapping[RowKey, str]] = { + RowKey("circuit", "connection/count"): _NODE_RULE, + RowKey("circuit", "connection/feeds-device-type"): _PEER_TYPE, + RowKey("circuit", "info/dedicated"): _NODE_RULE, + RowKey("circuit", "info/locations"): _NODE_RULE, + RowKey("circuit", "info/tags"): _NODE_RULE, + RowKey("lugs-downstream", "connection/feeds-role"): _NODE_RULE, + RowKey("lugs-upstream", "connection/service-rating"): _NODE_RULE, + RowKey("panel", "info/address-lines"): _SITE, + RowKey("panel", "info/data-model-version"): _DISPATCH, + RowKey("panel", "info/latitude"): _SITE, + RowKey("panel", "info/locality"): _SITE, + RowKey("panel", "info/longitude"): _SITE, + RowKey("panel", "info/name"): _SITE, + RowKey("panel", "info/region"): _SITE, + RowKey("panel", "info/utility-meter-serial-number"): _SITE, +} +"""The valued rows a drop rule covers in some reference capture, each reviewed, with why dropping it is right.""" + +DROPPED_BY_THE_NODE_RULE: Final = ( + RowKey("circuit", "info/tags"), + RowKey("circuit", "info/locations"), + RowKey("circuit", "info/dedicated"), + RowKey("circuit", "connection/backed-up"), + RowKey("lugs-upstream", "connection/service-rating"), + RowKey("lugs-downstream", "connection/feeds-role"), +) +"""Properties the library reads into nothing on purpose, by the identity and topology node rule.""" + + +@cache +def _report(stem: str) -> FidelityReport: + return run_cell(capture_path(stem), CAPTURED_RULES) + + +def _why(report: FidelityReport, leaves: tuple[str, ...]) -> str: + return "\n".join(f"{leaf}: {report.notes[leaf]}" for leaf in leaves) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_no_property_is_silently_dropped(stem: str) -> None: + assert _report(stem).silently_dropped == () + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_nothing_is_deferred(stem: str) -> None: + assert _report(stem).deferred == () + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_only_the_reviewed_rows_are_dropped_with_a_value(stem: str) -> None: + assert set(_report(stem).dropped_with_a_value) <= set(DROPPED_WITH_A_VALUE) + + +def test_every_reviewed_drop_is_seen() -> None: + """A reviewed row no capture drops any more is a stale review.""" + seen = set().union(*(_report(stem).dropped_with_a_value for stem in CAPTURES)) + assert seen == set(DROPPED_WITH_A_VALUE) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_the_node_rule_drops_what_it_should(stem: str) -> None: + rows = _report(stem).rows + for key in DROPPED_BY_THE_NODE_RULE: + if key in rows: + assert rows[key] == (Fate.INTENTIONAL,), key + + +def test_the_captures_declare_what_the_node_rule_drops() -> None: + declared = set().union(*(_report(stem).rows for stem in CAPTURES)) + assert set(DROPPED_BY_THE_NODE_RULE) <= declared + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_no_value_is_fabricated(stem: str) -> None: + report = _report(stem) + assert report.fabricated == (), _why(report, report.fabricated) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_every_mapped_value_matches_its_documented_transform(stem: str) -> None: + report = _report(stem) + assert report.mismatched == (), _why(report, report.mismatched) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_no_leaf_is_fabricated_outside_any_row(stem: str) -> None: + assert _report(stem).unowned_leaves() == frozenset() + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_the_matrix_covers_every_declared_property(stem: str) -> None: + report = _report(stem) + assert sum(1 for fates in report.rows.values() if fates) == len(report.rows) + assert report.declared_property_instances > 0 + assert sum(report.instance_fates.values()) == report.declared_property_instances + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_no_device_is_named_by_its_own_id(stem: str) -> None: + names = _report(stem).grid_forming_names + assert sorted(device_id for device_id, name in names.items() if name == device_id) == [] + + +def test_every_intentional_drop_and_derivation_cites_code() -> None: + assert set(CAPTURED_RULES.drops) == set(DropReason) + assert all(reason.strip() for reason in CAPTURED_RULES.justifications.values()) + + +def test_every_derivation_is_needed() -> None: + """A derivation no leaf needs is a standing excuse for the next fabrication.""" + used = frozenset().union(*(_report(stem).derivations_used for stem in CAPTURES)) + assert {derivation.family for derivation in CAPTURED_RULES.derivations} == used diff --git a/tests/adapter_fidelity/test_harness.py b/tests/adapter_fidelity/test_harness.py index b540161f..b750ad21 100644 --- a/tests/adapter_fidelity/test_harness.py +++ b/tests/adapter_fidelity/test_harness.py @@ -22,6 +22,7 @@ from span_panel_api_schema_1.const import TYPE_CIRCUIT, TYPE_PV from span_panel_api_schema_1.snapshot import build_snapshot +from . import harness from .harness import FidelityReport, RowKey, run_cell from .rules import MAIN32_RULES @@ -192,3 +193,49 @@ def test_a_deferred_row_is_reported_apart_from_the_silent_drops(small_capture: P report = run_cell(small_capture, replace(MAIN32_RULES, deferred={key: "planted for this test"})) assert report.silently_dropped == () assert report.deferred == (key,) + + +_FED_BY = "connection/fed-by-device-id" + + +@pytest.fixture +def valued_empty_capture(small_capture: Path) -> Path: + """The small capture with the upstream lugs publishing an empty `fed-by-device-id`. + + In a `tree-v1` document an empty value is written decoded, as `""`, the way + the masked export writes one: a retained store never holds a zero-length + payload, so `""` there cannot be a clear. + """ + tree = _mapping(json.loads(small_capture.read_text(encoding="utf-8"))) + devices = _mapping(tree["devices"]) + upstream = next( + device_id + for device_id, entry in devices.items() + if _mapping(_mapping(entry)["properties"]).get("info/direction") == "UPSTREAM" + ) + record = _mapping(devices[upstream]) + record["properties"] = {**_mapping(record["properties"]), _FED_BY: ""} + devices[upstream] = record + path = small_capture.with_name("valued-empty-tree-v1.json") + path.write_text(json.dumps({**tree, "devices": devices}), encoding="utf-8") + return path + + +def test_an_empty_value_is_measured_as_published(valued_empty_capture: Path) -> None: + """Published empty, nothing feeds the lugs: they are the service entrance, not unknown. + + Replayed as a zero-length payload, the value would be a clear and read as unpublished. + """ + leaves = harness._flatten(harness._replay(harness._load(valued_empty_capture))) + + assert leaves["panel.lugs_at_service_entrance"] is True + + +def test_republishing_an_empty_value_restores_the_session(valued_empty_capture: Path) -> None: + """Each perturbed property is set back to its captured value; an empty one must go back as a value. + + `run_cell` raises when the session does not end equal to the baseline. + """ + report = run_cell(valued_empty_capture, MAIN32_RULES) + + assert report.declared_property_instances > 0 diff --git a/tests/adapter_fidelity/test_main32_fidelity.py b/tests/adapter_fidelity/test_main32_fidelity.py index c91ef42c..7302690b 100644 --- a/tests/adapter_fidelity/test_main32_fidelity.py +++ b/tests/adapter_fidelity/test_main32_fidelity.py @@ -19,8 +19,13 @@ import pytest -from span_panel_api_schema_1.const import DEVICE_TYPE_PREFIX, NODE_METER, TYPE_PANEL -from span_panel_api_schema_1.field_metadata import _DOWNSTREAM_LUGS_FIELDS, _PROPERTY_FIELD_MAP, _UPSTREAM_LUGS_FIELDS +from span_panel_api_schema_1.const import DEVICE_TYPE_PREFIX, NODE_CONNECTION, NODE_METER, TYPE_PANEL +from span_panel_api_schema_1.field_metadata import ( + _DOWNSTREAM_LUGS_FIELDS, + _PROPERTY_FIELD_MAP, + _UPSTREAM_LUGS_CONNECTION_FIELDS, + _UPSTREAM_LUGS_FIELDS, +) from .harness import DropReason, FidelityReport, RowKey, run_cell from .rules import MAIN32_RULES @@ -160,8 +165,12 @@ def _role(device_type: str) -> str: def test_every_mapped_field_has_a_documented_transform() -> None: """A field the library starts mapping cannot reach a snapshot unchecked.""" mapped = {(RowKey(_role(device_type), f"{node}/{prop}"), path) for device_type, node, prop, path in _PROPERTY_FIELD_MAP} - for role, lugs_fields in (("lugs-upstream", _UPSTREAM_LUGS_FIELDS), ("lugs-downstream", _DOWNSTREAM_LUGS_FIELDS)): - mapped |= {(RowKey(role, f"{NODE_METER}/{prop}"), path) for prop, path in lugs_fields} + for role, node, lugs_fields in ( + ("lugs-upstream", NODE_METER, _UPSTREAM_LUGS_FIELDS), + ("lugs-downstream", NODE_METER, _DOWNSTREAM_LUGS_FIELDS), + ("lugs-upstream", NODE_CONNECTION, _UPSTREAM_LUGS_CONNECTION_FIELDS), + ): + mapped |= {(RowKey(role, f"{node}/{prop}"), path) for prop, path in lugs_fields} missing = sorted((key, path) for key, path in mapped if path not in MAIN32_RULES.transforms.get(key, {})) assert missing == [] diff --git a/tests/conftest.py b/tests/conftest.py index af34e56c..58712cbe 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,12 +2,13 @@ from __future__ import annotations +import ast import asyncio import itertools import json import os from pathlib import Path -from collections.abc import AsyncGenerator +from collections.abc import AsyncGenerator, Iterable from unittest.mock import MagicMock, patch import paho.mqtt.client as paho @@ -15,6 +16,7 @@ from paho.mqtt.client import ConnectFlags from paho.mqtt.reasoncodes import ReasonCode +from expected_failures import EXPECTED_FAILURES import span_panel_api._http as _http_mod from span_panel_api.models import V2HomieSchema from span_panel_api.mqtt.control import ControlDeadlines @@ -49,6 +51,57 @@ def _load_dotenv() -> None: _load_dotenv() +def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]) -> None: + """Mark every test `expected_failures.py` lists as a strict expected failure. + + A row naming a file that does not exist, or a test that file does not + define, is a typo, a rename or a deletion that would silently mark nothing, + so it stops the run. The check reads the files themselves rather than what + this run collected, so a partial run (`-k`, one file) judges every row the + same way a full one does. + """ + stale = stale_rows(EXPECTED_FAILURES, config.rootpath) + if stale: + raise pytest.UsageError(f"expected_failures.py names tests that do not exist: {', '.join(stale)}") + for item in items: + if not isinstance(item, pytest.Function): + continue + path = item.nodeid.partition("::")[0] + reason = EXPECTED_FAILURES.get(f"{path}::{item.originalname}") + if reason is not None: + item.add_marker(pytest.mark.xfail(strict=True, reason=reason)) + + +def stale_rows(rows: Iterable[str], root: Path) -> list[str]: + """The rows, sorted, whose file under `root` is missing or defines no such test.""" + defined: dict[str, frozenset[str]] = {} + stale: list[str] = [] + for key in rows: + path, _, name = key.partition("::") + if path not in defined: + defined[path] = _test_functions(root / path) + if name not in defined[path]: + stale.append(key) + return sorted(stale) + + +def _test_functions(path: Path) -> frozenset[str]: + """The test functions `path` defines under the default `test` prefix, or none if it is not a file. + + At module level or as a method of one of its `Test` classes, read from the + source, so nothing is imported to answer. + """ + if not path.is_file(): + return frozenset() + tree = ast.parse(path.read_text(encoding="utf-8"), filename=str(path)) + functions = (ast.FunctionDef, ast.AsyncFunctionDef) + names = {node.name for node in tree.body if isinstance(node, functions)} + for node in tree.body: + if isinstance(node, ast.ClassDef) and node.name.startswith("Test"): + names.update(member.name for member in node.body if isinstance(member, functions)) + return frozenset(name for name in names if name.startswith("test")) + + @pytest.fixture(autouse=True) def _reset_ssl_cache() -> None: """Ensure the module-level SSL context cache doesn't leak between tests.""" @@ -250,5 +303,6 @@ def _publish(_topic: str, _payload: str) -> asyncio.Future[bool]: priority=0.05, dominant_power_source=0.05, evse_charge_limit=0.05, + evse_lock=0.05, adopted_property=0.05, ) diff --git a/tests/expected_failures.py b/tests/expected_failures.py new file mode 100644 index 00000000..031ccb8f --- /dev/null +++ b/tests/expected_failures.py @@ -0,0 +1,48 @@ +"""Tests expected to fail on this line, each with the reason it does. + +Keyed by pytest node id without parameters or class (`::`), so +every parametrized case of a listed function is expected to fail. `conftest.py` marks +each one `xfail(strict=True)`: a listed test that starts passing fails the run +until its row is deleted, and a row naming a file that does not exist, or a test +function that file does not define, stops the run, partial runs included. + +`PENDING` rows assert behaviour a later change brings; that change deletes +them. `DIVERGENT` rows assert behaviour this library deliberately does not +have; they stay until the test or the decision changes. A strict xfail stops at +its first failing line, so a companion asserts what each `DIVERGENT` test checks +after its divergent line: `test_schema_one_acceptance_companions.py` for the +device-tree tests, and `test_register_rate_limit_companions.py` for +registration. +""" + +from __future__ import annotations + +from collections.abc import Mapping +from typing import Final + +_ACCEPTANCE = "tests/test_schema_one_other_models.py" +_RATE_LIMIT = "tests/test_register_rate_limit.py" + +PENDING: Final[Mapping[str, str]] = {} + +_DEVICE_TYPE_AS_PUBLISHED = "the library keeps device_type as published; a SOLAR feeds-role is carried by feeds_role" + +_RETRY_AFTER_IN_SECONDS = ( + "the delay is SpanPanelRateLimitError.retry_after_s, in seconds, and an HTTP-date Retry-After " + "is read as the seconds until that time" +) + +DIVERGENT: Final[Mapping[str, str]] = { + f"{_ACCEPTANCE}::test_a_circuit_whose_feeds_role_is_solar_is_labeled_pv": _DEVICE_TYPE_AS_PUBLISHED, + f"{_ACCEPTANCE}::test_the_shipped_tree_has_the_other_model_shape": _DEVICE_TYPE_AS_PUBLISHED, + f"{_ACCEPTANCE}::test_the_shipped_tree_reports_its_other_model_only_properties_as_discovered": ( + "the upstream lugs' connection/overcurrent-protection is read into upstream_protection_rating_a, " + "so it is an addressed property rather than a discovered one" + ), + f"{_RATE_LIMIT}::test_raises_the_rate_limit_class_with_its_status": _RETRY_AFTER_IN_SECONDS, + f"{_RATE_LIMIT}::test_retry_after_is_none_without_a_usable_header": _RETRY_AFTER_IN_SECONDS, +} + +assert not PENDING.keys() & DIVERGENT.keys(), "a test is either pending or divergent, never both" + +EXPECTED_FAILURES: Final[Mapping[str, str]] = {**PENDING, **DIVERGENT} diff --git a/tests/fixtures/captures/LICENSE b/tests/fixtures/captures/LICENSE new file mode 100644 index 00000000..1f404548 --- /dev/null +++ b/tests/fixtures/captures/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Bill Flood, Clark Communications Corporation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/tests/fixtures/captures/README.md b/tests/fixtures/captures/README.md new file mode 100644 index 00000000..d28912c3 --- /dev/null +++ b/tests/fixtures/captures/README.md @@ -0,0 +1,17 @@ +# Reference captures + +Masked captures of real panels on firmware `spanos3/r202639/03`. Each `r202639--tree-v1.json` (`r202639-a` to `r202639-e`) is byte-identical to `tests/fixtures/r202639--tree-v1.json` in +[electrification-bus/distribution-enclosure-simulator](https://github.com/electrification-bus/distribution-enclosure-simulator) at commit `79aa07c5382f4f2a253aec2143309b67f0b3a77f`, and is distributed under that repository's MIT license. `LICENSE` here is +that repository's `LICENSE` at the same commit, copied byte for byte. + +**Never regenerated in-test, and never edited here.** No emitter release produces these files, so unlike the payloads under `tests/reference_payloads/` there is nothing to regenerate them from. `SHA256SUMS` pins every byte of the captures and of `LICENSE`, +and `tests/test_captures_unchanged.py` fails on a copy that differs from its pin, on a capture without a pin, on a pin without a file, and on any other file in this directory. The same check by hand: `shasum -a 256 -c SHA256SUMS`, run here. + +**Format.** The emitter's `tree-v1`: per device, the parsed `$description` and the retained values split into `properties` and `numeric_properties`, every value the wire string as published. Identifiers, names, addresses and serial numbers are masked +upstream and are kept exactly as masked. + +**Reading them.** `tests/reference_payloads/captures.py` parses a capture into a `CaptureTree`, replays it through the schema-1 adapter, and offers selectors by what a tree declares. Tests over the captures are properties over `CAPTURES`: they read the +values they expect from the capture they replay, and name no capture, device id or value. + +**Following upstream.** Copy each capture from the new commit with `git show :tests/fixtures/`, and `LICENSE` with `git show :LICENSE`, check each with `git hash-object` against `git rev-parse` of the same path, update `SHA256SUMS` +and the commit above, and expect the capture tests to show what changed. diff --git a/tests/fixtures/captures/SHA256SUMS b/tests/fixtures/captures/SHA256SUMS new file mode 100644 index 00000000..43cb2a39 --- /dev/null +++ b/tests/fixtures/captures/SHA256SUMS @@ -0,0 +1,6 @@ +6174860cd3289ce0d1a39a186e9bbf907504dbac4ef0e00ab0d490d4a0fc2501 LICENSE +f48d9ba5cbd576a48ecbe5acf15fef2b16783fc643b7b58b41e43892f44d28d0 r202639-a-tree-v1.json +a00873f94a78da0dc563ff5fff7491106f9a5d4b6da45d5acf7a1315b190dad3 r202639-b-tree-v1.json +08a6563560cff39dc127fcc855d5376f5e0695259e2a8c11f288aea5a06ef696 r202639-c-tree-v1.json +ae43c1f5bd81a5a93050e0e3571ba0196a78ddc07906ba54833786b9985e96e6 r202639-d-tree-v1.json +eefdc2d1a1ae2884df64e58fdbac423c8f322a739e859c7c88b9151030e2d1d9 r202639-e-tree-v1.json diff --git a/tests/fixtures/captures/r202639-a-tree-v1.json b/tests/fixtures/captures/r202639-a-tree-v1.json new file mode 100644 index 00000000..091cb000 --- /dev/null +++ b/tests/fixtures/captures/r202639-a-tree-v1.json @@ -0,0 +1,1048 @@ +{ + "devices": { + "circuit-3": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-3", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-3940-9ooto", + "root": "xg-3940-9ooto", + "type": "energy.ebus.device.circuit", + "version": 1791326755985 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "4094.9", + "meter/imported-energy": "274.2", + "pcs/priority": "37" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "BATHROOM", + "info/name": "7 Bathroom / Outlets", + "info/spaces": "14", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-4": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-4", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-3940-9ooto", + "root": "xg-3940-9ooto", + "type": "energy.ebus.device.circuit", + "version": 1791326756039 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.1", + "meter/current": "0.0", + "meter/exported-energy": "4153.5", + "meter/imported-energy": "296.2", + "pcs/priority": "37" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "KITCHEN", + "info/name": "6 Kitchen / Outlets", + "info/spaces": "16", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "remote-ct-3": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "remote-ct-3", + "nodes": { + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + } + }, + "parent": "xg-3940-9ooto", + "root": "xg-3940-9ooto", + "type": "energy.ebus.device.circuit", + "version": 1791326756059 + }, + "numeric_properties": { + "meter/active-power": "13.5", + "meter/current": "0.1", + "meter/exported-energy": "944.4", + "meter/imported-energy": "150745.3" + }, + "properties": {} + }, + "xg-3940-9ooto": { + "description": { + "children": [ + "xg-3940-9ooto-lugs-up", + "xg-3940-9ooto-lugs-dn", + "circuit-3", + "circuit-4", + "remote-ct-3" + ], + "extensions": [], + "homie": "5.0", + "name": "SPAN Panel eBus Adapter", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "rating": { + "datatype": "integer", + "name": "Main breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "door": { + "name": "door", + "properties": { + "state": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Door state" + } + }, + "type": "energy.ebus.capability.door" + }, + "info": { + "name": "info", + "properties": { + "address-lines": { + "datatype": "string", + "name": "Street address lines as recorded at commissioning" + }, + "country-code": { + "datatype": "string", + "name": "Country or locale code as recorded at commissioning" + }, + "data-model-version": { + "datatype": "string", + "name": "eBus data-model version (parent/child schema discriminator)" + }, + "firmware-version": { + "datatype": "string", + "name": "Firmware version" + }, + "hardware-version": { + "datatype": "string", + "name": "Hardware version" + }, + "latitude": { + "datatype": "float", + "name": "Site latitude (WGS84 decimal degrees, positive north)", + "unit": "\u00b0" + }, + "locality": { + "datatype": "string", + "name": "City or locality" + }, + "longitude": { + "datatype": "float", + "name": "Site longitude (WGS84 decimal degrees, positive east)", + "unit": "\u00b0" + }, + "model": { + "datatype": "enum", + "format": "UNKNOWN,MAIN_16,MLO_24,MAIN_32,MAIN_40,MLO_48", + "name": "Model" + }, + "name": { + "datatype": "string", + "name": "User-assigned name for the site" + }, + "region": { + "datatype": "string", + "name": "State, province or region" + }, + "serial-number": { + "datatype": "string", + "name": "Serial number" + }, + "utility-meter-serial-number": { + "datatype": "string", + "name": "Serial number of the utility meter serving the site" + }, + "vendor-name": { + "datatype": "string", + "name": "Vendor name" + } + }, + "type": "energy.ebus.capability.info" + }, + "meter": { + "name": "meter", + "properties": { + "busbar-current": { + "datatype": "float", + "name": "Estimated busbar current", + "unit": "A" + }, + "frequency": { + "datatype": "float", + "name": "Line frequency", + "unit": "Hz" + }, + "voltage-a": { + "datatype": "float", + "name": "L1 voltage", + "unit": "V" + }, + "voltage-b": { + "datatype": "float", + "name": "L2 voltage", + "unit": "V" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "active": { + "datatype": "boolean", + "name": "PCS system actively controlling one (or more) loads" + }, + "binding-constraint": { + "datatype": "enum", + "format": "FSR,DOE,VOLTAGE,OFF_GRID,REQUESTED,OPERATOR,NONE,UNKNOWN", + "name": "Which constraint class currently sets the import limit" + }, + "enabled": { + "datatype": "boolean", + "name": "PCS system enabled" + }, + "feed-import-limit": { + "datatype": "float", + "name": "Limit of maximum power feeding the distribution enclosure", + "unit": "A" + }, + "feed-import-limit-active": { + "datatype": "boolean", + "name": "Is feed-import-limit currently being enforced?" + }, + "feed-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the feed-import-limit" + }, + "import-limit": { + "datatype": "float", + "name": "The power import limit currently being managed to", + "unit": "A" + }, + "off-grid-import-limit": { + "datatype": "float", + "name": "Off-Grid limit maximum import power", + "unit": "A" + }, + "off-grid-import-limit-active": { + "datatype": "boolean", + "name": "Is off-grid-import-limit currently being enforced?" + }, + "off-grid-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the off-grid-import-limit" + }, + "operator-import-limit": { + "datatype": "float", + "name": "Operator-imposed maximum import limit", + "unit": "A" + }, + "operator-import-limit-active": { + "datatype": "boolean", + "name": "Is operator-import-limit currently being enforced?" + }, + "operator-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the operator-import-limit" + }, + "requested-import-limit": { + "datatype": "float", + "name": "Requested limit maximum import power", + "unit": "A" + }, + "requested-import-limit-active": { + "datatype": "boolean", + "name": "Is requested-import-limit currently being enforced?" + }, + "requested-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the requested-import-limit" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "power-flows": { + "name": "power-flows", + "properties": { + "battery": { + "datatype": "float", + "name": "Battery/BESS power flow", + "unit": "W" + }, + "grid": { + "datatype": "float", + "name": "Grid power flow", + "unit": "W" + }, + "pv": { + "datatype": "float", + "name": "PV power flow", + "unit": "W" + }, + "site": { + "datatype": "float", + "name": "Site power flow", + "unit": "W" + } + }, + "type": "energy.ebus.capability.power-flows" + }, + "status": { + "name": "status", + "properties": { + "cloud-connection": { + "datatype": "enum", + "format": "UNKNOWN,UNCONNECTED,CONNECTED", + "name": "Device connected to vendor cloud?" + }, + "ethernet": { + "datatype": "boolean", + "name": "Is Ethernet network interface operational?" + }, + "postal-code": { + "datatype": "string", + "name": "Postal (Zip) code" + }, + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Main relay" + }, + "time-zone": { + "datatype": "string", + "name": "Time zone" + }, + "wifi": { + "datatype": "boolean", + "name": "Is Wi-Fi network interface operational?" + }, + "wifi-ssid": { + "datatype": "string", + "name": "SSID to which Wi-Fi network interface is connected" + } + }, + "type": "energy.ebus.capability.status" + } + }, + "type": "energy.ebus.device.distribution-enclosure", + "version": 1791326757028 + }, + "numeric_properties": { + "breaker/rating": "125", + "info/latitude": "0.0", + "info/longitude": "0.0", + "meter/busbar-current": "0.1", + "meter/frequency": "60.04", + "meter/voltage-a": "122.0", + "meter/voltage-b": "122.0", + "pcs/feed-import-limit": "100.0", + "pcs/import-limit": "100.0", + "pcs/operator-import-limit": "0.0", + "pcs/requested-import-limit": "200.0", + "power-flows/grid": "-13.5", + "power-flows/site": "4.8" + }, + "properties": { + "door/state": "CLOSED", + "info/address-lines": "Masked Address", + "info/data-model-version": "1.0", + "info/firmware-version": "spanos3/r202639/03", + "info/hardware-version": "3.0", + "info/locality": "Masked City", + "info/model": "UNKNOWN", + "info/name": "Masked Panel", + "info/region": "CA", + "info/serial-number": "xg-3940-9ooto", + "info/utility-meter-serial-number": "5TZ25874", + "info/vendor-name": "SPAN", + "pcs/active": "true", + "pcs/binding-constraint": "FSR", + "pcs/enabled": "true", + "pcs/feed-import-limit-active": "true", + "pcs/feed-import-limit-enablement": "ENABLED", + "pcs/off-grid-import-limit-active": "false", + "pcs/off-grid-import-limit-enablement": "UNCONFIGURED", + "pcs/operator-import-limit-active": "false", + "pcs/operator-import-limit-enablement": "DISABLED", + "pcs/requested-import-limit-active": "false", + "pcs/requested-import-limit-enablement": "UNCONFIGURED", + "status/cloud-connection": "UNKNOWN", + "status/ethernet": "true", + "status/postal-code": "00000", + "status/time-zone": "America/Los_Angeles", + "status/wifi": "true", + "status/wifi-ssid": "masked-ssid" + } + }, + "xg-3940-9ooto-lugs-dn": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "xg-3940-9ooto-lugs-dn", + "nodes": { + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether the downstream path is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated up/downstream" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the upstream device feeding this lugs" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this lugs" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + }, + "overcurrent-protection": { + "datatype": "integer", + "name": "Overcurrent-protection rating at a connection point that is not itself a breaker-protected circuit", + "unit": "A" + }, + "service-rating": { + "datatype": "integer", + "name": "Utility service rating (service size) at a service-entrance connection point", + "unit": "A" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "direction": { + "datatype": "enum", + "format": "UPSTREAM,DOWNSTREAM", + "name": "Lugs feed direction: upstream or downstream" + } + }, + "type": "energy.ebus.capability.info" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Active power", + "unit": "W" + }, + "current-a": { + "datatype": "float", + "name": "L1 current", + "unit": "A" + }, + "current-b": { + "datatype": "float", + "name": "L2 current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Exported energy", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Imported energy", + "unit": "Wh" + } + }, + "type": "energy.ebus.capability.meter" + } + }, + "parent": "xg-3940-9ooto", + "root": "xg-3940-9ooto", + "type": "energy.ebus.device.lugs", + "version": 1791326755912 + }, + "numeric_properties": { + "meter/current-a": "0.1", + "meter/current-b": "0.1" + }, + "properties": { + "info/direction": "DOWNSTREAM" + } + }, + "xg-3940-9ooto-lugs-up": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "xg-3940-9ooto-lugs-up", + "nodes": { + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether the downstream path is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated up/downstream" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the upstream device feeding this lugs" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this lugs" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + }, + "overcurrent-protection": { + "datatype": "integer", + "name": "Overcurrent-protection rating at a connection point that is not itself a breaker-protected circuit", + "unit": "A" + }, + "service-rating": { + "datatype": "integer", + "name": "Utility service rating (service size) at a service-entrance connection point", + "unit": "A" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "direction": { + "datatype": "enum", + "format": "UPSTREAM,DOWNSTREAM", + "name": "Lugs feed direction: upstream or downstream" + } + }, + "type": "energy.ebus.capability.info" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Active power", + "unit": "W" + }, + "current-a": { + "datatype": "float", + "name": "L1 current", + "unit": "A" + }, + "current-b": { + "datatype": "float", + "name": "L2 current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Exported energy", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Imported energy", + "unit": "Wh" + } + }, + "type": "energy.ebus.capability.meter" + } + }, + "parent": "xg-3940-9ooto", + "root": "xg-3940-9ooto", + "type": "energy.ebus.device.lugs", + "version": 1791326755886 + }, + "numeric_properties": { + "connection/overcurrent-protection": "125", + "connection/service-rating": "100", + "meter/active-power": "8.8", + "meter/current-a": "0.1", + "meter/current-b": "0.1", + "meter/exported-energy": "3.7", + "meter/imported-energy": "123071.0" + }, + "properties": { + "info/direction": "UPSTREAM" + } + } + }, + "metadata": { + "schema": "tree-v1" + } +} diff --git a/tests/fixtures/captures/r202639-b-tree-v1.json b/tests/fixtures/captures/r202639-b-tree-v1.json new file mode 100644 index 00000000..8a3d1e26 --- /dev/null +++ b/tests/fixtures/captures/r202639-b-tree-v1.json @@ -0,0 +1,4039 @@ +{ + "devices": { + "circuit-17": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-17", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1155-18fkf", + "root": "xg-1155-18fkf", + "type": "energy.ebus.device.circuit", + "version": 1791220635257 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "30", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "509.8", + "meter/imported-energy": "398.0", + "pcs/priority": "232" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/name": "breaker-1", + "info/spaces": "9", + "load-shed/priority": "UNKNOWN", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-18": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-18", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1155-18fkf", + "root": "xg-1155-18fkf", + "type": "energy.ebus.device.circuit", + "version": 1791220635308 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "30", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "526.3", + "meter/imported-energy": "392.4", + "pcs/priority": "232" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/name": "breaker-2", + "info/spaces": "10", + "load-shed/priority": "UNKNOWN", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-19": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-19", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1155-18fkf", + "root": "xg-1155-18fkf", + "type": "energy.ebus.device.circuit", + "version": 1791220635358 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "30", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "509.3", + "meter/imported-energy": "402.7", + "pcs/priority": "232" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/name": "breaker-3", + "info/spaces": "11", + "load-shed/priority": "UNKNOWN", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-20": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-20", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1155-18fkf", + "root": "xg-1155-18fkf", + "type": "energy.ebus.device.circuit", + "version": 1791220635407 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "30", + "info/nominal-voltage": "120.0", + "meter/active-power": "-0.1", + "meter/current": "0.0", + "meter/exported-energy": "1544.4", + "meter/imported-energy": "101.6", + "pcs/priority": "232" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/name": "breaker-4", + "info/spaces": "12", + "load-shed/priority": "UNKNOWN", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-21": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-21", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1155-18fkf", + "root": "xg-1155-18fkf", + "type": "energy.ebus.device.circuit", + "version": 1791220635455 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "30", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "527.9", + "meter/imported-energy": "400.3", + "pcs/priority": "232" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/name": "breaker-5", + "info/spaces": "13", + "load-shed/priority": "UNKNOWN", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-22": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-22", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1155-18fkf", + "root": "xg-1155-18fkf", + "type": "energy.ebus.device.circuit", + "version": 1791220635506 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "30", + "info/nominal-voltage": "120.0", + "meter/active-power": "-0.1", + "meter/current": "0.0", + "meter/exported-energy": "43718.5", + "meter/imported-energy": "295.3", + "pcs/priority": "232" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/name": "breaker-6", + "info/spaces": "14", + "load-shed/priority": "UNKNOWN", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-23": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-23", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1155-18fkf", + "root": "xg-1155-18fkf", + "type": "energy.ebus.device.circuit", + "version": 1791220635556 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "30", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "521.4", + "meter/imported-energy": "419.3", + "pcs/priority": "232" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/name": "breaker-7", + "info/spaces": "15", + "load-shed/priority": "UNKNOWN", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-24": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-24", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1155-18fkf", + "root": "xg-1155-18fkf", + "type": "energy.ebus.device.circuit", + "version": 1791220635606 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "30", + "info/nominal-voltage": "120.0", + "meter/active-power": "-0.1", + "meter/current": "0.0", + "meter/exported-energy": "519.0", + "meter/imported-energy": "418.2", + "pcs/priority": "232" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/name": "breaker-8", + "info/spaces": "16", + "load-shed/priority": "UNKNOWN", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-25": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-25", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1155-18fkf", + "root": "xg-1155-18fkf", + "type": "energy.ebus.device.circuit", + "version": 1791220635653 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "30", + "info/nominal-voltage": "120.0", + "meter/active-power": "-0.9", + "meter/current": "0.0", + "meter/exported-energy": "7413.9", + "meter/imported-energy": "74.9", + "pcs/priority": "232" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/name": "breaker-9", + "info/spaces": "17", + "load-shed/priority": "UNKNOWN", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-26": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-26", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1155-18fkf", + "root": "xg-1155-18fkf", + "type": "energy.ebus.device.circuit", + "version": 1791220635705 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "30", + "info/nominal-voltage": "120.0", + "meter/active-power": "-0.1", + "meter/current": "0.0", + "meter/exported-energy": "503.9", + "meter/imported-energy": "386.5", + "pcs/priority": "232" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/name": "breaker-10", + "info/spaces": "18", + "load-shed/priority": "UNKNOWN", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-27": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-27", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1155-18fkf", + "root": "xg-1155-18fkf", + "type": "energy.ebus.device.circuit", + "version": 1791220635753 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "30", + "info/nominal-voltage": "120.0", + "meter/active-power": "-1.1", + "meter/current": "0.0", + "meter/exported-energy": "9727.3", + "meter/imported-energy": "77.9", + "pcs/priority": "232" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/name": "breaker-11", + "info/spaces": "19", + "load-shed/priority": "UNKNOWN", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-28": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-28", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1155-18fkf", + "root": "xg-1155-18fkf", + "type": "energy.ebus.device.circuit", + "version": 1791220635801 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "30", + "info/nominal-voltage": "120.0", + "meter/active-power": "-0.1", + "meter/current": "0.0", + "meter/exported-energy": "516.8", + "meter/imported-energy": "406.3", + "pcs/priority": "232" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/name": "breaker-12", + "info/spaces": "20", + "load-shed/priority": "UNKNOWN", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-29": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-29", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1155-18fkf", + "root": "xg-1155-18fkf", + "type": "energy.ebus.device.circuit", + "version": 1791220635851 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "30", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "511.9", + "meter/imported-energy": "386.4", + "pcs/priority": "232" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/name": "breaker-13", + "info/spaces": "21", + "load-shed/priority": "UNKNOWN", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-30": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-30", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1155-18fkf", + "root": "xg-1155-18fkf", + "type": "energy.ebus.device.circuit", + "version": 1791220635916 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "30", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "524.6", + "meter/imported-energy": "399.7", + "pcs/priority": "232" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/name": "breaker-14", + "info/spaces": "22", + "load-shed/priority": "UNKNOWN", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-31": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-31", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1155-18fkf", + "root": "xg-1155-18fkf", + "type": "energy.ebus.device.circuit", + "version": 1791220635964 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "30", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "515.4", + "meter/imported-energy": "408.2", + "pcs/priority": "232" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/name": "breaker-15", + "info/spaces": "23", + "load-shed/priority": "UNKNOWN", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-32": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-32", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1155-18fkf", + "root": "xg-1155-18fkf", + "type": "energy.ebus.device.circuit", + "version": 1791220636016 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "30", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "508.6", + "meter/imported-energy": "421.8", + "pcs/priority": "232" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/name": "breaker-16", + "info/spaces": "24", + "load-shed/priority": "UNKNOWN", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "remote-ct-3": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "remote-ct-3", + "nodes": { + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + } + }, + "parent": "xg-1155-18fkf", + "root": "xg-1155-18fkf", + "type": "energy.ebus.device.circuit", + "version": 1791220636038 + }, + "numeric_properties": { + "meter/active-power": "0.2", + "meter/current": "0.0", + "meter/exported-energy": "685.2", + "meter/imported-energy": "2202.2" + }, + "properties": {} + }, + "xg-1155-18fkf": { + "description": { + "children": [ + "xg-1155-18fkf-lugs-up", + "xg-1155-18fkf-lugs-dn", + "circuit-17", + "circuit-18", + "circuit-19", + "circuit-20", + "circuit-21", + "circuit-22", + "circuit-23", + "circuit-24", + "circuit-25", + "circuit-26", + "circuit-27", + "circuit-28", + "circuit-29", + "circuit-30", + "circuit-31", + "circuit-32", + "remote-ct-3" + ], + "extensions": [], + "homie": "5.0", + "name": "SPAN Panel eBus Adapter", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "rating": { + "datatype": "integer", + "name": "Main breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "door": { + "name": "door", + "properties": { + "state": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Door state" + } + }, + "type": "energy.ebus.capability.door" + }, + "info": { + "name": "info", + "properties": { + "address-lines": { + "datatype": "string", + "name": "Street address lines as recorded at commissioning" + }, + "country-code": { + "datatype": "string", + "name": "Country or locale code as recorded at commissioning" + }, + "data-model-version": { + "datatype": "string", + "name": "eBus data-model version (parent/child schema discriminator)" + }, + "firmware-version": { + "datatype": "string", + "name": "Firmware version" + }, + "hardware-version": { + "datatype": "string", + "name": "Hardware version" + }, + "latitude": { + "datatype": "float", + "name": "Site latitude (WGS84 decimal degrees, positive north)", + "unit": "\u00b0" + }, + "locality": { + "datatype": "string", + "name": "City or locality" + }, + "longitude": { + "datatype": "float", + "name": "Site longitude (WGS84 decimal degrees, positive east)", + "unit": "\u00b0" + }, + "model": { + "datatype": "enum", + "format": "UNKNOWN,MAIN_16,MLO_24,MAIN_32,MAIN_40,MLO_48", + "name": "Model" + }, + "name": { + "datatype": "string", + "name": "User-assigned name for the site" + }, + "region": { + "datatype": "string", + "name": "State, province or region" + }, + "serial-number": { + "datatype": "string", + "name": "Serial number" + }, + "utility-meter-serial-number": { + "datatype": "string", + "name": "Serial number of the utility meter serving the site" + }, + "vendor-name": { + "datatype": "string", + "name": "Vendor name" + } + }, + "type": "energy.ebus.capability.info" + }, + "meter": { + "name": "meter", + "properties": { + "busbar-current": { + "datatype": "float", + "name": "Estimated busbar current", + "unit": "A" + }, + "frequency": { + "datatype": "float", + "name": "Line frequency", + "unit": "Hz" + }, + "voltage-a": { + "datatype": "float", + "name": "L1 voltage", + "unit": "V" + }, + "voltage-b": { + "datatype": "float", + "name": "L2 voltage", + "unit": "V" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "active": { + "datatype": "boolean", + "name": "PCS system actively controlling one (or more) loads" + }, + "binding-constraint": { + "datatype": "enum", + "format": "FSR,DOE,VOLTAGE,OFF_GRID,REQUESTED,OPERATOR,NONE,UNKNOWN", + "name": "Which constraint class currently sets the import limit" + }, + "enabled": { + "datatype": "boolean", + "name": "PCS system enabled" + }, + "feed-import-limit": { + "datatype": "float", + "name": "Limit of maximum power feeding the distribution enclosure", + "unit": "A" + }, + "feed-import-limit-active": { + "datatype": "boolean", + "name": "Is feed-import-limit currently being enforced?" + }, + "feed-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the feed-import-limit" + }, + "import-limit": { + "datatype": "float", + "name": "The power import limit currently being managed to", + "unit": "A" + }, + "off-grid-import-limit": { + "datatype": "float", + "name": "Off-Grid limit maximum import power", + "unit": "A" + }, + "off-grid-import-limit-active": { + "datatype": "boolean", + "name": "Is off-grid-import-limit currently being enforced?" + }, + "off-grid-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the off-grid-import-limit" + }, + "operator-import-limit": { + "datatype": "float", + "name": "Operator-imposed maximum import limit", + "unit": "A" + }, + "operator-import-limit-active": { + "datatype": "boolean", + "name": "Is operator-import-limit currently being enforced?" + }, + "operator-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the operator-import-limit" + }, + "requested-import-limit": { + "datatype": "float", + "name": "Requested limit maximum import power", + "unit": "A" + }, + "requested-import-limit-active": { + "datatype": "boolean", + "name": "Is requested-import-limit currently being enforced?" + }, + "requested-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the requested-import-limit" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "power-flows": { + "name": "power-flows", + "properties": { + "battery": { + "datatype": "float", + "name": "Battery/BESS power flow", + "unit": "W" + }, + "grid": { + "datatype": "float", + "name": "Grid power flow", + "unit": "W" + }, + "pv": { + "datatype": "float", + "name": "PV power flow", + "unit": "W" + }, + "site": { + "datatype": "float", + "name": "Site power flow", + "unit": "W" + } + }, + "type": "energy.ebus.capability.power-flows" + }, + "status": { + "name": "status", + "properties": { + "cloud-connection": { + "datatype": "enum", + "format": "UNKNOWN,UNCONNECTED,CONNECTED", + "name": "Device connected to vendor cloud?" + }, + "ethernet": { + "datatype": "boolean", + "name": "Is Ethernet network interface operational?" + }, + "postal-code": { + "datatype": "string", + "name": "Postal (Zip) code" + }, + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Main relay" + }, + "time-zone": { + "datatype": "string", + "name": "Time zone" + }, + "wifi": { + "datatype": "boolean", + "name": "Is Wi-Fi network interface operational?" + }, + "wifi-ssid": { + "datatype": "string", + "name": "SSID to which Wi-Fi network interface is connected" + } + }, + "type": "energy.ebus.capability.status" + } + }, + "type": "energy.ebus.device.distribution-enclosure", + "version": 1791220637039 + }, + "numeric_properties": { + "breaker/rating": "100", + "info/latitude": "0.0", + "info/longitude": "0.0", + "meter/busbar-current": "0.1", + "meter/frequency": "60.04", + "meter/voltage-a": "120.2", + "meter/voltage-b": "121.0", + "pcs/feed-import-limit": "100.0", + "pcs/import-limit": "100.0", + "pcs/requested-import-limit": "200.0", + "power-flows/grid": "-0.2", + "power-flows/site": "-8.8" + }, + "properties": { + "door/state": "CLOSED", + "info/address-lines": "Masked Address", + "info/data-model-version": "1.0", + "info/firmware-version": "spanos3/r202639/03", + "info/hardware-version": "3.0", + "info/locality": "Masked City", + "info/model": "MAIN_16", + "info/name": "Masked Panel", + "info/region": "CA", + "info/serial-number": "xg-1155-18fkf", + "info/vendor-name": "SPAN", + "pcs/active": "true", + "pcs/binding-constraint": "FSR", + "pcs/enabled": "true", + "pcs/feed-import-limit-active": "true", + "pcs/feed-import-limit-enablement": "ENABLED", + "pcs/off-grid-import-limit-active": "false", + "pcs/off-grid-import-limit-enablement": "UNCONFIGURED", + "pcs/operator-import-limit-active": "false", + "pcs/operator-import-limit-enablement": "UNCONFIGURED", + "pcs/requested-import-limit-active": "false", + "pcs/requested-import-limit-enablement": "UNCONFIGURED", + "status/cloud-connection": "UNKNOWN", + "status/ethernet": "true", + "status/postal-code": "00000", + "status/time-zone": "America/Los_Angeles", + "status/wifi": "false" + } + }, + "xg-1155-18fkf-lugs-dn": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "xg-1155-18fkf-lugs-dn", + "nodes": { + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether the downstream path is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated up/downstream" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the upstream device feeding this lugs" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this lugs" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + }, + "overcurrent-protection": { + "datatype": "integer", + "name": "Overcurrent-protection rating at a connection point that is not itself a breaker-protected circuit", + "unit": "A" + }, + "service-rating": { + "datatype": "integer", + "name": "Utility service rating (service size) at a service-entrance connection point", + "unit": "A" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "direction": { + "datatype": "enum", + "format": "UPSTREAM,DOWNSTREAM", + "name": "Lugs feed direction: upstream or downstream" + } + }, + "type": "energy.ebus.capability.info" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Active power", + "unit": "W" + }, + "current-a": { + "datatype": "float", + "name": "L1 current", + "unit": "A" + }, + "current-b": { + "datatype": "float", + "name": "L2 current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Exported energy", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Imported energy", + "unit": "Wh" + } + }, + "type": "energy.ebus.capability.meter" + } + }, + "parent": "xg-1155-18fkf", + "root": "xg-1155-18fkf", + "type": "energy.ebus.device.lugs", + "version": 1791220635170 + }, + "numeric_properties": { + "meter/current-a": "0.1", + "meter/current-b": "0.1" + }, + "properties": { + "connection/feeds-role": "UNUSED", + "info/direction": "DOWNSTREAM" + } + }, + "xg-1155-18fkf-lugs-up": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "xg-1155-18fkf-lugs-up", + "nodes": { + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether the downstream path is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated up/downstream" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the upstream device feeding this lugs" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this lugs" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + }, + "overcurrent-protection": { + "datatype": "integer", + "name": "Overcurrent-protection rating at a connection point that is not itself a breaker-protected circuit", + "unit": "A" + }, + "service-rating": { + "datatype": "integer", + "name": "Utility service rating (service size) at a service-entrance connection point", + "unit": "A" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "direction": { + "datatype": "enum", + "format": "UPSTREAM,DOWNSTREAM", + "name": "Lugs feed direction: upstream or downstream" + } + }, + "type": "energy.ebus.capability.info" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Active power", + "unit": "W" + }, + "current-a": { + "datatype": "float", + "name": "L1 current", + "unit": "A" + }, + "current-b": { + "datatype": "float", + "name": "L2 current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Exported energy", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Imported energy", + "unit": "Wh" + } + }, + "type": "energy.ebus.capability.meter" + } + }, + "parent": "xg-1155-18fkf", + "root": "xg-1155-18fkf", + "type": "energy.ebus.device.lugs", + "version": 1791220635144 + }, + "numeric_properties": { + "connection/service-rating": "100", + "meter/active-power": "11.5", + "meter/current-a": "0.1", + "meter/current-b": "0.1", + "meter/exported-energy": "0.0", + "meter/imported-energy": "153921.7" + }, + "properties": { + "info/direction": "UPSTREAM" + } + } + }, + "metadata": { + "schema": "tree-v1" + } +} diff --git a/tests/fixtures/captures/r202639-c-tree-v1.json b/tests/fixtures/captures/r202639-c-tree-v1.json new file mode 100644 index 00000000..d62ac4b4 --- /dev/null +++ b/tests/fixtures/captures/r202639-c-tree-v1.json @@ -0,0 +1,1863 @@ +{ + "devices": { + "circuit-1": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-1", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-7814-15i6h", + "root": "xg-7814-15i6h", + "type": "energy.ebus.device.circuit", + "version": 1791421618537 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "184509.3", + "meter/imported-energy": "427.2", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "BEDROOM", + "info/name": "Bedroom / Lights", + "info/spaces": "9", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-2": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-2", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-7814-15i6h", + "root": "xg-7814-15i6h", + "type": "energy.ebus.device.circuit", + "version": 1791421618586 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "4493.9", + "meter/imported-energy": "108.1", + "pcs/priority": "37" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "BATHROOM", + "info/name": "Bathroom / Outlets", + "info/spaces": "17", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-3": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-3", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-7814-15i6h", + "root": "xg-7814-15i6h", + "type": "energy.ebus.device.circuit", + "version": 1791421618644 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "-0.5", + "meter/current": "0.0", + "meter/exported-energy": "17866.6", + "meter/imported-energy": "111.3", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "LIVING_ROOM", + "info/name": "Living room / Lights", + "info/spaces": "19", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-4": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-4", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)" + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-7814-15i6h", + "root": "xg-7814-15i6h", + "type": "energy.ebus.device.circuit", + "version": 1791421618696 + }, + "numeric_properties": { + "breaker/poles": "2", + "breaker/rating": "30", + "info/nominal-voltage": "240.0", + "meter/active-power": "-0.1", + "meter/current": "0.0", + "meter/exported-energy": "116241.8", + "meter/imported-energy": "758.7", + "pcs/priority": "32" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/name": "Other", + "info/spaces": "10,12", + "info/tags": "OTHER", + "load-shed/priority": "OFF_GRID", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-5": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-5", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)" + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state" + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-7814-15i6h", + "root": "xg-7814-15i6h", + "type": "energy.ebus.device.circuit", + "version": 1791421618751 + }, + "numeric_properties": { + "breaker/poles": "2", + "breaker/rating": "60", + "connection/count": "1", + "info/nominal-voltage": "240.0", + "meter/active-power": "-0.1", + "meter/current": "0.0", + "meter/exported-energy": "139893.5", + "meter/imported-energy": "159710.3", + "pcs/priority": "232" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "connection/feeds-device-id": "xg-7814-15i6h-tg099828190yv6", + "connection/feeds-device-status": "OK", + "connection/feeds-device-type": "energy.ebus.device.bess", + "info/name": "Tesla", + "info/spaces": "43,45", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "false", + "switch/relay-requester": "NONE" + } + }, + "xg-7814-15i6h": { + "description": { + "children": [ + "xg-7814-15i6h-tg099828190yv6", + "xg-7814-15i6h-lugs-up", + "xg-7814-15i6h-lugs-dn", + "circuit-1", + "circuit-2", + "circuit-3", + "circuit-4", + "circuit-5" + ], + "extensions": [], + "homie": "5.0", + "name": "SPAN Panel eBus Adapter", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "rating": { + "datatype": "integer", + "name": "Main breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "door": { + "name": "door", + "properties": { + "state": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Door state" + } + }, + "type": "energy.ebus.capability.door" + }, + "info": { + "name": "info", + "properties": { + "address-lines": { + "datatype": "string", + "name": "Street address lines as recorded at commissioning" + }, + "country-code": { + "datatype": "string", + "name": "Country or locale code as recorded at commissioning" + }, + "data-model-version": { + "datatype": "string", + "name": "eBus data-model version (parent/child schema discriminator)" + }, + "firmware-version": { + "datatype": "string", + "name": "Firmware version" + }, + "hardware-version": { + "datatype": "string", + "name": "Hardware version" + }, + "latitude": { + "datatype": "float", + "name": "Site latitude (WGS84 decimal degrees, positive north)", + "unit": "\u00b0" + }, + "locality": { + "datatype": "string", + "name": "City or locality" + }, + "longitude": { + "datatype": "float", + "name": "Site longitude (WGS84 decimal degrees, positive east)", + "unit": "\u00b0" + }, + "model": { + "datatype": "enum", + "format": "UNKNOWN,MAIN_16,MLO_24,MAIN_32,MAIN_40,MLO_48", + "name": "Model" + }, + "name": { + "datatype": "string", + "name": "User-assigned name for the site" + }, + "region": { + "datatype": "string", + "name": "State, province or region" + }, + "serial-number": { + "datatype": "string", + "name": "Serial number" + }, + "utility-meter-serial-number": { + "datatype": "string", + "name": "Serial number of the utility meter serving the site" + }, + "vendor-name": { + "datatype": "string", + "name": "Vendor name" + } + }, + "type": "energy.ebus.capability.info" + }, + "meter": { + "name": "meter", + "properties": { + "busbar-current": { + "datatype": "float", + "name": "Estimated busbar current", + "unit": "A" + }, + "frequency": { + "datatype": "float", + "name": "Line frequency", + "unit": "Hz" + }, + "voltage-a": { + "datatype": "float", + "name": "L1 voltage", + "unit": "V" + }, + "voltage-b": { + "datatype": "float", + "name": "L2 voltage", + "unit": "V" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "active": { + "datatype": "boolean", + "name": "PCS system actively controlling one (or more) loads" + }, + "binding-constraint": { + "datatype": "enum", + "format": "FSR,DOE,VOLTAGE,OFF_GRID,REQUESTED,OPERATOR,NONE,UNKNOWN", + "name": "Which constraint class currently sets the import limit" + }, + "enabled": { + "datatype": "boolean", + "name": "PCS system enabled" + }, + "feed-import-limit": { + "datatype": "float", + "name": "Limit of maximum power feeding the distribution enclosure", + "unit": "A" + }, + "feed-import-limit-active": { + "datatype": "boolean", + "name": "Is feed-import-limit currently being enforced?" + }, + "feed-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the feed-import-limit" + }, + "import-limit": { + "datatype": "float", + "name": "The power import limit currently being managed to", + "unit": "A" + }, + "off-grid-import-limit": { + "datatype": "float", + "name": "Off-Grid limit maximum import power", + "unit": "A" + }, + "off-grid-import-limit-active": { + "datatype": "boolean", + "name": "Is off-grid-import-limit currently being enforced?" + }, + "off-grid-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the off-grid-import-limit" + }, + "operator-import-limit": { + "datatype": "float", + "name": "Operator-imposed maximum import limit", + "unit": "A" + }, + "operator-import-limit-active": { + "datatype": "boolean", + "name": "Is operator-import-limit currently being enforced?" + }, + "operator-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the operator-import-limit" + }, + "requested-import-limit": { + "datatype": "float", + "name": "Requested limit maximum import power", + "unit": "A" + }, + "requested-import-limit-active": { + "datatype": "boolean", + "name": "Is requested-import-limit currently being enforced?" + }, + "requested-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the requested-import-limit" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "power-flows": { + "name": "power-flows", + "properties": { + "battery": { + "datatype": "float", + "name": "Battery/BESS power flow", + "unit": "W" + }, + "grid": { + "datatype": "float", + "name": "Grid power flow", + "unit": "W" + }, + "pv": { + "datatype": "float", + "name": "PV power flow", + "unit": "W" + }, + "site": { + "datatype": "float", + "name": "Site power flow", + "unit": "W" + } + }, + "type": "energy.ebus.capability.power-flows" + }, + "shed": { + "name": "shed", + "properties": { + "asserted-islanding-state": { + "datatype": "enum", + "format": "NONE,ON_GRID,OFF_GRID", + "name": "Consumer-asserted islanding-state (grid-state override during MID/BESS comm-loss)", + "settable": true + }, + "policy": { + "datatype": "json", + "format": "{\"$id\":\"soc-priority.v1\",\"type\":\"object\",\"required\":[\"algorithm\",\"parameters\"],\"additionalProperties\":false,\"properties\":{\"algorithm\":{\"const\":\"soc-priority.v1\"},\"parameters\":{\"type\":\"object\",\"required\":[\"soc-threshold-shed\",\"soc-threshold-release\"],\"additionalProperties\":false,\"properties\":{\"soc-threshold-shed\":{\"type\":\"integer\",\"minimum\":0,\"maximum\":100,\"description\":\"SoC percent below which SOC_THRESHOLD circuits shed\"},\"soc-threshold-release\":{\"type\":\"integer\",\"minimum\":0,\"maximum\":100,\"description\":\"SoC percent above which shed SOC_THRESHOLD circuits restore\"}}}}}", + "name": "Shed policy (algorithm and parameters)" + } + }, + "type": "energy.ebus.capability.shed" + }, + "shed-forecast": { + "name": "shed-forecast", + "properties": { + "confidence": { + "datatype": "enum", + "format": "LOW,MEDIUM,HIGH", + "name": "Confidence of the shed-forecast estimate" + }, + "full-charge-time-to-priority-shed": { + "datatype": "integer", + "name": "Estimated time to next priority shed assuming BESS starts at full charge", + "unit": "min" + }, + "full-charge-total-time-remaining": { + "datatype": "integer", + "name": "Estimated total time assuming BESS starts at full charge", + "unit": "min" + }, + "time-to-priority-shed": { + "datatype": "integer", + "name": "Estimated time before the next priority tier is shed", + "unit": "min" + }, + "total-time-remaining": { + "datatype": "integer", + "name": "Estimated total time before all sheddable circuits are shed (off-grid runtime)", + "unit": "min" + } + }, + "type": "energy.ebus.capability.shed-forecast" + }, + "status": { + "name": "status", + "properties": { + "cloud-connection": { + "datatype": "enum", + "format": "UNKNOWN,UNCONNECTED,CONNECTED", + "name": "Device connected to vendor cloud?" + }, + "ethernet": { + "datatype": "boolean", + "name": "Is Ethernet network interface operational?" + }, + "postal-code": { + "datatype": "string", + "name": "Postal (Zip) code" + }, + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Main relay" + }, + "time-zone": { + "datatype": "string", + "name": "Time zone" + }, + "wifi": { + "datatype": "boolean", + "name": "Is Wi-Fi network interface operational?" + }, + "wifi-ssid": { + "datatype": "string", + "name": "SSID to which Wi-Fi network interface is connected" + } + }, + "type": "energy.ebus.capability.status" + } + }, + "type": "energy.ebus.device.distribution-enclosure", + "version": 1791421619229 + }, + "numeric_properties": { + "breaker/rating": "90", + "info/latitude": "0.0", + "info/longitude": "0.0", + "meter/busbar-current": "1.2", + "meter/frequency": "60.01", + "meter/voltage-a": "121.7", + "meter/voltage-b": "121.8", + "pcs/feed-import-limit": "90.0", + "pcs/import-limit": "90.0", + "pcs/off-grid-import-limit": "47.9", + "pcs/operator-import-limit": "0.0", + "pcs/requested-import-limit": "200.0", + "power-flows/battery": "0.0", + "power-flows/grid": "-32.0", + "power-flows/pv": "0.0", + "power-flows/site": "33.5" + }, + "properties": { + "door/state": "CLOSED", + "info/address-lines": "Masked Address", + "info/data-model-version": "1.0", + "info/firmware-version": "spanos3/r202639/03", + "info/hardware-version": "3.0", + "info/locality": "Masked City", + "info/model": "MAIN_40", + "info/name": "Masked Panel", + "info/region": "CA", + "info/serial-number": "xg-7814-15i6h", + "info/vendor-name": "SPAN", + "pcs/active": "true", + "pcs/binding-constraint": "FSR", + "pcs/enabled": "true", + "pcs/feed-import-limit-active": "true", + "pcs/feed-import-limit-enablement": "ENABLED", + "pcs/off-grid-import-limit-active": "false", + "pcs/off-grid-import-limit-enablement": "ENABLED", + "pcs/operator-import-limit-active": "false", + "pcs/operator-import-limit-enablement": "DISABLED", + "pcs/requested-import-limit-active": "false", + "pcs/requested-import-limit-enablement": "UNCONFIGURED", + "shed/asserted-islanding-state": "NONE", + "shed/policy": "{\"algorithm\": \"soc-priority.v1\", \"parameters\": {\"soc-threshold-shed\": 49, \"soc-threshold-release\": 51}}", + "status/cloud-connection": "UNKNOWN", + "status/ethernet": "true", + "status/postal-code": "00000", + "status/time-zone": "America/Los_Angeles", + "status/wifi": "true", + "status/wifi-ssid": "masked-ssid" + } + }, + "xg-7814-15i6h-lugs-dn": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "xg-7814-15i6h-lugs-dn", + "nodes": { + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether the downstream path is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated up/downstream" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the upstream device feeding this lugs" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this lugs" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + }, + "overcurrent-protection": { + "datatype": "integer", + "name": "Overcurrent-protection rating at a connection point that is not itself a breaker-protected circuit", + "unit": "A" + }, + "service-rating": { + "datatype": "integer", + "name": "Utility service rating (service size) at a service-entrance connection point", + "unit": "A" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "direction": { + "datatype": "enum", + "format": "UPSTREAM,DOWNSTREAM", + "name": "Lugs feed direction: upstream or downstream" + } + }, + "type": "energy.ebus.capability.info" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Active power", + "unit": "W" + }, + "current-a": { + "datatype": "float", + "name": "L1 current", + "unit": "A" + }, + "current-b": { + "datatype": "float", + "name": "L2 current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Exported energy", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Imported energy", + "unit": "Wh" + } + }, + "type": "energy.ebus.capability.meter" + } + }, + "parent": "xg-7814-15i6h", + "root": "xg-7814-15i6h", + "type": "energy.ebus.device.lugs", + "version": 1791421618469 + }, + "numeric_properties": { + "meter/active-power": "15.1", + "meter/current-a": "0.1", + "meter/current-b": "0.1", + "meter/exported-energy": "37262.1", + "meter/imported-energy": "2887082.7" + }, + "properties": { + "connection/feeds-role": "LOADS", + "info/direction": "DOWNSTREAM" + } + }, + "xg-7814-15i6h-lugs-up": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "xg-7814-15i6h-lugs-up", + "nodes": { + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether the downstream path is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated up/downstream" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the upstream device feeding this lugs" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this lugs" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + }, + "overcurrent-protection": { + "datatype": "integer", + "name": "Overcurrent-protection rating at a connection point that is not itself a breaker-protected circuit", + "unit": "A" + }, + "service-rating": { + "datatype": "integer", + "name": "Utility service rating (service size) at a service-entrance connection point", + "unit": "A" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "direction": { + "datatype": "enum", + "format": "UPSTREAM,DOWNSTREAM", + "name": "Lugs feed direction: upstream or downstream" + } + }, + "type": "energy.ebus.capability.info" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Active power", + "unit": "W" + }, + "current-a": { + "datatype": "float", + "name": "L1 current", + "unit": "A" + }, + "current-b": { + "datatype": "float", + "name": "L2 current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Exported energy", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Imported energy", + "unit": "Wh" + } + }, + "type": "energy.ebus.capability.meter" + } + }, + "parent": "xg-7814-15i6h", + "root": "xg-7814-15i6h", + "type": "energy.ebus.device.lugs", + "version": 1791421618443 + }, + "numeric_properties": { + "connection/service-rating": "90", + "meter/active-power": "13.5", + "meter/current-a": "0.1", + "meter/current-b": "0.1", + "meter/exported-energy": "71227.3", + "meter/imported-energy": "1763610.6" + }, + "properties": { + "info/direction": "UPSTREAM" + } + }, + "xg-7814-15i6h-tg099828190yv6": { + "description": { + "children": [ + "xg-7814-15i6h-tg607533669hu1-esz" + ], + "extensions": [], + "homie": "5.0", + "name": "xg-7814-15i6h-tg099828190yv6", + "nodes": { + "info": { + "name": "info", + "properties": { + "firmware-version": { + "datatype": "string", + "name": "Firmware version" + }, + "model": { + "datatype": "string", + "name": "Model" + }, + "nameplate-capacity": { + "datatype": "float", + "name": "Nameplate capacity", + "unit": "kWh" + }, + "part-number": { + "datatype": "string", + "name": "Part number" + }, + "serial-number": { + "datatype": "string", + "name": "Serial number" + }, + "vendor-name": { + "datatype": "string", + "name": "Vendor name" + } + }, + "type": "energy.ebus.capability.info" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Active power", + "unit": "W" + } + }, + "type": "energy.ebus.capability.meter" + }, + "soc": { + "name": "soc", + "properties": { + "soc": { + "datatype": "float", + "name": "State of charge", + "unit": "%" + }, + "soe": { + "datatype": "float", + "name": "State of energy", + "unit": "kWh" + } + }, + "type": "energy.ebus.capability.soc" + }, + "status": { + "name": "status", + "properties": { + "communication-state": { + "datatype": "enum", + "format": "OK,DEGRADED,LOST,UNKNOWN", + "name": "Communication state" + } + }, + "type": "energy.ebus.capability.status" + } + }, + "parent": "xg-7814-15i6h", + "root": "xg-7814-15i6h", + "type": "energy.ebus.device.bess", + "version": 1791421618345 + }, + "numeric_properties": { + "info/nameplate-capacity": "13.5", + "meter/active-power": "0.0", + "soc/soc": "53.4", + "soc/soe": "7.2" + }, + "properties": { + "info/model": "Powerwall 3", + "info/part-number": "1707000-11-K", + "info/serial-number": "tg099828190yv6", + "info/vendor-name": "Tesla", + "status/communication-state": "OK" + } + }, + "xg-7814-15i6h-tg607533669hu1-esz": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "xg-7814-15i6h-tg607533669hu1-esz", + "nodes": { + "grid": { + "name": "grid", + "properties": { + "grid-forming-entity": { + "datatype": "string", + "name": "Identity of the currently grid-forming entity" + }, + "grid-state": { + "datatype": "enum", + "format": "UP,DOWN,DEGRADED,UNKNOWN", + "name": "Sensed grid condition" + }, + "islanding-state": { + "datatype": "enum", + "format": "ON_GRID,OFF_GRID,UNKNOWN", + "name": "Islanding state of the BESS-integrated grid-forming device" + } + }, + "type": "energy.ebus.capability.grid" + }, + "info": { + "name": "info", + "properties": { + "firmware-version": { + "datatype": "string", + "name": "Firmware version" + }, + "hardware-version": { + "datatype": "string", + "name": "Hardware version" + }, + "model": { + "datatype": "string", + "name": "Model" + }, + "serial-number": { + "datatype": "string", + "name": "Serial number" + }, + "vendor-name": { + "datatype": "string", + "name": "Vendor name" + } + }, + "type": "energy.ebus.capability.info" + } + }, + "parent": "xg-7814-15i6h-tg099828190yv6", + "root": "xg-7814-15i6h", + "type": "energy.ebus.device.mid", + "version": 1791421618358 + }, + "numeric_properties": {}, + "properties": { + "grid/grid-forming-entity": "GRID", + "grid/grid-state": "UNKNOWN", + "grid/islanding-state": "ON_GRID", + "info/serial-number": "tg607533669hu1-esz", + "info/vendor-name": "Tesla" + } + } + }, + "metadata": { + "schema": "tree-v1" + } +} diff --git a/tests/fixtures/captures/r202639-d-tree-v1.json b/tests/fixtures/captures/r202639-d-tree-v1.json new file mode 100644 index 00000000..59ae0089 --- /dev/null +++ b/tests/fixtures/captures/r202639-d-tree-v1.json @@ -0,0 +1,2372 @@ +{ + "devices": { + "circuit-1": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-1", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1334-066e8", + "root": "xg-1334-066e8", + "type": "energy.ebus.device.circuit", + "version": 1791332999159 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "8106.5", + "meter/imported-energy": "402.0", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "BEDROOM,KITCHEN", + "info/name": "Bedroom, Kitchen / Lights", + "info/spaces": "3", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-2": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-2", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1334-066e8", + "root": "xg-1334-066e8", + "type": "energy.ebus.device.circuit", + "version": 1791332999210 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "96785.1", + "meter/imported-energy": "415.9", + "pcs/priority": "37" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "OFFICE", + "info/name": "Office / Outlets", + "info/spaces": "11", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-3": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-3", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1334-066e8", + "root": "xg-1334-066e8", + "type": "energy.ebus.device.circuit", + "version": 1791332999262 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "8337.7", + "meter/imported-energy": "427.3", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "false", + "info/locations": "UTILITY_ROOM", + "info/name": "Utility room / Lights & Outlets", + "info/spaces": "19", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-4": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-4", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1334-066e8", + "root": "xg-1334-066e8", + "type": "energy.ebus.device.circuit", + "version": 1791332999312 + }, + "numeric_properties": { + "breaker/poles": "2", + "breaker/rating": "60", + "info/nominal-voltage": "240.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "12213.2", + "meter/imported-energy": "816.2", + "pcs/priority": "30" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "true", + "info/name": "Electric oven", + "info/spaces": "14,16", + "info/tags": "OVEN", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-5": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-5", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1334-066e8", + "root": "xg-1334-066e8", + "type": "energy.ebus.device.circuit", + "version": 1791332999106 + }, + "numeric_properties": { + "breaker/poles": "2", + "breaker/rating": "60", + "info/nominal-voltage": "240.0", + "meter/active-power": "-9.7", + "meter/current": "0.1", + "meter/exported-energy": "1326749.9", + "meter/imported-energy": "15.2", + "pcs/priority": "1" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "connection/feeds-device-id": "xg-1334-066e8-dt-5599-00321", + "connection/feeds-device-status": "OK", + "connection/feeds-device-type": "energy.ebus.device.evse", + "info/dedicated": "true", + "info/name": "FLEX\u207a", + "info/spaces": "22,24", + "info/tags": "EVSE", + "load-shed/priority": "OFF_GRID", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-8": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-8", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)" + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state" + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1334-066e8", + "root": "xg-1334-066e8", + "type": "energy.ebus.device.circuit", + "version": 1791332999365 + }, + "numeric_properties": { + "breaker/poles": "2", + "breaker/rating": "40", + "connection/count": "1", + "info/nominal-voltage": "240.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "965.9", + "meter/imported-energy": "384.8", + "pcs/priority": "3" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "connection/feeds-device-id": "xg-1334-066e8-6689454643", + "connection/feeds-device-status": "OK", + "connection/feeds-device-type": "energy.ebus.device.bess", + "info/dedicated": "true", + "info/name": "Lucid charger", + "info/spaces": "13,15", + "info/tags": "EVSE", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "OPEN", + "switch/relay-controllable": "false", + "switch/relay-requester": "FAULT" + } + }, + "circuit-9": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-9", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1334-066e8", + "root": "xg-1334-066e8", + "type": "energy.ebus.device.circuit", + "version": 1791332999415 + }, + "numeric_properties": { + "breaker/poles": "2", + "breaker/rating": "20", + "info/nominal-voltage": "240.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "78533900304.6", + "meter/imported-energy": "456.5" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/name": "Neutral forming transformer (NFT)", + "info/spaces": "6,8", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "xg-1334-066e8": { + "description": { + "children": [ + "xg-1334-066e8-6689454643", + "xg-1334-066e8-lugs-up", + "xg-1334-066e8-lugs-dn", + "circuit-5", + "circuit-1", + "circuit-2", + "circuit-3", + "circuit-4", + "circuit-8", + "circuit-9", + "xg-1334-066e8-dt-5599-00321" + ], + "extensions": [], + "homie": "5.0", + "name": "SPAN Panel eBus Adapter", + "nodes": { + "door": { + "name": "door", + "properties": { + "state": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Door state" + } + }, + "type": "energy.ebus.capability.door" + }, + "info": { + "name": "info", + "properties": { + "address-lines": { + "datatype": "string", + "name": "Street address lines as recorded at commissioning" + }, + "country-code": { + "datatype": "string", + "name": "Country or locale code as recorded at commissioning" + }, + "data-model-version": { + "datatype": "string", + "name": "eBus data-model version (parent/child schema discriminator)" + }, + "firmware-version": { + "datatype": "string", + "name": "Firmware version" + }, + "hardware-version": { + "datatype": "string", + "name": "Hardware version" + }, + "latitude": { + "datatype": "float", + "name": "Site latitude (WGS84 decimal degrees, positive north)", + "unit": "\u00b0" + }, + "locality": { + "datatype": "string", + "name": "City or locality" + }, + "longitude": { + "datatype": "float", + "name": "Site longitude (WGS84 decimal degrees, positive east)", + "unit": "\u00b0" + }, + "model": { + "datatype": "enum", + "format": "UNKNOWN,MAIN_16,MLO_24,MAIN_32,MAIN_40,MLO_48", + "name": "Model" + }, + "name": { + "datatype": "string", + "name": "User-assigned name for the site" + }, + "region": { + "datatype": "string", + "name": "State, province or region" + }, + "serial-number": { + "datatype": "string", + "name": "Serial number" + }, + "utility-meter-serial-number": { + "datatype": "string", + "name": "Serial number of the utility meter serving the site" + }, + "vendor-name": { + "datatype": "string", + "name": "Vendor name" + } + }, + "type": "energy.ebus.capability.info" + }, + "meter": { + "name": "meter", + "properties": { + "busbar-current": { + "datatype": "float", + "name": "Estimated busbar current", + "unit": "A" + }, + "frequency": { + "datatype": "float", + "name": "Line frequency", + "unit": "Hz" + }, + "voltage-a": { + "datatype": "float", + "name": "L1 voltage", + "unit": "V" + }, + "voltage-b": { + "datatype": "float", + "name": "L2 voltage", + "unit": "V" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "active": { + "datatype": "boolean", + "name": "PCS system actively controlling one (or more) loads" + }, + "binding-constraint": { + "datatype": "enum", + "format": "FSR,DOE,VOLTAGE,OFF_GRID,REQUESTED,OPERATOR,NONE,UNKNOWN", + "name": "Which constraint class currently sets the import limit" + }, + "enabled": { + "datatype": "boolean", + "name": "PCS system enabled" + }, + "feed-import-limit": { + "datatype": "float", + "name": "Limit of maximum power feeding the distribution enclosure", + "unit": "A" + }, + "feed-import-limit-active": { + "datatype": "boolean", + "name": "Is feed-import-limit currently being enforced?" + }, + "feed-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the feed-import-limit" + }, + "import-limit": { + "datatype": "float", + "name": "The power import limit currently being managed to", + "unit": "A" + }, + "off-grid-import-limit": { + "datatype": "float", + "name": "Off-Grid limit maximum import power", + "unit": "A" + }, + "off-grid-import-limit-active": { + "datatype": "boolean", + "name": "Is off-grid-import-limit currently being enforced?" + }, + "off-grid-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the off-grid-import-limit" + }, + "operator-import-limit": { + "datatype": "float", + "name": "Operator-imposed maximum import limit", + "unit": "A" + }, + "operator-import-limit-active": { + "datatype": "boolean", + "name": "Is operator-import-limit currently being enforced?" + }, + "operator-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the operator-import-limit" + }, + "requested-import-limit": { + "datatype": "float", + "name": "Requested limit maximum import power", + "unit": "A" + }, + "requested-import-limit-active": { + "datatype": "boolean", + "name": "Is requested-import-limit currently being enforced?" + }, + "requested-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the requested-import-limit" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "power-flows": { + "name": "power-flows", + "properties": { + "battery": { + "datatype": "float", + "name": "Battery/BESS power flow", + "unit": "W" + }, + "grid": { + "datatype": "float", + "name": "Grid power flow", + "unit": "W" + }, + "pv": { + "datatype": "float", + "name": "PV power flow", + "unit": "W" + }, + "site": { + "datatype": "float", + "name": "Site power flow", + "unit": "W" + } + }, + "type": "energy.ebus.capability.power-flows" + }, + "shed": { + "name": "shed", + "properties": { + "asserted-islanding-state": { + "datatype": "enum", + "format": "NONE,ON_GRID,OFF_GRID", + "name": "Consumer-asserted islanding-state (grid-state override during MID/BESS comm-loss)", + "settable": true + }, + "policy": { + "datatype": "json", + "format": "{\"$id\":\"soc-priority.v1\",\"type\":\"object\",\"required\":[\"algorithm\",\"parameters\"],\"additionalProperties\":false,\"properties\":{\"algorithm\":{\"const\":\"soc-priority.v1\"},\"parameters\":{\"type\":\"object\",\"required\":[\"soc-threshold-shed\",\"soc-threshold-release\"],\"additionalProperties\":false,\"properties\":{\"soc-threshold-shed\":{\"type\":\"integer\",\"minimum\":0,\"maximum\":100,\"description\":\"SoC percent below which SOC_THRESHOLD circuits shed\"},\"soc-threshold-release\":{\"type\":\"integer\",\"minimum\":0,\"maximum\":100,\"description\":\"SoC percent above which shed SOC_THRESHOLD circuits restore\"}}}}}", + "name": "Shed policy (algorithm and parameters)" + } + }, + "type": "energy.ebus.capability.shed" + }, + "shed-forecast": { + "name": "shed-forecast", + "properties": { + "confidence": { + "datatype": "enum", + "format": "LOW,MEDIUM,HIGH", + "name": "Confidence of the shed-forecast estimate" + }, + "full-charge-time-to-priority-shed": { + "datatype": "integer", + "name": "Estimated time to next priority shed assuming BESS starts at full charge", + "unit": "min" + }, + "full-charge-total-time-remaining": { + "datatype": "integer", + "name": "Estimated total time assuming BESS starts at full charge", + "unit": "min" + }, + "time-to-priority-shed": { + "datatype": "integer", + "name": "Estimated time before the next priority tier is shed", + "unit": "min" + }, + "total-time-remaining": { + "datatype": "integer", + "name": "Estimated total time before all sheddable circuits are shed (off-grid runtime)", + "unit": "min" + } + }, + "type": "energy.ebus.capability.shed-forecast" + }, + "status": { + "name": "status", + "properties": { + "cloud-connection": { + "datatype": "enum", + "format": "UNKNOWN,UNCONNECTED,CONNECTED", + "name": "Device connected to vendor cloud?" + }, + "ethernet": { + "datatype": "boolean", + "name": "Is Ethernet network interface operational?" + }, + "postal-code": { + "datatype": "string", + "name": "Postal (Zip) code" + }, + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Main relay" + }, + "time-zone": { + "datatype": "string", + "name": "Time zone" + }, + "wifi": { + "datatype": "boolean", + "name": "Is Wi-Fi network interface operational?" + }, + "wifi-ssid": { + "datatype": "string", + "name": "SSID to which Wi-Fi network interface is connected" + } + }, + "type": "energy.ebus.capability.status" + } + }, + "type": "energy.ebus.device.distribution-enclosure", + "version": 1791333000039 + }, + "numeric_properties": { + "info/latitude": "0.0", + "info/longitude": "0.0", + "meter/busbar-current": "0.1", + "meter/frequency": "60.01", + "meter/voltage-a": "122.1", + "meter/voltage-b": "121.9", + "pcs/feed-import-limit": "80.0", + "pcs/import-limit": "80.0", + "pcs/operator-import-limit": "0.0", + "pcs/requested-import-limit": "200.0", + "power-flows/battery": "0.0", + "power-flows/grid": "-18.9", + "power-flows/site": "9.7" + }, + "properties": { + "door/state": "CLOSED", + "info/address-lines": "Masked Address", + "info/data-model-version": "1.0", + "info/firmware-version": "spanos3/r202639/03", + "info/hardware-version": "3.0", + "info/locality": "Masked City", + "info/model": "MLO_24", + "info/name": "Masked Panel", + "info/region": "CA", + "info/serial-number": "xg-1334-066e8", + "info/vendor-name": "SPAN", + "pcs/active": "true", + "pcs/binding-constraint": "FSR", + "pcs/enabled": "true", + "pcs/feed-import-limit-active": "true", + "pcs/feed-import-limit-enablement": "ENABLED", + "pcs/off-grid-import-limit-active": "false", + "pcs/off-grid-import-limit-enablement": "DISABLED", + "pcs/operator-import-limit-active": "false", + "pcs/operator-import-limit-enablement": "DISABLED", + "pcs/requested-import-limit-active": "false", + "pcs/requested-import-limit-enablement": "UNCONFIGURED", + "shed/asserted-islanding-state": "NONE", + "shed/policy": "{\"algorithm\": \"soc-priority.v1\", \"parameters\": {\"soc-threshold-shed\": 49, \"soc-threshold-release\": 51}}", + "status/cloud-connection": "UNKNOWN", + "status/ethernet": "true", + "status/postal-code": "00000", + "status/time-zone": "America/Los_Angeles", + "status/wifi": "true", + "status/wifi-ssid": "masked-ssid" + } + }, + "xg-1334-066e8-0751202395-uex": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "xg-1334-066e8-0751202395-uex", + "nodes": { + "grid": { + "name": "grid", + "properties": { + "grid-forming-entity": { + "datatype": "string", + "name": "Identity of the currently grid-forming entity" + }, + "grid-state": { + "datatype": "enum", + "format": "UP,DOWN,DEGRADED,UNKNOWN", + "name": "Sensed grid condition" + }, + "islanding-state": { + "datatype": "enum", + "format": "ON_GRID,OFF_GRID,UNKNOWN", + "name": "Islanding state of the BESS-integrated grid-forming device" + } + }, + "type": "energy.ebus.capability.grid" + }, + "info": { + "name": "info", + "properties": { + "firmware-version": { + "datatype": "string", + "name": "Firmware version" + }, + "hardware-version": { + "datatype": "string", + "name": "Hardware version" + }, + "model": { + "datatype": "string", + "name": "Model" + }, + "serial-number": { + "datatype": "string", + "name": "Serial number" + }, + "vendor-name": { + "datatype": "string", + "name": "Vendor name" + } + }, + "type": "energy.ebus.capability.info" + } + }, + "parent": "xg-1334-066e8-6689454643", + "root": "xg-1334-066e8", + "type": "energy.ebus.device.mid", + "version": 1791332998903 + }, + "numeric_properties": {}, + "properties": { + "grid/grid-state": "UNKNOWN", + "info/serial-number": "0751202395-uex", + "info/vendor-name": "Lucid" + } + }, + "xg-1334-066e8-6689454643": { + "description": { + "children": [ + "xg-1334-066e8-0751202395-uex" + ], + "extensions": [], + "homie": "5.0", + "name": "xg-1334-066e8-6689454643", + "nodes": { + "info": { + "name": "info", + "properties": { + "firmware-version": { + "datatype": "string", + "name": "Firmware version" + }, + "model": { + "datatype": "string", + "name": "Model" + }, + "nameplate-capacity": { + "datatype": "float", + "name": "Nameplate capacity", + "unit": "kWh" + }, + "part-number": { + "datatype": "string", + "name": "Part number" + }, + "serial-number": { + "datatype": "string", + "name": "Serial number" + }, + "vendor-name": { + "datatype": "string", + "name": "Vendor name" + } + }, + "type": "energy.ebus.capability.info" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Active power", + "unit": "W" + } + }, + "type": "energy.ebus.capability.meter" + }, + "soc": { + "name": "soc", + "properties": { + "soc": { + "datatype": "float", + "name": "State of charge", + "unit": "%" + }, + "soe": { + "datatype": "float", + "name": "State of energy", + "unit": "kWh" + } + }, + "type": "energy.ebus.capability.soc" + }, + "status": { + "name": "status", + "properties": { + "communication-state": { + "datatype": "enum", + "format": "OK,DEGRADED,LOST,UNKNOWN", + "name": "Communication state" + } + }, + "type": "energy.ebus.capability.status" + } + }, + "parent": "xg-1334-066e8", + "root": "xg-1334-066e8", + "type": "energy.ebus.device.bess", + "version": 1791332998888 + }, + "numeric_properties": { + "meter/active-power": "0.0" + }, + "properties": { + "info/part-number": "P21-Y04401-00", + "info/serial-number": "6689454643", + "info/vendor-name": "Lucid", + "status/communication-state": "OK" + } + }, + "xg-1334-066e8-dt-5599-00321": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "xg-1334-066e8-dt-5599-00321", + "nodes": { + "config": { + "name": "config", + "properties": { + "max-charge-current": { + "datatype": "integer", + "name": "Commissioned maximum EVSE charge current (installer-configured)", + "unit": "A" + }, + "user-max-charge-current": { + "datatype": "integer", + "format": "6:48", + "name": "User-configured maximum EVSE charge current (ceiling)", + "settable": true, + "unit": "A" + } + }, + "type": "energy.ebus.capability.config" + }, + "info": { + "name": "info", + "properties": { + "firmware-version": { + "datatype": "string", + "name": "Firmware version" + }, + "model": { + "datatype": "string", + "name": "Model" + }, + "part-number": { + "datatype": "string", + "name": "Part number" + }, + "serial-number": { + "datatype": "string", + "name": "Serial number" + }, + "vendor-name": { + "datatype": "string", + "name": "Vendor name" + } + }, + "type": "energy.ebus.capability.info" + }, + "status": { + "name": "status", + "properties": { + "status": { + "datatype": "enum", + "format": "AVAILABLE,PREPARING,CHARGING,UNAVAILABLE", + "name": "Status" + } + }, + "type": "energy.ebus.capability.status" + }, + "switch": { + "name": "switch", + "properties": { + "lock-state": { + "datatype": "enum", + "format": "UNLOCKED,LOCKED", + "name": "Lock state", + "settable": true + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-1334-066e8", + "root": "xg-1334-066e8", + "type": "energy.ebus.device.evse", + "version": 1791332999440 + }, + "numeric_properties": { + "config/max-charge-current": "48", + "config/user-max-charge-current": "48" + }, + "properties": { + "info/firmware-version": "001.001.011.980bd33.8a49f9f1.b1c7ea7d.A", + "info/part-number": "1-09001", + "info/serial-number": "dt-5599-00321", + "info/vendor-name": "SPAN", + "status/status": "AVAILABLE", + "switch/lock-state": "UNLOCKED" + } + }, + "xg-1334-066e8-lugs-dn": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "xg-1334-066e8-lugs-dn", + "nodes": { + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether the downstream path is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated up/downstream" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the upstream device feeding this lugs" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this lugs" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + }, + "overcurrent-protection": { + "datatype": "integer", + "name": "Overcurrent-protection rating at a connection point that is not itself a breaker-protected circuit", + "unit": "A" + }, + "service-rating": { + "datatype": "integer", + "name": "Utility service rating (service size) at a service-entrance connection point", + "unit": "A" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "direction": { + "datatype": "enum", + "format": "UPSTREAM,DOWNSTREAM", + "name": "Lugs feed direction: upstream or downstream" + } + }, + "type": "energy.ebus.capability.info" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Active power", + "unit": "W" + }, + "current-a": { + "datatype": "float", + "name": "L1 current", + "unit": "A" + }, + "current-b": { + "datatype": "float", + "name": "L2 current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Exported energy", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Imported energy", + "unit": "Wh" + } + }, + "type": "energy.ebus.capability.meter" + } + }, + "parent": "xg-1334-066e8", + "root": "xg-1334-066e8", + "type": "energy.ebus.device.lugs", + "version": 1791332999014 + }, + "numeric_properties": { + "meter/current-a": "0.1", + "meter/current-b": "0.1" + }, + "properties": { + "connection/feeds-role": "UNUSED", + "info/direction": "DOWNSTREAM" + } + }, + "xg-1334-066e8-lugs-up": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "xg-1334-066e8-lugs-up", + "nodes": { + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether the downstream path is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated up/downstream" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the upstream device feeding this lugs" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this lugs" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + }, + "overcurrent-protection": { + "datatype": "integer", + "name": "Overcurrent-protection rating at a connection point that is not itself a breaker-protected circuit", + "unit": "A" + }, + "service-rating": { + "datatype": "integer", + "name": "Utility service rating (service size) at a service-entrance connection point", + "unit": "A" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "direction": { + "datatype": "enum", + "format": "UPSTREAM,DOWNSTREAM", + "name": "Lugs feed direction: upstream or downstream" + } + }, + "type": "energy.ebus.capability.info" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Active power", + "unit": "W" + }, + "current-a": { + "datatype": "float", + "name": "L1 current", + "unit": "A" + }, + "current-b": { + "datatype": "float", + "name": "L2 current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Exported energy", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Imported energy", + "unit": "Wh" + } + }, + "type": "energy.ebus.capability.meter" + } + }, + "parent": "xg-1334-066e8", + "root": "xg-1334-066e8", + "type": "energy.ebus.device.lugs", + "version": 1791332998987 + }, + "numeric_properties": { + "connection/overcurrent-protection": "80", + "connection/service-rating": "100", + "meter/active-power": "19.1", + "meter/current-a": "0.1", + "meter/current-b": "0.1", + "meter/exported-energy": "0.0", + "meter/imported-energy": "1633751.9" + }, + "properties": { + "info/direction": "UPSTREAM" + } + } + }, + "metadata": { + "schema": "tree-v1" + } +} diff --git a/tests/fixtures/captures/r202639-e-tree-v1.json b/tests/fixtures/captures/r202639-e-tree-v1.json new file mode 100644 index 00000000..94c8eb4f --- /dev/null +++ b/tests/fixtures/captures/r202639-e-tree-v1.json @@ -0,0 +1,10577 @@ +{ + "devices": { + "circuit-1": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-1", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423355649 + }, + "numeric_properties": { + "breaker/poles": "2", + "breaker/rating": "35", + "info/nominal-voltage": "240.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "60911.5", + "meter/imported-energy": "373.3", + "pcs/priority": "40" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "true", + "info/name": "HVAC", + "info/spaces": "1,3", + "info/tags": "HVAC", + "load-shed/priority": "OFF_GRID", + "pcs/managed": "true", + "switch/relay": "OPEN", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-12": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-12", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423356384 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "-0.1", + "meter/current": "0.0", + "meter/exported-energy": "726.9", + "meter/imported-energy": "546.7", + "pcs/priority": "47" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "true", + "info/name": "Kitchen Sink Garbage Disposal", + "info/spaces": "23", + "info/tags": "DISPOSAL", + "load-shed/priority": "SOC_THRESHOLD", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-13": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-13", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423356460 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "677.1", + "meter/imported-energy": "509.7", + "pcs/priority": "46" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "true", + "info/name": "Dishwasher", + "info/spaces": "25", + "info/tags": "DISHWASHER", + "load-shed/priority": "SOC_THRESHOLD", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-14": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-14", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423356529 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "671.9", + "meter/imported-energy": "504.2", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "false", + "info/locations": "OFFICE", + "info/name": "Main Office & Fam TV", + "info/spaces": "27", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-15": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-15", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423356587 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.1", + "meter/current": "0.0", + "meter/exported-energy": "717.4", + "meter/imported-energy": "549.8", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "false", + "info/locations": "BASEMENT", + "info/name": "Basement Outlets French Door Wall", + "info/spaces": "29", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-16": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-16", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423356651 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "712.7", + "meter/imported-energy": "548.5", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "false", + "info/locations": "BASEMENT", + "info/name": "Basement / Lights & Outlets", + "info/spaces": "31", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-17": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-17", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423356716 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "-0.1", + "meter/current": "0.0", + "meter/exported-energy": "678.9", + "meter/imported-energy": "522.7", + "pcs/priority": "37" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "BATHROOM", + "info/name": "Utility Room", + "info/spaces": "33", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-18": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-18", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423356781 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "664.0", + "meter/imported-energy": "495.1", + "pcs/priority": "44" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "true", + "info/name": "Hood", + "info/spaces": "35", + "info/tags": "HOOD", + "load-shed/priority": "UNKNOWN", + "pcs/managed": "false", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-19": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-19", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423356850 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "726.3", + "meter/imported-energy": "555.1", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "false", + "info/locations": "BASEMENT", + "info/name": "Basement / Lights & Outlets", + "info/spaces": "37", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-2": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-2", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423355726 + }, + "numeric_properties": { + "breaker/poles": "2", + "breaker/rating": "30", + "info/nominal-voltage": "240.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "1012.5", + "meter/imported-energy": "19111749.6", + "pcs/priority": "9" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "true", + "info/name": "Heat Pump Water Heater", + "info/spaces": "5,7", + "info/tags": "WATER_HEATER_HEAT_PUMP", + "load-shed/priority": "SOC_THRESHOLD", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-21": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-21", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423356917 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "485.9", + "meter/imported-energy": "375.2", + "pcs/priority": "17" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "true", + "info/name": "Electric Infared Sauna", + "info/spaces": "43", + "info/tags": "SAUNA_HEATER", + "load-shed/priority": "OFF_GRID", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-22": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-22", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423356979 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "709.6", + "meter/imported-energy": "547.7", + "pcs/priority": "37" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "OFFICE", + "info/name": "Main Office Dedicated Outlets", + "info/spaces": "45", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-23": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-23", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423357049 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "720.5", + "meter/imported-energy": "554.7", + "pcs/priority": "5" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "true", + "info/name": "Bidet Outlets Basement & Main Floor", + "info/spaces": "47", + "info/tags": "MACHINERY", + "load-shed/priority": "OFF_GRID", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-24": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-24", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423357133 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "520.7", + "meter/imported-energy": "414.4", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "false", + "info/locations": "DINING_ROOM", + "info/name": "Dining room / Lights & Outlets", + "info/spaces": "10", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-25": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-25", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423357209 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "527.5", + "meter/imported-energy": "420.5", + "pcs/priority": "37" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "KITCHEN", + "info/name": "Kitchen fr. door & Isle Alt. Outlets", + "info/spaces": "12", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-26": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-26", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423357286 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "426.4", + "meter/imported-energy": "339.8", + "pcs/priority": "20" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "true", + "info/name": "Furnace", + "info/spaces": "14", + "info/tags": "FURNACE", + "load-shed/priority": "SOC_THRESHOLD", + "pcs/managed": "true", + "switch/relay": "OPEN", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-27": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-27", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423357369 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "513.3", + "meter/imported-energy": "408.9", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "false", + "info/locations": "BEDROOM", + "info/name": "Bed 2 & Shared Bath Lights & Outlets", + "info/spaces": "16", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-28": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-28", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423357451 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "-0.1", + "meter/current": "0.0", + "meter/exported-energy": "664.0", + "meter/imported-energy": "505.6", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "false", + "info/locations": "MASTER_BEDROOM", + "info/name": "Primary bedroom / Lights & Outlets", + "info/spaces": "18", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-3": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-3", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423355804 + }, + "numeric_properties": { + "breaker/poles": "2", + "breaker/rating": "40", + "info/nominal-voltage": "240.0", + "meter/active-power": "-4.5", + "meter/current": "0.0", + "meter/exported-energy": "88644.0", + "meter/imported-energy": "2504911685498.9", + "pcs/priority": "30" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "true", + "info/name": "Electric Double-Oven", + "info/spaces": "2,4", + "info/tags": "OVEN", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-30": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-30", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423357520 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "743.2", + "meter/imported-energy": "569.4", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "false", + "info/locations": "BATHROOM", + "info/name": "Primary Bath & Closets", + "info/spaces": "22", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-31": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-31", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423357589 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "700.8", + "meter/imported-energy": "549.7", + "pcs/priority": "51" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "true", + "info/name": "Smoke/CO Detectors", + "info/spaces": "24", + "info/tags": "SMOKE_CO_DETECTOR", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-32": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-32", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423357641 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "667.0", + "meter/imported-energy": "181.1", + "pcs/priority": "37" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "BASEMENT", + "info/name": "Basement Outlets exit door wall", + "info/spaces": "26", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-33": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-33", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423357703 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "-0.1", + "meter/current": "0.0", + "meter/exported-energy": "664.9", + "meter/imported-energy": "532.6", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "false", + "info/locations": "LIVING_ROOM", + "info/name": "Living room / Lights & Outlets", + "info/spaces": "28", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-34": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-34", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423357768 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.1", + "meter/current": "0.0", + "meter/exported-energy": "721.4", + "meter/imported-energy": "569.1", + "pcs/priority": "23" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "true", + "info/name": "Sump Pump", + "info/spaces": "30", + "info/tags": "PUMP", + "load-shed/priority": "OFF_GRID", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-35": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-35", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423357836 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "-0.1", + "meter/current": "0.0", + "meter/exported-energy": "709.2", + "meter/imported-energy": "561.4", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "KITCHEN", + "info/name": "Kitchen / Lights", + "info/spaces": "32", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-36": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-36", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423357893 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "677.3", + "meter/imported-energy": "529.0", + "pcs/priority": "53" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "true", + "info/name": "Security system", + "info/spaces": "34", + "info/tags": "SECURITY_SYSTEM", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-37": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-37", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423357957 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "728.1", + "meter/imported-energy": "557.5", + "pcs/priority": "38" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "true", + "info/name": "Refrigerator", + "info/spaces": "38", + "info/tags": "FRIDGE", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-38": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-38", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423358024 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.1", + "meter/current": "0.0", + "meter/exported-energy": "714.3", + "meter/imported-energy": "567.8", + "pcs/priority": "38" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "true", + "info/name": "Freezer", + "info/spaces": "40", + "info/tags": "FREEZER", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-4": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-4", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423355911 + }, + "numeric_properties": { + "breaker/poles": "2", + "breaker/rating": "30", + "info/nominal-voltage": "240.0", + "meter/active-power": "0.1", + "meter/current": "0.0", + "meter/exported-energy": "86490.0", + "meter/imported-energy": "766.5", + "pcs/priority": "24" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "true", + "info/name": "Laundry Room", + "info/spaces": "6,8", + "info/tags": "DRYER", + "load-shed/priority": "OFF_GRID", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-41": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-41", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423358095 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "662.7", + "meter/imported-energy": "519.8", + "pcs/priority": "32" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "true", + "info/name": "Utility Room Dedicated", + "info/spaces": "36", + "info/tags": "OTHER", + "load-shed/priority": "OFF_GRID", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-48": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-48", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423358159 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.1", + "meter/current": "0.0", + "meter/exported-energy": "666.5", + "meter/imported-energy": "508.8", + "pcs/priority": "37" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "BEDROOM", + "info/name": "Bedroom / Outlets", + "info/spaces": "20", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-49": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-49", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423358221 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "10", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "734.1", + "meter/imported-energy": "569.5", + "pcs/priority": "37" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "BATHROOM", + "info/name": "Bathroom / Outlets", + "info/spaces": "39", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-5": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-5", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423355995 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "8385.6", + "meter/imported-energy": "404.4", + "pcs/priority": "31" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "true", + "info/name": "Electric range", + "info/spaces": "9", + "info/tags": "RANGE", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-50": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-50", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423358281 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "152888357.7", + "meter/imported-energy": "507.5", + "pcs/priority": "37" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "KITCHEN", + "info/name": "Kitchen / Outlets", + "info/spaces": "41", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-51": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-51", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423358353 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "1223102142.9", + "meter/imported-energy": "543.2", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "KITCHEN", + "info/name": "Kitchen / Lights", + "info/spaces": "42", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-52": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-52", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423358418 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.1", + "meter/current": "0.0", + "meter/exported-energy": "494.8", + "meter/imported-energy": "387.5", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "BEDROOM", + "info/name": "Bedroom / Lights", + "info/spaces": "44", + "load-shed/priority": "NEVER", + "meter/shared-with-device-ids": "circuit-53", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE", + "switch/shared-with-device-ids": "circuit-53" + } + }, + "circuit-53": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-53", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423358493 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.1", + "meter/current": "0.0", + "meter/exported-energy": "494.8", + "meter/imported-energy": "387.5", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "BEDROOM", + "info/name": "Bedroom / Outlets", + "info/spaces": "44", + "load-shed/priority": "NEVER", + "meter/shared-with-device-ids": "circuit-52", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE", + "switch/shared-with-device-ids": "circuit-52" + } + }, + "circuit-54": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-54", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423358561 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "735.9", + "meter/imported-energy": "586.6", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "LIVING_ROOM", + "info/name": "Living room / Outlets", + "info/spaces": "46", + "load-shed/priority": "NEVER", + "meter/shared-with-device-ids": "circuit-55", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE", + "switch/shared-with-device-ids": "circuit-55" + } + }, + "circuit-55": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-55", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423358634 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "735.9", + "meter/imported-energy": "586.6", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "LIVING_ROOM", + "info/name": "Living room / Lights", + "info/spaces": "46", + "load-shed/priority": "NEVER", + "meter/shared-with-device-ids": "circuit-54", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE", + "switch/shared-with-device-ids": "circuit-54" + } + }, + "circuit-56": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-56", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423358774 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "715.0", + "meter/imported-energy": "570.3", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "DINING_ROOM", + "info/name": "Dining room / Outlets", + "info/spaces": "48", + "load-shed/priority": "NEVER", + "meter/shared-with-device-ids": "circuit-57", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE", + "switch/shared-with-device-ids": "circuit-57" + } + }, + "circuit-57": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-57", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423358704 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "10", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "715.0", + "meter/imported-energy": "570.3", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "DINING_ROOM", + "info/name": "Dining room / Lights", + "info/spaces": "48", + "load-shed/priority": "NEVER", + "meter/shared-with-device-ids": "circuit-56", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE", + "switch/shared-with-device-ids": "circuit-56" + } + }, + "circuit-6": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-6", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423356089 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "5934.2", + "meter/imported-energy": "245.0", + "pcs/priority": "48" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/dedicated": "true", + "info/name": "Microwave", + "info/spaces": "11", + "info/tags": "MICROWAVE", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "OPEN", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-60": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-60", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423358838 + }, + "numeric_properties": { + "breaker/poles": "2", + "breaker/rating": "60", + "info/nominal-voltage": "240.0", + "meter/active-power": "-1.3", + "meter/current": "0.0", + "meter/exported-energy": "4770835.0", + "meter/imported-energy": "174.7", + "pcs/priority": "1" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "connection/feeds-device-id": "xg-6159-74dlx-dt-6692-e9t57", + "connection/feeds-device-status": "OK", + "connection/feeds-device-type": "energy.ebus.device.evse", + "info/dedicated": "true", + "info/name": "SPAN Drive", + "info/spaces": "19,21", + "info/tags": "EVSE", + "load-shed/priority": "OFF_GRID", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-7": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-7", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423356162 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "37343.3", + "meter/imported-energy": "546.9", + "pcs/priority": "37" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "BATHROOM", + "info/name": "Primary Bath Outlets", + "info/spaces": "13", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-8": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-8", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423356236 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "20", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "536.0", + "meter/imported-energy": "403.7", + "pcs/priority": "37" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/locations": "KITCHEN", + "info/name": "Kitchen / Outlets", + "info/spaces": "15", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "circuit-9": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "circuit-9", + "nodes": { + "breaker": { + "name": "breaker", + "properties": { + "poles": { + "datatype": "integer", + "format": "1:4:1", + "name": "Number of breaker poles" + }, + "protection-functions": { + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + "name": "Protections this breaker provides" + }, + "rating": { + "datatype": "integer", + "name": "Circuit breaker rating", + "unit": "A" + } + }, + "type": "energy.ebus.capability.breaker" + }, + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether this circuit is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated downstream (e.g. microinverters, packs)" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the device wired upstream of this circuit" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this circuit" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "dedicated": { + "datatype": "boolean", + "name": "Commissioned as serving a single load" + }, + "locations": { + "datatype": "string", + "name": "Where in the home the circuit serves" + }, + "name": { + "datatype": "string", + "name": "Circuit name" + }, + "nominal-voltage": { + "datatype": "float", + "name": "Nominal circuit voltage", + "unit": "V" + }, + "spaces": { + "datatype": "string", + "name": "Physical panel position(s) the circuit occupies" + }, + "tags": { + "datatype": "string", + "name": "Load-type tags for the circuit" + } + }, + "type": "energy.ebus.capability.info" + }, + "load-shed": { + "name": "load-shed", + "properties": { + "priority": { + "datatype": "enum", + "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER", + "name": "Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)", + "settable": true + } + }, + "type": "energy.ebus.capability.load-shed" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Measured active power", + "unit": "W" + }, + "current": { + "datatype": "float", + "name": "Measured current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Measured energy exported", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Measured energy imported", + "unit": "Wh" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this meter's hardware also measures" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "managed": { + "datatype": "boolean", + "name": "Is circuit managed by PCS?" + }, + "priority": { + "datatype": "integer", + "name": "Circuit PCS priority ranking" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "switch": { + "name": "switch", + "properties": { + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Circuit relay state", + "settable": true + }, + "relay-controllable": { + "datatype": "boolean", + "name": "Can the circuit's relay be commanded by the user?" + }, + "relay-requester": { + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL", + "name": "Actor requesting the relay state" + }, + "shared-with-device-ids": { + "datatype": "string", + "name": "Other circuits this relay also switches" + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.circuit", + "version": 1791423356316 + }, + "numeric_properties": { + "breaker/poles": "1", + "breaker/rating": "15", + "info/nominal-voltage": "120.0", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "15724.0", + "meter/imported-energy": "374.5", + "pcs/priority": "43" + }, + "properties": { + "breaker/protection-functions": "OVERCURRENT", + "info/name": "Family Room", + "info/spaces": "17", + "load-shed/priority": "NEVER", + "pcs/managed": "true", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + } + }, + "xg-6159-74dlx": { + "description": { + "children": [ + "xg-6159-74dlx-lugs-up", + "xg-6159-74dlx-lugs-dn", + "xg-6159-74dlx-dt-6692-e9t57", + "circuit-1", + "circuit-2", + "circuit-3", + "circuit-4", + "circuit-5", + "circuit-6", + "circuit-7", + "circuit-8", + "circuit-9", + "circuit-12", + "circuit-13", + "circuit-14", + "circuit-15", + "circuit-16", + "circuit-17", + "circuit-18", + "circuit-19", + "circuit-21", + "circuit-22", + "circuit-23", + "circuit-24", + "circuit-25", + "circuit-26", + "circuit-27", + "circuit-28", + "circuit-30", + "circuit-31", + "circuit-32", + "circuit-33", + "circuit-34", + "circuit-35", + "circuit-36", + "circuit-37", + "circuit-38", + "circuit-41", + "circuit-48", + "circuit-49", + "circuit-50", + "circuit-51", + "circuit-52", + "circuit-53", + "circuit-54", + "circuit-55", + "circuit-57", + "circuit-56", + "circuit-60" + ], + "extensions": [], + "homie": "5.0", + "name": "Masked Panel", + "nodes": { + "door": { + "name": "door", + "properties": { + "state": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Door state" + } + }, + "type": "energy.ebus.capability.door" + }, + "info": { + "name": "info", + "properties": { + "address-lines": { + "datatype": "string", + "name": "Street address lines as recorded at commissioning" + }, + "country-code": { + "datatype": "string", + "name": "Country or locale code as recorded at commissioning" + }, + "data-model-version": { + "datatype": "string", + "name": "eBus data-model version (parent/child schema discriminator)" + }, + "firmware-version": { + "datatype": "string", + "name": "Firmware version" + }, + "hardware-version": { + "datatype": "string", + "name": "Hardware version" + }, + "latitude": { + "datatype": "float", + "name": "Site latitude (WGS84 decimal degrees, positive north)", + "unit": "\u00b0" + }, + "locality": { + "datatype": "string", + "name": "City or locality" + }, + "longitude": { + "datatype": "float", + "name": "Site longitude (WGS84 decimal degrees, positive east)", + "unit": "\u00b0" + }, + "model": { + "datatype": "enum", + "format": "UNKNOWN,MAIN_16,MLO_24,MAIN_32,MAIN_40,MLO_48", + "name": "Model" + }, + "name": { + "datatype": "string", + "name": "User-assigned name for the site" + }, + "region": { + "datatype": "string", + "name": "State, province or region" + }, + "serial-number": { + "datatype": "string", + "name": "Serial number" + }, + "utility-meter-serial-number": { + "datatype": "string", + "name": "Serial number of the utility meter serving the site" + }, + "vendor-name": { + "datatype": "string", + "name": "Vendor name" + } + }, + "type": "energy.ebus.capability.info" + }, + "meter": { + "name": "meter", + "properties": { + "busbar-current": { + "datatype": "float", + "name": "Estimated busbar current", + "unit": "A" + }, + "frequency": { + "datatype": "float", + "name": "Line frequency", + "unit": "Hz" + }, + "voltage-a": { + "datatype": "float", + "name": "L1 voltage", + "unit": "V" + }, + "voltage-b": { + "datatype": "float", + "name": "L2 voltage", + "unit": "V" + } + }, + "type": "energy.ebus.capability.meter" + }, + "pcs": { + "name": "pcs", + "properties": { + "active": { + "datatype": "boolean", + "name": "PCS system actively controlling one (or more) loads" + }, + "binding-constraint": { + "datatype": "enum", + "format": "FSR,DOE,VOLTAGE,OFF_GRID,REQUESTED,OPERATOR,NONE,UNKNOWN", + "name": "Which constraint class currently sets the import limit" + }, + "enabled": { + "datatype": "boolean", + "name": "PCS system enabled" + }, + "feed-import-limit": { + "datatype": "float", + "name": "Limit of maximum power feeding the distribution enclosure", + "unit": "A" + }, + "feed-import-limit-active": { + "datatype": "boolean", + "name": "Is feed-import-limit currently being enforced?" + }, + "feed-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the feed-import-limit" + }, + "import-limit": { + "datatype": "float", + "name": "The power import limit currently being managed to", + "unit": "A" + }, + "off-grid-import-limit": { + "datatype": "float", + "name": "Off-Grid limit maximum import power", + "unit": "A" + }, + "off-grid-import-limit-active": { + "datatype": "boolean", + "name": "Is off-grid-import-limit currently being enforced?" + }, + "off-grid-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the off-grid-import-limit" + }, + "operator-import-limit": { + "datatype": "float", + "name": "Operator-imposed maximum import limit", + "unit": "A" + }, + "operator-import-limit-active": { + "datatype": "boolean", + "name": "Is operator-import-limit currently being enforced?" + }, + "operator-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the operator-import-limit" + }, + "requested-import-limit": { + "datatype": "float", + "name": "Requested limit maximum import power", + "unit": "A" + }, + "requested-import-limit-active": { + "datatype": "boolean", + "name": "Is requested-import-limit currently being enforced?" + }, + "requested-import-limit-enablement": { + "datatype": "enum", + "format": "UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED", + "name": "Enablement status of the requested-import-limit" + } + }, + "type": "energy.ebus.capability.pcs" + }, + "power-flows": { + "name": "power-flows", + "properties": { + "battery": { + "datatype": "float", + "name": "Battery/BESS power flow", + "unit": "W" + }, + "grid": { + "datatype": "float", + "name": "Grid power flow", + "unit": "W" + }, + "pv": { + "datatype": "float", + "name": "PV power flow", + "unit": "W" + }, + "site": { + "datatype": "float", + "name": "Site power flow", + "unit": "W" + } + }, + "type": "energy.ebus.capability.power-flows" + }, + "status": { + "name": "status", + "properties": { + "cloud-connection": { + "datatype": "enum", + "format": "UNKNOWN,UNCONNECTED,CONNECTED", + "name": "Device connected to vendor cloud?" + }, + "ethernet": { + "datatype": "boolean", + "name": "Is Ethernet network interface operational?" + }, + "postal-code": { + "datatype": "string", + "name": "Postal (Zip) code" + }, + "relay": { + "datatype": "enum", + "format": "UNKNOWN,OPEN,CLOSED", + "name": "Main relay" + }, + "time-zone": { + "datatype": "string", + "name": "Time zone" + }, + "wifi": { + "datatype": "boolean", + "name": "Is Wi-Fi network interface operational?" + }, + "wifi-ssid": { + "datatype": "string", + "name": "SSID to which Wi-Fi network interface is connected" + } + }, + "type": "energy.ebus.capability.status" + } + }, + "type": "energy.ebus.device.distribution-enclosure", + "version": 1791423360087 + }, + "numeric_properties": { + "info/latitude": "0.0", + "info/longitude": "0.0", + "meter/busbar-current": "0.1", + "meter/frequency": "60.01", + "meter/voltage-a": "121.8", + "meter/voltage-b": "121.9", + "pcs/feed-import-limit": "180.0", + "pcs/import-limit": "180.0", + "pcs/requested-import-limit": "200.0", + "power-flows/grid": "-18.4", + "power-flows/site": "6.2" + }, + "properties": { + "door/state": "CLOSED", + "info/address-lines": "Masked Address", + "info/data-model-version": "1.0", + "info/firmware-version": "spanos3/r202639/03", + "info/hardware-version": "3.0", + "info/locality": "Masked City", + "info/model": "MLO_48", + "info/name": "Masked Panel", + "info/region": "MD", + "info/serial-number": "xg-6159-74dlx", + "info/vendor-name": "SPAN", + "pcs/active": "true", + "pcs/binding-constraint": "FSR", + "pcs/enabled": "true", + "pcs/feed-import-limit-active": "true", + "pcs/feed-import-limit-enablement": "ENABLED", + "pcs/off-grid-import-limit-active": "false", + "pcs/off-grid-import-limit-enablement": "UNCONFIGURED", + "pcs/operator-import-limit-active": "false", + "pcs/operator-import-limit-enablement": "UNCONFIGURED", + "pcs/requested-import-limit-active": "false", + "pcs/requested-import-limit-enablement": "UNCONFIGURED", + "status/cloud-connection": "UNKNOWN", + "status/ethernet": "true", + "status/postal-code": "00000", + "status/time-zone": "America/New_York", + "status/wifi": "false" + } + }, + "xg-6159-74dlx-dt-6692-e9t57": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "xg-6159-74dlx-dt-6692-e9t57", + "nodes": { + "config": { + "name": "config", + "properties": { + "max-charge-current": { + "datatype": "integer", + "name": "Commissioned maximum EVSE charge current (installer-configured)", + "unit": "A" + }, + "user-max-charge-current": { + "datatype": "integer", + "format": "6:48", + "name": "User-configured maximum EVSE charge current (ceiling)", + "settable": true, + "unit": "A" + } + }, + "type": "energy.ebus.capability.config" + }, + "info": { + "name": "info", + "properties": { + "firmware-version": { + "datatype": "string", + "name": "Firmware version" + }, + "model": { + "datatype": "string", + "name": "Model" + }, + "part-number": { + "datatype": "string", + "name": "Part number" + }, + "serial-number": { + "datatype": "string", + "name": "Serial number" + }, + "vendor-name": { + "datatype": "string", + "name": "Vendor name" + } + }, + "type": "energy.ebus.capability.info" + }, + "status": { + "name": "status", + "properties": { + "status": { + "datatype": "enum", + "format": "AVAILABLE,PREPARING,CHARGING,UNAVAILABLE", + "name": "Status" + } + }, + "type": "energy.ebus.capability.status" + }, + "switch": { + "name": "switch", + "properties": { + "lock-state": { + "datatype": "enum", + "format": "UNLOCKED,LOCKED", + "name": "Lock state", + "settable": true + } + }, + "type": "energy.ebus.capability.switch" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.evse", + "version": 1791423355548 + }, + "numeric_properties": { + "config/max-charge-current": "48", + "config/user-max-charge-current": "48" + }, + "properties": { + "info/part-number": "1-01400-04", + "info/serial-number": "dt-6692-e9t57", + "info/vendor-name": "SPAN", + "status/status": "UNAVAILABLE", + "switch/lock-state": "UNLOCKED" + } + }, + "xg-6159-74dlx-lugs-dn": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "xg-6159-74dlx-lugs-dn", + "nodes": { + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether the downstream path is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated up/downstream" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the upstream device feeding this lugs" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this lugs" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + }, + "overcurrent-protection": { + "datatype": "integer", + "name": "Overcurrent-protection rating at a connection point that is not itself a breaker-protected circuit", + "unit": "A" + }, + "service-rating": { + "datatype": "integer", + "name": "Utility service rating (service size) at a service-entrance connection point", + "unit": "A" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "direction": { + "datatype": "enum", + "format": "UPSTREAM,DOWNSTREAM", + "name": "Lugs feed direction: upstream or downstream" + } + }, + "type": "energy.ebus.capability.info" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Active power", + "unit": "W" + }, + "current-a": { + "datatype": "float", + "name": "L1 current", + "unit": "A" + }, + "current-b": { + "datatype": "float", + "name": "L2 current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Exported energy", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Imported energy", + "unit": "Wh" + } + }, + "type": "energy.ebus.capability.meter" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.lugs", + "version": 1791423355454 + }, + "numeric_properties": { + "meter/current-a": "0.1", + "meter/current-b": "0.1" + }, + "properties": { + "connection/feeds-role": "UNUSED", + "info/direction": "DOWNSTREAM" + } + }, + "xg-6159-74dlx-lugs-up": { + "description": { + "children": [], + "extensions": [], + "homie": "5.0", + "name": "xg-6159-74dlx-lugs-up", + "nodes": { + "connection": { + "name": "connection", + "properties": { + "backed-up": { + "datatype": "enum", + "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN", + "name": "Whether the downstream path is on the backup (island) side of a microgrid interconnect device" + }, + "count": { + "datatype": "integer", + "name": "Number of physical units aggregated up/downstream" + }, + "fed-by-device-id": { + "datatype": "string", + "name": "Homie device-id of the upstream device feeding this lugs" + }, + "fed-by-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the upstream device" + }, + "fed-by-device-type": { + "datatype": "string", + "name": "Homie $type of the upstream device" + }, + "feeds-device-id": { + "datatype": "string", + "name": "Homie device-id of the downstream device fed by this lugs" + }, + "feeds-device-status": { + "datatype": "enum", + "format": "OK,LOST,DEGRADED", + "name": "Panel's view of comm health to the downstream device" + }, + "feeds-device-type": { + "datatype": "string", + "name": "Homie $type of the downstream device" + }, + "feeds-role": { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + "name": "Coarse role of a downstream node not published as its own eBus device" + }, + "overcurrent-protection": { + "datatype": "integer", + "name": "Overcurrent-protection rating at a connection point that is not itself a breaker-protected circuit", + "unit": "A" + }, + "service-rating": { + "datatype": "integer", + "name": "Utility service rating (service size) at a service-entrance connection point", + "unit": "A" + } + }, + "type": "energy.ebus.capability.connection" + }, + "info": { + "name": "info", + "properties": { + "direction": { + "datatype": "enum", + "format": "UPSTREAM,DOWNSTREAM", + "name": "Lugs feed direction: upstream or downstream" + } + }, + "type": "energy.ebus.capability.info" + }, + "meter": { + "name": "meter", + "properties": { + "active-power": { + "datatype": "float", + "name": "Active power", + "unit": "W" + }, + "current-a": { + "datatype": "float", + "name": "L1 current", + "unit": "A" + }, + "current-b": { + "datatype": "float", + "name": "L2 current", + "unit": "A" + }, + "exported-energy": { + "datatype": "float", + "name": "Exported energy", + "unit": "Wh" + }, + "imported-energy": { + "datatype": "float", + "name": "Imported energy", + "unit": "Wh" + } + }, + "type": "energy.ebus.capability.meter" + } + }, + "parent": "xg-6159-74dlx", + "root": "xg-6159-74dlx", + "type": "energy.ebus.device.lugs", + "version": 1791423355413 + }, + "numeric_properties": { + "connection/overcurrent-protection": "200", + "connection/service-rating": "200", + "meter/active-power": "18.4", + "meter/current-a": "0.1", + "meter/current-b": "0.1", + "meter/exported-energy": "181.4", + "meter/imported-energy": "3550605.9" + }, + "properties": { + "info/direction": "UPSTREAM" + } + } + }, + "metadata": { + "schema": "tree-v1" + } +} diff --git a/tests/fixtures/other_model_tree.json b/tests/fixtures/other_model_tree.json new file mode 100644 index 00000000..d04d87d9 --- /dev/null +++ b/tests/fixtures/other_model_tree.json @@ -0,0 +1,276 @@ +{ + "bess": { + "$description": "{\"homie\": \"5.0\", \"version\": 1790000000000, \"type\": \"energy.ebus.device.bess\", \"name\": \"Battery\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"vendor-name\": {\"name\": \"Vendor name\", \"datatype\": \"string\"}, \"model\": {\"name\": \"Model\", \"datatype\": \"string\"}, \"part-number\": {\"name\": \"Part number\", \"datatype\": \"string\"}, \"serial-number\": {\"name\": \"Serial number\", \"datatype\": \"string\"}, \"firmware-version\": {\"name\": \"Firmware version\", \"datatype\": \"string\"}, \"nameplate-capacity\": {\"name\": \"Nameplate capacity\", \"datatype\": \"float\", \"unit\": \"kWh\"}}}, \"soc\": {\"name\": \"soc\", \"type\": \"energy.ebus.capability.soc\", \"properties\": {\"soc\": {\"name\": \"State of charge\", \"datatype\": \"float\", \"unit\": \"%\"}, \"soe\": {\"name\": \"State of energy\", \"datatype\": \"float\", \"unit\": \"kWh\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"active-power\": {\"name\": \"Active power\", \"datatype\": \"float\", \"unit\": \"W\"}}}, \"status\": {\"name\": \"status\", \"type\": \"energy.ebus.capability.status\", \"properties\": {\"communication-state\": {\"name\": \"Communication state\", \"datatype\": \"enum\", \"format\": \"OK,DEGRADED,LOST,UNKNOWN\"}}}}, \"children\": [\"bess-mid\"], \"root\": \"example-48t-001\", \"parent\": \"example-48t-001\", \"extensions\": []}", + "$state": "ready", + "info/firmware-version": "example-bess/v0.1.0", + "info/model": "Example BESS", + "info/nameplate-capacity": "13.5", + "info/part-number": "SPN-BESS-001", + "info/serial-number": "example-bess-48t-001", + "info/vendor-name": "Span", + "meter/active-power": "3500.0", + "soc/soc": "50.410493827160494", + "soc/soe": "6.805416666666667", + "status/communication-state": "OK" + }, + "bess-mid": { + "$description": "{\"homie\": \"5.0\", \"version\": 1790000000000, \"type\": \"energy.ebus.device.mid\", \"name\": \"Microgrid Interconnect Device\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"vendor-name\": {\"name\": \"Vendor name\", \"datatype\": \"string\"}, \"serial-number\": {\"name\": \"Serial number\", \"datatype\": \"string\"}, \"model\": {\"name\": \"Model\", \"datatype\": \"string\"}, \"firmware-version\": {\"name\": \"Firmware version\", \"datatype\": \"string\"}, \"hardware-version\": {\"name\": \"Hardware version\", \"datatype\": \"string\"}}}, \"grid\": {\"name\": \"grid\", \"type\": \"energy.ebus.capability.grid\", \"properties\": {\"islanding-state\": {\"name\": \"Islanding state of the BESS-integrated grid-forming device\", \"datatype\": \"enum\", \"format\": \"ON_GRID,OFF_GRID,UNKNOWN\"}, \"grid-state\": {\"name\": \"Sensed grid condition\", \"datatype\": \"enum\", \"format\": \"UP,DOWN,DEGRADED,UNKNOWN\"}, \"grid-forming-entity\": {\"name\": \"Identity of the currently grid-forming entity\", \"datatype\": \"string\"}}}}, \"children\": [], \"root\": \"example-48t-001\", \"parent\": \"bess\", \"extensions\": []}", + "$state": "ready", + "grid/grid-forming-entity": "GRID", + "grid/grid-state": "UP", + "grid/islanding-state": "ON_GRID", + "info/firmware-version": "example-mid/v0.1.0", + "info/hardware-version": "rev1", + "info/model": "SPAN MID", + "info/serial-number": "example-bess-48t-001-mid", + "info/vendor-name": "Span" + }, + "circuit-1": { + "$description": "{\"homie\": \"5.0\", \"version\": 1790000000000, \"type\": \"energy.ebus.device.circuit\", \"name\": \"Kitchen Lights\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"name\": {\"name\": \"Circuit name\", \"datatype\": \"string\"}, \"spaces\": {\"name\": \"Physical panel position(s) the circuit occupies\", \"datatype\": \"string\"}, \"tags\": {\"name\": \"Load-type tags for the circuit\", \"datatype\": \"string\"}, \"locations\": {\"name\": \"Where in the home the circuit serves\", \"datatype\": \"string\"}, \"dedicated\": {\"name\": \"Commissioned as serving a single load\", \"datatype\": \"boolean\"}, \"nominal-voltage\": {\"name\": \"Nominal circuit voltage\", \"datatype\": \"float\", \"unit\": \"V\"}}}, \"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"relay\": {\"name\": \"Circuit relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\", \"settable\": true}, \"relay-requester\": {\"name\": \"Actor requesting the relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,NONE,LOAD_SHED,USER,PCS,CONFIGURATION,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL\"}, \"relay-controllable\": {\"name\": \"Can the circuit's relay be commanded by the user?\", \"datatype\": \"boolean\"}, \"shared-with-device-ids\": {\"name\": \"Other circuits this relay also switches\", \"datatype\": \"string\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Circuit breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"poles\": {\"name\": \"Number of breaker poles\", \"datatype\": \"integer\", \"format\": \"1:4:1\"}, \"protection-functions\": {\"name\": \"Protections this breaker provides\", \"datatype\": \"enum\", \"format\": \"OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"shared-with-device-ids\": {\"name\": \"Other circuits this meter's hardware also measures\", \"datatype\": \"string\"}}}, \"load-shed\": {\"name\": \"load-shed\", \"type\": \"energy.ebus.capability.load-shed\", \"properties\": {\"priority\": {\"name\": \"Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER\", \"settable\": true}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"managed\": {\"name\": \"Is circuit managed by PCS?\", \"datatype\": \"boolean\"}, \"priority\": {\"name\": \"Circuit PCS priority ranking\", \"datatype\": \"integer\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this circuit\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"count\": {\"name\": \"Number of physical units aggregated downstream (e.g. microinverters, packs)\", \"datatype\": \"integer\"}, \"fed-by-device-id\": {\"name\": \"Homie device-id of the device wired upstream of this circuit\", \"datatype\": \"string\"}, \"fed-by-device-type\": {\"name\": \"Homie $type of the upstream device\", \"datatype\": \"string\"}, \"fed-by-device-status\": {\"name\": \"Panel's view of comm health to the upstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"backed-up\": {\"name\": \"Whether this circuit is on the backup (island) side of a microgrid interconnect device\", \"datatype\": \"enum\", \"format\": \"BACKED_UP,NOT_BACKED_UP,UNKNOWN\"}, \"feeds-role\": {\"name\": \"Coarse role of a downstream node not published as its own eBus device\", \"datatype\": \"enum\", \"format\": \"LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED\"}}}}, \"children\": [], \"root\": \"example-48t-001\", \"parent\": \"example-48t-001\", \"extensions\": []}", + "$state": "ready", + "breaker/poles": "1", + "breaker/protection-functions": "OVERCURRENT,SHORT_CIRCUIT,ARC_FAULT", + "breaker/rating": "15", + "connection/backed-up": "BACKED_UP", + "connection/feeds-role": "LOADS", + "info/dedicated": "false", + "info/locations": "KITCHEN", + "info/name": "Kitchen Lights", + "info/nominal-voltage": "120", + "info/spaces": "1", + "info/tags": "LIGHTING", + "load-shed/priority": "SOC_THRESHOLD", + "meter/active-power": "-121.0", + "meter/current": "1.0083333333333333", + "meter/exported-energy": "4.033333333333333", + "meter/imported-energy": "0.0", + "meter/shared-with-device-ids": "circuit-2", + "pcs/managed": "true", + "pcs/priority": "1", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE", + "switch/shared-with-device-ids": "circuit-2" + }, + "circuit-2": { + "$description": "{\"homie\": \"5.0\", \"version\": 1790000000000, \"type\": \"energy.ebus.device.circuit\", \"name\": \"Garage Outlet\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"name\": {\"name\": \"Circuit name\", \"datatype\": \"string\"}, \"spaces\": {\"name\": \"Physical panel position(s) the circuit occupies\", \"datatype\": \"string\"}, \"tags\": {\"name\": \"Load-type tags for the circuit\", \"datatype\": \"string\"}, \"locations\": {\"name\": \"Where in the home the circuit serves\", \"datatype\": \"string\"}, \"dedicated\": {\"name\": \"Commissioned as serving a single load\", \"datatype\": \"boolean\"}, \"nominal-voltage\": {\"name\": \"Nominal circuit voltage\", \"datatype\": \"float\", \"unit\": \"V\"}}}, \"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"relay\": {\"name\": \"Circuit relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\", \"settable\": true}, \"relay-requester\": {\"name\": \"Actor requesting the relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,NONE,LOAD_SHED,USER,PCS,CONFIGURATION,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL\"}, \"relay-controllable\": {\"name\": \"Can the circuit's relay be commanded by the user?\", \"datatype\": \"boolean\"}, \"shared-with-device-ids\": {\"name\": \"Other circuits this relay also switches\", \"datatype\": \"string\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Circuit breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"poles\": {\"name\": \"Number of breaker poles\", \"datatype\": \"integer\", \"format\": \"1:4:1\"}, \"protection-functions\": {\"name\": \"Protections this breaker provides\", \"datatype\": \"enum\", \"format\": \"OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"shared-with-device-ids\": {\"name\": \"Other circuits this meter's hardware also measures\", \"datatype\": \"string\"}}}, \"load-shed\": {\"name\": \"load-shed\", \"type\": \"energy.ebus.capability.load-shed\", \"properties\": {\"priority\": {\"name\": \"Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER\", \"settable\": true}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"managed\": {\"name\": \"Is circuit managed by PCS?\", \"datatype\": \"boolean\"}, \"priority\": {\"name\": \"Circuit PCS priority ranking\", \"datatype\": \"integer\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this circuit\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"count\": {\"name\": \"Number of physical units aggregated downstream (e.g. microinverters, packs)\", \"datatype\": \"integer\"}, \"fed-by-device-id\": {\"name\": \"Homie device-id of the device wired upstream of this circuit\", \"datatype\": \"string\"}, \"fed-by-device-type\": {\"name\": \"Homie $type of the upstream device\", \"datatype\": \"string\"}, \"fed-by-device-status\": {\"name\": \"Panel's view of comm health to the upstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"backed-up\": {\"name\": \"Whether this circuit is on the backup (island) side of a microgrid interconnect device\", \"datatype\": \"enum\", \"format\": \"BACKED_UP,NOT_BACKED_UP,UNKNOWN\"}, \"feeds-role\": {\"name\": \"Coarse role of a downstream node not published as its own eBus device\", \"datatype\": \"enum\", \"format\": \"LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED\"}}}}, \"children\": [], \"root\": \"example-48t-001\", \"parent\": \"example-48t-001\", \"extensions\": []}", + "$state": "ready", + "breaker/poles": "1", + "breaker/rating": "20", + "connection/backed-up": "BACKED_UP", + "connection/feeds-role": "LOADS", + "info/name": "Garage Outlet", + "info/nominal-voltage": "120", + "info/spaces": "2", + "load-shed/priority": "SOC_THRESHOLD", + "meter/active-power": "-122.0", + "meter/current": "1.0166666666666666", + "meter/exported-energy": "4.066666666666666", + "meter/imported-energy": "0.0", + "meter/shared-with-device-ids": "circuit-1", + "pcs/managed": "true", + "pcs/priority": "2", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE", + "switch/shared-with-device-ids": "circuit-1" + }, + "circuit-3": { + "$description": "{\"homie\": \"5.0\", \"version\": 1790000000000, \"type\": \"energy.ebus.device.circuit\", \"name\": \"SPAN Drive - Garage\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"name\": {\"name\": \"Circuit name\", \"datatype\": \"string\"}, \"spaces\": {\"name\": \"Physical panel position(s) the circuit occupies\", \"datatype\": \"string\"}, \"tags\": {\"name\": \"Load-type tags for the circuit\", \"datatype\": \"string\"}, \"locations\": {\"name\": \"Where in the home the circuit serves\", \"datatype\": \"string\"}, \"dedicated\": {\"name\": \"Commissioned as serving a single load\", \"datatype\": \"boolean\"}, \"nominal-voltage\": {\"name\": \"Nominal circuit voltage\", \"datatype\": \"float\", \"unit\": \"V\"}}}, \"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"relay\": {\"name\": \"Circuit relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\", \"settable\": true}, \"relay-requester\": {\"name\": \"Actor requesting the relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,NONE,LOAD_SHED,USER,PCS,CONFIGURATION,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL\"}, \"relay-controllable\": {\"name\": \"Can the circuit's relay be commanded by the user?\", \"datatype\": \"boolean\"}, \"shared-with-device-ids\": {\"name\": \"Other circuits this relay also switches\", \"datatype\": \"string\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Circuit breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"poles\": {\"name\": \"Number of breaker poles\", \"datatype\": \"integer\", \"format\": \"1:4:1\"}, \"protection-functions\": {\"name\": \"Protections this breaker provides\", \"datatype\": \"enum\", \"format\": \"OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"shared-with-device-ids\": {\"name\": \"Other circuits this meter's hardware also measures\", \"datatype\": \"string\"}}}, \"load-shed\": {\"name\": \"load-shed\", \"type\": \"energy.ebus.capability.load-shed\", \"properties\": {\"priority\": {\"name\": \"Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER\", \"settable\": true}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"managed\": {\"name\": \"Is circuit managed by PCS?\", \"datatype\": \"boolean\"}, \"priority\": {\"name\": \"Circuit PCS priority ranking\", \"datatype\": \"integer\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this circuit\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"count\": {\"name\": \"Number of physical units aggregated downstream (e.g. microinverters, packs)\", \"datatype\": \"integer\"}, \"fed-by-device-id\": {\"name\": \"Homie device-id of the device wired upstream of this circuit\", \"datatype\": \"string\"}, \"fed-by-device-type\": {\"name\": \"Homie $type of the upstream device\", \"datatype\": \"string\"}, \"fed-by-device-status\": {\"name\": \"Panel's view of comm health to the upstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"backed-up\": {\"name\": \"Whether this circuit is on the backup (island) side of a microgrid interconnect device\", \"datatype\": \"enum\", \"format\": \"BACKED_UP,NOT_BACKED_UP,UNKNOWN\"}, \"feeds-role\": {\"name\": \"Coarse role of a downstream node not published as its own eBus device\", \"datatype\": \"enum\", \"format\": \"LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED\"}}}}, \"children\": [], \"root\": \"example-48t-001\", \"parent\": \"example-48t-001\", \"extensions\": []}", + "$state": "ready", + "breaker/poles": "2", + "breaker/rating": "50", + "connection/backed-up": "NOT_BACKED_UP", + "connection/feeds-device-id": "evse", + "connection/feeds-device-status": "OK", + "connection/feeds-device-type": "energy.ebus.device.evse", + "info/dedicated": "true", + "info/name": "SPAN Drive - Garage", + "info/nominal-voltage": "240", + "info/spaces": "32,34", + "load-shed/priority": "OFF_GRID", + "meter/active-power": "-2410.0", + "meter/current": "10.041666666666666", + "meter/exported-energy": "80.33333333333333", + "meter/imported-energy": "0.0", + "pcs/managed": "true", + "pcs/priority": "3", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "NONE" + }, + "circuit-4": { + "$description": "{\"homie\": \"5.0\", \"version\": 1790000000000, \"type\": \"energy.ebus.device.circuit\", \"name\": \"Dryer\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"name\": {\"name\": \"Circuit name\", \"datatype\": \"string\"}, \"spaces\": {\"name\": \"Physical panel position(s) the circuit occupies\", \"datatype\": \"string\"}, \"tags\": {\"name\": \"Load-type tags for the circuit\", \"datatype\": \"string\"}, \"locations\": {\"name\": \"Where in the home the circuit serves\", \"datatype\": \"string\"}, \"dedicated\": {\"name\": \"Commissioned as serving a single load\", \"datatype\": \"boolean\"}, \"nominal-voltage\": {\"name\": \"Nominal circuit voltage\", \"datatype\": \"float\", \"unit\": \"V\"}}}, \"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"relay\": {\"name\": \"Circuit relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\", \"settable\": true}, \"relay-requester\": {\"name\": \"Actor requesting the relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,NONE,LOAD_SHED,USER,PCS,CONFIGURATION,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL\"}, \"relay-controllable\": {\"name\": \"Can the circuit's relay be commanded by the user?\", \"datatype\": \"boolean\"}, \"shared-with-device-ids\": {\"name\": \"Other circuits this relay also switches\", \"datatype\": \"string\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Circuit breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"poles\": {\"name\": \"Number of breaker poles\", \"datatype\": \"integer\", \"format\": \"1:4:1\"}, \"protection-functions\": {\"name\": \"Protections this breaker provides\", \"datatype\": \"enum\", \"format\": \"OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"shared-with-device-ids\": {\"name\": \"Other circuits this meter's hardware also measures\", \"datatype\": \"string\"}}}, \"load-shed\": {\"name\": \"load-shed\", \"type\": \"energy.ebus.capability.load-shed\", \"properties\": {\"priority\": {\"name\": \"Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER\", \"settable\": true}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"managed\": {\"name\": \"Is circuit managed by PCS?\", \"datatype\": \"boolean\"}, \"priority\": {\"name\": \"Circuit PCS priority ranking\", \"datatype\": \"integer\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this circuit\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"count\": {\"name\": \"Number of physical units aggregated downstream (e.g. microinverters, packs)\", \"datatype\": \"integer\"}, \"fed-by-device-id\": {\"name\": \"Homie device-id of the device wired upstream of this circuit\", \"datatype\": \"string\"}, \"fed-by-device-type\": {\"name\": \"Homie $type of the upstream device\", \"datatype\": \"string\"}, \"fed-by-device-status\": {\"name\": \"Panel's view of comm health to the upstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"backed-up\": {\"name\": \"Whether this circuit is on the backup (island) side of a microgrid interconnect device\", \"datatype\": \"enum\", \"format\": \"BACKED_UP,NOT_BACKED_UP,UNKNOWN\"}, \"feeds-role\": {\"name\": \"Coarse role of a downstream node not published as its own eBus device\", \"datatype\": \"enum\", \"format\": \"LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED\"}}}}, \"children\": [], \"root\": \"example-48t-001\", \"parent\": \"example-48t-001\", \"extensions\": []}", + "$state": "ready", + "breaker/poles": "2", + "breaker/rating": "30", + "connection/backed-up": "NOT_BACKED_UP", + "connection/feeds-role": "LOADS", + "info/dedicated": "true", + "info/name": "Dryer", + "info/nominal-voltage": "240", + "info/spaces": "35,37", + "load-shed/priority": "OFF_GRID", + "meter/active-power": "0.0", + "meter/current": "0.0", + "meter/exported-energy": "40.333333333333336", + "meter/imported-energy": "0.0", + "pcs/managed": "true", + "pcs/priority": "4", + "switch/relay": "OPEN", + "switch/relay-controllable": "true", + "switch/relay-requester": "USER" + }, + "circuit-5": { + "$description": "{\"homie\": \"5.0\", \"version\": 1790000000000, \"type\": \"energy.ebus.device.circuit\", \"name\": \"Pool Pump\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"name\": {\"name\": \"Circuit name\", \"datatype\": \"string\"}, \"spaces\": {\"name\": \"Physical panel position(s) the circuit occupies\", \"datatype\": \"string\"}, \"tags\": {\"name\": \"Load-type tags for the circuit\", \"datatype\": \"string\"}, \"locations\": {\"name\": \"Where in the home the circuit serves\", \"datatype\": \"string\"}, \"dedicated\": {\"name\": \"Commissioned as serving a single load\", \"datatype\": \"boolean\"}, \"nominal-voltage\": {\"name\": \"Nominal circuit voltage\", \"datatype\": \"float\", \"unit\": \"V\"}}}, \"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"relay\": {\"name\": \"Circuit relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\", \"settable\": true}, \"relay-requester\": {\"name\": \"Actor requesting the relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,NONE,LOAD_SHED,USER,PCS,CONFIGURATION,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL\"}, \"relay-controllable\": {\"name\": \"Can the circuit's relay be commanded by the user?\", \"datatype\": \"boolean\"}, \"shared-with-device-ids\": {\"name\": \"Other circuits this relay also switches\", \"datatype\": \"string\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Circuit breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"poles\": {\"name\": \"Number of breaker poles\", \"datatype\": \"integer\", \"format\": \"1:4:1\"}, \"protection-functions\": {\"name\": \"Protections this breaker provides\", \"datatype\": \"enum\", \"format\": \"OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"shared-with-device-ids\": {\"name\": \"Other circuits this meter's hardware also measures\", \"datatype\": \"string\"}}}, \"load-shed\": {\"name\": \"load-shed\", \"type\": \"energy.ebus.capability.load-shed\", \"properties\": {\"priority\": {\"name\": \"Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER\", \"settable\": true}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"managed\": {\"name\": \"Is circuit managed by PCS?\", \"datatype\": \"boolean\"}, \"priority\": {\"name\": \"Circuit PCS priority ranking\", \"datatype\": \"integer\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this circuit\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"count\": {\"name\": \"Number of physical units aggregated downstream (e.g. microinverters, packs)\", \"datatype\": \"integer\"}, \"fed-by-device-id\": {\"name\": \"Homie device-id of the device wired upstream of this circuit\", \"datatype\": \"string\"}, \"fed-by-device-type\": {\"name\": \"Homie $type of the upstream device\", \"datatype\": \"string\"}, \"fed-by-device-status\": {\"name\": \"Panel's view of comm health to the upstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"backed-up\": {\"name\": \"Whether this circuit is on the backup (island) side of a microgrid interconnect device\", \"datatype\": \"enum\", \"format\": \"BACKED_UP,NOT_BACKED_UP,UNKNOWN\"}, \"feeds-role\": {\"name\": \"Coarse role of a downstream node not published as its own eBus device\", \"datatype\": \"enum\", \"format\": \"LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED\"}}}}, \"children\": [], \"root\": \"example-48t-001\", \"parent\": \"example-48t-001\", \"extensions\": []}", + "$state": "ready", + "breaker/poles": "1", + "breaker/rating": "20", + "connection/backed-up": "NOT_BACKED_UP", + "connection/feeds-role": "LOADS", + "info/name": "Pool Pump", + "info/spaces": "3", + "load-shed/priority": "OFF_GRID", + "meter/active-power": "-1230.0", + "meter/current": "10.25", + "meter/exported-energy": "41.0", + "meter/imported-energy": "0.0", + "pcs/managed": "true", + "pcs/priority": "5", + "switch/relay": "CLOSED", + "switch/relay-controllable": "true", + "switch/relay-requester": "CIRCUIT_SCHEDULER" + }, + "circuit-6": { + "$description": "{\"homie\": \"5.0\", \"version\": 1790000000000, \"type\": \"energy.ebus.device.circuit\", \"name\": \"Solar Inverter\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"name\": {\"name\": \"Circuit name\", \"datatype\": \"string\"}, \"spaces\": {\"name\": \"Physical panel position(s) the circuit occupies\", \"datatype\": \"string\"}, \"tags\": {\"name\": \"Load-type tags for the circuit\", \"datatype\": \"string\"}, \"locations\": {\"name\": \"Where in the home the circuit serves\", \"datatype\": \"string\"}, \"dedicated\": {\"name\": \"Commissioned as serving a single load\", \"datatype\": \"boolean\"}, \"nominal-voltage\": {\"name\": \"Nominal circuit voltage\", \"datatype\": \"float\", \"unit\": \"V\"}}}, \"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"relay\": {\"name\": \"Circuit relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\", \"settable\": true}, \"relay-requester\": {\"name\": \"Actor requesting the relay state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,NONE,LOAD_SHED,USER,PCS,CONFIGURATION,FAULT,CIRCUIT_SCHEDULER,CONTROL_MANAGER,MID_CONTROL_DER,MODBUS_CONTROL_REQUEST,NFT_RELAY_CONTROL,BATTERY_SOLAR_MID_RELAY_CONTROL\"}, \"relay-controllable\": {\"name\": \"Can the circuit's relay be commanded by the user?\", \"datatype\": \"boolean\"}, \"shared-with-device-ids\": {\"name\": \"Other circuits this relay also switches\", \"datatype\": \"string\"}}}, \"breaker\": {\"name\": \"breaker\", \"type\": \"energy.ebus.capability.breaker\", \"properties\": {\"rating\": {\"name\": \"Circuit breaker rating\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"poles\": {\"name\": \"Number of breaker poles\", \"datatype\": \"integer\", \"format\": \"1:4:1\"}, \"protection-functions\": {\"name\": \"Protections this breaker provides\", \"datatype\": \"enum\", \"format\": \"OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"shared-with-device-ids\": {\"name\": \"Other circuits this meter's hardware also measures\", \"datatype\": \"string\"}}}, \"load-shed\": {\"name\": \"load-shed\", \"type\": \"energy.ebus.capability.load-shed\", \"properties\": {\"priority\": {\"name\": \"Configured priority of circuit shedding when off-grid (dominant-power-source != GRID)\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER\", \"settable\": true}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"managed\": {\"name\": \"Is circuit managed by PCS?\", \"datatype\": \"boolean\"}, \"priority\": {\"name\": \"Circuit PCS priority ranking\", \"datatype\": \"integer\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this circuit\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"count\": {\"name\": \"Number of physical units aggregated downstream (e.g. microinverters, packs)\", \"datatype\": \"integer\"}, \"fed-by-device-id\": {\"name\": \"Homie device-id of the device wired upstream of this circuit\", \"datatype\": \"string\"}, \"fed-by-device-type\": {\"name\": \"Homie $type of the upstream device\", \"datatype\": \"string\"}, \"fed-by-device-status\": {\"name\": \"Panel's view of comm health to the upstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"backed-up\": {\"name\": \"Whether this circuit is on the backup (island) side of a microgrid interconnect device\", \"datatype\": \"enum\", \"format\": \"BACKED_UP,NOT_BACKED_UP,UNKNOWN\"}, \"feeds-role\": {\"name\": \"Coarse role of a downstream node not published as its own eBus device\", \"datatype\": \"enum\", \"format\": \"LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED\"}}}}, \"children\": [], \"root\": \"example-48t-001\", \"parent\": \"example-48t-001\", \"extensions\": []}", + "$state": "ready", + "breaker/poles": "2", + "breaker/rating": "30", + "connection/backed-up": "BACKED_UP", + "connection/feeds-role": "SOLAR", + "info/dedicated": "true", + "info/name": "Solar Inverter", + "info/nominal-voltage": "240", + "info/spaces": "36,38", + "load-shed/priority": "NEVER", + "meter/active-power": "8500.0", + "meter/current": "35.416666666666664", + "meter/exported-energy": "0.0", + "meter/imported-energy": "182.16666666666666", + "pcs/managed": "false", + "pcs/priority": "6", + "switch/relay": "CLOSED", + "switch/relay-controllable": "false", + "switch/relay-requester": "NONE" + }, + "evse": { + "$description": "{\"homie\": \"5.0\", \"version\": 1790000000000, \"type\": \"energy.ebus.device.evse\", \"name\": \"SPAN Drive - Garage\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"vendor-name\": {\"name\": \"Vendor name\", \"datatype\": \"string\"}, \"model\": {\"name\": \"Model\", \"datatype\": \"string\"}, \"part-number\": {\"name\": \"Part number\", \"datatype\": \"string\"}, \"serial-number\": {\"name\": \"Serial number\", \"datatype\": \"string\"}, \"firmware-version\": {\"name\": \"Firmware version\", \"datatype\": \"string\"}}}, \"switch\": {\"name\": \"switch\", \"type\": \"energy.ebus.capability.switch\", \"properties\": {\"lock-state\": {\"name\": \"Lock state\", \"datatype\": \"enum\", \"format\": \"UNLOCKED,LOCKED\", \"settable\": true}}}, \"status\": {\"name\": \"status\", \"type\": \"energy.ebus.capability.status\", \"properties\": {\"status\": {\"name\": \"Status\", \"datatype\": \"enum\", \"format\": \"AVAILABLE,PREPARING,CHARGING,UNAVAILABLE\"}}}, \"config\": {\"name\": \"config\", \"type\": \"energy.ebus.capability.config\", \"properties\": {\"user-max-charge-current\": {\"name\": \"User-configured maximum EVSE charge current (ceiling)\", \"datatype\": \"integer\", \"unit\": \"A\", \"settable\": true}, \"max-charge-current\": {\"name\": \"Commissioned maximum EVSE charge current (installer-configured)\", \"datatype\": \"integer\", \"unit\": \"A\"}}}}, \"children\": [], \"root\": \"example-48t-001\", \"parent\": \"example-48t-001\", \"extensions\": []}", + "$state": "ready", + "config/max-charge-current": "32", + "config/user-max-charge-current": "32", + "info/firmware-version": "example/v0.1.0", + "info/model": "SPAN Drive", + "info/part-number": "SPN-DRV-001", + "info/serial-number": "sim-evse-example-48t-001", + "info/vendor-name": "SPAN", + "status/status": "CHARGING", + "switch/lock-state": "LOCKED" + }, + "example-48t-001": { + "$description": "{\"homie\": \"5.0\", \"version\": 1790000000000, \"type\": \"energy.ebus.device.distribution-enclosure\", \"name\": \"Example 48-space Panel\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"vendor-name\": {\"name\": \"Vendor name\", \"datatype\": \"string\"}, \"name\": {\"name\": \"User-assigned name for the site\", \"datatype\": \"string\"}, \"latitude\": {\"name\": \"Site latitude (WGS84 decimal degrees, positive north)\", \"datatype\": \"float\", \"unit\": \"\\u00b0\"}, \"longitude\": {\"name\": \"Site longitude (WGS84 decimal degrees, positive east)\", \"datatype\": \"float\", \"unit\": \"\\u00b0\"}, \"address-lines\": {\"name\": \"Street address lines as recorded at commissioning\", \"datatype\": \"string\"}, \"locality\": {\"name\": \"City or locality\", \"datatype\": \"string\"}, \"region\": {\"name\": \"State, province or region\", \"datatype\": \"string\"}, \"country-code\": {\"name\": \"Country or locale code as recorded at commissioning\", \"datatype\": \"string\"}, \"utility-meter-serial-number\": {\"name\": \"Serial number of the utility meter serving the site\", \"datatype\": \"string\"}, \"model\": {\"name\": \"Model\", \"datatype\": \"enum\", \"format\": \"MAIN_16,MLO_24,MAIN_32,MAIN_40,MLO_48,UNKNOWN\"}, \"serial-number\": {\"name\": \"Serial number\", \"datatype\": \"string\"}, \"hardware-version\": {\"name\": \"Hardware version\", \"datatype\": \"string\"}, \"firmware-version\": {\"name\": \"Firmware version\", \"datatype\": \"string\"}, \"data-model-version\": {\"name\": \"eBus data-model version (parent/child schema discriminator)\", \"datatype\": \"string\"}}}, \"door\": {\"name\": \"door\", \"type\": \"energy.ebus.capability.door\", \"properties\": {\"state\": {\"name\": \"Door state\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\"}}}, \"status\": {\"name\": \"status\", \"type\": \"energy.ebus.capability.status\", \"properties\": {\"relay\": {\"name\": \"Main relay\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,OPEN,CLOSED\"}, \"ethernet\": {\"name\": \"Is Ethernet network interface operational?\", \"datatype\": \"boolean\"}, \"wifi\": {\"name\": \"Is Wi-Fi network interface operational?\", \"datatype\": \"boolean\"}, \"wifi-ssid\": {\"name\": \"SSID to which Wi-Fi network interface is connected\", \"datatype\": \"string\"}, \"cloud-connection\": {\"name\": \"Device connected to vendor cloud?\", \"datatype\": \"enum\", \"format\": \"UNKNOWN,UNCONNECTED,CONNECTED\"}, \"postal-code\": {\"name\": \"Postal (Zip) code\", \"datatype\": \"string\"}, \"time-zone\": {\"name\": \"Time zone\", \"datatype\": \"string\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"voltage-a\": {\"name\": \"L1 voltage\", \"datatype\": \"float\", \"unit\": \"V\"}, \"voltage-b\": {\"name\": \"L2 voltage\", \"datatype\": \"float\", \"unit\": \"V\"}, \"busbar-current\": {\"name\": \"Estimated busbar current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"frequency\": {\"name\": \"Line frequency\", \"datatype\": \"float\", \"unit\": \"Hz\"}}}, \"power-flows\": {\"name\": \"power-flows\", \"type\": \"energy.ebus.capability.power-flows\", \"properties\": {\"pv\": {\"name\": \"PV power flow\", \"datatype\": \"float\", \"unit\": \"W\"}, \"battery\": {\"name\": \"Battery/BESS power flow\", \"datatype\": \"float\", \"unit\": \"W\"}, \"grid\": {\"name\": \"Grid power flow\", \"datatype\": \"float\", \"unit\": \"W\"}, \"site\": {\"name\": \"Site power flow\", \"datatype\": \"float\", \"unit\": \"W\"}}}, \"pcs\": {\"name\": \"pcs\", \"type\": \"energy.ebus.capability.pcs\", \"properties\": {\"enabled\": {\"name\": \"PCS system enabled\", \"datatype\": \"boolean\"}, \"active\": {\"name\": \"PCS system actively controlling one (or more) loads\", \"datatype\": \"boolean\"}, \"import-limit\": {\"name\": \"The power import limit currently being managed to\", \"datatype\": \"float\", \"unit\": \"A\"}, \"binding-constraint\": {\"name\": \"Which constraint class currently sets the import limit\", \"datatype\": \"enum\", \"format\": \"FSR,DOE,VOLTAGE,OFF_GRID,REQUESTED,OPERATOR,NONE,UNKNOWN\"}, \"feed-import-limit\": {\"name\": \"Limit of maximum power feeding the distribution enclosure\", \"datatype\": \"float\", \"unit\": \"A\"}, \"feed-import-limit-enablement\": {\"name\": \"Enablement status of the feed-import-limit\", \"datatype\": \"enum\", \"format\": \"UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED\"}, \"feed-import-limit-active\": {\"name\": \"Is feed-import-limit currently being enforced?\", \"datatype\": \"boolean\"}, \"operator-import-limit\": {\"name\": \"Operator-imposed maximum import limit\", \"datatype\": \"float\", \"unit\": \"A\"}, \"operator-import-limit-enablement\": {\"name\": \"Enablement status of the operator-import-limit\", \"datatype\": \"enum\", \"format\": \"UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED\"}, \"operator-import-limit-active\": {\"name\": \"Is operator-import-limit currently being enforced?\", \"datatype\": \"boolean\"}, \"off-grid-import-limit\": {\"name\": \"Off-Grid limit maximum import power\", \"datatype\": \"float\", \"unit\": \"A\"}, \"off-grid-import-limit-enablement\": {\"name\": \"Enablement status of the off-grid-import-limit\", \"datatype\": \"enum\", \"format\": \"UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED\"}, \"off-grid-import-limit-active\": {\"name\": \"Is off-grid-import-limit currently being enforced?\", \"datatype\": \"boolean\"}, \"requested-import-limit\": {\"name\": \"Requested limit maximum import power\", \"datatype\": \"float\", \"unit\": \"A\"}, \"requested-import-limit-enablement\": {\"name\": \"Enablement status of the requested-import-limit\", \"datatype\": \"enum\", \"format\": \"UNSPECIFIED,UNCONFIGURED,DISABLED,ENABLED\"}, \"requested-import-limit-active\": {\"name\": \"Is requested-import-limit currently being enforced?\", \"datatype\": \"boolean\"}}}, \"shed-forecast\": {\"name\": \"shed-forecast\", \"type\": \"energy.ebus.capability.shed-forecast\", \"properties\": {\"total-time-remaining\": {\"name\": \"Estimated total time before all sheddable circuits are shed (off-grid runtime)\", \"datatype\": \"integer\", \"unit\": \"min\"}, \"time-to-priority-shed\": {\"name\": \"Estimated time before the next priority tier is shed\", \"datatype\": \"integer\", \"unit\": \"min\"}, \"full-charge-total-time-remaining\": {\"name\": \"Estimated total time assuming BESS starts at full charge\", \"datatype\": \"integer\", \"unit\": \"min\"}, \"full-charge-time-to-priority-shed\": {\"name\": \"Estimated time to next priority shed assuming BESS starts at full charge\", \"datatype\": \"integer\", \"unit\": \"min\"}, \"confidence\": {\"name\": \"Confidence of the shed-forecast estimate\", \"datatype\": \"enum\", \"format\": \"LOW,MEDIUM,HIGH\"}}}, \"shed\": {\"name\": \"shed\", \"type\": \"energy.ebus.capability.shed\", \"properties\": {\"asserted-islanding-state\": {\"name\": \"Consumer-asserted islanding-state (grid-state override during MID/BESS comm-loss)\", \"datatype\": \"enum\", \"format\": \"NONE,ON_GRID,OFF_GRID\", \"settable\": true}, \"policy\": {\"name\": \"Shed policy (algorithm and parameters)\", \"datatype\": \"json\", \"format\": \"{\\\"$id\\\":\\\"soc-priority.v1\\\",\\\"type\\\":\\\"object\\\",\\\"required\\\":[\\\"algorithm\\\",\\\"parameters\\\"],\\\"additionalProperties\\\":false,\\\"properties\\\":{\\\"algorithm\\\":{\\\"const\\\":\\\"soc-priority.v1\\\"},\\\"parameters\\\":{\\\"type\\\":\\\"object\\\",\\\"required\\\":[\\\"soc-threshold-shed\\\",\\\"soc-threshold-release\\\"],\\\"additionalProperties\\\":false,\\\"properties\\\":{\\\"soc-threshold-shed\\\":{\\\"type\\\":\\\"integer\\\",\\\"minimum\\\":0,\\\"maximum\\\":100,\\\"description\\\":\\\"SoC percent below which SOC_THRESHOLD circuits shed\\\"},\\\"soc-threshold-release\\\":{\\\"type\\\":\\\"integer\\\",\\\"minimum\\\":0,\\\"maximum\\\":100,\\\"description\\\":\\\"SoC percent above which shed SOC_THRESHOLD circuits restore\\\"}}}}}\"}}}}, \"children\": [\"circuit-1\", \"circuit-2\", \"circuit-3\", \"circuit-4\", \"circuit-5\", \"circuit-6\", \"remote-ct-1\", \"remote-ct-2\", \"evse\", \"bess\", \"bess-mid\", \"lugs-upstream\", \"lugs-downstream\"], \"extensions\": []}", + "$state": "ready", + "door/state": "CLOSED", + "info/country-code": "US", + "info/data-model-version": "1.0", + "info/firmware-version": "spanos2/r202639/01", + "info/hardware-version": "3.0", + "info/latitude": "37.7749", + "info/locality": "Example City", + "info/longitude": "-122.4194", + "info/model": "MLO_48", + "info/name": "Example Home", + "info/region": "CA", + "info/serial-number": "example-48t-001", + "info/vendor-name": "Span", + "meter/busbar-current": "41.5", + "meter/frequency": "60.01", + "meter/voltage-a": "120.0", + "meter/voltage-b": "120.0", + "pcs/active": "false", + "pcs/binding-constraint": "NONE", + "pcs/enabled": "false", + "pcs/feed-import-limit": "0.0", + "pcs/feed-import-limit-active": "false", + "pcs/feed-import-limit-enablement": "UNCONFIGURED", + "pcs/import-limit": "0.0", + "pcs/off-grid-import-limit": "0.0", + "pcs/off-grid-import-limit-active": "false", + "pcs/off-grid-import-limit-enablement": "UNCONFIGURED", + "pcs/operator-import-limit": "0.0", + "pcs/operator-import-limit-active": "false", + "pcs/operator-import-limit-enablement": "UNCONFIGURED", + "pcs/requested-import-limit-active": "false", + "pcs/requested-import-limit-enablement": "UNCONFIGURED", + "power-flows/battery": "3500.0", + "power-flows/grid": "1117.0", + "power-flows/pv": "-8500.0", + "power-flows/site": "3883.0", + "shed-forecast/confidence": "HIGH", + "shed-forecast/full-charge-time-to-priority-shed": "3038", + "shed-forecast/full-charge-total-time-remaining": "4320", + "shed-forecast/time-to-priority-shed": "3037", + "shed-forecast/total-time-remaining": "4320", + "shed/asserted-islanding-state": "NONE", + "shed/policy": "{\"algorithm\": \"soc-priority.v1\", \"parameters\": {\"soc-threshold-shed\": 20, \"soc-threshold-release\": 30}}", + "status/cloud-connection": "CONNECTED", + "status/ethernet": "true", + "status/postal-code": "94103", + "status/relay": "CLOSED", + "status/time-zone": "America/Los_Angeles", + "status/wifi": "true", + "status/wifi-ssid": "example-wifi" + }, + "lugs-downstream": { + "$description": "{\"homie\": \"5.0\", \"version\": 1790000000000, \"type\": \"energy.ebus.device.lugs\", \"name\": \"Downstream lugs\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"direction\": {\"name\": \"Lugs feed direction: upstream or downstream\", \"datatype\": \"enum\", \"format\": \"UPSTREAM,DOWNSTREAM\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current-a\": {\"name\": \"L1 current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"current-b\": {\"name\": \"L2 current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Imported energy\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Exported energy\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"fed-by-device-id\": {\"name\": \"Homie device-id of the upstream device feeding this lugs\", \"datatype\": \"string\"}, \"fed-by-device-type\": {\"name\": \"Homie $type of the upstream device\", \"datatype\": \"string\"}, \"fed-by-device-status\": {\"name\": \"Panel's view of comm health to the upstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this lugs\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"count\": {\"name\": \"Number of physical units aggregated up/downstream\", \"datatype\": \"integer\"}, \"backed-up\": {\"name\": \"Whether the downstream path is on the backup (island) side of a microgrid interconnect device\", \"datatype\": \"enum\", \"format\": \"BACKED_UP,NOT_BACKED_UP,UNKNOWN\"}, \"feeds-role\": {\"name\": \"Coarse role of a downstream node not published as its own eBus device\", \"datatype\": \"enum\", \"format\": \"LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED\"}, \"service-rating\": {\"name\": \"Utility service rating (service size) at a service-entrance connection point\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"overcurrent-protection\": {\"name\": \"Overcurrent-protection rating at a connection point that is not itself a breaker-protected circuit\", \"datatype\": \"integer\", \"unit\": \"A\"}}}}, \"children\": [], \"root\": \"example-48t-001\", \"parent\": \"example-48t-001\", \"extensions\": []}", + "$state": "ready", + "connection/backed-up": "BACKED_UP", + "connection/feeds-role": "SUBPANEL", + "info/direction": "DOWNSTREAM", + "meter/active-power": "-4617.0", + "meter/current-a": "56.71666666666666", + "meter/current-b": "46.474999999999994", + "meter/exported-energy": "76.95", + "meter/imported-energy": "64.55" + }, + "lugs-upstream": { + "$description": "{\"homie\": \"5.0\", \"version\": 1790000000000, \"type\": \"energy.ebus.device.lugs\", \"name\": \"Upstream lugs\", \"nodes\": {\"info\": {\"name\": \"info\", \"type\": \"energy.ebus.capability.info\", \"properties\": {\"direction\": {\"name\": \"Lugs feed direction: upstream or downstream\", \"datatype\": \"enum\", \"format\": \"UPSTREAM,DOWNSTREAM\"}}}, \"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current-a\": {\"name\": \"L1 current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"current-b\": {\"name\": \"L2 current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Imported energy\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Exported energy\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}, \"connection\": {\"name\": \"connection\", \"type\": \"energy.ebus.capability.connection\", \"properties\": {\"fed-by-device-id\": {\"name\": \"Homie device-id of the upstream device feeding this lugs\", \"datatype\": \"string\"}, \"fed-by-device-type\": {\"name\": \"Homie $type of the upstream device\", \"datatype\": \"string\"}, \"fed-by-device-status\": {\"name\": \"Panel's view of comm health to the upstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"feeds-device-id\": {\"name\": \"Homie device-id of the downstream device fed by this lugs\", \"datatype\": \"string\"}, \"feeds-device-type\": {\"name\": \"Homie $type of the downstream device\", \"datatype\": \"string\"}, \"feeds-device-status\": {\"name\": \"Panel's view of comm health to the downstream device\", \"datatype\": \"enum\", \"format\": \"OK,LOST,DEGRADED\"}, \"count\": {\"name\": \"Number of physical units aggregated up/downstream\", \"datatype\": \"integer\"}, \"backed-up\": {\"name\": \"Whether the downstream path is on the backup (island) side of a microgrid interconnect device\", \"datatype\": \"enum\", \"format\": \"BACKED_UP,NOT_BACKED_UP,UNKNOWN\"}, \"feeds-role\": {\"name\": \"Coarse role of a downstream node not published as its own eBus device\", \"datatype\": \"enum\", \"format\": \"LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED\"}, \"service-rating\": {\"name\": \"Utility service rating (service size) at a service-entrance connection point\", \"datatype\": \"integer\", \"unit\": \"A\"}, \"overcurrent-protection\": {\"name\": \"Overcurrent-protection rating at a connection point that is not itself a breaker-protected circuit\", \"datatype\": \"integer\", \"unit\": \"A\"}}}}, \"children\": [], \"root\": \"example-48t-001\", \"parent\": \"example-48t-001\", \"extensions\": []}", + "$state": "ready", + "connection/fed-by-device-id": "bess", + "connection/fed-by-device-status": "OK", + "connection/fed-by-device-type": "energy.ebus.device.bess", + "connection/overcurrent-protection": "200", + "connection/service-rating": "200", + "info/direction": "UPSTREAM", + "meter/active-power": "-4617.0", + "meter/current-a": "56.71666666666666", + "meter/current-b": "46.474999999999994", + "meter/exported-energy": "76.95", + "meter/imported-energy": "64.55" + }, + "remote-ct-1": { + "$description": "{\"homie\": \"5.0\", \"version\": 1790000000000, \"type\": \"energy.ebus.device.circuit\", \"name\": \"remote-ct-1\", \"nodes\": {\"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}}, \"children\": [], \"root\": \"example-48t-001\", \"parent\": \"example-48t-001\", \"extensions\": []}", + "$state": "ready", + "meter/active-power": "250.0", + "meter/current": "2.1", + "meter/exported-energy": "0.0", + "meter/imported-energy": "900.0" + }, + "remote-ct-2": { + "$description": "{\"homie\": \"5.0\", \"version\": 1790000000000, \"type\": \"energy.ebus.device.circuit\", \"name\": \"remote-ct-2\", \"nodes\": {\"meter\": {\"name\": \"meter\", \"type\": \"energy.ebus.capability.meter\", \"properties\": {\"current\": {\"name\": \"Measured current\", \"datatype\": \"float\", \"unit\": \"A\"}, \"active-power\": {\"name\": \"Measured active power\", \"datatype\": \"float\", \"unit\": \"W\"}, \"imported-energy\": {\"name\": \"Measured energy imported\", \"datatype\": \"float\", \"unit\": \"Wh\"}, \"exported-energy\": {\"name\": \"Measured energy exported\", \"datatype\": \"float\", \"unit\": \"Wh\"}}}}, \"children\": [], \"root\": \"example-48t-001\", \"parent\": \"example-48t-001\", \"extensions\": []}", + "$state": "ready", + "meter/active-power": "480.0", + "meter/current": "4.0", + "meter/exported-energy": "0.0", + "meter/imported-energy": "1500.0" + } +} diff --git a/tests/fixtures/panelbench_unvalued_by_both.json b/tests/fixtures/panelbench_unvalued_by_both.json index 3fd47e6b..ed5cc491 100644 --- a/tests/fixtures/panelbench_unvalued_by_both.json +++ b/tests/fixtures/panelbench_unvalued_by_both.json @@ -80,6 +80,8 @@ "energy.ebus.device.circuit::kitchen Lights connection/feeds-device-id", "energy.ebus.device.circuit::kitchen Lights connection/feeds-device-status", "energy.ebus.device.circuit::kitchen Lights connection/feeds-device-type", + "energy.ebus.device.evse::SPAN Drive - Driveway config/user-max-charge-current", + "energy.ebus.device.evse::SPAN Drive - Garage config/user-max-charge-current", "energy.ebus.device.lugs::Downstream lugs connection/fed-by-device-id", "energy.ebus.device.lugs::Downstream lugs connection/fed-by-device-status", "energy.ebus.device.lugs::Downstream lugs connection/fed-by-device-type", diff --git a/tests/reference_payloads/README.md b/tests/reference_payloads/README.md index 3d32e879..a2d77c8c 100644 --- a/tests/reference_payloads/README.md +++ b/tests/reference_payloads/README.md @@ -13,6 +13,12 @@ Captures of what a panel actually serves, read by this repository's test suite t a version of an adapter reads the same bytes that version was built and tested against, out of its own site-packages. The alternative is what the integration was doing: vendoring copies, and then maintaining a guard to keep the copies honest — more machinery than 59 KB in two wheels. That reverses the 3.1.0 decision, whose reasoning (no runtime path reads them) was true and turned out not to be the deciding cost. `tests/test_packaging.py` and CI both assert each adapter wheel carries its capture. +**Synthetic trees live beside the loaders.** `synthetic_trees.py` builds parent/child trees by hand for shapes no capture here carries, each named by the builder that makes it. They are not captures and claim no provenance; every id and value is invented. +They come out in the capture's `{device_id: {topic: payload}}` shape, so `replay` and `devices_from_tree` in `schema_one.py` read both alike. + +**The reference captures are the one exception to package data.** `captures.py` reads the masked panel captures vendored under `tests/fixtures/captures/`: no emitter release produces them, so there is nothing to regenerate them from, and a SHA-256 pin +against their upstream commit keeps the copies honest instead. That directory's README records where they come from. `captures.py` turns each into the same `RetainedTopicTree` and replays it through `replay`. + ## `homie_schema.json` The `GET /api/v2/homie/schema` response, captured from a live SPAN Panel running firmware `spanos2/r202603/05`. Unauthenticated endpoint. Serial numbers are masked (last 4 chars replaced with `XXXX`). diff --git a/tests/reference_payloads/__init__.py b/tests/reference_payloads/__init__.py index 2f707841..984fe575 100644 --- a/tests/reference_payloads/__init__.py +++ b/tests/reference_payloads/__init__.py @@ -21,6 +21,16 @@ SDK in behind it, which is the same reason the two payloads were in different distributions to begin with. +`synthetic_trees` sits beside `schema_one` and builds parent/child trees by +hand, for shapes no reference payload carries. Its trees have the capture's +shape, so `schema_one` reads them the same way, and it reaches the SDK for the +same reason. + +`captures` reads the reference captures vendored under `tests/fixtures/captures/` +and replays each through `schema_one`'s `replay`. They are the one set of bytes +kept as a pinned copy rather than as package data, because no producer release +generates them. + Imported as a top-level package — `from reference_payloads.schema_one import ...` — because pytest puts `tests/` on `sys.path`, the same arrangement that makes `from conftest import ...` work throughout this suite. diff --git a/tests/reference_payloads/captures.py b/tests/reference_payloads/captures.py new file mode 100644 index 00000000..51cdd8f5 --- /dev/null +++ b/tests/reference_payloads/captures.py @@ -0,0 +1,253 @@ +"""The reference captures, and the replay that turns each into a snapshot. + +`tests/fixtures/captures/` holds masked captures of real panels on firmware +`spanos3/r202639/03`, vendored byte for byte from an upstream commit and pinned +by SHA-256 (see that directory's README). Unlike the payloads `schema_one` reads, +they are not package data: no emitter release produces them, so there is +nothing to regenerate them from, and the pin is what keeps the copies honest. + +A capture is in the emitter's `tree-v1` form: each device's parsed +`$description`, and its retained values split into `properties` and +`numeric_properties`. Both halves are the wire strings the panel published, in +its own literal form, so `CaptureTree.retained` merges them back into the +`RetainedTopicTree` a broker holds and `replay` feeds that to the adapter like +any other tree. Nothing here interprets a value. + +Tests over the captures are properties: they iterate `CAPTURES`, select what to +check by what each tree declares (the selectors below), and read the values they +expect from the same `CaptureTree` they replay. No capture name, device id or +value belongs in a test. +""" + +from __future__ import annotations + +from collections.abc import Callable, Mapping +from dataclasses import dataclass +import json +from pathlib import Path +import time +from types import MappingProxyType +from typing import Final + +from span_panel_api.models import SpanPanelSnapshot +from span_panel_api_schema_1 import SchemaOneAdapter + +from .schema_one import RetainedTopicTree, replay + +CAPTURES_DIR: Final = Path(__file__).resolve().parent.parent / "fixtures" / "captures" +"""Where the vendored captures, their `SHA256SUMS` and their provenance live.""" + +_SUFFIX: Final = "-tree-v1.json" + +CAPTURES: Final[tuple[str, ...]] = tuple( + sorted(path.name.removesuffix(_SUFFIX) for path in CAPTURES_DIR.glob(f"*{_SUFFIX}")) +) +"""Every capture's stem, sorted: the parametrize list of each property.""" + +_TYPE_PANEL: Final = "energy.ebus.device.distribution-enclosure" +_TYPE_CIRCUIT: Final = "energy.ebus.device.circuit" +_TYPE_BESS: Final = "energy.ebus.device.bess" + +_SPACES: Final = "info/spaces" +_FEEDS_DEVICE_ID: Final = "connection/feeds-device-id" +_METER_SHARED_WITH: Final = "meter/shared-with-device-ids" + + +@dataclass(frozen=True) +class CapturedDevice: + """One device of a capture: what its description declares and what it retained. + + `declared` holds every `node/property` the description declares, valued or + not; `values` holds the retained values, keyed the same way. A property in + `declared` and absent from `values` was declared and never published. + """ + + device_id: str + device_type: str + description: str + declared: frozenset[str] + values: Mapping[str, str] + + +@dataclass(frozen=True) +class CaptureTree: + """A parsed capture: its devices in the capture's order, and its panel.""" + + devices: Mapping[str, CapturedDevice] + root_id: str + + def device_type(self, device_id: str) -> str: + return self.devices[device_id].device_type + + def circuits(self) -> tuple[str, ...]: + """Every circuit-typed device, hosted in a breaker space or not.""" + return tuple(device_id for device_id, device in self.devices.items() if device.device_type == _TYPE_CIRCUIT) + + def declares(self, device_id: str, topic: str) -> bool: + """Whether the device's description declares `node/property`.""" + return topic in self.devices[device_id].declared + + def value(self, device_id: str, topic: str) -> str | None: + """The retained `node/property` value as the wire carries it, or None if unpublished.""" + return self.devices[device_id].values.get(topic) + + def number(self, device_id: str, topic: str) -> float | None: + """The retained value read as a number, or None if unpublished.""" + value = self.value(device_id, topic) + return None if value is None else float(value) + + def retained(self, *, drop_values_of: str | None = None) -> RetainedTopicTree: + """The tree as a broker retains it, optionally withholding one device's values. + + A withheld device keeps its description, so it is declared and unvalued: + what the adapter sees between a device describing itself and its values + arriving. + """ + if drop_values_of is not None and drop_values_of not in self.devices: + raise KeyError(f"no device {drop_values_of!r} to withhold") + return { + device_id: { + "$description": device.description, + **({} if device_id == drop_values_of else device.values), + } + for device_id, device in self.devices.items() + } + + +def capture_path(stem: str) -> Path: + return CAPTURES_DIR / f"{stem}{_SUFFIX}" + + +_TREES: Final[dict[str, CaptureTree]] = {} + + +def capture_tree(stem: str) -> CaptureTree: + """Parse one capture. Cached and read-only, so every test reads the same tree.""" + if stem not in _TREES: + _TREES[stem] = _parse(capture_path(stem)) + return _TREES[stem] + + +def _parse(path: Path) -> CaptureTree: + raw: object = json.loads(path.read_text(encoding="utf-8")) + return capture_tree_from_document(_json_object(raw, path.name), path.name) + + +def capture_tree_from_document(document: Mapping[str, object], where: str) -> CaptureTree: + """Parse a `tree-v1` document already read from JSON; `where` names it in errors.""" + devices = { + device_id: _device(device_id, body, f"{where}: {device_id}") + for device_id, body in _json_object(document["devices"], f"{where}: devices").items() + } + roots = [device_id for device_id, device in devices.items() if device.device_type == _TYPE_PANEL] + if len(roots) != 1: + raise ValueError(f"{where} holds {len(roots)} panels, not one") + return CaptureTree(devices=MappingProxyType(devices), root_id=roots[0]) + + +def capture_adapter( + stem: str, *, drop_values_of: str | None = None, clock: Callable[[], float] = time.monotonic +) -> SchemaOneAdapter: + """A fresh adapter that has received the whole capture, the way a broker replays it. + + `clock` is the adapter's monotonic source, as `replay` takes it. + """ + tree = capture_tree(stem) + return replay(tree.retained(drop_values_of=drop_values_of), tree.root_id, clock=clock) + + +def capture_snapshot(stem: str, *, drop_values_of: str | None = None) -> SpanPanelSnapshot: + """The snapshot the adapter builds from the replayed capture.""" + return capture_adapter(stem, drop_values_of=drop_values_of).build_snapshot() + + +def hosted_circuits(tree: CaptureTree) -> tuple[str, ...]: + """Circuits whose description declares the breaker spaces they occupy.""" + return tuple(circuit_id for circuit_id in tree.circuits() if tree.declares(circuit_id, _SPACES)) + + +def space_less_meters(tree: CaptureTree) -> tuple[str, ...]: + """Circuit-typed devices whose description declares no breaker space.""" + return tuple(circuit_id for circuit_id in tree.circuits() if not tree.declares(circuit_id, _SPACES)) + + +def circuit_fed_batteries(tree: CaptureTree) -> Mapping[str, str]: + """Battery id -> the circuit whose `connection/feeds-device-id` names it. + + A battery named by two circuits raises: no capture has that shape, and a + property written for one feeding circuit would silently check only one. + """ + fed: dict[str, str] = {} + for circuit_id in tree.circuits(): + target = tree.value(circuit_id, _FEEDS_DEVICE_ID) + if target is not None and target in tree.devices and tree.device_type(target) == _TYPE_BESS: + if target in fed: + raise ValueError(f"battery {target!r} is fed by both {fed[target]!r} and {circuit_id!r}") + fed[target] = circuit_id + return fed + + +def shared_meter_peers(tree: CaptureTree) -> Mapping[str, tuple[str, ...]]: + """Circuit id -> the ids its `meter/shared-with-device-ids` value lists, as published. + + Read from the wire value alone, split on commas as the eBus meter catalog + defines the property, so a property can compare the adapter's grouping with + what each circuit declared. Circuits that publish no value, or an empty one, + are absent. + """ + peers: dict[str, tuple[str, ...]] = {} + for circuit_id in tree.circuits(): + listed = tuple( + part.strip() for part in (tree.value(circuit_id, _METER_SHARED_WITH) or "").split(",") if part.strip() + ) + if listed: + peers[circuit_id] = listed + return peers + + +def _device(device_id: str, body: object, where: str) -> CapturedDevice: + fields = _json_object(body, where) + description = _json_object(fields["description"], f"{where}: description") + device_type = description["type"] + if not isinstance(device_type, str): + raise TypeError(f"{where}: description type is not a string") + declared = frozenset( + f"{node_id}/{property_id}" + for node_id, node in _json_object(description["nodes"], f"{where}: nodes").items() + for property_id in _json_object(_json_object(node, f"{where}: {node_id}")["properties"], f"{where}: {node_id}") + ) + properties = _json_strings(fields["properties"], f"{where}: properties") + numeric = _json_strings(fields["numeric_properties"], f"{where}: numeric_properties") + if properties.keys() & numeric.keys(): + raise ValueError(f"{where} retains {sorted(properties.keys() & numeric.keys())} twice") + values = {**properties, **numeric} + undeclared = sorted(set(values) - declared) + if undeclared: + raise ValueError(f"{where} retains values it does not declare: {undeclared}") + return CapturedDevice( + device_id=device_id, + device_type=device_type, + description=json.dumps(description), + declared=declared, + values=MappingProxyType(values), + ) + + +def _json_object(value: object, where: str) -> dict[str, object]: + if not isinstance(value, dict): + raise TypeError(f"{where} is not a JSON object") + entries: dict[str, object] = {} + for key, item in value.items(): + if not isinstance(key, str): + raise TypeError(f"{where} has a non-string key") + entries[key] = item + return entries + + +def _json_strings(value: object, where: str) -> dict[str, str]: + strings: dict[str, str] = {} + for key, item in _json_object(value, where).items(): + if not isinstance(item, str): + raise TypeError(f"{where}: {key} is not a string") + strings[key] = item + return strings diff --git a/tests/reference_payloads/reidentify.py b/tests/reference_payloads/reidentify.py new file mode 100644 index 00000000..9a59b149 --- /dev/null +++ b/tests/reference_payloads/reidentify.py @@ -0,0 +1,207 @@ +"""Give every device of a retained-topic tree a new id, keeping the tree intact. + +Firmware may change device ids without changing the devices. A test that wants +to know whether something follows the device rather than its id renames a tree +with `rename_devices` and replays both. + +Everything that names a device moves together: the tree's keys, a description's +`children`, `parent` and `root`, and the values of the properties that carry a +device id. An id the tree does not hold (a dangling reference) is left as +published. + +The reference captures are masked upstream, with ids such as `circuit-1` and +site values such as `Masked Address`, so a test that looked for their originals +in an export would test nothing. `reidentify` plants identifying values for it +to look for instead: realistic, seeded, and every one of them invented. +""" + +from __future__ import annotations + +from collections.abc import Callable, Mapping +from dataclasses import dataclass +import json +import random +import string +from typing import Final + +from .schema_one import RetainedTopicTree + +_ID_PROPERTIES: Final = frozenset({"connection/feeds-device-id", "connection/fed-by-device-id", "grid/grid-forming-entity"}) +_ID_LIST_SUFFIX: Final = "/shared-with-device-ids" + +_TYPE_CIRCUIT: Final = "energy.ebus.device.circuit" +_TYPE_LUGS: Final = "energy.ebus.device.lugs" +_LUGS_SUFFIXES: Final[Mapping[str, str]] = {"UPSTREAM": "lugs-up", "DOWNSTREAM": "lugs-dn"} +_DIRECTION: Final = "info/direction" +_SERIAL: Final = "info/serial-number" +_DESCRIPTION: Final = "$description" +_NAME: Final = "info/name" +_ALNUM: Final = string.ascii_lowercase + string.digits +_SEEDED_SITE: Final[Mapping[str, str]] = { + "address-lines": "4821 Seeded Lane", + "locality": "Seededville", + "region": "ZQ", + "postal-code": "98000", + "wifi-ssid": "seeded-network", + "latitude": "47.6", + "longitude": "-122.3", + "utility-meter-serial-number": "SEEDED-METER-77", + "time-zone": "Etc/GMT+9", + "country-code": "QZ", +} +"""The planted value of each masked site property, by property id on whichever node publishes it.""" +_SEEDED_SITE_NAME: Final = "Seeded Residence" + + +@dataclass(frozen=True) +class Reidentified: + """A re-identified tree, its root, and every identifying value planted in it.""" + + tree: RetainedTopicTree + root_id: str + planted: frozenset[str] + + +def rename_devices(tree: RetainedTopicTree, root_id: str, new_id: Callable[[str], str]) -> tuple[RetainedTopicTree, str]: + """The tree with every device renamed by `new_id`, and the new root id.""" + names = {device_id: new_id(device_id) for device_id in tree} + if len(set(names.values())) != len(names): + raise ValueError("new_id gave two devices the same id") + renamed = { + names[device_id]: {topic: _value(topic, value, names) for topic, value in topics.items()} + for device_id, topics in tree.items() + } + return renamed, names[root_id] + + +def _value(topic: str, value: str, names: Mapping[str, str]) -> str: + if topic == _DESCRIPTION: + return _description(value, names) + if topic in _ID_PROPERTIES: + return names.get(value, value) + if topic.endswith(_ID_LIST_SUFFIX): + return ",".join(names.get(part.strip(), part.strip()) for part in value.split(",") if part.strip()) + return value + + +def _description(text: str, names: Mapping[str, str]) -> str: + description: object = json.loads(text) + if not isinstance(description, dict): + raise TypeError("a $description is not a JSON object") + for key in ("parent", "root"): + reference = description.get(key) + if isinstance(reference, str): + description[key] = names.get(reference, reference) + children = description.get("children") + if isinstance(children, list): + description["children"] = [names.get(child, child) if isinstance(child, str) else child for child in children] + return json.dumps(description) + + +def reidentify(tree: RetainedTopicTree, root_id: str, seed: int) -> Reidentified: + """The tree with every device id, serial number and masked site value replaced by a seeded one. + + Ids take the shapes a panel publishes: a circuit a 32-hex id, the root + `nt-<4 digits>-<5 alnum>`, lugs `-lugs-up` / `-lugs-dn` by direction, + every other device `-<10 alnum>`. Each distinct `info/serial-number` + becomes a distinct vendor-style serial, except a serial that is a device's + id, as the panel's is: it becomes that device's new id, so the new root id + is also the panel serial embedded in its children's ids. Every masked site + property takes its value in `_SEEDED_SITE`, and one a device declares but leaves + unvalued or valued `""` is planted too (a capture may only declare it), and the panel's `info/name` and + `$description` `name` the site's name. A description `name` that is a + device's id (as the captures' are) follows the id. + + Every reference moves with its device (`rename_devices`); a valued-empty + `""` stays empty. A device with no `$description` (one that has not + described itself) has no type to read, so it takes the `-<10 alnum>` + shape, and stays without one. `planted` holds every new id, serial and site value, and + the same seed always gives the same tree. + """ + rng = random.Random(seed) + taken: set[str] = set() + + def alnum(length: int) -> str: + return "".join(rng.choice(_ALNUM) for _ in range(length)) + + def fresh(make: Callable[[], str]) -> str: + value = make() + while value in taken: + value = make() + taken.add(value) + return value + + new_root = fresh(lambda: f"nt-{rng.randrange(10_000):04d}-{alnum(5)}") + names = {root_id: new_root} + for device_id in sorted(tree): + if device_id == root_id: + continue + topics = tree[device_id] + device_type = _description_object(topics[_DESCRIPTION]).get("type") if _DESCRIPTION in topics else None + suffix = _LUGS_SUFFIXES.get(topics.get(_DIRECTION, "")) if device_type == _TYPE_LUGS else None + if device_type == _TYPE_CIRCUIT: + names[device_id] = fresh(lambda: f"{rng.getrandbits(128):032x}") + elif suffix is not None and f"{new_root}-{suffix}" not in taken: + names[device_id] = fresh(lambda: f"{new_root}-{suffix}") + else: + names[device_id] = fresh(lambda: f"{new_root}-{alnum(10)}") + + serials: dict[str, str] = {} + for device_id in sorted(tree): + serial = tree[device_id].get(_SERIAL, "") + if serial and serial not in serials: + serials[serial] = names.get(serial) or fresh(lambda: f"tg{rng.randrange(10**9):09d}{alnum(3)}") + + renamed, new_root = rename_devices(tree, root_id, names.__getitem__) + planted = set(renamed) + seeded: dict[str, dict[str, str]] = {} + for device_id, topics in renamed.items(): + values = dict(topics) + for topic, value in topics.items(): + property_id = topic.partition("/")[2] + if not value or topic.startswith("$") or "/$" in topic: + continue + if topic == _SERIAL: + values[topic] = serials[value] + elif property_id in _SEEDED_SITE: + values[topic] = _SEEDED_SITE[property_id] + elif topic == _NAME and device_id == new_root: + values[topic] = _SEEDED_SITE_NAME + else: + continue + planted.add(values[topic]) + if _DESCRIPTION in topics: + description = _description_object(topics[_DESCRIPTION]) + for topic in _declared_site_topics(description): + if not values.get(topic): + values[topic] = _SEEDED_SITE[topic.partition("/")[2]] + planted.add(values[topic]) + name = description.get("name") + if device_id == new_root and isinstance(name, str) and name: + description["name"] = _SEEDED_SITE_NAME + planted.add(_SEEDED_SITE_NAME) + elif isinstance(name, str) and name in names: + description["name"] = names[name] + values[_DESCRIPTION] = json.dumps(description) + seeded[device_id] = values + return Reidentified(seeded, new_root, frozenset(planted)) + + +def _declared_site_topics(description: Mapping[str, object]) -> list[str]: + """The `/` topics a description declares for a masked site property.""" + declared = description.get("nodes") + if not isinstance(declared, dict): + return [] + found: list[str] = [] + for node_id, node in declared.items(): + node_properties = node.get("properties") if isinstance(node, dict) else None + if isinstance(node_properties, dict): + found.extend(f"{node_id}/{property_id}" for property_id in node_properties if property_id in _SEEDED_SITE) + return found + + +def _description_object(text: str) -> dict[str, object]: + description: object = json.loads(text) + if not isinstance(description, dict): + raise TypeError("a $description is not a JSON object") + return {str(key): value for key, value in description.items()} diff --git a/tests/reference_payloads/schema_one.py b/tests/reference_payloads/schema_one.py index 466e63b3..76567f57 100644 --- a/tests/reference_payloads/schema_one.py +++ b/tests/reference_payloads/schema_one.py @@ -8,7 +8,8 @@ `devices_from_tree` stays beside the capture for the reason it was written: a tree is not directly usable, every consumer of it has to replay the retained topics through `DiscoveredDevice` first, and separating the two would put the -same twelve lines in each of the test modules that read it. +same twelve lines in each of the test modules that read it. `replay` is the same +step one level up, for a test that wants the adapter rather than the devices. **The bytes come out of the installed wheel, not out of this tree.** The capture is package data of `span-panel-api-schema-1` — read through @@ -21,23 +22,49 @@ from __future__ import annotations -from collections.abc import Mapping +from collections.abc import Callable, Mapping from importlib.resources import files import json +from pathlib import Path +import time +from ebus_sdk import decode_empty_string, encode_empty_string from ebus_sdk.homie import DiscoveredDevice +from span_panel_api.models import V2HomieSchema +from span_panel_api_schema_1 import SchemaOneAdapter + type RetainedTopicTree = Mapping[str, Mapping[str, str]] """A retained-topic capture: device id -> topic -> payload, all strings. `$description` is a JSON *string*, not a nested object — it is stored on the wire exactly as the panel publishes it, and `update_description` parses it. + +A value is the payload as retained, with one reading added: `""` is an empty +value. A broker never retains a zero-length payload, because publishing one +deletes the retained message, so a tree can only hold `""` where an empty value +was written in its decoded form, as the masked export writes it. It is replayed +as Homie 5 spells an empty value on the wire, a single `0x00`, and read as +`""`, exactly as `"\x00"` is. """ + +def retained_payload(value: str) -> str: + """The payload a tree's value is replayed as: `""` as `0x00`, anything else as itself. + + The one rule every replay of a tree applies (see `RetainedTopicTree`), shared + so that a replay sending `""` raw, which is a clear, cannot be written again. + """ + return encode_empty_string(value) + + _PARENT_CHILD_TREE = files("span_panel_api_schema_1") / "reference" / "parent_child_tree.json" +_OTHER_MODEL_TREE = Path(__file__).parent.parent / "fixtures" / "other_model_tree.json" _DEFAULT_STATE = "ready" _DOMAIN = "ebus" +_HOMIE_VERSION = "5" +_INFO = "info" def parent_child_tree() -> RetainedTopicTree: @@ -53,6 +80,18 @@ def parent_child_tree() -> RetainedTopicTree: return tree +def other_model_tree() -> RetainedTopicTree: + """The hand-authored tree `test_schema_one_other_models.py` reads. + + Test data only, kept under `tests/fixtures/` rather than shipped with + schema-1: it is not a capture, and no downstream suite replays it. + """ + tree: object = json.loads(_OTHER_MODEL_TREE.read_text(encoding="utf-8")) + if not isinstance(tree, dict): + raise TypeError(f"{_OTHER_MODEL_TREE.name} is not a JSON object") + return tree + + def device_from_topics(device_id: str, topics: Mapping[str, str]) -> DiscoveredDevice: """Rebuild one discovered device from its retained topics. @@ -69,7 +108,7 @@ def device_from_topics(device_id: str, topics: Mapping[str, str]) -> DiscoveredD continue node, _, prop = topic.partition("/") if prop: - device.update_property(node, prop, value) + device.update_property(node, prop, decode_empty_string(value)) return device @@ -81,3 +120,55 @@ def devices_from_tree(tree: RetainedTopicTree) -> list[DiscoveredDevice]: build devices the same way. """ return [device_from_topics(device_id, topics) for device_id, topics in tree.items()] + + +def replay( + tree: RetainedTopicTree, + root_id: str, + *, + clock: Callable[[], float] = time.monotonic, + withhold_description_of: str | None = None, +) -> SchemaOneAdapter: + """Feed a whole tree to a fresh adapter the way the broker replays it. + + Every message goes through `handle_message`, so the tree takes the SDK's real + discovery path rather than a stubbed one. The root comes first, then the + rest in the tree's order. That is the friendly order, not a requirement: the + SDK routes a child only once its parent is ready, and the adapter holds a + message that arrives earlier until its route exists. + + The REST half of connecting is answered from the tree itself: the schema's + firmware and data-model versions are the ones the root retains, so a test + never states a second firmware beside the one its tree publishes. + + `clock` is the adapter's monotonic source, for a test that steps through a + grace the adapter waits out. + + `withhold_description_of` leaves out one device's `$description` and `$state` + but still delivers its values: the device its parent declared as a child and + that has not yet described itself, with whatever it has already published. + + An empty value goes out as `0x00` (see `RetainedTopicTree`): sent as `""`, + it would be a clear, which no retained tree holds. + """ + root = tree[root_id] + adapter = SchemaOneAdapter( + root_id, + V2HomieSchema( + firmware_version=root.get(f"{_INFO}/firmware-version", ""), + types_schema_hash="sha256:test", + types={}, + data_model_version=root.get(f"{_INFO}/data-model-version", "1.0"), + ), + clock=clock, + ) + for device_id in [root_id, *(other for other in tree if other != root_id)]: + topics = tree[device_id] + prefix = f"{_DOMAIN}/{_HOMIE_VERSION}/{device_id}" + if device_id != withhold_description_of: + adapter.handle_message(f"{prefix}/$description", topics["$description"]) + adapter.handle_message(f"{prefix}/$state", topics.get("$state", _DEFAULT_STATE)) + for topic, value in topics.items(): + if not topic.startswith("$"): + adapter.handle_message(f"{prefix}/{topic}", retained_payload(value)) + return adapter diff --git a/tests/reference_payloads/synthetic_trees.py b/tests/reference_payloads/synthetic_trees.py new file mode 100644 index 00000000..c3fcd4aa --- /dev/null +++ b/tests/reference_payloads/synthetic_trees.py @@ -0,0 +1,457 @@ +"""Hand-built parent/child trees, for shapes the reference payloads do not carry. + +A test that needs a meter without a breaker space, a pair of circuits sharing one +meter, or a reading the reference tree never publishes builds it here rather than +editing a capture: the capture stays what a producer actually sent, and the shape +a test asks about is named by the builder that makes it. + +**Everything is synthetic.** Device ids are neutral (`panel-a`, `c-1`, +`meter-a`), values are invented and chosen only to be told apart, and nothing is +copied from any capture. Datatypes and units follow the eBus capability +catalogs vendored under `packages/schema-1/spec/catalogs/` where those define +the property. + +**A builder declares, and values, exactly what its shape needs.** Each takes only +what a test varies; everything else is fixed. An absent property is not +declared at all, while one declared and not yet arrived comes from +`without_values`, so the two stay distinct the way they are on the wire. Values are published as the wire +carries them, in the publisher's frame, and no builder interprets a sign or a +direction: that is the adapter's job, and the tests are about whether it does it. + +Builders return `SyntheticDevice`; `tree` assembles a panel and its children into +the same `RetainedTopicTree` shape a capture has, so `replay` and +`devices_from_tree` read both alike, and `discovered` rebuilds one device alone +for a test that calls a per-device builder directly. +""" + +from __future__ import annotations + +from collections.abc import Mapping, Sequence +from dataclasses import dataclass, replace +import json +from typing import Final, Literal, NotRequired, TypedDict + +from ebus_sdk.homie import DiscoveredDevice + +from .schema_one import RetainedTopicTree, device_from_topics + +PANEL_ID: Final = "panel-a" +"""The panel's device id, which is also its serial number.""" + +FIRMWARE_VERSION: Final = "spanos3/r202639/03" +"""The firmware every synthetic panel reports.""" + +_TYPE_PANEL: Final = "energy.ebus.device.distribution-enclosure" +_TYPE_CIRCUIT: Final = "energy.ebus.device.circuit" +_TYPE_LUGS: Final = "energy.ebus.device.lugs" +_TYPE_EVSE: Final = "energy.ebus.device.evse" +_TYPE_BESS: Final = "energy.ebus.device.bess" +_CAPABILITY_PREFIX: Final = "energy.ebus.capability" + + +class PropertyDeclaration(TypedDict): + """One property as a `$description` declares it.""" + + name: str + datatype: str + format: NotRequired[str] + unit: NotRequired[str] + settable: NotRequired[bool] + + +type NodeDeclarations = Mapping[str, Mapping[str, PropertyDeclaration]] +"""Node id -> property id -> declaration.""" + + +@dataclass(frozen=True) +class SyntheticDevice: + """One device of a synthetic tree: its declaration and its retained values. + + `name` is the `$description.name`, fixed when the device is built, so dropping + a value never changes the description. `values` is keyed `node/property`, the + topic suffix the broker retains, and every key in it is declared in `nodes`. + """ + + device_id: str + device_type: str + name: str + nodes: NodeDeclarations + values: Mapping[str, str] + + +@dataclass(frozen=True) +class MeterReading: + """The four values a circuit meter publishes, as the wire carries them.""" + + active_power_w: float + current_a: float + imported_energy_wh: float + exported_energy_wh: float + + +METER_READING: Final = MeterReading( + active_power_w=-240.5, + current_a=2.0, + imported_energy_wh=1250.5, + exported_energy_wh=3875.25, +) +"""The default reading. Imported and exported differ, so a swap shows.""" + +_DECLARATIONS: Final[NodeDeclarations] = { + "info": { + "name": {"name": "Name", "datatype": "string"}, + "spaces": {"name": "Breaker space number(s), comma-separated", "datatype": "string"}, + "nominal-voltage": {"name": "Rated voltage of the circuit", "datatype": "float", "unit": "V"}, + "serial-number": {"name": "Serial number", "datatype": "string"}, + "vendor-name": {"name": "Vendor name", "datatype": "string"}, + "model": {"name": "Model", "datatype": "string"}, + "firmware-version": {"name": "Firmware version", "datatype": "string"}, + "data-model-version": {"name": "eBus data-model version", "datatype": "string"}, + "direction": {"name": "Direction", "datatype": "enum", "format": "UPSTREAM,DOWNSTREAM"}, + }, + "meter": { + "active-power": {"name": "Active power", "datatype": "float", "unit": "W"}, + "current": {"name": "Current", "datatype": "float", "unit": "A"}, + "imported-energy": {"name": "Energy imported", "datatype": "float", "unit": "Wh"}, + "exported-energy": {"name": "Energy exported", "datatype": "float", "unit": "Wh"}, + "shared-with-device-ids": {"name": "Other devices this meter also measures", "datatype": "string"}, + "voltage-a": {"name": "L1 voltage", "datatype": "float", "unit": "V"}, + "voltage-b": {"name": "L2 voltage", "datatype": "float", "unit": "V"}, + "busbar-current": {"name": "Busbar current", "datatype": "float", "unit": "A"}, + "frequency": {"name": "AC frequency", "datatype": "float", "unit": "Hz"}, + }, + "switch": { + "relay": {"name": "Relay state", "datatype": "enum", "format": "UNKNOWN,OPEN,CLOSED"}, + "relay-controllable": {"name": "Can the relay be commanded by the user?", "datatype": "boolean"}, + "relay-requester": { + "name": "Actor requesting the relay state", + "datatype": "enum", + "format": "UNKNOWN,NONE,LOAD_SHED,USER,PCS,CONFIGURATION,FAULT", + }, + "shared-with-device-ids": {"name": "Other devices this relay also switches", "datatype": "string"}, + "lock-state": {"name": "Lock state", "datatype": "enum", "format": "UNLOCKED,LOCKED"}, + }, + "breaker": { + "rating": {"name": "Breaker rating", "datatype": "integer", "unit": "A"}, + "poles": {"name": "Number of breaker poles", "datatype": "integer", "format": "1:4:1"}, + "protection-functions": { + "name": "Protection types", + "datatype": "enum", + "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT", + }, + }, + "load-shed": { + "priority": {"name": "Shed priority", "datatype": "enum", "format": "UNKNOWN,OFF_GRID,SOC_THRESHOLD,NEVER"}, + }, + "connection": { + "feeds-device-id": {"name": "Device id fed by this connection", "datatype": "string"}, + "feeds-device-type": {"name": "Type of the device fed", "datatype": "string"}, + "feeds-device-status": {"name": "Link health to the device fed", "datatype": "enum", "format": "OK,LOST,DEGRADED"}, + "feeds-role": { + "name": "Role of a downstream node not published as a device", + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + }, + "overcurrent-protection": {"name": "Overcurrent protection rating", "datatype": "integer", "unit": "A"}, + }, + "soc": { + "soc": {"name": "State of charge", "datatype": "float", "unit": "%"}, + "soe": {"name": "State of energy", "datatype": "float", "unit": "kWh"}, + }, + "status": { + "communication-state": {"name": "Communication state", "datatype": "enum", "format": "OK,DEGRADED,LOST,UNKNOWN"}, + "status": {"name": "Status", "datatype": "enum", "format": "AVAILABLE,PREPARING,CHARGING,UNAVAILABLE"}, + }, +} +"""Every property a builder may declare. + +Datatypes and units follow the vendored catalogs wherever they define the +property; the names are this suite's own, and the adapter reads none of them. +""" + + +def _declare(values: Mapping[str, str], *, settable: Sequence[str] = ()) -> NodeDeclarations: + """The declaration of every valued path. + + `settable` names the paths whose declaration carries `settable: true`; every + other declaration omits the attribute, which Homie 5 reads as not settable. + """ + nodes: dict[str, dict[str, PropertyDeclaration]] = {} + for path in values: + node, _, prop = path.partition("/") + declaration = _DECLARATIONS[node][prop] + nodes.setdefault(node, {})[prop] = {**declaration, "settable": True} if path in settable else declaration + return nodes + + +def _number(value: float) -> str: + return repr(float(value)) + + +def _meter(reading: MeterReading) -> dict[str, str]: + return { + "meter/active-power": _number(reading.active_power_w), + "meter/current": _number(reading.current_a), + "meter/imported-energy": _number(reading.imported_energy_wh), + "meter/exported-energy": _number(reading.exported_energy_wh), + } + + +def panel( + *, + model: str = "MAIN_32", + advertised_models: Sequence[str] | None = None, + busbar_current_a: float | None = None, + frequency_hz: float | None = None, +) -> SyntheticDevice: + """The panel, reporting `model` and advertising `advertised_models`. + + The advertised set is the `$format` of `info/model`, and defaults to the one + model reported. The busbar current and the line frequency are declared only + when given. + """ + values = { + "info/serial-number": PANEL_ID, + "info/vendor-name": "SPAN", + "info/model": model, + "info/firmware-version": FIRMWARE_VERSION, + "info/data-model-version": "1.0", + "meter/voltage-a": _number(120.5), + "meter/voltage-b": _number(121.5), + } + if busbar_current_a is not None: + values["meter/busbar-current"] = _number(busbar_current_a) + if frequency_hz is not None: + values["meter/frequency"] = _number(frequency_hz) + nodes = _declare(values) + advertised = ",".join(advertised_models if advertised_models is not None else (model,)) + model_declaration: PropertyDeclaration = {"name": "Model", "datatype": "enum", "format": advertised} + return SyntheticDevice( + device_id=PANEL_ID, + device_type=_TYPE_PANEL, + name="Panel", + nodes={**nodes, "info": {**nodes["info"], "model": model_declaration}}, + values=values, + ) + + +def lugs(direction: Literal["UPSTREAM", "DOWNSTREAM"], *, overcurrent_protection_a: int | None = None) -> SyntheticDevice: + """A lugs device, `lugs-upstream` or `lugs-downstream`. + + Its overcurrent-protection rating is declared only when given. + """ + values = { + "info/direction": direction, + "meter/active-power": _number(0.0), + "meter/imported-energy": _number(0.0), + "meter/exported-energy": _number(0.0), + } + if overcurrent_protection_a is not None: + values["connection/overcurrent-protection"] = str(overcurrent_protection_a) + return SyntheticDevice( + device_id=f"lugs-{direction.lower()}", + device_type=_TYPE_LUGS, + name=f"{direction.capitalize()} lugs", + nodes=_declare(values), + values=values, + ) + + +def hosted_circuit( + device_id: str, + spaces: Sequence[int], + *, + name: str | None = None, + reading: MeterReading = METER_READING, + feeds_role: str | None = None, + feeds: SyntheticDevice | None = None, + feed_status: str = "OK", + nominal_voltage_v: float | None = None, + protection_functions: Sequence[str] = (), + relay: bool = True, + meter_shared_with: Sequence[str] = (), + relay_shared_with: Sequence[str] = (), +) -> SyntheticDevice: + """A circuit occupying `spaces`, with a breaker and a controllable relay. + + One pole per space. With `relay` false the circuit declares no `switch` node + at all. The connection node is declared only when the circuit has a role or + feeds a device; the nominal voltage, the protection functions and each + shared-with list only when given. `feeds_role` and the shared-with lists are + published exactly as given, so an out-of-set role, or a list naming the + circuit itself or an id no device has, can be published too. + """ + if relay_shared_with and not relay: + raise ValueError(f"{device_id} has no relay to share") + circuit_name = name if name is not None else f"Circuit {device_id}" + values = { + "info/name": circuit_name, + "info/spaces": ",".join(str(space) for space in spaces), + **_meter(reading), + "breaker/rating": "20", + "breaker/poles": str(len(spaces)), + "load-shed/priority": "SOC_THRESHOLD", + } + if relay: + values["switch/relay"] = "CLOSED" + values["switch/relay-controllable"] = "true" + values["switch/relay-requester"] = "NONE" + if meter_shared_with: + values["meter/shared-with-device-ids"] = ",".join(meter_shared_with) + if relay_shared_with: + values["switch/shared-with-device-ids"] = ",".join(relay_shared_with) + if feeds_role is not None: + values["connection/feeds-role"] = feeds_role + if feeds is not None: + values["connection/feeds-device-id"] = feeds.device_id + values["connection/feeds-device-type"] = feeds.device_type + values["connection/feeds-device-status"] = feed_status + if nominal_voltage_v is not None: + values["info/nominal-voltage"] = _number(nominal_voltage_v) + if protection_functions: + values["breaker/protection-functions"] = ",".join(protection_functions) + return SyntheticDevice( + device_id=device_id, + device_type=_TYPE_CIRCUIT, + name=circuit_name, + nodes=_declare(values, settable=("switch/relay", "load-shed/priority")), + values=values, + ) + + +def space_less_meter(device_id: str = "meter-a", *, reading: MeterReading = METER_READING) -> SyntheticDevice: + """A circuit-typed device that is only a meter. + + It declares no `info` node, so no breaker space and no name, and no + `switch` node, so no relay. + """ + values = _meter(reading) + return SyntheticDevice( + device_id=device_id, device_type=_TYPE_CIRCUIT, name="Meter", nodes=_declare(values), values=values + ) + + +def shared_pair(first: str = "c-1", second: str = "c-2", *, space: int = 1) -> tuple[SyntheticDevice, SyntheticDevice]: + """Two circuits on one space, sharing one meter and one relay. + + Each names the other in `meter/` and `switch/shared-with-device-ids`, and + both publish the same reading, as one meter measuring both would. + """ + + def member(device_id: str, peer: str) -> SyntheticDevice: + return hosted_circuit(device_id, (space,), meter_shared_with=(peer,), relay_shared_with=(peer,)) + + return member(first, second), member(second, first) + + +def evse(device_id: str = "evse-a", *, lock_settable: bool = True) -> SyntheticDevice: + """A charger whose `switch/lock-state` is settable unless told otherwise.""" + values = { + "info/vendor-name": "SPAN", + "info/model": "Charger", + "info/serial-number": f"{device_id}-serial", + "switch/lock-state": "UNLOCKED", + "status/status": "AVAILABLE", + } + return SyntheticDevice( + device_id=device_id, + device_type=_TYPE_EVSE, + name="Charger", + nodes=_declare(values, settable=("switch/lock-state",) if lock_settable else ()), + values=values, + ) + + +def battery(device_id: str = "battery-a") -> SyntheticDevice: + """A battery with its identity, state of charge, power and link state.""" + values = { + "info/vendor-name": "Example", + "info/model": "Battery", + "info/serial-number": f"{device_id}-serial", + "soc/soc": _number(50.0), + "soc/soe": _number(6.5), + "meter/active-power": _number(0.0), + "status/communication-state": "OK", + } + return SyntheticDevice( + device_id=device_id, device_type=_TYPE_BESS, name="Battery", nodes=_declare(values), values=values + ) + + +def circuit_fed_battery( + circuit_id: str = "c-1", battery_id: str = "battery-a", *, space: int = 1, status: str = "OK" +) -> tuple[SyntheticDevice, SyntheticDevice]: + """A battery and the circuit whose `connection/feeds-device-id` names it. + + `status` is the circuit's `connection/feeds-device-status`, the panel's view + of its link to the battery. + """ + fed = battery(battery_id) + return hosted_circuit(circuit_id, (space,), feeds=fed, feed_status=status), fed + + +def without_values(device: SyntheticDevice, *paths: str) -> SyntheticDevice: + """The same device, still declaring everything, with `paths` unvalued. + + No paths drops every value: a device that has described itself and whose + retained values have not arrived. A path the device does not declare is + refused, so a misspelt one cannot pass as a dropped value. + """ + declared = {f"{node}/{prop}" for node, properties in device.nodes.items() for prop in properties} + if undeclared := [path for path in paths if path not in declared]: + raise ValueError(f"{device.device_id} declares no {', '.join(undeclared)}") + dropped = set(paths) if paths else set(device.values) + return replace(device, values={path: value for path, value in device.values.items() if path not in dropped}) + + +def panel_with_positions(model: str, positions: Sequence[int]) -> RetainedTopicTree: + """A panel reporting `model`, with one single-pole circuit `c-` at each position.""" + return tree(panel(model=model), *(hosted_circuit(f"c-{position}", (position,)) for position in positions)) + + +def tree(root: SyntheticDevice, *children: SyntheticDevice) -> RetainedTopicTree: + """The retained topics of `root` and its `children`, as a capture holds them. + + Every child is a direct child of the root, listed in the root's + `$description.children` in the order given. A device id given twice is + refused. + """ + seen = {root.device_id} + for child in children: + if child.device_id in seen: + raise ValueError(f"device id {child.device_id} is given twice") + seen.add(child.device_id) + child_ids = [child.device_id for child in children] + topics = {root.device_id: _retained(root, root_id=None, children=child_ids)} + for child in children: + topics[child.device_id] = _retained(child, root_id=root.device_id, children=()) + return topics + + +def discovered(device: SyntheticDevice) -> DiscoveredDevice: + """One device rebuilt alone, as a child of `PANEL_ID`, for a per-device builder.""" + return device_from_topics(device.device_id, _retained(device, root_id=PANEL_ID, children=())) + + +def _retained(device: SyntheticDevice, *, root_id: str | None, children: Sequence[str]) -> dict[str, str]: + """`$description`, `$state` and every value, as the broker retains them. + + A root's description carries neither `root` nor `parent`, as Homie 5 has it; + every other device names the root as both. + """ + description: dict[str, object] = { + "homie": "5.0", + "version": 1, + "type": device.device_type, + "name": device.name, + "nodes": { + node: {"name": node, "type": f"{_CAPABILITY_PREFIX}.{node}", "properties": dict(properties)} + for node, properties in device.nodes.items() + }, + "children": list(children), + "extensions": [], + } + if root_id is not None: + description["root"] = root_id + description["parent"] = root_id + return {"$description": json.dumps(description), "$state": "ready", **device.values} diff --git a/tests/test_adoption.py b/tests/test_adoption.py index 8de87cad..09afd333 100644 --- a/tests/test_adoption.py +++ b/tests/test_adoption.py @@ -13,16 +13,32 @@ from __future__ import annotations +import dataclasses import json from typing import TYPE_CHECKING import pytest from reference_payloads.schema_one import device_from_topics, parent_child_tree -from span_panel_api.models import SpanPanelSnapshot +from span_panel_api.models import DISCOVERY_NAMESPACE, FieldMetadata, SpanPanelSnapshot from span_panel_api_schema_1.adoption import MODELLED_TYPES +from span_panel_api_schema_1.const import ( + DEVICE_TYPE_PREFIX, + TYPE_BESS, + TYPE_CIRCUIT, + TYPE_EVSE, + TYPE_INVERTER, + TYPE_LUGS, + TYPE_MID, + TYPE_PANEL, + TYPE_PV, +) +from span_panel_api_schema_1.field_metadata import build_discovery, build_field_metadata from span_panel_api_schema_1.snapshot import build_snapshot if TYPE_CHECKING: + from collections.abc import Callable, Mapping + + from ebus_sdk.homie import DiscoveredDevice from span_panel_api.models import AdoptedDevice PANEL = "example-40t-001" @@ -119,6 +135,204 @@ def test_a_subtype_of_a_modelled_type_is_not_adopted(subtype: str) -> None: assert "extra-device" not in _adopted(_snapshot(tree)) +# -- A subtype is read as its class, and a look-alike is not ----------------- +# +# Not adopting a subtype is half the rule. The other half is that the snapshot +# reads it, or the device is invisible to both paths at once -- the failure +# `MODELLED_TYPES` exists to rule out, arriving through a spelling (#228). + +INVERTER = "bess-inverter" + +_Reading = tuple[SpanPanelSnapshot, dict[str, FieldMetadata]] + + +def _tree_with_an_inverter() -> dict[str, dict[str, str]]: + """The reference tree plus a BESS inverter that declares it can form a grid. + + The emitter models no inverter child, so without one the inverter class + would have nothing to retype and its case below would pass on an empty tree. + """ + capable: dict[str, object] = {"name": "Can form a grid", "datatype": "boolean"} + inverter = _device( + TYPE_INVERTER, + name="BESS Inverter", + nodes={"grid-forming": {"properties": {"capable": capable}}}, + values={"grid-forming/capable": "true"}, + parent="bess", + ) + return _with(_tree(), INVERTER, inverter) + + +def _retyped( + tree: dict[str, dict[str, str]], declared: str, replacement: str +) -> tuple[dict[str, dict[str, str]], frozenset[str]]: + """A copy of the tree with every device declaring exactly `declared` declaring `replacement`. + + Returned with the ids it retyped, so a case can assert it changed something. + """ + retyped: dict[str, dict[str, str]] = {} + ids: set[str] = set() + for device_id, topics in tree.items(): + description = json.loads(topics["$description"]) + if description.get("type") == declared: + description["type"] = replacement + ids.add(device_id) + retyped[device_id] = {**topics, "$description": json.dumps(description)} + return retyped, frozenset(ids) + + +def _devices(tree: dict[str, dict[str, str]]) -> list[DiscoveredDevice]: + """Every device in the tree, the root included, as the adapter hands them to field metadata.""" + return [device_from_topics(device_id, topics) for device_id, topics in tree.items()] + + +def _read(tree: dict[str, dict[str, str]]) -> _Reading: + return _snapshot(tree), build_field_metadata(_devices(tree)) + + +def _renamed(rows: Mapping[str, FieldMetadata], declared: str, replacement: str) -> dict[str, FieldMetadata]: + """Metadata rows with `declared`'s discovery paths spelled as `replacement`'s. + + A discovery path carries the declaring device's type, so the same property + on a retyped device is a differently spelled path. Renaming it back is what + lets two trees that differ only in that spelling be compared whole. + """ + old = f"{DISCOVERY_NAMESPACE}.{declared.removeprefix(DEVICE_TYPE_PREFIX)}/" + new = f"{DISCOVERY_NAMESPACE}.{replacement.removeprefix(DEVICE_TYPE_PREFIX)}/" + return {(new + path.removeprefix(old) if path.startswith(old) else path): row for path, row in rows.items()} + + +_ROLE: dict[str, Callable[[_Reading], object]] = { + # The root is read as the panel whatever it declares; its type decides + # only which metadata rows answer for it. + TYPE_PANEL: lambda reading: reading[1].get("panel.firmware_version"), + TYPE_CIRCUIT: lambda reading: reading[0].circuits, + TYPE_LUGS: lambda reading: (reading[0].instant_grid_power_w, reading[0].feedthrough_power_w), + TYPE_EVSE: lambda reading: reading[0].evse, + TYPE_BESS: lambda reading: (reading[0].battery.present, reading[0].battery.soe_percentage), + TYPE_PV: lambda reading: reading[0].pv_inverters, + TYPE_MID: lambda reading: reading[0].mid, + TYPE_INVERTER: lambda reading: reading[0].grid_islandable, +} +"""What each modelled type fills, for a failure that names the role rather than a diff.""" + + +def test_every_modelled_type_names_the_role_it_fills() -> None: + assert set(_ROLE) == set(MODELLED_TYPES) + + +@pytest.mark.parametrize("modelled", MODELLED_TYPES) +def test_a_subtype_of_a_modelled_type_is_read_as_that_type(modelled: str) -> None: + """A device typed `X.hybrid` reaches the snapshot exactly as a device typed `X` does. + + eBus device types are hierarchical, and a subtype carries its parent's class. + Asserted on the whole snapshot and the whole field-metadata map, discovery + rows included, so no reader of the type can be left exact-matching: a + battery that drops out of `snapshot.battery`, or whose mapped properties + resurface as discovered, fails here. + """ + base = _tree_with_an_inverter() + subtype = f"{modelled}.hybrid" + subtyped, retyped = _retyped(base, modelled, subtype) + unmodelled, _ = _retyped(base, modelled, UNMODELLED_TYPE) + assert retyped, f"precondition: the tree carries a {modelled} device" + + role = _ROLE[modelled] + expected = _read(base) + assert role(expected) != role(_read(unmodelled)), f"precondition: {modelled} fills its role" + + snapshot, metadata = _read(subtyped) + assert role((snapshot, metadata)) == role(expected) + assert snapshot == expected[0] + assert _renamed(metadata, subtype, modelled) == expected[1] + assert _renamed(build_discovery(_devices(subtyped)), subtype, modelled) == build_discovery(_devices(base)) + + +def _adopted_as_untyped(snapshot: SpanPanelSnapshot) -> SpanPanelSnapshot: + """The snapshot with each adopted device's declared type blanked, for comparing two spellings.""" + return dataclasses.replace( + snapshot, + adopted_devices=tuple(dataclasses.replace(device, device_type="") for device in snapshot.adopted_devices), + ) + + +@pytest.mark.parametrize("modelled", MODELLED_TYPES) +def test_a_type_that_merely_begins_with_a_modelled_type_is_unmodelled(modelled: str) -> None: + """`…lugsfoo` is not a subtype of `…lugs`; it is a different class, read as any unmodelled one is. + + The hierarchy is dotted, so a subtype begins with its parent's type *and a + dot*. A bare prefix match would read a look-alike as the class it resembles + -- into the snapshot and the metadata -- while adoption, which honours the + dot, adopts it as well: one device, two surfaces. + """ + base = _tree_with_an_inverter() + lookalike = f"{modelled}foo" + retyped_tree, retyped = _retyped(base, modelled, lookalike) + unmodelled_tree, _ = _retyped(base, modelled, UNMODELLED_TYPE) + assert retyped, f"precondition: the tree carries a {modelled} device" + + snapshot, metadata = _read(retyped_tree) + unmodelled_snapshot, unmodelled_metadata = _read(unmodelled_tree) + assert set(_adopted(snapshot)) == retyped - {PANEL} + assert _adopted_as_untyped(snapshot) == _adopted_as_untyped(unmodelled_snapshot) + assert _renamed(metadata, lookalike, UNMODELLED_TYPE) == unmodelled_metadata + + +def test_lugs_subtyped_by_direction_are_lugs_and_a_look_alike_is_not() -> None: + """The case `TreeRoles` was written for, and the look-alike its prefix match let in.""" + expected = _snapshot(_tree()).instant_grid_power_w + assert expected is not None, "precondition: the upstream lugs publish grid power" + + tree = _tree() + upstream = json.loads(tree["lugs-upstream"]["$description"]) + + upstream["type"] = f"{TYPE_LUGS}.upstream" + tree["lugs-upstream"]["$description"] = json.dumps(upstream) + subtyped = _snapshot(tree) + assert subtyped.instant_grid_power_w == expected + assert "lugs-upstream" not in _adopted(subtyped) + + upstream["type"] = f"{TYPE_LUGS}foo" + tree["lugs-upstream"]["$description"] = json.dumps(upstream) + lookalike = _snapshot(tree) + assert lookalike.instant_grid_power_w is None + assert "lugs-upstream" in _adopted(lookalike) + + +@pytest.mark.parametrize( + ("forming", "device_id", "run_config", "power_source"), + [(TYPE_BESS, "bess", "PANEL_BACKUP", "BATTERY"), (TYPE_PV, "pv", "PANEL_OFF_GRID", "PV")], +) +def test_a_subtyped_grid_forming_device_resolves_to_its_class( + forming: str, device_id: str, run_config: str, power_source: str +) -> None: + """The MID names the device forming the grid, and its class is what the run config reads. + + A battery forming the grid is backup whatever subtype it declares; resolved + by exact type, a `bess.` would read as some other device forming it. + """ + tree = _tree() + tree["bess-mid"] = {**tree["bess-mid"], "grid/grid-forming-entity": device_id, "grid/islanding-state": "OFF_GRID"} + base = _snapshot(tree) + assert (base.current_run_config, base.dominant_power_source) == (run_config, power_source), "precondition" + + subtyped_tree, retyped = _retyped(tree, forming, f"{forming}.hybrid") + assert retyped == {device_id} + subtyped = _snapshot(subtyped_tree) + assert (subtyped.current_run_config, subtyped.dominant_power_source) == (run_config, power_source) + + +def test_a_grid_forming_look_alike_is_not_a_battery() -> None: + """A device typed `bessfoo` forming the grid is some other device, not backup from a battery.""" + tree = _tree() + tree["bess-mid"] = {**tree["bess-mid"], "grid/grid-forming-entity": "bess", "grid/islanding-state": "OFF_GRID"} + lookalike_tree, retyped = _retyped(tree, TYPE_BESS, f"{TYPE_BESS}foo") + assert retyped == {"bess"} + + lookalike = _snapshot(lookalike_tree) + assert (lookalike.current_run_config, lookalike.dominant_power_source) == ("PANEL_OFF_GRID", "UNKNOWN") + + def test_a_device_declaring_no_type_yet_is_skipped_rather_than_adopted() -> None: """A device describing itself without a type yet is not an unmodelled device. diff --git a/tests/test_capture_replay.py b/tests/test_capture_replay.py new file mode 100644 index 00000000..1bb1e778 --- /dev/null +++ b/tests/test_capture_replay.py @@ -0,0 +1,166 @@ +"""Every reference capture replays through the adapter into the panel it declares. + +Properties over the whole capture set, never one capture's literals: each test +reads what it expects out of the same capture it replays, so a capture added to +`fixtures/captures/` is covered by every test here without an edit. What the +adapter makes of a particular shape belongs to the tests of that behaviour; +these pin that every capture is a usable snapshot of its own panel, and that the +selectors other capture tests rely on find what the files hold. + +The selectors are checked against evidence they do not read themselves: the +capture file parsed again here with plain `json`, the adapter's own reading of +each circuit's spaces, the feeding circuit's own statement of what it feeds, +and each peer's list of its peers. +""" + +from __future__ import annotations + +import json + +import pytest + +from reference_payloads.captures import ( + CAPTURES, + capture_adapter, + capture_path, + capture_snapshot, + capture_tree, + circuit_fed_batteries, + hosted_circuits, + shared_meter_peers, + space_less_meters, +) + +_CIRCUIT_TYPE = "energy.ebus.device.circuit" +_BATTERY_TYPE = "energy.ebus.device.bess" + + +def _file_devices(stem: str) -> dict[str, dict[str, object]]: + """The capture's devices, parsed from the file with plain `json` and nothing of the helper's.""" + document: object = json.loads(capture_path(stem).read_text(encoding="utf-8")) + assert isinstance(document, dict) + devices = document["devices"] + assert isinstance(devices, dict) + parsed: dict[str, dict[str, object]] = {} + for device_id, body in devices.items(): + assert isinstance(device_id, str) and isinstance(body, dict) + parsed[device_id] = {str(key): value for key, value in body.items()} + return parsed + + +def _type(body: dict[str, object]) -> str: + description = body["description"] + assert isinstance(description, dict) + device_type = description["type"] + assert isinstance(device_type, str) + return device_type + + +def _declares_spaces(body: dict[str, object]) -> bool: + description = body["description"] + assert isinstance(description, dict) + nodes: object = description["nodes"] + assert isinstance(nodes, dict) + info: object = nodes.get("info", {}) + assert isinstance(info, dict) + properties: object = info.get("properties", {}) + assert isinstance(properties, dict) + return "spaces" in properties + + +def _string_value(body: dict[str, object], topic: str) -> str | None: + """A string-typed retained value; numbers live under `numeric_properties`.""" + properties = body["properties"] + assert isinstance(properties, dict) + value = properties.get(topic) + assert value is None or isinstance(value, str) + return value + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_every_capture_is_ready_once_replayed(stem: str) -> None: + assert capture_adapter(stem).is_ready() + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_the_snapshot_identifies_the_panel_its_tree_declares(stem: str) -> None: + tree, snapshot = capture_tree(stem), capture_snapshot(stem) + root = tree.root_id + declared = {topic: tree.value(root, topic) for topic in ("info/serial-number", "info/firmware-version", "info/model")} + assert None not in declared.values(), declared + assert snapshot.serial_number == declared["info/serial-number"] + assert snapshot.firmware_version == declared["info/firmware-version"] + # `UNKNOWN` is a member of the model enum that names no model, so it reads as absent. + assert snapshot.model == (None if declared["info/model"] == "UNKNOWN" else declared["info/model"]) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_the_snapshot_holds_exactly_the_circuits_its_tree_declares(stem: str) -> None: + tree, snapshot = capture_tree(stem), capture_snapshot(stem) + assert tree.circuits() + assert sorted(snapshot.circuits) == sorted(tree.circuits()) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_the_selectors_agree_with_the_file_read_independently(stem: str) -> None: + devices = _file_devices(stem) + circuits = {device_id for device_id, body in devices.items() if _type(body) == _CIRCUIT_TYPE} + fed: dict[str, str] = {} + peers: dict[str, tuple[str, ...]] = {} + for circuit_id in circuits: + body = devices[circuit_id] + target = _string_value(body, "connection/feeds-device-id") + if target is not None and target in devices and _type(devices[target]) == _BATTERY_TYPE: + fed[target] = circuit_id + listed = _string_value(body, "meter/shared-with-device-ids") + if listed: + peers[circuit_id] = tuple(part.strip() for part in listed.split(",")) + + tree = capture_tree(stem) + assert set(tree.circuits()) == circuits + assert set(hosted_circuits(tree)) == {c for c in circuits if _declares_spaces(devices[c])} + assert set(space_less_meters(tree)) == {c for c in circuits if not _declares_spaces(devices[c])} + assert dict(circuit_fed_batteries(tree)) == fed + assert dict(shared_meter_peers(tree)) == peers + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_the_adapter_places_exactly_the_hosted_circuits_in_breaker_spaces(stem: str) -> None: + tree, snapshot = capture_tree(stem), capture_snapshot(stem) + assert all(snapshot.circuits[circuit_id].tabs for circuit_id in hosted_circuits(tree)) + assert all(snapshot.circuits[meter_id].tabs == [] for meter_id in space_less_meters(tree)) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_a_fed_batterys_circuit_says_it_feeds_a_battery(stem: str) -> None: + tree = capture_tree(stem) + for circuit_id in circuit_fed_batteries(tree).values(): + assert tree.value(circuit_id, "connection/feeds-device-type") == _BATTERY_TYPE + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_shared_meter_peers_name_each_other(stem: str) -> None: + tree = capture_tree(stem) + peers = shared_meter_peers(tree) + for circuit_id, listed in peers.items(): + assert circuit_id not in listed + for peer_id in listed: + assert peer_id in tree.circuits() + assert circuit_id in peers.get(peer_id, ()) + + +def test_the_captures_hold_every_shape_a_selector_finds() -> None: + """A selector that matched nothing anywhere would leave its properties vacuous.""" + trees = [capture_tree(stem) for stem in CAPTURES] + assert any(space_less_meters(tree) for tree in trees) + assert any(circuit_fed_batteries(tree) for tree in trees) + assert any(shared_meter_peers(tree) for tree in trees) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_withholding_a_circuits_values_keeps_it_declared(stem: str) -> None: + """A declared device whose values have not arrived is still the tree's device.""" + circuit_id = hosted_circuits(capture_tree(stem))[0] + assert circuit_id in capture_snapshot(stem, drop_values_of=circuit_id).circuits + assert circuit_id in capture_adapter(stem, drop_values_of=circuit_id).circuit_nodes_missing_names() + assert circuit_id not in capture_adapter(stem).circuit_nodes_missing_names() diff --git a/tests/test_captures_unchanged.py b/tests/test_captures_unchanged.py new file mode 100644 index 00000000..6285be58 --- /dev/null +++ b/tests/test_captures_unchanged.py @@ -0,0 +1,53 @@ +"""The vendored reference captures are the bytes their upstream commit holds. + +`fixtures/captures/SHA256SUMS` records the SHA-256 of every file copied byte for +byte from the upstream commit that directory's README names: each capture, and +the upstream `LICENSE` they are distributed under. A copy edited, reformatted or +regenerated here fails, and so does a capture added without a pin, a pin left +behind for a file that was removed, or any other file dropped into the +directory, which `CAPTURES` would otherwise skip without a word. +""" + +from __future__ import annotations + +import hashlib + +import pytest + +from reference_payloads.captures import CAPTURES, CAPTURES_DIR, capture_path + +_SUMS = CAPTURES_DIR / "SHA256SUMS" +_RECORDS = frozenset({"README.md", "SHA256SUMS"}) +"""This repository's own files in the directory, which nothing pins.""" +_UPSTREAM_NOTICES = frozenset({"LICENSE"}) +"""Upstream files copied beside the captures and pinned like them.""" + + +def _pins() -> dict[str, str]: + """File name -> pinned SHA-256, in the format `shasum -a 256` writes and `-c` reads.""" + pins: dict[str, str] = {} + for line in _SUMS.read_text(encoding="utf-8").splitlines(): + digest, _, name = line.partition(" ") + assert len(digest) == 64 and name, f"malformed SHA256SUMS line: {line!r}" + assert name not in pins, f"{name} is pinned twice" + pins[name] = digest + return pins + + +def test_there_are_captures_to_replay() -> None: + """An empty set would make every property over the captures pass vacuously.""" + assert CAPTURES + + +def test_every_copy_is_pinned_and_every_pin_names_a_copy() -> None: + assert sorted(_pins()) == sorted(_UPSTREAM_NOTICES | {capture_path(stem).name for stem in CAPTURES}) + + +def test_the_directory_holds_only_the_pinned_copies_and_their_records() -> None: + present = sorted(path.name for path in CAPTURES_DIR.iterdir()) + assert present == sorted(_RECORDS | set(_pins())) + + +@pytest.mark.parametrize("name", sorted(_pins())) +def test_each_copy_matches_its_pinned_digest(name: str) -> None: + assert hashlib.sha256((CAPTURES_DIR / name).read_bytes()).hexdigest() == _pins()[name] diff --git a/tests/test_circuit_fed_battery_captures.py b/tests/test_circuit_fed_battery_captures.py new file mode 100644 index 00000000..b6b0f7a3 --- /dev/null +++ b/tests/test_circuit_fed_battery_captures.py @@ -0,0 +1,21 @@ +"""A battery fed by a circuit reports that circuit's link status, over every reference capture.""" + +from __future__ import annotations + +import pytest + +from reference_payloads.captures import CAPTURES, capture_snapshot, capture_tree, circuit_fed_batteries + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_a_circuit_fed_battery_follows_its_circuit(stem: str) -> None: + tree, snapshot = capture_tree(stem), capture_snapshot(stem) + for circuit_id in circuit_fed_batteries(tree).values(): + status = tree.value(circuit_id, "connection/feeds-device-status") + assert snapshot.battery.connected == (None if status is None else status == "OK") + assert snapshot.battery.feed_circuit_id == circuit_id + assert snapshot.circuits[circuit_id].device_type == "circuit" + + +def test_the_captures_hold_a_circuit_fed_battery() -> None: + assert any(circuit_fed_batteries(capture_tree(stem)) for stem in CAPTURES) diff --git a/tests/test_declared_unvalued_captures.py b/tests/test_declared_unvalued_captures.py new file mode 100644 index 00000000..302f57be --- /dev/null +++ b/tests/test_declared_unvalued_captures.py @@ -0,0 +1,126 @@ +"""Declared but unvalued properties, over every reference capture. + +A panel can declare a property and never publish a value for it. Declaring it +still says something: a declared battery is there before it reports, and a +declared feed for the upstream lugs that carries no value says the panel has +not told us what feeds them. Neither may stall connecting, and neither may be +read as a value nobody published. + +Properties over the whole capture set: each test selects its cases by what the +capture declares and reads the values it expects from the same capture. +""" + +from __future__ import annotations + +import logging + +import pytest + +from reference_payloads.captures import CAPTURES, CaptureTree, capture_adapter, capture_snapshot, capture_tree +from span_panel_api_schema_1.adapter import FEED_GRACE_S + +_BATTERY_TYPE = "energy.ebus.device.bess" +_LUGS_TYPE = "energy.ebus.device.lugs" +_DER_TYPES = frozenset({_BATTERY_TYPE, "energy.ebus.device.pv", "energy.ebus.device.evse"}) + +_MODEL = "info/model" +_DIRECTION = "info/direction" +_FED_BY_DEVICE_ID = "connection/fed-by-device-id" + + +def _batteries(tree: CaptureTree) -> tuple[str, ...]: + return tuple(device_id for device_id in tree.devices if tree.device_type(device_id) == _BATTERY_TYPE) + + +def _unvalued_models(tree: CaptureTree) -> tuple[str, ...]: + """Battery, inverter and charger devices that declare a model and publish none.""" + return tuple( + device_id + for device_id in tree.devices + if tree.device_type(device_id) in _DER_TYPES + and tree.declares(device_id, _MODEL) + and tree.value(device_id, _MODEL) is None + ) + + +def _upstream_lugs(tree: CaptureTree) -> str | None: + lugs = [ + device_id + for device_id in tree.devices + if tree.device_type(device_id) == _LUGS_TYPE and tree.value(device_id, _DIRECTION) == "UPSTREAM" + ] + assert len(lugs) <= 1, lugs + return lugs[0] if lugs else None + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_a_declared_battery_is_present_before_it_reports(stem: str) -> None: + tree, snapshot = capture_tree(stem), capture_snapshot(stem) + for battery_id in _batteries(tree): + assert snapshot.battery.present is True + assert snapshot.battery.soe_kwh == tree.number(battery_id, "soc/soe") + assert snapshot.battery.soe_percentage == tree.number(battery_id, "soc/soc") + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_a_tree_without_a_battery_reports_absent(stem: str) -> None: + tree = capture_tree(stem) + if not _batteries(tree): + assert capture_snapshot(stem).battery.present is False + + +def test_the_captures_hold_a_battery_that_has_not_reported() -> None: + """At least one capture declares a battery whose state of energy is unvalued.""" + assert any( + capture_tree(stem).value(battery_id, "soc/soe") is None + for stem in CAPTURES + for battery_id in _batteries(capture_tree(stem)) + ) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_the_device_model_wait_releases_after_the_grace(stem: str, caplog: pytest.LogCaptureFixture) -> None: + """A model that is declared and never published holds connecting for the grace only. + + Before the grace has run the device is still waited on, so a model landing in + the same burst as the rest of the tree still makes the first snapshot. After + it, the device is no longer waited on, and each is reported once at INFO. + """ + tree = capture_tree(stem) + unvalued = _unvalued_models(tree) + now = [100.0] + adapter = capture_adapter(stem, clock=lambda: now[0]) + + assert set(unvalued) <= set(adapter.circuit_nodes_missing_names()) + + now[0] += FEED_GRACE_S + with caplog.at_level(logging.INFO, logger="span_panel_api_schema_1.adapter"): + assert adapter.circuit_nodes_missing_names() == [] + assert adapter.circuit_nodes_missing_names() == [] + + reported = [record for record in caplog.records if record.levelno == logging.INFO] + assert sorted(device_id for record in reported for device_id in unvalued if device_id in record.getMessage()) == ( + sorted(unvalued) + ) + assert len(reported) == len(unvalued) + + +def test_the_captures_hold_a_device_model_that_is_never_published() -> None: + assert any(_unvalued_models(capture_tree(stem)) for stem in CAPTURES) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_unvalued_upstream_feed_leaves_the_service_entrance_unknown(stem: str) -> None: + """Unknown where the upstream lugs declare their feed and publish none. + + `False` where the feed names a device and `True` where the lugs do not + declare a feed or publish it empty. + """ + tree = capture_tree(stem) + lugs = _upstream_lugs(tree) + expected: bool | None = True + if lugs is not None and tree.declares(lugs, _FED_BY_DEVICE_ID): + fed_by = tree.value(lugs, _FED_BY_DEVICE_ID) + expected = None if fed_by is None else not fed_by + + assert capture_snapshot(stem).lugs_at_service_entrance is expected diff --git a/tests/test_evse_lock_captures.py b/tests/test_evse_lock_captures.py new file mode 100644 index 00000000..25bed0ca --- /dev/null +++ b/tests/test_evse_lock_captures.py @@ -0,0 +1,59 @@ +"""Every charger whose lock is declared settable has a target for it, over every reference capture.""" + +from __future__ import annotations + +import json + +import pytest + +from reference_payloads.captures import CAPTURES, CaptureTree, capture_snapshot, capture_tree + +_EVSE_TYPE = "energy.ebus.device.evse" + + +def _lock_settable(tree: CaptureTree, device_id: str) -> bool: + description = json.loads(tree.devices[device_id].description) + declaration = description["nodes"].get("switch", {}).get("properties", {}).get("lock-state", {}) + return declaration.get("settable") is True + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_a_settable_lock_is_addressed_on_its_own_charger(stem: str) -> None: + tree, snapshot = capture_tree(stem), capture_snapshot(stem) + chargers = [device_id for device_id in tree.devices if tree.device_type(device_id) == _EVSE_TYPE] + by_device = {} + for charger in snapshot.evse.values(): + target = charger.lock_control + if target is not None: + by_device[target.device_id] = target + + assert set(by_device) == {device_id for device_id in chargers if _lock_settable(tree, device_id)} + for device_id, target in by_device.items(): + assert target.topic == f"ebus/5/{device_id}/switch/lock-state/set" + assert (target.node_id, target.property_id) == ("switch", "lock-state") + + +def test_the_captures_hold_a_settable_lock() -> None: + assert any( + _lock_settable(capture_tree(stem), device_id) + for stem in CAPTURES + for device_id in capture_tree(stem).devices + if capture_tree(stem).device_type(device_id) == _EVSE_TYPE + ) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_each_charger_reports_the_lock_states_it_declares(stem: str) -> None: + tree, snapshot = capture_tree(stem), capture_snapshot(stem) + declared = sorted( + tuple( + json.loads(tree.devices[device_id].description)["nodes"]["switch"]["properties"]["lock-state"]["format"].split( + "," + ) + ) + for device_id in tree.devices + if tree.device_type(device_id) == _EVSE_TYPE + and "lock-state" in json.loads(tree.devices[device_id].description)["nodes"].get("switch", {}).get("properties", {}) + ) + + assert sorted(charger.lock_state_options for charger in snapshot.evse.values() if charger.lock_state_options) == declared diff --git a/tests/test_evse_lock_control.py b/tests/test_evse_lock_control.py new file mode 100644 index 00000000..63405611 --- /dev/null +++ b/tests/test_evse_lock_control.py @@ -0,0 +1,112 @@ +"""Locking and unlocking a charger's connector, and the ways that refuses. + +The write is authorised by the snapshot: the charger must carry +`lock_control`, which the adapter sets only where `switch/lock-state` is +declared settable, and the value must be one the declaration's `$format` lists. +The values themselves are the ones the panel publishes, pinned here to a +reference capture's declaration rather than assumed. +""" + +from __future__ import annotations + +import json +from unittest.mock import MagicMock + +import pytest + +from conftest import FAST_CONTROL_DEADLINES, acking_bridge +from reference_payloads.captures import CAPTURES, capture_tree +from span_panel_api import EvseLockControlProtocol +from span_panel_api.exceptions import SpanPanelServerError +from span_panel_api.models import ControlTarget, SpanEvseSnapshot +from span_panel_api.mqtt import MqttClientConfig +from span_panel_api.mqtt.client import LOCK_STATE_LOCKED, LOCK_STATE_UNLOCKED, SpanMqttClient + +SERIAL = "panel-a" +CHARGER = "evse-a-serial" +TARGET = ControlTarget( + topic="ebus/5/evse-a/switch/lock-state/set", device_id="evse-a", node_id="switch", property_id="lock-state" +) + + +def _client(charger: SpanEvseSnapshot) -> tuple[SpanMqttClient, MagicMock]: + """A client whose adapter reports one charger, under the key `CHARGER`.""" + client = SpanMqttClient( + host="192.168.1.1", + serial_number=SERIAL, + broker_config=MqttClientConfig(broker_host="h", username="u", password="p"), + control_deadlines=FAST_CONTROL_DEADLINES, + ) + adapter = MagicMock() + adapter.build_snapshot.return_value = MagicMock(evse={CHARGER: charger}) + client._adapter = adapter + bridge = acking_bridge() + client._bridge = bridge + return client, bridge + + +def _charger( + *, target: ControlTarget | None = TARGET, options: tuple[str, ...] | None = ("UNLOCKED", "LOCKED") +) -> SpanEvseSnapshot: + return SpanEvseSnapshot(node_id=CHARGER, feed_circuit_id="c-1", lock_control=target, lock_state_options=options) + + +def _declared_lock_formats() -> set[str]: + formats: set[str] = set() + for stem in CAPTURES: + tree = capture_tree(stem) + for device in tree.devices.values(): + declaration = json.loads(device.description)["nodes"].get("switch", {}).get("properties", {}).get("lock-state") + if declaration is not None: + formats.add(declaration["format"]) + return formats + + +def test_the_payloads_are_the_values_the_panel_declares() -> None: + formats = _declared_lock_formats() + + assert formats, "no capture declares a charger lock" + for declared in formats: + assert {LOCK_STATE_LOCKED, LOCK_STATE_UNLOCKED} <= set(declared.split(",")) + + +def test_the_client_satisfies_the_protocol() -> None: + assert issubclass(SpanMqttClient, EvseLockControlProtocol) + + +@pytest.mark.asyncio +@pytest.mark.parametrize(("locked", "payload"), [(True, LOCK_STATE_LOCKED), (False, LOCK_STATE_UNLOCKED)]) +async def test_a_settable_lock_publishes_to_its_target(locked: bool, payload: str) -> None: + client, bridge = _client(_charger()) + + await client.set_evse_lock(CHARGER, locked) + + bridge.publish.assert_called_once_with(TARGET.topic, payload) + + +@pytest.mark.asyncio +async def test_a_lock_without_a_target_is_refused() -> None: + client, bridge = _client(_charger(target=None)) + + with pytest.raises(SpanPanelServerError, match="No settable lock"): + await client.set_evse_lock(CHARGER, True) + bridge.publish.assert_not_called() + + +@pytest.mark.asyncio +async def test_an_unknown_charger_is_refused() -> None: + client, bridge = _client(_charger()) + + with pytest.raises(SpanPanelServerError, match="No settable lock"): + await client.set_evse_lock("another-charger", True) + bridge.publish.assert_not_called() + + +@pytest.mark.asyncio +@pytest.mark.parametrize("options", [("UNLOCKED",), None], ids=["not-in-format", "no-format"]) +async def test_a_value_the_declaration_does_not_list_is_refused(options: tuple[str, ...] | None) -> None: + client, bridge = _client(_charger(options=options)) + + with pytest.raises(SpanPanelServerError, match="does not declare"): + await client.set_evse_lock(CHARGER, True) + bridge.publish.assert_not_called() diff --git a/tests/test_expected_failures_registry.py b/tests/test_expected_failures_registry.py new file mode 100644 index 00000000..7f4cddcc --- /dev/null +++ b/tests/test_expected_failures_registry.py @@ -0,0 +1,89 @@ +"""The expected-failure registry stops the run on a row that names nothing. + +A row whose file was renamed or deleted, or whose test no longer exists, would +otherwise mark nothing and stay in the registry unnoticed. The check reads the +files, not what a run collected, so a partial run judges the rows the same way +a full one does and raises no false alarm. +""" + +from __future__ import annotations + +from pathlib import Path + +import pytest + +import conftest +from conftest import stale_rows +from expected_failures import EXPECTED_FAILURES + +_ROOT = Path(__file__).resolve().parent.parent + +_SOURCE = ''' +def test_module_level(): + pass + + +async def test_async(): + pass + + +def helper(): + pass + + +class TestGroup: + def test_method(self): + pass + + +class Helpers: + def test_not_collected(self): + pass +''' + + +def _tree(tmp_path: Path) -> Path: + (tmp_path / "tests").mkdir() + (tmp_path / "tests" / "test_sample.py").write_text(_SOURCE, encoding="utf-8") + return tmp_path + + +def test_the_registry_names_only_tests_that_exist() -> None: + assert stale_rows(EXPECTED_FAILURES, _ROOT) == [] + + +def test_tests_at_module_level_and_on_test_classes_are_found(tmp_path: Path) -> None: + root = _tree(tmp_path) + rows = [f"tests/test_sample.py::{name}" for name in ("test_module_level", "test_async", "test_method")] + + assert stale_rows(rows, root) == [] + + +@pytest.mark.parametrize( + "row", + [ + "tests/test_renamed.py::test_module_level", + "tests/test_sample.py::test_gone", + "tests/test_sample.py::helper", + "tests/test_sample.py::test_not_collected", + ], + ids=["missing-file", "missing-test", "not-a-test", "not-on-a-test-class"], +) +def test_a_row_naming_nothing_is_stale(tmp_path: Path, row: str) -> None: + assert stale_rows([row], _tree(tmp_path)) == [row] + + +def test_a_stale_row_stops_even_a_run_that_collected_nothing_of_it( + monkeypatch: pytest.MonkeyPatch, pytestconfig: pytest.Config +) -> None: + """A partial run collects none of the registry's files, and still sees a stale row.""" + stale = "tests/test_does_not_exist.py::test_anything" + monkeypatch.setattr(conftest, "EXPECTED_FAILURES", {**EXPECTED_FAILURES, stale: "planted"}) + + with pytest.raises(pytest.UsageError, match="test_does_not_exist"): + conftest.pytest_collection_modifyitems(pytestconfig, []) + + +def test_a_partial_run_raises_no_false_alarm(pytestconfig: pytest.Config) -> None: + """With every row naming a test that exists, a run that collected none of them proceeds.""" + conftest.pytest_collection_modifyitems(pytestconfig, []) diff --git a/tests/test_feeds_role_captures.py b/tests/test_feeds_role_captures.py new file mode 100644 index 00000000..10cebeb8 --- /dev/null +++ b/tests/test_feeds_role_captures.py @@ -0,0 +1,30 @@ +"""Every circuit's feeds role equals what its capture declares, over every reference capture.""" + +from __future__ import annotations + +import pytest + +from reference_payloads.captures import CAPTURES, capture_adapter, capture_snapshot, capture_tree +from span_panel_api import FEEDS_ROLES + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_each_circuit_reports_its_declared_feeds_role(stem: str) -> None: + tree, snapshot = capture_tree(stem), capture_snapshot(stem) + for circuit_id in tree.circuits(): + published = tree.value(circuit_id, "connection/feeds-role") + expected = published if published in FEEDS_ROLES else None + assert snapshot.circuits[circuit_id].feeds_role == expected, circuit_id + + +def test_the_captures_declare_feeds_roles() -> None: + assert any( + capture_tree(stem).declares(circuit_id, "connection/feeds-role") + for stem in CAPTURES + for circuit_id in capture_tree(stem).circuits() + ) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_the_feeds_role_a_circuit_declares_is_not_reported_as_discovered(stem: str) -> None: + assert "discovered.circuit/connection/feeds-role" not in capture_adapter(stem).build_field_metadata() diff --git a/tests/test_mqtt_client_connection.py b/tests/test_mqtt_client_connection.py index 8d64102c..d2cc27e5 100644 --- a/tests/test_mqtt_client_connection.py +++ b/tests/test_mqtt_client_connection.py @@ -556,3 +556,36 @@ def build_field_metadata(self) -> dict[str, FieldMetadata]: adapter.discovered = True assert client.field_metadata == {"circuit.instant_power_w": FieldMetadata(unit="W", datatype="float")} + + +def test_masked_tree_is_none_without_an_adapter() -> None: + client = SpanMqttClient.__new__(SpanMqttClient) + client._adapter = None + assert client.masked_tree() is None + + +def test_masked_tree_is_none_when_the_adapter_does_not_export() -> None: + class FlatAdapter: + schema_major = "0" + + client = SpanMqttClient.__new__(SpanMqttClient) + client._adapter = FlatAdapter() + assert client.masked_tree() is None + + +def test_masked_tree_is_the_adapters_export() -> None: + from span_panel_api.models import MaskedTree + + export = MaskedTree( + metadata={"schema": "tree-v1", "masked": True, "producer": "double 1", "tree_complete": True}, + devices={}, + undescribed_devices={}, + ) + + class ExportingAdapter: + def export_masked_tree(self) -> MaskedTree | None: + return export + + client = SpanMqttClient.__new__(SpanMqttClient) + client._adapter = ExportingAdapter() + assert client.masked_tree() is export diff --git a/tests/test_mqtt_homie.py b/tests/test_mqtt_homie.py index 3fe74528..0b0a19c6 100644 --- a/tests/test_mqtt_homie.py +++ b/tests/test_mqtt_homie.py @@ -1434,6 +1434,23 @@ def test_evse_metadata_parsed(self): assert evse.serial_number == "SN12345" assert evse.software_version == "2.1.0" + def test_evse_reports_no_charge_limit_range(self): + """Flat EVSE types declare no charge-current limit, so no range: None, never a guessed one.""" + circuit_uuid = "aabbccdd-1122-3344-5566-778899001122" + acc, consumer = _build_ready_consumer( + { + "core": {"type": TYPE_CORE}, + circuit_uuid: {"type": TYPE_CIRCUIT}, + "evse-0": {"type": TYPE_EVSE}, + } + ) + acc.handle_message(f"{PREFIX}/evse-0/feed", circuit_uuid) + acc.handle_message(f"{PREFIX}/evse-0/advertised-current", "32.0") + + evse = consumer.build_snapshot().evse["evse-0"] + assert evse.charge_current_limit_minimum_a is None + assert evse.charge_current_limit_maximum_a is None + def test_evse_multiple_devices(self): """Two EVSE nodes produce two snapshot entries.""" circ_a = "aaaaaaaa-1111-2222-3333-444444444444" diff --git a/tests/test_panel_properties_captures.py b/tests/test_panel_properties_captures.py new file mode 100644 index 00000000..bf2cabf8 --- /dev/null +++ b/tests/test_panel_properties_captures.py @@ -0,0 +1,87 @@ +"""Panel and circuit readings and the site properties, over every reference capture. + +Each reading equals the wire value its capture declares. No site property +becomes an extension or adopted reading, while the two site readings the panel +already offered, its postal code and time zone, still do. +""" + +from __future__ import annotations + +import pytest + +from reference_payloads.captures import CAPTURES, capture_adapter, capture_snapshot, capture_tree +from span_panel_api import PROTECTION_FUNCTIONS +from span_panel_api_schema_1.const import SITE_PROPERTIES + +_LUGS_TYPE = "energy.ebus.device.lugs" +_KEPT_SITE_READINGS = ("status/postal-code", "status/time-zone") +_NEW_ROWS = ( + "panel.busbar_current_a", + "panel.frequency_hz", + "circuit.nominal_voltage_v", + "circuit.protection_functions", +) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_the_panel_readings_equal_their_wire_values(stem: str) -> None: + tree, snapshot = capture_tree(stem), capture_snapshot(stem) + upstream = [ + device_id + for device_id in tree.devices + if tree.device_type(device_id) == _LUGS_TYPE and tree.value(device_id, "info/direction") == "UPSTREAM" + ] + rating = tree.number(upstream[0], "connection/overcurrent-protection") if upstream else None + + assert snapshot.busbar_current_a == tree.number(tree.root_id, "meter/busbar-current") + assert snapshot.frequency_hz == tree.number(tree.root_id, "meter/frequency") + assert snapshot.upstream_protection_rating_a == (None if rating is None else int(rating)) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_each_circuit_reading_equals_its_wire_value(stem: str) -> None: + tree, circuits = capture_tree(stem), capture_snapshot(stem).circuits + for circuit_id in tree.circuits(): + published = tree.value(circuit_id, "breaker/protection-functions") + functions = ( + None + if published is None + else tuple(part.strip() for part in published.split(",") if part.strip() in PROTECTION_FUNCTIONS) + ) + assert circuits[circuit_id].nominal_voltage_v == tree.number(circuit_id, "info/nominal-voltage") + assert circuits[circuit_id].protection_functions == functions + + +def test_the_captures_publish_the_new_readings() -> None: + snapshots = [capture_snapshot(stem) for stem in CAPTURES] + + assert any(snapshot.busbar_current_a is not None for snapshot in snapshots) + assert any(snapshot.frequency_hz is not None for snapshot in snapshots) + assert any(snapshot.upstream_protection_rating_a is not None for snapshot in snapshots) + circuits = [circuit for snapshot in snapshots for circuit in snapshot.circuits.values()] + assert any(circuit.protection_functions for circuit in circuits) + assert any(circuit.nominal_voltage_v is not None for circuit in circuits) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_no_site_property_becomes_a_reading_but_postal_code_and_time_zone_still_do(stem: str) -> None: + tree, snapshot = capture_tree(stem), capture_snapshot(stem) + readings = {f"{row.node_id}/{row.property_id}" for row in snapshot.extension_properties} + readings |= {f"{row.node_id}/{row.property_id}" for device in snapshot.adopted_devices for row in device.properties} + + assert not [reading for reading in readings if reading.rsplit("/", 1)[-1] in SITE_PROPERTIES] + assert "info/name" not in readings + for topic in _KEPT_SITE_READINGS: + assert (topic in readings) == tree.declares(tree.root_id, topic) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_the_new_readings_carry_resolved_metadata_where_declared(stem: str) -> None: + metadata = capture_adapter(stem).build_field_metadata() + + assert not [path for path in _NEW_ROWS if path in metadata and not metadata[path].resolved] + assert not [ + path + for path in metadata + if path.endswith(("/busbar-current", "/frequency", "/nominal-voltage", "/protection-functions")) + ] diff --git a/tests/test_positions_captures.py b/tests/test_positions_captures.py new file mode 100644 index 00000000..91653420 --- /dev/null +++ b/tests/test_positions_captures.py @@ -0,0 +1,107 @@ +"""Breaker positions and the solar-role signal, over every reference capture. + +Each test reads the model, the occupied spaces and the declared roles from the +capture it replays, so a capture added later is covered without an edit. +""" + +from __future__ import annotations + +import logging + +import pytest + +from reference_payloads.captures import ( + CAPTURES, + CaptureTree, + capture_adapter, + capture_snapshot, + capture_tree, + hosted_circuits, +) +from reference_payloads.schema_one import parent_child_tree, replay +from span_panel_api_schema_1.const import PANEL_POSITIONS_BY_MODEL, PANEL_SIZE_BY_MODEL + +_REFERENCE_PANEL = "example-40t-001" + + +def _model(tree: CaptureTree) -> str | None: + return tree.value(tree.root_id, "info/model") + + +def _occupied(tree: CaptureTree) -> set[int]: + return { + int(space) + for circuit_id in hosted_circuits(tree) + for space in (tree.value(circuit_id, "info/spaces") or "").split(",") + if space.strip() + } + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_positions_follow_the_declared_model(stem: str, caplog: pytest.LogCaptureFixture) -> None: + tree = capture_tree(stem) + model = _model(tree) + if model not in PANEL_POSITIONS_BY_MODEL: + return + with caplog.at_level(logging.WARNING): + snapshot = capture_adapter(stem).build_snapshot() + first, last = PANEL_POSITIONS_BY_MODEL[model] + + assert (snapshot.first_position, snapshot.last_position, snapshot.panel_size) == ( + first, + last, + PANEL_SIZE_BY_MODEL[model], + ) + assert all(first <= space <= last for space in _occupied(tree)) + assert not [record for record in caplog.records if "breaker positions" in record.getMessage()] + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_an_unknown_model_takes_its_range_from_occupied_spaces_and_size_zero( + stem: str, caplog: pytest.LogCaptureFixture +) -> None: + tree = capture_tree(stem) + if _model(tree) != "UNKNOWN": + return + with caplog.at_level(logging.WARNING): + snapshot = capture_snapshot(stem) + occupied = _occupied(tree) + + assert snapshot.model is None + assert snapshot.panel_size == 0 + assert (snapshot.first_position, snapshot.last_position) == (min(occupied), max(occupied)) + assert not [record for record in caplog.records if "Unknown panel model" in record.getMessage()] + + +def test_the_captures_hold_both_a_sized_model_and_an_unknown_one() -> None: + models = {_model(capture_tree(stem)) for stem in CAPTURES} + + assert models & set(PANEL_POSITIONS_BY_MODEL) + assert "UNKNOWN" in models + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_no_position_is_synthesised(stem: str) -> None: + assert set(capture_snapshot(stem).circuits) == set(capture_tree(stem).circuits()) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_solar_roles_are_published_only_where_declared(stem: str) -> None: + tree = capture_tree(stem) + declared = any(tree.declares(circuit_id, "connection/feeds-role") for circuit_id in tree.circuits()) + + assert declared + assert capture_snapshot(stem).publishes_solar_roles is declared + + +def test_the_reference_tree_lies_inside_its_model_range_and_publishes_no_solar_roles( + caplog: pytest.LogCaptureFixture, +) -> None: + with caplog.at_level(logging.WARNING): + snapshot = replay(parent_child_tree(), _REFERENCE_PANEL).build_snapshot() + first, last = PANEL_POSITIONS_BY_MODEL[str(snapshot.model)] + + assert snapshot.publishes_solar_roles is False + assert (snapshot.first_position, snapshot.last_position) == (first, last) + assert all(first <= tab <= last for circuit in snapshot.circuits.values() for tab in circuit.tabs) + assert not [record for record in caplog.records if "breaker positions" in record.getMessage()] diff --git a/tests/test_protocol_conformance.py b/tests/test_protocol_conformance.py index db062cc8..c546cc2b 100644 --- a/tests/test_protocol_conformance.py +++ b/tests/test_protocol_conformance.py @@ -14,6 +14,7 @@ from span_panel_api.protocol import ( CircuitControlProtocol, EvseControlProtocol, + EvseLockControlProtocol, PanelControlProtocol, SpanPanelClientProtocol, StreamingCapableProtocol, @@ -48,6 +49,10 @@ def test_satisfies_evse_control_protocol(self) -> None: if not issubclass(SpanMqttClient, EvseControlProtocol): raise TypeError("SpanMqttClient does not satisfy EvseControlProtocol") + def test_satisfies_evse_lock_control_protocol(self) -> None: + if not issubclass(SpanMqttClient, EvseLockControlProtocol): + raise TypeError("SpanMqttClient does not satisfy EvseLockControlProtocol") + def test_satisfies_streaming_protocol(self) -> None: if not issubclass(SpanMqttClient, StreamingCapableProtocol): raise TypeError("SpanMqttClient does not satisfy StreamingCapableProtocol") diff --git a/tests/test_public_api_unchanged.py b/tests/test_public_api_unchanged.py index a60e476b..fe9ff9c5 100644 --- a/tests/test_public_api_unchanged.py +++ b/tests/test_public_api_unchanged.py @@ -59,7 +59,19 @@ "ControlTarget", "ExtensionProperty", "ExtensionSubject", + # Added 2026-10-31: the masked device tree a consumer forwards in diagnostics, + # and the optional protocol an adapter offers it through. Deliberately not a + # SchemaAdapter member: the protocol derives its required set from itself, so a + # member there would invalidate every built adapter wheel. + "MaskedTree", + "MaskedTreeDevice", + "MaskedTreeMetadata", + "UndescribedDevice", + "TreeExportingAdapter", "AdoptedControlProtocol", + # Added 2026-10-09: a charger's connector lock. A protocol of its own, so + # `EvseControlProtocol` and its implementers are unchanged. + "EvseLockControlProtocol", # Added 2026-08-25 (3.1.0): one veto/observe point for every control # command, the consumer-side half of its authorisation gate. A protocol of # its own so the four control protocols are not broken twice in one release. @@ -80,6 +92,20 @@ # `None` on every existing consumer's data and nothing that reads the # snapshot today changes. "SpanPcsSnapshot", + # Added 2026-10-09: the closed set a circuit's `connection/feeds-role` + # declares, read into `SpanCircuitSnapshot.feeds_role`. Purely additive -- + # the field defaults to `None`, and the flat schema declares no roles. + "FEEDS_ROLES", + "FeedsRole", + # Added 2026-10-09: the closed set a circuit's `breaker/protection-functions` + # lists, read into `SpanCircuitSnapshot.protection_functions`. Purely + # additive -- the field defaults to `None`. + "PROTECTION_FUNCTIONS", + "ProtectionFunction", + # Added 2026-10-09: groups the circuits that share one meter, from + # `SpanCircuitSnapshot.meter_shared_with`. Purely additive -- a snapshot in + # which no circuit shares a meter has no groups. + "shared_meter_groups", # Factory "create_span_client", # Detection @@ -166,6 +192,10 @@ # SpanPanelAuthError, so no existing except clause starts telling a user # their passphrase is wrong. "SpanPanelPassphraseUnavailableError", + # Added 2026-10-09: registration refused with HTTP 429. A subclass of + # SpanPanelAPIError, which register_v2 already raised for a 429, so every + # existing except clause keeps catching it. + "SpanPanelRateLimitError", "SpanPanelServerError", "SpanPanelStaleDataError", # Added 2026-08-31 (3.4.0): a bootstrap REST call that failed *verification* diff --git a/tests/test_publish_outcome.py b/tests/test_publish_outcome.py index a36b9de9..4f9fd942 100644 --- a/tests/test_publish_outcome.py +++ b/tests/test_publish_outcome.py @@ -372,6 +372,25 @@ async def test_a_no_op_short_circuits_without_publishing(self) -> None: assert outcome.no_op is True paho_client.publish.assert_not_called() + @pytest.mark.asyncio + async def test_a_value_the_panel_cleared_is_not_current(self) -> None: + """An adapter reports a cleared property as `None`: there is no value for a write to match. + + Keeping the last value instead would answer "already reports this value" + for a property that reports nothing, and the write would never be sent. + """ + paho_client = _paho() + client = _client(deadlines=ControlDeadlines(relay=0.05)) + client._bridge = _bridge(connected=True, paho_client=paho_client) + target = client._adapter.set_circuit_relay_target(CIRCUIT) + self._observe(client, target, "OPEN") + client._on_property_value(target.device_id, target.node_id, target.property_id, None) + + outcome = await client.set_circuit_relay(CIRCUIT, "OPEN") + + assert outcome.no_op is False + paho_client.publish.assert_called_once() + @pytest.mark.asyncio async def test_the_no_op_check_compares_wire_vocabulary(self) -> None: """The caller says BATTERY; the wire says OFF_GRID under v1.0. diff --git a/tests/test_reference_tree_values.py b/tests/test_reference_tree_values.py index 247ba9a6..26f15d75 100644 --- a/tests/test_reference_tree_values.py +++ b/tests/test_reference_tree_values.py @@ -26,27 +26,38 @@ makes, for the same reason. The reduction loses nothing here, and that is measured rather than assumed: -reduced the same way, panelbench's baseline is exactly the declared-but-unvalued -set of its own committed wire capture (`tests/conformance/fixtures/golden_wire.json`). +reduced the same way, panelbench's baseline at `7ddd953` is exactly the +declared-but-unvalued set of the wire capture committed beside it +(`tests/conformance/fixtures/golden_wire.json` at that commit). -Refresh the vendored copy with: +The vendored copy is panelbench's baseline at commit `7ddd953`: - cp ../panelbench/tests/fidelity/fixtures/unvalued_by_both_baseline.json \ - tests/fixtures/panelbench_unvalued_by_both.json + git -C ../panelbench show 7ddd953:tests/fidelity/fixtures/unvalued_by_both_baseline.json \ + > tests/fixtures/panelbench_unvalued_by_both.json It is vendored verbatim rather than pre-reduced so that refreshing it is a copy whose correctness a reader can check with `diff`, and so the reduction stays here where it is explained. -**A failure here does not say which side moved, and both have.** Refreshing the -vendored baseline is the fix when panelbench has already re-captured, which was -the case the first time this fired: the copy carried 32 `connection/count` -entries that panelbench had itself already dropped, so the two -artifacts agreed only because both were stale. Regenerating the reference tree -is the fix when the producer this side follows has moved -- see -`scripts/capture_parent_child_reference.py`, which reproduces every identifier -and every device in this capture, so the old instruction to port values in by -hand rather than recapture no longer applies. +**Why that commit and not panelbench's current baseline.** After it +(`a89f104`, `e551701`) panelbench keys each line by role rather than by +`type::name`, and measures upstream's example panel rather than its own, which +names no battery, MID or inverter identity and no network. That file reduces to +something this comparison cannot read, and disagrees with this capture for +reasons that are not drift, so it cannot be copied verbatim until this +comparison is reworked. + +**A failure here does not say which side moved, and both have.** The first time +this fired the vendored copy was the stale side: it carried 32 +`connection/count` entries that panelbench had itself already dropped, so the +two artifacts agreed only because both were stale, and the fix was a fresh copy +of panelbench's baseline. That fix is closed until this comparison is reworked +(above): panelbench's current baseline cannot be copied verbatim, so a +disagreement with it today is settled by reading both sides, not by copying. +Regenerating the reference tree is the fix when the producer this side follows +has moved -- see `scripts/capture_parent_child_reference.py`, which reproduces +every identifier and every device in this capture, so the old instruction to +port values in by hand rather than recapture no longer applies. """ from __future__ import annotations diff --git a/tests/test_register_rate_limit.py b/tests/test_register_rate_limit.py new file mode 100644 index 00000000..5aad8014 --- /dev/null +++ b/tests/test_register_rate_limit.py @@ -0,0 +1,87 @@ +"""Registration refused with HTTP 429. + +The panel limits registrations per client address and answers 429 with a +`RateLimitOut` body once the limit is reached. The library does not retry; it +raises a distinct class carrying `Retry-After` so the caller can decide when. +""" + +from __future__ import annotations + +import json +import logging +from unittest.mock import AsyncMock + +import httpx +import pytest + +from span_panel_api import SpanPanelRateLimitError +from span_panel_api.auth import register_v2 +from span_panel_api.exceptions import SpanPanelAPIError, SpanPanelAuthError + +HOST = "panel.invalid" +SECRET = "correct-horse-battery-staple" + + +def _client(headers: dict[str, str] | None = None, body: object | None = None) -> AsyncMock: + payload = {"error": "rate limit exceeded"} if body is None else body + response = httpx.Response( + 429, + content=json.dumps(payload).encode(), + headers={"content-type": "application/json", **(headers or {})}, + request=httpx.Request("POST", f"http://{HOST}/api/v2/auth/register"), + ) + injected = AsyncMock(spec=httpx.AsyncClient) + injected.post = AsyncMock(return_value=response) + return injected + + +async def _register(client: AsyncMock) -> None: + await register_v2(HOST, "home-assistant", SECRET, httpx_client=client) + + +class TestRateLimited: + @pytest.mark.asyncio + async def test_raises_the_rate_limit_class_with_its_status(self) -> None: + with pytest.raises(SpanPanelRateLimitError) as caught: + await _register(_client({"Retry-After": "30"})) + assert caught.value.status_code == 429 + assert caught.value.retry_after == 30.0 + + @pytest.mark.asyncio + async def test_is_an_api_error_and_not_an_auth_error(self) -> None: + """Existing `except SpanPanelAPIError` clauses keep catching it; nothing calls the passphrase wrong.""" + with pytest.raises(SpanPanelAPIError) as caught: + await _register(_client()) + assert not isinstance(caught.value, SpanPanelAuthError) + + @pytest.mark.asyncio + async def test_is_not_retried(self) -> None: + client = _client({"Retry-After": "1"}) + with pytest.raises(SpanPanelRateLimitError): + await _register(client) + assert client.post.await_count == 1 + + @pytest.mark.asyncio + @pytest.mark.parametrize( + "headers", + [ + {}, + {"Retry-After": "Wed, 21 Oct 2026 07:28:00 GMT"}, + {"Retry-After": "-5"}, + {"Retry-After": "inf"}, + {"Retry-After": "nan"}, + ], + ids=["absent", "http-date", "negative", "infinite", "nan"], + ) + async def test_retry_after_is_none_without_a_usable_header(self, headers: dict[str, str]) -> None: + with pytest.raises(SpanPanelRateLimitError) as caught: + await _register(_client(headers)) + assert caught.value.retry_after is None + + @pytest.mark.asyncio + async def test_the_body_stays_out_of_the_message(self, caplog: pytest.LogCaptureFixture) -> None: + body = {"error": f"limit for {SECRET}"} + with caplog.at_level(logging.DEBUG, logger="span_panel_api.auth"), pytest.raises(SpanPanelRateLimitError) as caught: + await _register(_client(body=body)) + assert "limit for" not in str(caught.value) + assert SECRET not in caplog.text diff --git a/tests/test_register_rate_limit_companions.py b/tests/test_register_rate_limit_companions.py new file mode 100644 index 00000000..d461559a --- /dev/null +++ b/tests/test_register_rate_limit_companions.py @@ -0,0 +1,92 @@ +"""What the divergent registration acceptance tests assert after their divergent line, and more. + +`expected_failures.py` lists two tests in `test_register_rate_limit.py` as +divergent: they read the delay as `retry_after` and expect `None` for an +HTTP-date, where this library reports `retry_after_s` in seconds and reads an +HTTP-date as the seconds until then. A strict xfail stops at that line, so the +cases here pin the delay and the statuses around 429, over the same responses. +""" + +from __future__ import annotations + +from datetime import UTC, datetime, timedelta +from email.utils import format_datetime +import json +from unittest.mock import AsyncMock + +import httpx +import pytest + +from span_panel_api import SpanPanelRateLimitError +from span_panel_api.auth import _retry_delay +from span_panel_api.exceptions import SpanPanelAPIError, SpanPanelAuthError +from test_register_rate_limit import HOST, _client, _register + + +def _future(seconds: float) -> str: + """An HTTP-date `seconds` from now.""" + return format_datetime(datetime.now(UTC) + timedelta(seconds=seconds), usegmt=True) + + +class TestRetryAfterSeconds: + @pytest.mark.asyncio + async def test_delta_seconds_are_the_delay_and_the_status_is_429(self) -> None: + with pytest.raises(SpanPanelRateLimitError) as caught: + await _register(_client({"Retry-After": "30"})) + assert caught.value.status_code == 429 + assert caught.value.retry_after_s == 30.0 + + @pytest.mark.asyncio + async def test_an_http_date_is_the_seconds_until_then(self) -> None: + with pytest.raises(SpanPanelRateLimitError) as caught: + await _register(_client({"Retry-After": _future(120)})) + assert caught.value.retry_after_s == pytest.approx(120, abs=5) + + @pytest.mark.asyncio + async def test_an_http_date_already_passed_is_no_wait(self) -> None: + with pytest.raises(SpanPanelRateLimitError) as caught: + await _register(_client({"Retry-After": "Wed, 21 Oct 2015 07:28:00 GMT"})) + assert caught.value.retry_after_s == 0.0 + + @pytest.mark.asyncio + @pytest.mark.parametrize( + "headers", + [{}, {"Retry-After": "-5"}, {"Retry-After": "inf"}, {"Retry-After": "nan"}, {"Retry-After": "soon"}], + ids=["absent", "negative", "infinite", "nan", "neither-form"], + ) + async def test_the_delay_is_none_without_a_usable_header(self, headers: dict[str, str]) -> None: + with pytest.raises(SpanPanelRateLimitError) as caught: + await _register(_client(headers)) + assert caught.value.retry_after_s is None + + +class TestOtherStatusesUnchanged: + @pytest.mark.asyncio + @pytest.mark.parametrize("status", [401, 403, 422]) + async def test_a_rejected_credential_is_still_an_auth_error(self, status: int) -> None: + with pytest.raises(SpanPanelAuthError): + await _register(_answering(status)) + + @pytest.mark.asyncio + async def test_another_4xx_is_still_an_api_error_and_not_a_rate_limit(self) -> None: + with pytest.raises(SpanPanelAPIError) as caught: + await _register(_answering(400)) + assert not isinstance(caught.value, SpanPanelRateLimitError) + + +def _answering(status: int) -> AsyncMock: + response = httpx.Response( + status, + content=json.dumps({"detail": "refused"}).encode(), + headers={"content-type": "application/json"}, + request=httpx.Request("POST", f"http://{HOST}/api/v2/auth/register"), + ) + injected = AsyncMock(spec=httpx.AsyncClient) + injected.post = AsyncMock(return_value=response) + return injected + + +def test_the_retry_backoff_takes_an_http_date_and_never_waits_forever() -> None: + """The CA download's 429 retry reads `Retry-After` through the same parser.""" + assert _retry_delay(_future(60), attempt=1, backoff_s=1.5) == pytest.approx(60, abs=5) + assert _retry_delay("inf", attempt=2, backoff_s=1.5) == 3.0 diff --git a/tests/test_schema_migration_delta.py b/tests/test_schema_migration_delta.py index c66883d1..0ffdba0e 100644 --- a/tests/test_schema_migration_delta.py +++ b/tests/test_schema_migration_delta.py @@ -218,6 +218,12 @@ "else -- so nothing can orphan and no entity changes meaning. v1.0 is the first " "schema in which the enclosure says anything about the PV link" ), + "battery.present": ( + "whether the device tree declares a battery. Flat has no battery device to declare, " + "and publishes its battery values whether or not one is installed, so it cannot " + "answer and leaves the field `None`; nothing can orphan and no entity changes " + "meaning. v1.0 is the first schema in which presence is a declaration" + ), } """Additions with no flat property to have been re-sourced from. diff --git a/tests/test_schema_one_acceptance_companions.py b/tests/test_schema_one_acceptance_companions.py new file mode 100644 index 00000000..2e28415b --- /dev/null +++ b/tests/test_schema_one_acceptance_companions.py @@ -0,0 +1,57 @@ +"""What the divergent acceptance tests assert after their divergent line. + +`expected_failures.py` lists three acceptance tests as divergent: two first +assert a `device_type` this library deliberately does not report, and one a +discovery row for a property this library reads. A strict xfail stops there, +so nothing after that line ever runs. These tests assert the rest, over the +same trees, so a regression in it still fails the run. Where an assertion needs +a later change, its test is listed as pending instead. +""" + +from __future__ import annotations + +from span_panel_api.models import SpanPVSnapshot, is_discovery_path +from test_schema_one_other_models import KITCHEN, SOLAR, _shipped, _shipped_metadata, _snapshot, _tree + + +def test_a_solar_role_circuit_keeps_its_reading_and_its_neighbour_its_type() -> None: + snapshot = _snapshot(_tree()) + + assert snapshot.circuits[SOLAR].instant_power_w == -8500.0 + assert snapshot.circuits[KITCHEN].device_type == "circuit" + + +def test_the_shipped_tree_labels_its_charger_circuit_and_has_no_pv_device() -> None: + snapshot = _shipped() + + assert snapshot.circuits["circuit-3"].device_type == "evse" + assert snapshot.pv == SpanPVSnapshot() + assert snapshot.pv_inverters == {} + + +def test_the_shipped_tree_reports_a_scheduled_relay_requester() -> None: + assert _shipped().circuits["circuit-5"].relay_requester == "CIRCUIT_SCHEDULER" + + +def test_the_shipped_tree_reads_busbar_current_and_frequency() -> None: + snapshot = _shipped() + + assert snapshot.busbar_current_a == 41.5 + assert snapshot.frequency_hz == 60.01 + + +def test_the_shipped_tree_resolves_its_shared_relay() -> None: + assert _shipped().circuits["circuit-1"].relay_shared_with == ("circuit-2",) + + +def test_the_shipped_tree_reports_its_unread_properties_as_discovered() -> None: + """Every discovery row the divergent test expects, except the one this library reads.""" + discovered = {path for path in _shipped_metadata() if is_discovery_path(path)} + + for prop in ("name", "latitude", "longitude", "address-lines", "utility-meter-serial-number"): + assert f"discovered.distribution-enclosure/info/{prop}" in discovered + for path in ("info/tags", "info/locations", "info/dedicated", "connection/backed-up"): + assert f"discovered.circuit/{path}" in discovered + for prop in ("service-rating", "feeds-role"): + assert f"discovered.lugs/connection/{prop}" in discovered + assert "discovered.lugs/connection/overcurrent-protection" not in discovered diff --git a/tests/test_schema_one_adapter.py b/tests/test_schema_one_adapter.py index 1cef910b..e60fa838 100644 --- a/tests/test_schema_one_adapter.py +++ b/tests/test_schema_one_adapter.py @@ -9,9 +9,11 @@ import copy import json +import random import pytest +from ebus_sdk import Controller from reference_payloads.schema_one import RetainedTopicTree, parent_child_tree from span_panel_api.adapters import _derive_required_members from span_panel_api.models import V2HomieSchema @@ -52,14 +54,28 @@ def _feed( appears; `test_children_before_the_panel` covers the unfriendly order, which a broker is equally entitled to replay. """ + for topic, payload in _retained(device_ids, omit, tree): + adapter.handle_message(topic, payload) + + +def _retained( + device_ids: list[str] | None = None, + omit: tuple[str, ...] = (), + tree: RetainedTopicTree = _TREE, +) -> list[tuple[str, str]]: + """The messages `_feed` delivers, in the order it delivers them.""" + messages: list[tuple[str, str]] = [] for device_id in device_ids or [PANEL, *[d for d in tree if d != PANEL]]: topics = tree[device_id] prefix = f"ebus/5/{device_id}" - adapter.handle_message(f"{prefix}/$description", topics["$description"]) - adapter.handle_message(f"{prefix}/$state", topics["$state"]) - for topic, value in topics.items(): - if not topic.startswith("$") and topic not in omit: - adapter.handle_message(f"{prefix}/{topic}", value) + messages.append((f"{prefix}/$description", topics["$description"])) + messages.append((f"{prefix}/$state", topics["$state"])) + messages.extend( + (f"{prefix}/{topic}", value) + for topic, value in topics.items() + if not topic.startswith("$") and topic not in omit + ) + return messages @pytest.fixture(name="adapter") @@ -212,6 +228,152 @@ def test_a_panel_that_declares_no_model_still_connects() -> None: assert adapter.build_snapshot().panel_size == 0 +# --------------------------------------------------------------------------- +# Readiness is remembered between messages +# +# The transport asks `is_ready()` before and after every message, and walking +# the tree each time cost more than routing the message did (#223). The answer +# is kept until the tree changes. Each check below asks after every message, +# as the transport does, and compares the answer with an adapter that has seen +# the same messages and is asked for the first time. +# --------------------------------------------------------------------------- + + +def _readiness_after_each(messages: list[tuple[str, str]], *, from_message: int = 0) -> list[bool]: + """Readiness after each message past `from_message`, each checked against a fresh adapter.""" + adapter = SchemaOneAdapter(PANEL, _schema()) + answers: list[bool] = [] + for count, (topic, payload) in enumerate(messages, start=1): + adapter.handle_message(topic, payload) + remembered = adapter.is_ready() + if count <= from_message: + continue + fresh = SchemaOneAdapter(PANEL, _schema()) + for earlier in messages[:count]: + fresh.handle_message(*earlier) + assert remembered is fresh.is_ready(), f"readiness was stale after {topic} = {payload!r}" + answers.append(remembered) + return answers + + +def _panel_description(**changes: object) -> str: + description = json.loads(_TREE[PANEL]["$description"]) + description.update(changes) + return json.dumps(description) + + +def _shuffled(seed: int) -> list[tuple[str, str]]: + messages = _retained() + random.Random(seed).shuffle(messages) + return messages + + +@pytest.mark.parametrize( + "messages", + [ + pytest.param(_retained(), id="panel-first"), + pytest.param(_retained([*[d for d in _TREE if d != PANEL], PANEL]), id="children-first"), + *(pytest.param(_shuffled(seed), id=f"shuffled-{seed}") for seed in (1, 2, 3)), + ], +) +def test_readiness_follows_every_message_of_a_replay(messages: list[tuple[str, str]]) -> None: + """A broker replays its retained store in any order, `$state` before + `$description` and children before parents included.""" + answers = _readiness_after_each(messages) + + assert answers[-1] is True + + +def test_readiness_follows_the_panel_leaving_ready_and_returning() -> None: + base = _retained() + messages = [*base, (f"ebus/5/{PANEL}/$state", "init"), (f"ebus/5/{PANEL}/$state", "ready")] + + assert _readiness_after_each(messages, from_message=len(base)) == [False, True] + + +def test_readiness_follows_a_child_that_is_removed_and_returns() -> None: + """An empty retained `$state` removes a device; the panel still declares it.""" + base = _retained() + prefix = f"ebus/5/{KITCHEN_CIRCUIT}" + messages = [ + *base, + (f"{prefix}/$state", ""), + (f"{prefix}/$state", "ready"), + (f"{prefix}/$description", _TREE[KITCHEN_CIRCUIT]["$description"]), + ] + + assert _readiness_after_each(messages, from_message=len(base)) == [False, False, True] + + +def test_readiness_follows_the_panel_withdrawing_a_child_it_was_waiting_on() -> None: + """A device commissioned and decommissioned before it ever described itself.""" + base = _retained() + children = json.loads(_TREE[PANEL]["$description"])["children"] + messages = [ + *base, + (f"ebus/5/{PANEL}/$description", _panel_description(children=[*children, "circuit-38"])), + (f"ebus/5/{PANEL}/$description", _TREE[PANEL]["$description"]), + ] + + assert _readiness_after_each(messages, from_message=len(base)) == [False, True] + + +def test_readiness_follows_the_panel_redeclaring_its_model() -> None: + """Whether the model is waited for is itself read from the panel's description.""" + base = _retained(omit=("info/model",)) + description = json.loads(_TREE[PANEL]["$description"]) + del description["nodes"]["info"]["properties"]["model"] + messages = [ + *base, + (f"ebus/5/{PANEL}/$description", json.dumps(description)), + (f"ebus/5/{PANEL}/$description", _TREE[PANEL]["$description"]), + (f"ebus/5/{PANEL}/info/model", _TREE[PANEL]["info/model"]), + ] + + assert _readiness_after_each(messages, from_message=len(base)) == [True, False, True] + + +def test_readiness_follows_a_childless_panel_whose_state_arrives_last() -> None: + """The panel's first `$state` is the only change here, and nothing else + re-examines the tree after it.""" + panel = {topic: value for topic, value in _TREE[PANEL].items() if not topic.startswith("$")} + prefix = f"ebus/5/{PANEL}" + messages = [ + (f"{prefix}/$description", _panel_description(children=[])), + *((f"{prefix}/{topic}", value) for topic, value in panel.items()), + (f"{prefix}/$state", "ready"), + ] + + answers = _readiness_after_each(messages) + + assert answers[-1] is True + assert not any(answers[:-1]) + + +def test_a_reading_or_a_rename_does_not_walk_the_tree(adapter: SchemaOneAdapter, monkeypatch: pytest.MonkeyPatch) -> None: + """The per-message cost #223 measured: values change constantly and + readiness never depends on them.""" + assert adapter.is_ready() is True + walks = 0 + is_tree_complete = Controller.is_tree_complete + + def counting(controller: Controller, root_id: str) -> bool: + nonlocal walks + walks += 1 + return is_tree_complete(controller, root_id) + + monkeypatch.setattr(Controller, "is_tree_complete", counting) + prefix = f"ebus/5/{KITCHEN_CIRCUIT}" + + adapter.handle_message(f"{prefix}/meter/active-power", "-250.0") + assert adapter.is_ready() is True + adapter.handle_message(f"{prefix}/info/name", "Kitchen island") + assert adapter.is_ready() is True + + assert walks == 0 + assert adapter.build_snapshot().circuits[KITCHEN_CIRCUIT].name == "Kitchen island" + + def test_snapshot_is_built_from_the_discovered_tree(adapter: SchemaOneAdapter) -> None: snapshot = adapter.build_snapshot() @@ -546,7 +708,7 @@ def test_the_feed_grace_restarts_once_every_inverter_has_been_placed() -> None: second_circuit: { topic: value for topic, value in _TREE[SOLAR_CIRCUIT].items() if topic != "connection/feeds-device-id" } - | {"info/name": "Garage Solar", "info/spaces": "5,7"}, + | {"info/name": "Garage Solar", "info/spaces": "13,15"}, } _feed(adapter, [PANEL, second_pv, second_circuit], tree=tree) assert {inverter.device_id for inverter in adapter.build_snapshot().pv_inverters.values()} == { @@ -605,6 +767,21 @@ def test_find_node_by_type_answers_with_a_device_id(adapter: SchemaOneAdapter) - assert adapter.find_node_by_type("energy.ebus.device.nonexistent") is None +@pytest.mark.parametrize( + ("declared", "found"), [("energy.ebus.device.bess.hybrid", "bess"), ("energy.ebus.device.bessfoo", None)] +) +def test_find_node_by_type_answers_for_a_subtype_and_not_for_a_look_alike(declared: str, found: str | None) -> None: + """A device typed `bess.` declares the `bess` class; one typed `bessfoo` does not (#228).""" + tree = {device_id: dict(topics) for device_id, topics in _TREE.items()} + description = json.loads(tree["bess"]["$description"]) + description["type"] = declared + tree["bess"]["$description"] = json.dumps(description) + adapter = SchemaOneAdapter(PANEL, _schema()) + _feed(adapter, tree=tree) + + assert adapter.find_node_by_type("energy.ebus.device.bess") == found + + def test_property_callbacks_receive_updates() -> None: seen: list[tuple[str, str, str, str | None]] = [] adapter = SchemaOneAdapter(PANEL, _schema()) diff --git a/tests/test_schema_one_charge_limit.py b/tests/test_schema_one_charge_limit.py index e2aa32ee..8a64c89e 100644 --- a/tests/test_schema_one_charge_limit.py +++ b/tests/test_schema_one_charge_limit.py @@ -7,9 +7,14 @@ So the parser is written against the *rule* rather than against either name, and these tests hold it to that: every read expectation is computed from the captured -tree, the catalogued spelling is driven through a rewritten description and has to -behave identically, and every write assertion names the exact topic and payload -the transport puts on the wire. +tree or from a value republished on it, the catalogued spelling is driven through a +rewritten description and has to behave identically, and every write assertion +names the exact topic and payload the transport puts on the wire. + +The capture sets no user limit. From firmware r202639 a charger publishes +`config/user-max-charge-current` only once a user sets one, and `ebus-panel-sim` +0.9.0 publishes that behaviour, so a test about a valued limit publishes one +(`_user_limit`) the way a charger would after a user set it. """ from __future__ import annotations @@ -24,6 +29,7 @@ from ebus_sdk.homie import DiscoveredDevice +from reference_payloads.captures import CAPTURES, capture_snapshot, capture_tree from reference_payloads.schema_one import device_from_topics, parent_child_tree from span_panel_api.exceptions import SpanPanelServerError from span_panel_api.models import V2HomieSchema @@ -37,6 +43,7 @@ PANEL = "example-40t-001" EVSE = "evse" EVSE_2 = "evse-2" +_EVSE_TYPE = "energy.ebus.device.evse" CEILING_TOPIC = "config/max-charge-current" LIMIT_TOPIC = "config/user-max-charge-current" @@ -69,6 +76,15 @@ def _published(device_id: str, topic: str) -> str: return value +def _user_limit(device_id: str) -> int: + """A limit a user would set on this charger: inside its ceiling, and not equal to it. + + Below the ceiling so it cannot be mistaken for the ceiling standing in for an + absent limit, which is what the effective limit reports when none is set. + """ + return int(_published(device_id, CEILING_TOPIC)) - 8 + + def _tree(**overrides: Mapping[str, str | None]) -> dict[str, dict[str, str]]: """The capture with topics rewritten per device, or removed where `None`. @@ -94,15 +110,18 @@ def _snapshot_evse(tree: dict[str, dict[str, str]], device_id: str) -> object: return build_evse(_evse_device(tree, device_id), {}, node_id=device_id, feed_statuses={}) -def _renamed_to_catalog(device_id: str) -> dict[str, dict[str, str]]: - """The capture with one charger publishing the catalogued spelling instead. +def _renamed_to_catalog(device_id: str, base: dict[str, dict[str, str]] | None = None) -> dict[str, dict[str, str]]: + """The capture (or `base`, a tree built from it) with one charger publishing the catalogued spelling instead. Both halves move — the `$description` node and the value topics — because a charger that renamed one and not the other would be publishing to a property it never declared, which is a different (and illegal) situation from the one - under test. + under test. The limit's value topic moves only where the charger publishes + one: unset, it is unpublished under either spelling. The ceiling is always + published, so its absence is a fixture fault and fails here. """ - topics = dict(_TREE[device_id]) + source = _TREE if base is None else base + topics = dict(source[device_id]) description = json.loads(topics["$description"]) config = description["nodes"].pop("config") properties = config["properties"] @@ -116,8 +135,9 @@ def _renamed_to_catalog(device_id: str) -> dict[str, dict[str, str]]: } topics["$description"] = json.dumps(description) topics[CATALOG_CEILING_TOPIC] = topics.pop(CEILING_TOPIC) - topics[CATALOG_LIMIT_TOPIC] = topics.pop(LIMIT_TOPIC) - tree = {other: dict(values) for other, values in _TREE.items()} + if LIMIT_TOPIC in topics: + topics[CATALOG_LIMIT_TOPIC] = topics.pop(LIMIT_TOPIC) + tree = {other: dict(values) for other, values in source.items()} tree[device_id] = topics return tree @@ -178,21 +198,48 @@ def _key(adapter: SchemaOneAdapter, device_id: str) -> str: def test_both_halves_come_off_the_wire() -> None: - evse = _snapshot_evse(_TREE, EVSE) + """A charger with a limit set publishes both halves, and each is read off its own topic.""" + limit = _user_limit(EVSE) + + evse = _snapshot_evse(_tree(**{EVSE: {LIMIT_TOPIC: str(limit)}}), EVSE) - assert evse.charge_current_limit_a == int(_published(EVSE, LIMIT_TOPIC)) + assert evse.charge_current_limit_a == limit assert evse.charge_current_ceiling_a == int(_published(EVSE, CEILING_TOPIC)) +def test_the_capture_sets_no_user_limit_on_either_charger() -> None: + """The capture's own state, read the way the broker replays it. + + Each charger declares the limit, settable, and publishes no value for it, so + each reads no limit, its own ceiling as the limit in force, and still a + control. Asserted per charger, because the capture is the producer's account + of r202639 and a parser that defaulted the absent limit to anything would + report it here. + """ + adapter = _adapter() + snapshot = adapter.build_snapshot() + + for device_id in (EVSE, EVSE_2): + declared = json.loads(_TREE[device_id]["$description"])["nodes"]["config"]["properties"] + assert declared["user-max-charge-current"]["settable"] is True + assert LIMIT_TOPIC not in _TREE[device_id] + + evse = snapshot.evse[_key(adapter, device_id)] + + assert evse.charge_current_limit_a is None + assert evse.effective_charge_current_limit_a == int(_published(device_id, CEILING_TOPIC)) + assert evse.charge_current_limit_settable is True + + def test_each_charger_reads_its_own_limit() -> None: """Two chargers, two different values, and neither may answer for the other. - The capture publishes 32 on both, so an assertion against it as-published - would pass for a parser that read one charger and reported it twice. The - values are made to differ first, which is the only shape of this test that - proves anything. + The capture sets no limit on either and publishes the same ceiling on both, + so limits derived from it as-is would pass for a parser that read one + charger and reported it twice. The values are set and made to differ first, + which is the only shape of this test that proves anything. """ - first, second = int(_published(EVSE, LIMIT_TOPIC)) - 8, int(_published(EVSE_2, LIMIT_TOPIC)) - 16 + first, second = _user_limit(EVSE), _user_limit(EVSE_2) - 8 assert first != second tree = _tree(**{EVSE: {LIMIT_TOPIC: str(first)}, EVSE_2: {LIMIT_TOPIC: str(second)}}) @@ -213,9 +260,15 @@ def test_each_charger_reads_its_own_ceiling() -> None: def test_republishing_moves_the_reading() -> None: - raised = int(_published(EVSE, LIMIT_TOPIC)) - 12 + """A limit the user changes moves the reading on the same device, rather than holding the first one seen.""" + first = _user_limit(EVSE) + moved = first - 4 + device = _evse_device(_tree(**{EVSE: {LIMIT_TOPIC: str(first)}}), EVSE) + assert build_evse(device, {}, node_id=EVSE, feed_statuses={}).charge_current_limit_a == first + + device.update_property("config", "user-max-charge-current", str(moved)) - assert _snapshot_evse(_tree(**{EVSE: {LIMIT_TOPIC: str(raised)}}), EVSE).charge_current_limit_a == raised + assert build_evse(device, {}, node_id=EVSE, feed_statuses={}).charge_current_limit_a == moved def test_an_unpublished_value_is_none_rather_than_zero() -> None: @@ -288,14 +341,32 @@ def test_the_ceiling_is_never_reported_settable() -> None: def test_a_pending_write_shows_as_a_target() -> None: """The Homie `$target` echo, the same pending-command signal the priority select already reads through `circuit.priority_target`.""" + current = _user_limit(EVSE) + device = _evse_device(_tree(**{EVSE: {LIMIT_TOPIC: str(current)}}), EVSE) + pending = current - 8 + device.update_property_target("config", "user-max-charge-current", str(pending)) + + evse = build_evse(device, {}, node_id=EVSE, feed_statuses={}) + + assert evse.charge_current_limit_target_a == pending + assert evse.charge_current_limit_a == current + + +def test_a_first_limit_still_pending_shows_as_a_target_and_no_reading() -> None: + """The capture's own state with a user's first write in flight. + + The target shows at once; the limit stays unread until the charger + publishes one, and the ceiling stays the limit in force meanwhile. + """ device = _evse_device(_TREE, EVSE) - pending = int(_published(EVSE, LIMIT_TOPIC)) - 8 + pending = _user_limit(EVSE) device.update_property_target("config", "user-max-charge-current", str(pending)) evse = build_evse(device, {}, node_id=EVSE, feed_statuses={}) assert evse.charge_current_limit_target_a == pending - assert evse.charge_current_limit_a == int(_published(EVSE, LIMIT_TOPIC)) + assert evse.charge_current_limit_a is None + assert evse.effective_charge_current_limit_a == int(_published(EVSE, CEILING_TOPIC)) def test_no_pending_write_is_no_target() -> None: @@ -325,13 +396,17 @@ def test_the_catalogued_spelling_reads_identically() -> None: The claim this whole design rests on: nothing outside `charge_limit.py` names a node, so a charger publishing the specified spelling produces the same snapshot as one publishing SPAN's. Asserted field by field against the - unrenamed capture rather than against literals, so the two paths are held to - each other and not merely to the same numbers. + unrenamed tree rather than against literals, so the two paths are held to + each other and not merely to the same numbers: once with a limit set, and + once as captured, with none. """ - published = _snapshot_evse(_TREE, EVSE) - catalogued = _snapshot_evse(_renamed_to_catalog(EVSE), EVSE) + limit = _user_limit(EVSE) + valued = _tree(**{EVSE: {LIMIT_TOPIC: str(limit)}}) + catalogued = _snapshot_evse(_renamed_to_catalog(EVSE, valued), EVSE) - assert catalogued == published + assert catalogued == _snapshot_evse(valued, EVSE) + assert catalogued.charge_current_limit_a == limit + assert _snapshot_evse(_renamed_to_catalog(EVSE), EVSE) == _snapshot_evse(_TREE, EVSE) def test_the_catalogued_spelling_is_written_to_its_own_topic() -> None: @@ -348,13 +423,14 @@ def test_the_catalogued_spelling_wins_where_both_are_declared() -> None: retiring the old, and a reader that took whichever it saw first would flip between them on the strength of dict ordering. """ - tree = _renamed_to_catalog(EVSE) + limit = str(_user_limit(EVSE)) + tree = _renamed_to_catalog(EVSE, _tree(**{EVSE: {LIMIT_TOPIC: limit}})) stale = json.loads(_TREE[EVSE]["$description"])["nodes"]["config"] description = json.loads(tree[EVSE]["$description"]) description["nodes"]["config"] = stale tree[EVSE]["$description"] = json.dumps(description) tree[EVSE][CEILING_TOPIC] = _published(EVSE, CEILING_TOPIC) - tree[EVSE][LIMIT_TOPIC] = _published(EVSE, LIMIT_TOPIC) + tree[EVSE][LIMIT_TOPIC] = limit surface = resolve_charge_limit(_evse_device(tree, EVSE)) @@ -425,7 +501,93 @@ def test_a_value_at_or_below_the_ceiling_is_published_as_it_is() -> None: assert adapter.evse_charge_limit_payload(key, ceiling) == str(ceiling) assert adapter.evse_charge_limit_payload(key, ceiling - 16) == str(ceiling - 16) + assert adapter.evse_charge_limit_payload(key, _declared_minimum(EVSE)) == str(_declared_minimum(EVSE)) + + +def _declared_minimum(device_id: str) -> int: + """The lower bound the capture's limit declares in `$format` (`:`).""" + declared = json.loads(_TREE[device_id]["$description"])["nodes"]["config"]["properties"] + return int(declared["user-max-charge-current"]["format"].split(":")[0]) + + +def _with_limit_format( + fmt: str | None, device_id: str = EVSE, base: dict[str, dict[str, str]] | None = None +) -> dict[str, dict[str, str]]: + """The capture (or `base`, a tree built from it) with the limit's declared `$format` replaced, or removed where `None`.""" + source = _TREE if base is None else base + topics = dict(source[device_id]) + description = json.loads(topics["$description"]) + declaration = description["nodes"]["config"]["properties"]["user-max-charge-current"] + if fmt is None: + declaration.pop("format") + else: + declaration["format"] = fmt + topics["$description"] = json.dumps(description) + tree = {other: dict(values) for other, values in source.items()} + tree[device_id] = topics + return tree + + +def test_below_the_declared_minimum_is_refused() -> None: + """The panel declares the range it accepts (`6:`); a value under it + is not a smaller limit but one the charger does not take.""" + adapter = _adapter() + key = _key(adapter, EVSE) + minimum = _declared_minimum(EVSE) + + assert adapter.evse_charge_limit_payload(key, minimum - 1) is None + assert adapter.evse_charge_limit_payload(key, 0) is None + + +def test_the_declared_minimum_itself_is_accepted() -> None: + adapter = _adapter() + key = _key(adapter, EVSE) + minimum = _declared_minimum(EVSE) + + assert adapter.evse_charge_limit_payload(key, minimum) == str(minimum) + + +def test_a_declared_maximum_tighter_than_the_ceiling_is_enforced() -> None: + ceiling = int(_published(EVSE, CEILING_TOPIC)) + adapter = _adapter(_with_limit_format(f"6:{ceiling - 8}")) + key = _key(adapter, EVSE) + + assert adapter.evse_charge_limit_payload(key, ceiling - 8) == str(ceiling - 8) + assert adapter.evse_charge_limit_payload(key, ceiling - 7) is None + + +def test_a_range_with_an_open_side_enforces_only_the_other() -> None: + low_open = _adapter(_with_limit_format(":20")) + assert low_open.evse_charge_limit_payload(_key(low_open, EVSE), 0) == "0" + assert low_open.evse_charge_limit_payload(_key(low_open, EVSE), 21) is None + + high_open = _adapter(_with_limit_format("6:")) + ceiling = int(_published(EVSE, CEILING_TOPIC)) + assert high_open.evse_charge_limit_payload(_key(high_open, EVSE), 5) is None + assert high_open.evse_charge_limit_payload(_key(high_open, EVSE), ceiling) == str(ceiling) + assert high_open.evse_charge_limit_payload(_key(high_open, EVSE), ceiling + 1) is None + + +def test_no_declared_format_keeps_the_ceiling_as_the_only_bound() -> None: + adapter = _adapter(_with_limit_format(None)) + key = _key(adapter, EVSE) + ceiling = int(_published(EVSE, CEILING_TOPIC)) + + assert adapter.evse_charge_limit_payload(key, 0) == "0" + assert adapter.evse_charge_limit_payload(key, ceiling) == str(ceiling) + assert adapter.evse_charge_limit_payload(key, ceiling + 1) is None + + +@pytest.mark.parametrize( + "fmt", ["garbage", "6", "a:b", "6:32:1", "6.5:32", "UNLOCKED,LOCKED", "1_0:32", "+6:32", "6:+32", "\u0666:32", "32:6"] +) +def test_an_uninterpretable_format_keeps_the_ceiling_as_the_only_bound(fmt: str) -> None: + adapter = _adapter(_with_limit_format(fmt)) + key = _key(adapter, EVSE) + ceiling = int(_published(EVSE, CEILING_TOPIC)) + assert adapter.evse_charge_limit_payload(key, 0) == "0" + assert adapter.evse_charge_limit_payload(key, ceiling + 1) is None def test_above_the_ceiling_is_refused_rather_than_clamped() -> None: @@ -461,6 +623,9 @@ def test_a_charger_with_no_ceiling_is_not_second_guessed() -> None: topics = dict(_TREE[EVSE]) description = json.loads(topics["$description"]) description["nodes"]["config"]["properties"].pop("max-charge-current") + # A declared range would bound 1000 A too; this test is about a charger that + # declares neither a ceiling nor a range, which nothing bounds. + description["nodes"]["config"]["properties"]["user-max-charge-current"].pop("format") topics["$description"] = json.dumps(description) topics.pop(CEILING_TOPIC) tree = {other: dict(values) for other, values in _TREE.items()} @@ -473,6 +638,166 @@ def test_a_charger_with_no_ceiling_is_not_second_guessed() -> None: assert adapter.set_evse_charge_limit_target(key).topic == f"ebus/5/{EVSE}/config/user-max-charge-current/set" +def test_a_declared_maximum_bounds_a_charger_that_publishes_no_ceiling() -> None: + """With no ceiling the declared `$format` maximum is still a published bound.""" + topics = dict(_TREE[EVSE]) + description = json.loads(topics["$description"]) + description["nodes"]["config"]["properties"].pop("max-charge-current") + topics["$description"] = json.dumps(description) + topics.pop(CEILING_TOPIC) + tree = {other: dict(values) for other, values in _TREE.items()} + tree[EVSE] = topics + + adapter = _adapter(tree) + key = _key(adapter, EVSE) + maximum = int( + json.loads(topics["$description"])["nodes"]["config"]["properties"]["user-max-charge-current"]["format"].split(":")[ + 1 + ] + ) + + assert adapter.evse_charge_limit_payload(key, maximum) == str(maximum) + assert adapter.evse_charge_limit_payload(key, maximum + 1) is None + + +# --------------------------------------------------------------------------- +# The declared range — what a control may offer, reported before any write +# --------------------------------------------------------------------------- + + +def _range(evse: object) -> tuple[int | None, int | None]: + return evse.charge_current_limit_minimum_a, evse.charge_current_limit_maximum_a + + +def _declared_range(device_id: str) -> tuple[int, int]: + """The `:` the capture's limit declares, read from its `$description`.""" + declared = json.loads(_TREE[device_id]["$description"])["nodes"]["config"]["properties"] + low, high = declared["user-max-charge-current"]["format"].split(":") + return int(low), int(high) + + +def test_each_charger_reports_the_range_its_limit_declares() -> None: + """The capture's own declarations, read the way the broker replays them. + + Each charger declares `6:32`; a control bounded by anything else offers a + value the write path then refuses. + """ + adapter = _adapter() + snapshot = adapter.build_snapshot() + + for device_id in (EVSE, EVSE_2): + assert _declared_range(device_id) == (6, 32) + assert _range(snapshot.evse[_key(adapter, device_id)]) == _declared_range(device_id) + + +def test_the_range_is_not_the_ceiling() -> None: + """The declared maximum and the commissioned ceiling are separate readings. + + The ceiling is lowered below the declared maximum so a mapper that reported + the ceiling as the range, or the range as the ceiling, would show here. + """ + lowered = _declared_range(EVSE)[1] - 8 + evse = _snapshot_evse(_tree(**{EVSE: {CEILING_TOPIC: str(lowered)}}), EVSE) + + assert evse.charge_current_ceiling_a == lowered + assert _range(evse) == _declared_range(EVSE) + + +def test_each_charger_reports_its_own_range() -> None: + """Both chargers declare the same range in the capture, so they are made to differ first.""" + tree = _with_limit_format("8:16", EVSE_2, base=_with_limit_format("6:24", EVSE)) + adapter = _adapter(tree) + snapshot = adapter.build_snapshot() + + assert _range(snapshot.evse[_key(adapter, EVSE)]) == (6, 24) + assert _range(snapshot.evse[_key(adapter, EVSE_2)]) == (8, 16) + + +def test_no_declared_format_reports_no_range() -> None: + assert _range(_snapshot_evse(_with_limit_format(None), EVSE)) == (None, None) + + +@pytest.mark.parametrize( + "fmt", ["garbage", "6", "a:b", "6:32:1", "6.5:32", "UNLOCKED,LOCKED", "1_0:32", "+6:32", "6:+32", "٦:32", "32:6"] +) +def test_an_uninterpretable_or_inverted_format_reports_no_range(fmt: str) -> None: + """The same formats the write path refuses to read bound nothing here either.""" + assert _range(_snapshot_evse(_with_limit_format(fmt), EVSE)) == (None, None) + + +def test_an_open_side_is_none_on_that_side_only() -> None: + assert _range(_snapshot_evse(_with_limit_format(":20"), EVSE)) == (None, 20) + assert _range(_snapshot_evse(_with_limit_format("6:"), EVSE)) == (6, None) + + +def test_a_float_limit_reports_no_range() -> None: + """Only an `integer` declaration's range is read, as on the write path.""" + topics = dict(_TREE[EVSE]) + description = json.loads(topics["$description"]) + description["nodes"]["config"]["properties"]["user-max-charge-current"]["datatype"] = "float" + topics["$description"] = json.dumps(description) + tree = {other: dict(values) for other, values in _TREE.items()} + tree[EVSE] = topics + + assert _range(_snapshot_evse(tree, EVSE)) == (None, None) + + +def test_a_charger_with_no_charge_limit_node_reports_no_range() -> None: + assert _range(_snapshot_evse(_without_node(EVSE), EVSE)) == (None, None) + + +def test_the_range_is_reported_whether_or_not_the_limit_is_settable() -> None: + """A declaration, reported as declared; `charge_current_limit_settable` is the separate answer to whether to offer it. + + The same rule `lock_state_options` follows for a lock the charger does not + accept writes to. + """ + evse = _snapshot_evse(_without_settable(EVSE), EVSE) + + assert evse.charge_current_limit_settable is False + assert _range(evse) == _declared_range(EVSE) + + +def test_the_catalogued_spelling_reports_the_same_range() -> None: + catalogued = _snapshot_evse(_renamed_to_catalog(EVSE), EVSE) + + assert _range(catalogued) == _declared_range(EVSE) + + +def test_the_range_does_not_wait_for_a_value() -> None: + """The range is in the declaration, so it is reported before the charger publishes either half.""" + evse = _snapshot_evse(_tree(**{EVSE: {LIMIT_TOPIC: None, CEILING_TOPIC: None}}), EVSE) + + assert evse.charge_current_ceiling_a is None + assert _range(evse) == _declared_range(EVSE) + + +def _captured_ranges(stem: str) -> list[tuple[int, int]]: + """The `:` each charger in a reference capture declares for its limit.""" + tree = capture_tree(stem) + declared = [] + for device_id in tree.devices: + if tree.device_type(device_id) != _EVSE_TYPE: + continue + properties = json.loads(tree.devices[device_id].description)["nodes"]["config"]["properties"] + low, high = properties["user-max-charge-current"]["format"].split(":") + declared.append((int(low), int(high))) + return sorted(declared) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_each_captured_charger_reports_the_range_it_declares(stem: str) -> None: + """Every reference capture, against its own declarations rather than the reference tree's.""" + snapshot = capture_snapshot(stem) + + assert sorted(_range(charger) for charger in snapshot.evse.values()) == _captured_ranges(stem) + + +def test_the_captures_hold_a_declared_range() -> None: + """Without one, the test above compares two empty lists and proves nothing.""" + assert any(_captured_ranges(stem) for stem in CAPTURES) + + # --------------------------------------------------------------------------- # The transport — what actually reaches the wire # --------------------------------------------------------------------------- @@ -554,7 +879,13 @@ def test_metadata_carries_the_declared_unit_and_datatype() -> None: def test_metadata_follows_the_catalogued_spelling_too() -> None: - metadata = _metadata(_renamed_to_catalog(EVSE)) + # Only the renamed charger is described. With the second charger present it + # would answer for the first, and the metadata would resolve with the + # catalogued spelling unrecognised. + tree = _renamed_to_catalog(EVSE) + tree.pop(EVSE_2) + + metadata = _metadata(tree) assert metadata["evse.charge_current_limit_a"].unit == "A" assert metadata["evse.charge_current_ceiling_a"].datatype == "integer" diff --git a/tests/test_schema_one_circuit_fed_battery.py b/tests/test_schema_one_circuit_fed_battery.py new file mode 100644 index 00000000..38438f40 --- /dev/null +++ b/tests/test_schema_one_circuit_fed_battery.py @@ -0,0 +1,61 @@ +"""A battery fed by a circuit takes its link status from that circuit. + +Where a circuit's `connection/feeds-device-id` names the battery, the +circuit's `feeds-device-status` is the panel's view of the link, exactly as it +is for an inverter or a charger: `SpanBatterySnapshot.connected` follows it and +`feed_circuit_id` names the circuit. The circuit stays a circuit. A battery +claimed by the upstream lugs keeps reading its link from them. +""" + +from __future__ import annotations + +import pytest + +from conftest import flat_schema +from reference_payloads.schema_one import parent_child_tree, replay +from reference_payloads.synthetic_trees import PANEL_ID, SyntheticDevice, circuit_fed_battery, panel, tree, without_values +from span_panel_api import SpanPanelSnapshot +from span_panel_api_schema_0 import SchemaZeroAdapter + +_REFERENCE_PANEL = "example-40t-001" + + +def _snapshot(*children: SyntheticDevice) -> SpanPanelSnapshot: + return replay(tree(panel(), *children), PANEL_ID).build_snapshot() + + +@pytest.mark.parametrize(("status", "connected"), [("OK", True), ("LOST", False), ("DEGRADED", False)]) +def test_the_feeding_circuits_status_is_the_link(status: str, connected: bool) -> None: + snapshot = _snapshot(*circuit_fed_battery("c-1", "battery-a", status=status)) + + assert snapshot.battery.connected is connected + assert snapshot.battery.feed_circuit_id == "c-1" + assert snapshot.circuits["c-1"].device_type == "circuit" + + +def test_an_unpublished_status_leaves_the_link_unknown() -> None: + circuit, battery = circuit_fed_battery("c-1", "battery-a") + snapshot = _snapshot(without_values(circuit, "connection/feeds-device-status"), battery) + + assert snapshot.battery.connected is None + assert snapshot.battery.feed_circuit_id == "c-1" + + +def test_an_unpublished_feed_names_no_circuit() -> None: + circuit, battery = circuit_fed_battery("c-1", "battery-a") + snapshot = _snapshot(without_values(circuit, "connection/feeds-device-id", "connection/feeds-device-status"), battery) + + assert (snapshot.battery.connected, snapshot.battery.feed_circuit_id) == (None, None) + + +def test_a_battery_behind_the_upstream_lugs_keeps_their_link() -> None: + battery = replay(parent_child_tree(), _REFERENCE_PANEL).build_snapshot().battery + + assert battery.connected is True + assert battery.feed_circuit_id is None + + +def test_a_flat_panel_names_no_feeding_circuit() -> None: + snapshot = SchemaZeroAdapter(serial_number="sim-40t-001", schema=flat_schema(40)).build_snapshot() + + assert snapshot.battery.feed_circuit_id is None diff --git a/tests/test_schema_one_circuits.py b/tests/test_schema_one_circuits.py index 2ad534a6..8d0b756d 100644 --- a/tests/test_schema_one_circuits.py +++ b/tests/test_schema_one_circuits.py @@ -101,7 +101,7 @@ def test_tabs_come_from_the_published_list_not_a_derivation(solar: DiscoveredDev def test_single_pole_circuit(kitchen: DiscoveredDevice) -> None: circuit = build_circuit(kitchen) - assert circuit.tabs == [1] + assert circuit.tabs == [9] assert circuit.is_240v is False diff --git a/tests/test_schema_one_cleared_retained.py b/tests/test_schema_one_cleared_retained.py new file mode 100644 index 00000000..68ce69a5 --- /dev/null +++ b/tests/test_schema_one_cleared_retained.py @@ -0,0 +1,253 @@ +"""A retained value the panel clears reads as unpublished, not as an empty value. + +MQTT deletes a retained message when a zero-length payload is published to its +topic, and Homie 5 keeps that meaning: a device removes a value by clearing its +topic. Homie 5 therefore spells an empty *string* differently, as a single +``0x00`` byte. The two arrive apart -- the transport hands the adapter ``""`` +for a clear and ``"\\x00"`` for an empty string -- but ebus-sdk 0.22.0's +`Controller` decodes both to ``""`` and stores that, so a property the panel +cleared went on reading as a value the panel published. + +That is not merely stale. The reference tree's upstream lugs publish +`connection/fed-by-device-id: bess`; cleared, the stored ``""`` read as "fed by +nothing", and the snapshot claimed the lugs were the service entrance. Declared +and unvalued, the honest answer is `None`. + +Every test drives `handle_message`, the path the transport takes. +""" + +from __future__ import annotations + +from collections.abc import Iterable + +from reference_payloads.captures import capture_tree_from_document +from reference_payloads.schema_one import RetainedTopicTree, parent_child_tree, replay +from span_panel_api.models import V2HomieSchema +from span_panel_api_schema_1 import SchemaOneAdapter +from span_panel_api_schema_1.tree_export import placeholder_ids + +_TREE = parent_child_tree() + +PANEL = "example-40t-001" +LUGS = "lugs-upstream" +FED_BY = "connection/fed-by-device-id" +FED_BY_TOPIC = f"ebus/5/{LUGS}/{FED_BY}" +KITCHEN_CIRCUIT = "0ab966b95f92a6a51ec548485aa85f54" +"""A controllable circuit, so a relay `$target` on it is one the panel could publish.""" +RELAY_TARGET_TOPIC = f"ebus/5/{KITCHEN_CIRCUIT}/switch/relay/$target" +MODEL_TOPIC = f"ebus/5/{PANEL}/info/model" + +CLEARED = "" +"""A zero-length MQTT payload, as the transport decodes it: the retained topic is deleted.""" +EMPTY_STRING = "\x00" +"""Homie 5's empty-string value, as the transport decodes it: published, and empty.""" + + +def _schema() -> V2HomieSchema: + return V2HomieSchema( + firmware_version="spanos2/r202633/01", + types_schema_hash="sha256:test", + types={}, + data_model_version="1.0", + ) + + +def _retained(tree: RetainedTopicTree = _TREE) -> list[tuple[str, str]]: + """The tree as the broker replays it, the panel first.""" + messages: list[tuple[str, str]] = [] + for device_id in [PANEL, *[other for other in tree if other != PANEL]]: + topics = tree[device_id] + prefix = f"ebus/5/{device_id}" + messages.append((f"{prefix}/$description", topics["$description"])) + messages.append((f"{prefix}/$state", topics["$state"])) + messages.extend((f"{prefix}/{topic}", value) for topic, value in topics.items() if not topic.startswith("$")) + return messages + + +def _adapter( + *messages: tuple[str, str], before: Iterable[tuple[str, str]] = (), tree: RetainedTopicTree = _TREE +) -> SchemaOneAdapter: + """`tree` replayed, then `messages`; `before` arrives ahead of the replay, before any route exists.""" + adapter = SchemaOneAdapter(PANEL, _schema()) + for topic, payload in [*before, *_retained(tree), *messages]: + adapter.handle_message(topic, payload) + return adapter + + +def _exported_lugs(adapter: SchemaOneAdapter) -> dict[str, str]: + """The upstream lugs' declared non-numeric values in the masked export.""" + tree = adapter.export_masked_tree() + assert tree is not None + root = adapter._controller.get_root(PANEL) + assert root is not None + placeholder = placeholder_ids(root, adapter._children())[LUGS] + return tree["devices"][placeholder]["properties"] + + +# -- a cleared value ------------------------------------------------------- + + +def test_the_reference_lugs_are_fed_by_the_battery() -> None: + """The baseline the clears below move away from.""" + assert _adapter().build_snapshot().lugs_at_service_entrance is False + + +def test_a_cleared_property_reads_as_unpublished() -> None: + """Declared and unvalued: the lugs have not said what feeds them.""" + adapter = _adapter((FED_BY_TOPIC, CLEARED)) + + assert adapter.build_snapshot().lugs_at_service_entrance is None + + +def test_an_empty_string_still_reads_as_a_published_empty_value() -> None: + """Homie 5's ``0x00`` is a value: published empty, which reads as fed by nothing.""" + adapter = _adapter((FED_BY_TOPIC, EMPTY_STRING)) + + assert adapter.build_snapshot().lugs_at_service_entrance is True + + +def test_a_value_published_after_a_clear_is_read_again() -> None: + adapter = _adapter((FED_BY_TOPIC, CLEARED), (FED_BY_TOPIC, "bess")) + + assert adapter.build_snapshot().lugs_at_service_entrance is False + + +def test_a_cleared_property_leaves_no_empty_node_behind() -> None: + """A node whose every value is cleared is gone from the stored values, as from the broker.""" + lugs_values = {topic for topic in _TREE[LUGS] if topic.startswith("connection/")} + adapter = _adapter(*((f"ebus/5/{LUGS}/{topic}", CLEARED) for topic in lugs_values)) + + lugs = adapter._controller.get_device(LUGS) + assert lugs is not None + assert "connection" not in lugs.properties + + +def test_a_clear_is_reported_to_property_observers_as_no_value() -> None: + """The protocol's `None`: the property now has no value, which observers must not keep.""" + adapter = _adapter() + seen: list[tuple[str, str, str, str | None]] = [] + adapter.register_property_callback(lambda *change: seen.append(change)) + + adapter.handle_message(FED_BY_TOPIC, CLEARED) + + assert seen == [(LUGS, "connection", "fed-by-device-id", None)] + + +def test_clearing_the_model_readiness_waits_on_makes_the_tree_not_ready() -> None: + """The remembered readiness is forgotten by a clear exactly as by a value change.""" + adapter = _adapter() + assert adapter.is_ready() is True + + adapter.handle_message(MODEL_TOPIC, CLEARED) + + assert adapter.is_ready() is False + + +# -- a cleared $target ----------------------------------------------------- + + +def test_a_cleared_target_is_dropped() -> None: + published = _adapter((RELAY_TARGET_TOPIC, "OPEN")) + assert published.build_snapshot().circuits[KITCHEN_CIRCUIT].relay_state_target == "OPEN" + + cleared = _adapter((RELAY_TARGET_TOPIC, "OPEN"), (RELAY_TARGET_TOPIC, CLEARED)) + + assert cleared.build_snapshot().circuits[KITCHEN_CIRCUIT].relay_state_target is None + + +def test_an_empty_string_target_is_still_a_published_empty_target() -> None: + adapter = _adapter((RELAY_TARGET_TOPIC, "OPEN"), (RELAY_TARGET_TOPIC, EMPTY_STRING)) + + assert adapter.build_snapshot().circuits[KITCHEN_CIRCUIT].relay_state_target == "" + + +# -- the masked export ----------------------------------------------------- + + +def test_the_export_shows_a_cleared_property_as_declared_and_unvalued() -> None: + """No key, the export's spelling of a declared property with no value.""" + assert FED_BY in _exported_lugs(_adapter()) + + exported = _exported_lugs(_adapter((FED_BY_TOPIC, CLEARED))) + + assert FED_BY not in exported + + +def test_the_export_keeps_an_empty_string_as_empty() -> None: + assert _exported_lugs(_adapter((FED_BY_TOPIC, EMPTY_STRING)))[FED_BY] == "" + + +def test_an_exported_empty_value_replays_as_an_empty_value() -> None: + """The export writes an empty value decoded, as ``""``, and replaying it must not turn it into a clear.""" + export = _adapter((FED_BY_TOPIC, EMPTY_STRING)).export_masked_tree() + assert export is not None + captured = capture_tree_from_document(export, "export") + + again = replay(captured.retained(), captured.root_id) + + assert again.build_snapshot().lugs_at_service_entrance is True + + +# -- clears that change nothing -------------------------------------------- + + +def test_a_clear_for_a_value_never_published_is_a_no_op() -> None: + """Nothing to remove, nothing to report, and no empty node created for it.""" + adapter = _adapter() + before = adapter.build_snapshot() + seen: list[tuple[str, str, str, str | None]] = [] + adapter.register_property_callback(lambda *change: seen.append(change)) + + adapter.handle_message(f"ebus/5/{LUGS}/vendor/never-published", CLEARED) + adapter.handle_message(RELAY_TARGET_TOPIC, CLEARED) + + lugs = adapter._controller.get_device(LUGS) + circuit = adapter._controller.get_device(KITCHEN_CIRCUIT) + assert lugs is not None and circuit is not None + assert "vendor" not in lugs.properties + assert circuit.property_targets == {} + assert seen == [] + assert adapter.build_snapshot() == before + + +def test_a_clear_for_a_device_outside_the_tree_is_a_no_op() -> None: + """Not held either: a broker replays nothing for a cleared topic.""" + adapter = _adapter() + before = adapter.build_snapshot() + held = adapter._routes.held + seen: list[tuple[str, str, str, str | None]] = [] + adapter.register_property_callback(lambda *change: seen.append(change)) + + adapter.handle_message("ebus/5/no-such-device/meter/active-power", CLEARED) + adapter.handle_message("ebus/5/no-such-device/switch/relay/$target", CLEARED) + + assert adapter._routes.held == held + assert seen == [] + assert adapter.build_snapshot() == before + + +def test_a_value_cleared_before_its_device_is_routed_never_arrives() -> None: + """A message ahead of its route is held for it, and a clear takes the held value back. + + Under a per-device subscription the broker would replay nothing for the + cleared topic, so releasing the held value, or an empty one, would invent a + reading. + """ + without = {device: dict(topics) for device, topics in _TREE.items()} + del without[LUGS][FED_BY] + + adapter = _adapter(before=[(FED_BY_TOPIC, "bess"), (FED_BY_TOPIC, CLEARED)], tree=without) + + assert adapter.build_snapshot().lugs_at_service_entrance is None + assert _exported_lugs(adapter).get(FED_BY) is None + + +def test_a_value_published_after_a_clear_before_its_device_is_routed_is_the_one_read() -> None: + """A clear then a value, both ahead of the route: the broker retains the value, so it is held and delivered.""" + without = {device: dict(topics) for device, topics in _TREE.items()} + del without[LUGS][FED_BY] + + adapter = _adapter(before=[(FED_BY_TOPIC, CLEARED), (FED_BY_TOPIC, "bess")], tree=without) + + assert adapter.build_snapshot().lugs_at_service_entrance is False + assert _exported_lugs(adapter)[FED_BY].startswith("masked-") diff --git a/tests/test_schema_one_conformance.py b/tests/test_schema_one_conformance.py index f11fd785..054c6c82 100644 --- a/tests/test_schema_one_conformance.py +++ b/tests/test_schema_one_conformance.py @@ -233,6 +233,14 @@ def _emitter_declared() -> set[tuple[str, str]]: "which is stored energy with an abstract unit — a different quantity with a confusable name." ), (const.NODE_SWITCH, "lock-state"): "EVSE connector lock", + (const.NODE_METER, "busbar-current"): ( + "the panel's busbar current. Not in the public meter catalog (0.4), which carries " + "the line frequency the panel publishes beside it." + ), + (const.NODE_INFO, "nominal-voltage"): ( + "a circuit's rated voltage. Not in the public info catalog (0.3); the panel declares " + "it on the circuit's identity node." + ), ("config", "max-charge-current"): ( "the EVSE's commissioned charge-current ceiling, in SPAN's pre-catalog spelling. " "No `config` capability exists upstream at all; the catalogued surface is " @@ -282,6 +290,35 @@ def _emitter_declared() -> set[tuple[str, str]]: "in test_schema_one_charge_limit.py drives it from a synthetic description, which is " "evidence of a parser and not of a producer -- which is what this entry records." ), + ("meter", "busbar-current"): ( + "a panel reading the emitter's reference tree does not declare. The reference captures " + "publish it, and test_panel_properties_captures.py reads it from each of them." + ), + ("meter", "frequency"): ( + "the line frequency, which the emitter's reference tree does not declare. The reference " + "captures publish it, and test_panel_properties_captures.py reads it from each of them." + ), + ("connection", "overcurrent-protection"): ( + "the upstream lugs' protection rating, which the emitter's reference tree does not " + "declare. The reference captures publish it, and test_panel_properties_captures.py " + "reads it from each of them." + ), + ("info", "nominal-voltage"): ( + "a circuit's rated voltage, which the emitter's reference tree does not declare. The " + "reference captures publish it, and test_panel_properties_captures.py reads it from " + "each of them." + ), + ("breaker", "protection-functions"): ( + "the protections a circuit's breaker provides, which the emitter's reference tree " + "does not declare. The reference captures publish them, and " + "test_panel_properties_captures.py reads them from each of them." + ), + ("connection", "feeds-role"): ( + "what a circuit feeds when that is not itself a device on the tree. The emitter's " + "reference tree declares no role on any circuit; the reference captures declare it on " + "their circuits and leave it unvalued there, so the values are driven by synthetic trees in " + "test_schema_one_feeds_role.py." + ), } diff --git a/tests/test_schema_one_connection_health.py b/tests/test_schema_one_connection_health.py index 7957a75e..5333fa2d 100644 --- a/tests/test_schema_one_connection_health.py +++ b/tests/test_schema_one_connection_health.py @@ -307,7 +307,7 @@ def _split_feed_tree(status: str | None) -> tuple[dict[str, dict[str, str]], str """ tree = _mutable_tree() solar = _feeding_circuit(tree, PV) - split = {**tree[solar], "info/spaces": "9,11"} + split = {**tree[solar], "info/spaces": "13,15"} if status is None: del split[FEEDS_STATUS_TOPIC] else: diff --git a/tests/test_schema_one_control_refusal.py b/tests/test_schema_one_control_refusal.py index 21bad579..7d080d59 100644 --- a/tests/test_schema_one_control_refusal.py +++ b/tests/test_schema_one_control_refusal.py @@ -266,7 +266,7 @@ def test_either_signal_alone_is_enough_to_refuse() -> None: def test_a_circuit_the_tree_does_not_carry_yields_no_target(adapter: SchemaOneAdapter) -> None: - """`_target` is string formatting, so an unknown id used to produce a topic.""" + """`control_target` is string formatting, so an unknown id used to produce a topic.""" assert adapter.set_circuit_relay_target("0" * 32) is None assert adapter.set_circuit_priority_target("0" * 32) is None @@ -409,7 +409,7 @@ def test_a_device_that_declares_no_priority_yields_no_priority_target(adapter: S """A BESS, a MID and the lugs declare no `load-shed` node at all. They have published no shed priority for anything to be settable *on*, and - `_target` is pure string formatting from a device id — so this is the case + `control_target` is pure string formatting from a device id — so this is the case that produced a write topic for a control the device never offered. It is asserted separately from the settability tests because it does not depend on them: an id in the tree is not a control, whatever any `$settable` says. @@ -499,3 +499,21 @@ def test_has_circuit_answers_for_the_circuits_and_nothing_else(adapter: SchemaOn assert adapter.has_circuit(device_id) is False, device_id assert adapter.has_circuit(PANEL) is False assert adapter.has_circuit("0" * 32) is False + + +@pytest.mark.parametrize( + ("declared", "is_circuit"), [("energy.ebus.device.circuit.hybrid", True), ("energy.ebus.device.circuitfoo", False)] +) +def test_has_circuit_answers_for_a_subtype_and_not_for_a_look_alike(declared: str, is_circuit: bool) -> None: + """A device typed `circuit.` is a circuit; one typed `circuitfoo` is another class (#228). + + The refusal this names has to agree with the snapshot, which reads a + subtyped circuit into `circuits`: a circuit the snapshot shows must not be + reported to its caller as no such circuit. + """ + tree = _copy() + description = json.loads(tree[CONTROLLABLE_CIRCUIT]["$description"]) + description["type"] = declared + tree[CONTROLLABLE_CIRCUIT]["$description"] = json.dumps(description) + + assert _adapter(tree).has_circuit(CONTROLLABLE_CIRCUIT) is is_circuit diff --git a/tests/test_schema_one_declared_unvalued.py b/tests/test_schema_one_declared_unvalued.py new file mode 100644 index 00000000..aa5a4995 --- /dev/null +++ b/tests/test_schema_one_declared_unvalued.py @@ -0,0 +1,125 @@ +"""Declared but unvalued: a battery before it reports, and a model never published. + +A `$description` says what a device has; its values arrive separately, and some +never do. The declaration alone decides that a battery is present. A declared +model with no value holds connecting only for `FEED_GRACE_S`, because the model +fills device metadata and nothing else: a value that lands later changes the +battery's or the charger's model and moves no key. +""" + +from __future__ import annotations + +from dataclasses import replace +import logging + +import pytest + +from conftest import flat_schema +from reference_payloads.schema_one import parent_child_tree, replay +from reference_payloads.synthetic_trees import PANEL_ID, battery, evse, hosted_circuit, panel, tree, without_values +from span_panel_api_schema_0 import SchemaZeroAdapter +from span_panel_api_schema_1.adapter import FEED_GRACE_S + +_MODEL = "info/model" +_REFERENCE_PANEL = "example-40t-001" +_START = 100.0 + + +def test_a_declared_battery_is_present_before_it_reports() -> None: + snapshot = replay(tree(panel(), without_values(battery())), PANEL_ID).build_snapshot() + + assert snapshot.battery.present is True + assert (snapshot.battery.soe_percentage, snapshot.battery.soe_kwh, snapshot.battery.model) == (None, None, None) + + +def test_a_tree_without_a_battery_reports_absent() -> None: + snapshot = replay(tree(panel(), hosted_circuit("c-1", (1,))), PANEL_ID).build_snapshot() + + assert snapshot.battery.present is False + + +def test_a_flat_panel_does_not_answer_battery_presence() -> None: + """The flat schema has no device for a battery, so it cannot say whether one is there.""" + adapter = SchemaZeroAdapter(serial_number="sim-40t-001", schema=flat_schema(40)) + + assert adapter.build_snapshot().battery.present is None + + +def test_the_reference_tree_reports_its_battery_present() -> None: + assert replay(parent_child_tree(), _REFERENCE_PANEL).build_snapshot().battery.present is True + + +def test_a_declared_model_is_waited_on_until_the_grace_runs_out(caplog: pytest.LogCaptureFixture) -> None: + now = [_START] + adapter = replay( + tree(panel(), without_values(battery(), _MODEL), without_values(evse(), _MODEL)), + PANEL_ID, + clock=lambda: now[0], + ) + + assert sorted(adapter.circuit_nodes_missing_names()) == ["battery-a", "evse-a"] + + now[0] = _START + FEED_GRACE_S - 0.1 + assert sorted(adapter.circuit_nodes_missing_names()) == ["battery-a", "evse-a"] + + now[0] = _START + FEED_GRACE_S + with caplog.at_level(logging.INFO, logger="span_panel_api_schema_1.adapter"): + assert adapter.circuit_nodes_missing_names() == [] + now[0] += FEED_GRACE_S + assert adapter.circuit_nodes_missing_names() == [] + + messages = [record.getMessage() for record in caplog.records if record.levelno == logging.INFO] + assert len(messages) == 2 + assert any("battery-a" in message and _MODEL in message for message in messages) + assert any("evse-a" in message and _MODEL in message for message in messages) + + +def test_the_model_grace_starts_only_once_every_name_has_arrived() -> None: + now = [_START] + circuit = hosted_circuit("c-1", (1,), name="Kitchen") + adapter = replay( + tree(panel(), without_values(battery(), _MODEL), without_values(circuit, "info/name")), + PANEL_ID, + clock=lambda: now[0], + ) + assert sorted(adapter.circuit_nodes_missing_names()) == ["battery-a", "c-1"] + + now[0] = _START + FEED_GRACE_S + adapter.handle_message("ebus/5/c-1/info/name", "Kitchen") + + assert adapter.circuit_nodes_missing_names() == ["battery-a"] + + +def test_a_model_that_arrives_is_no_longer_waited_on() -> None: + now = [_START] + adapter = replay(tree(panel(), without_values(battery(), _MODEL)), PANEL_ID, clock=lambda: now[0]) + assert adapter.circuit_nodes_missing_names() == ["battery-a"] + + adapter.handle_message("ebus/5/battery-a/info/model", "Battery") + + assert adapter.circuit_nodes_missing_names() == [] + + +def test_a_late_model_value_only_fills_metadata() -> None: + """After the grace a model value changes the device's model and nothing else.""" + now = [_START] + adapter = replay( + tree(panel(), without_values(battery(), _MODEL), without_values(evse(), _MODEL)), + PANEL_ID, + clock=lambda: now[0], + ) + adapter.circuit_nodes_missing_names() + now[0] = _START + FEED_GRACE_S + assert adapter.circuit_nodes_missing_names() == [] + before = adapter.build_snapshot() + + adapter.handle_message("ebus/5/battery-a/info/model", "Battery") + adapter.handle_message("ebus/5/evse-a/info/model", "Charger") + after = adapter.build_snapshot() + + assert after == replace( + before, + battery=replace(before.battery, model="Battery"), + evse={key: replace(charger, model="Charger") for key, charger in before.evse.items()}, + ) + assert before.evse, "precondition: the charger is in the snapshot" diff --git a/tests/test_schema_one_devices.py b/tests/test_schema_one_devices.py index 5b6e76ed..254c2dee 100644 --- a/tests/test_schema_one_devices.py +++ b/tests/test_schema_one_devices.py @@ -10,6 +10,7 @@ from ebus_sdk.homie import DiscoveredDevice from reference_payloads.schema_one import device_from_topics, parent_child_tree +from span_panel_api.models import SpanPanelSnapshot from span_panel_api_schema_1.devices import ( build_mid, build_battery, @@ -18,9 +19,11 @@ connection_status_for, feed_circuit_ids, ) +from span_panel_api_schema_1.firmware import release_build _TREE = parent_child_tree() +PANEL = "example-40t-001" SOLAR_CIRCUIT = "573066aaddd7b75114c4563ce3af18c4" @@ -35,6 +38,20 @@ def _circuits() -> list[DiscoveredDevice]: BESS_POWER_TOPIC = "meter/active-power" BESS_COMMS_TOPIC = "status/communication-state" +R202633 = "spanos2/r202633/01" +R202639 = "spanos2/r202639/03" + + +def _in_the_old_frame(raw: float) -> float: + """A BESS meter reading as a release before r202639 publishes the same instant. + + The capture is in r202639's frame, which negated the BESS meter and left + `power-flows/battery` alone, so the old frame's reading of the same battery + is the negation. Named rather than written as a bare minus sign so a test + that builds the old frame says that it does. + """ + return -raw + def _published(device_id: str, topic: str) -> str: """What the capture publishes on this topic, or fail saying it does not. @@ -211,14 +228,16 @@ def test_the_capture_is_a_charging_battery() -> None: without appealing to any convention this library chose. In this capture 8500 W of PV meets 2653 W of site load and exports 2347 W; - the 3500 W left over is going into the battery. So the battery is charging, - and both the enclosure and the BESS publish that as a positive number. + the 3500 W left over is going into the battery. So the battery is charging. + The enclosure publishes that as a positive number, and the BESS, in the + discharge-positive frame firmware r202639 introduced and `ebus-panel-sim` + 0.9.0 publishes, as a negative one. Were the capture ever retaken with the battery discharging, this fails first - and says so, rather than the negation tests failing and reading as a mapper + and says so, rather than the frame tests failing and reading as a mapper bug. """ - flows = {name: float(_published("example-40t-001", f"power-flows/{name}")) for name in ("pv", "battery", "grid", "site")} + flows = {name: float(_published(PANEL, f"power-flows/{name}")) for name in ("pv", "battery", "grid", "site")} assert flows["pv"] + flows["battery"] + flows["grid"] + flows["site"] == pytest.approx(0.0, abs=1e-9) # PV alone exceeds the site load, so the surplus has nowhere to go but the @@ -226,11 +245,11 @@ def test_the_capture_is_a_charging_battery() -> None: assert -flows["pv"] > flows["site"] assert flows["grid"] > 0 assert flows["battery"] > 0 - assert float(_published("bess", BESS_POWER_TOPIC)) > 0 + assert float(_published("bess", BESS_POWER_TOPIC)) < 0 def test_battery_power_is_the_negation_of_the_wire() -> None: - """One negation, and the frame it lands in is the BESS device's own. + """One negation before r202639, and the frame it lands in is the BESS device's own. Positive means power flowing *out of* the battery -- discharging -- which is what the eBus specification asks of a device's own meter, and deliberately @@ -257,21 +276,27 @@ def test_battery_power_is_the_negation_of_the_wire() -> None: frame until it was recaptured, so this assertion used to read `> 0` on a capture the test above calls a charging battery -- the two contradicted each other, and only the fixture was wrong. + + It flipped again at 0.9.0, which publishes r202639's discharge-positive meter, + so the capture no longer carries the frame this test is about. The frame is + built instead: the capture's battery as a release before r202639 publishes it + (`_in_the_old_frame`), named as such. The capture's own frame is held end to + end by `test_the_captured_tree_resolves_to_the_new_frame_through_the_snapshot`. """ - raw = float(_published("bess", BESS_POWER_TOPIC)) + old_frame = _in_the_old_frame(float(_published("bess", BESS_POWER_TOPIC))) - battery = build_battery(_device("bess"), []) + battery = build_battery(_bess_with({BESS_POWER_TOPIC: str(old_frame)}), [], firmware_version=R202633) - assert battery.power_w == -raw + assert battery.power_w == -old_frame assert battery.power_w is not None and battery.power_w < 0 def test_battery_power_follows_a_republished_value() -> None: """Proof the value is read off the wire and not defaulted into place.""" - raw = float(_published("bess", BESS_POWER_TOPIC)) - discharging = -raw / 2 + charging = _in_the_old_frame(float(_published("bess", BESS_POWER_TOPIC))) + discharging = -charging / 2 - battery = build_battery(_bess_with({BESS_POWER_TOPIC: str(discharging)}), []) + battery = build_battery(_bess_with({BESS_POWER_TOPIC: str(discharging)}), [], firmware_version=R202633) # Charging became discharging, so the snapshot's sign flips with it. assert battery.power_w == -discharging @@ -300,29 +325,37 @@ def test_a_bess_with_no_meter_node_has_no_power() -> None: assert build_battery(_bess_without_node("meter"), []).power_w is None -def test_the_bess_meter_and_the_enclosure_flow_agree_about_direction() -> None: - """The two properties describing this battery's power must not disagree. +def test_the_bess_meter_and_the_enclosure_flow_disagree_about_direction() -> None: + """The two properties describing this battery's power are published in opposite frames. `panel.power_flow_battery` is the enclosure's own arbitrated figure and is - passed through untouched; `battery.power_w` is the BESS's own meter and is - negated. That is only coherent because the two properties are published in - the *same* frame on the wire -- asserted here rather than assumed, because a - consumer rendering both beside each other has to negate exactly one of them, - and which one is a fact about the capture rather than a preference. + passed through untouched; `battery.power_w` is the BESS's own meter, which + from r202639 is published discharge-positive and passes through. That is + only coherent because the two properties are published in *opposite* frames + on the wire -- asserted here rather than assumed, because a consumer + rendering both beside each other has to negate exactly one of them, and + which frame the BESS meter is in is a fact about the capture rather than a + preference. + + It is also what lets the frame be told without a SPAN release string: the + capture names none, so the opposite signs decide + (`test_the_captured_tree_resolves_to_the_new_frame_through_the_snapshot`). + Before r202639 the two carried one sign, and this test asserted that until + the capture was retaken with `ebus-panel-sim` 0.9.0; that frame is now built + by republishing + (`test_an_unversioned_tree_with_matching_signs_resolves_to_the_old_frame_through_the_snapshot`). """ bess_meter = float(_published("bess", BESS_POWER_TOPIC)) - enclosure_flow = float(_published("example-40t-001", "power-flows/battery")) + enclosure_flow = float(_published(PANEL, "power-flows/battery")) - assert (bess_meter < 0) == (enclosure_flow < 0) + assert bess_meter != 0.0 and enclosure_flow != 0.0 + assert (bess_meter < 0) != (enclosure_flow < 0) # --------------------------------------------------------------------------- # Battery power: the wire frame by firmware release # --------------------------------------------------------------------------- -R202633 = "spanos2/r202633/01" -R202639 = "spanos2/r202639/03" - def _battery_power(raw: str, *, firmware_version: str | None, power_flow_battery: float | None = None) -> float | None: bess = _bess_with({BESS_POWER_TOPIC: raw}) @@ -395,40 +428,64 @@ def test_without_a_release_or_a_signed_flow_the_old_frame_is_assumed(power_flow_ assert _battery_power("1000.0", firmware_version="example/v0.1.0", power_flow_battery=power_flow_battery) == -1000.0 -def test_the_captured_tree_resolves_to_the_old_frame_through_the_snapshot() -> None: - """End to end: the capture carries no SPAN version string and equal signs. +def _snapshot_with(*, panel: Mapping[str, str], bess: Mapping[str, str]) -> SpanPanelSnapshot: + """The capture through the real snapshot builder, with enclosure and BESS topics rewritten.""" + from span_panel_api_schema_1.snapshot import build_snapshot + + children = [_bess_with(bess) if device_id == "bess" else _device(device_id) for device_id in _TREE if device_id != PANEL] + return build_snapshot(device_from_topics(PANEL, {**_TREE[PANEL], **panel}), children) + - So the fallback picks the old frame, and the snapshot's battery is the - negation of its wire meter: the charging battery the capture describes. +def test_the_captured_tree_resolves_to_the_new_frame_through_the_snapshot() -> None: + """End to end: the capture carries no SPAN version string, and opposite signs. + + So the fallback picks r202639's frame, and the snapshot's battery is its wire + meter passed through: the charging battery the capture describes. """ - from span_panel_api_schema_1.snapshot import build_snapshot + assert release_build(_published(PANEL, "info/firmware-version")) is None + + snapshot = _snapshot_with(panel={}, bess={}) + + assert snapshot.battery.power_w == float(_published("bess", BESS_POWER_TOPIC)) + assert snapshot.battery.power_w is not None and snapshot.battery.power_w < 0 + + +def test_an_unversioned_tree_with_matching_signs_resolves_to_the_old_frame_through_the_snapshot() -> None: + """End to end: no SPAN version string, and the BESS meter in the flow figure's sign. + + The capture's own state until it was retaken with `ebus-panel-sim` 0.9.0, and + now built from it: the same charging battery with its BESS meter + charge-positive, as a release before r202639 publishes it. The fallback picks + the old frame, and the snapshot's battery is the negation of its wire meter. + """ + old_frame = _in_the_old_frame(float(_published("bess", BESS_POWER_TOPIC))) - panel_id = "example-40t-001" - children = [_device(device_id) for device_id in _TREE if device_id != panel_id] - snapshot = build_snapshot(_device(panel_id), children) + snapshot = _snapshot_with(panel={}, bess={BESS_POWER_TOPIC: str(old_frame)}) - assert snapshot.battery.power_w == -float(_published("bess", BESS_POWER_TOPIC)) + assert snapshot.battery.power_w == -old_frame assert snapshot.battery.power_w is not None and snapshot.battery.power_w < 0 def test_an_r202639_tree_reports_the_same_charging_battery_through_the_snapshot() -> None: - """The capture republished as r202639 would publish it: BESS meter negated, flow unchanged.""" - from span_panel_api_schema_1.snapshot import build_snapshot + """The capture under an r202639 release string: its BESS meter is already in that frame.""" + snapshot = _snapshot_with(panel={"info/firmware-version": R202639}, bess={}) + + assert snapshot.firmware_version == R202639 + assert snapshot.battery.power_w == float(_published("bess", BESS_POWER_TOPIC)) + assert snapshot.battery.power_w is not None and snapshot.battery.power_w < 0 + assert snapshot.power_flow_battery == float(_published(PANEL, "power-flows/battery")) - panel_id = "example-40t-001" + +def test_an_r202633_tree_reports_the_same_charging_battery_through_the_snapshot() -> None: + """The capture republished as r202633 would publish it: BESS meter negated, flow unchanged.""" raw = float(_published("bess", BESS_POWER_TOPIC)) - panel_topics = {**_TREE[panel_id], "info/firmware-version": R202639} - bess_topics = {**_TREE["bess"], BESS_POWER_TOPIC: str(-raw)} - children = [ - device_from_topics("bess", bess_topics) if device_id == "bess" else _device(device_id) - for device_id in _TREE - if device_id != panel_id - ] - snapshot = build_snapshot(device_from_topics(panel_id, panel_topics), children) - assert snapshot.firmware_version == R202639 - assert snapshot.battery.power_w == -raw - assert snapshot.power_flow_battery == float(_published(panel_id, "power-flows/battery")) + snapshot = _snapshot_with(panel={"info/firmware-version": R202633}, bess={BESS_POWER_TOPIC: str(_in_the_old_frame(raw))}) + + assert snapshot.firmware_version == R202633 + assert snapshot.battery.power_w == raw + assert snapshot.battery.power_w is not None and snapshot.battery.power_w < 0 + assert snapshot.power_flow_battery == float(_published(PANEL, "power-flows/battery")) # --------------------------------------------------------------------------- diff --git a/tests/test_schema_one_discovery.py b/tests/test_schema_one_discovery.py index d4a76c0c..dccc13dd 100644 --- a/tests/test_schema_one_discovery.py +++ b/tests/test_schema_one_discovery.py @@ -266,13 +266,76 @@ def test_an_off_snapshot_route_that_became_observable_must_be_retired() -> None: ) +_FEEDS_ROLE: Declaration = (TYPE_CIRCUIT, "connection", "feeds-role") +_METER_SHARED_WITH: Declaration = (TYPE_CIRCUIT, "meter", "shared-with-device-ids") +_SWITCH_SHARED_WITH: Declaration = (TYPE_CIRCUIT, "switch", "shared-with-device-ids") +_ABSENT_FROM_THE_CAPTURE: frozenset[Declaration] = frozenset({_FEEDS_ROLE, _METER_SHARED_WITH, _SWITCH_SHARED_WITH}) +"""Addressed entries the capture never declares, each proved on a synthetic declaration below.""" + +_A_LOAD_CIRCUIT = "0ab966b95f92a6a51ec548485aa85f54" +"""A circuit that feeds no device, so nothing else labels it.""" + + def test_no_addressed_entry_has_gone_stale() -> None: """A table entry outlives its declaration silently; the file only ever grows.""" declared = _declared() - stale = [entry for entry in (*_CONSUMED_WITHOUT_A_ROW, *_CONSUMED_OFF_SNAPSHOT) if entry not in declared] + stale = [ + entry + for entry in (*_CONSUMED_WITHOUT_A_ROW, *_CONSUMED_OFF_SNAPSHOT) + if entry not in declared and entry not in _ABSENT_FROM_THE_CAPTURE + ] assert not stale, f"addressed-property entries the reference tree no longer declares:\n{_rendered(stale)}" +def test_an_entry_excused_from_the_capture_is_still_absent_from_it() -> None: + """Once the capture declares it, the experiment above can prove it directly.""" + assert not (_ABSENT_FROM_THE_CAPTURE & _declared()) + + +def test_feeds_role_moves_the_snapshot_on_a_circuit_that_declares_it() -> None: + """The experiment above, run on a circuit given the declaration the capture lacks.""" + _type, node, prop = _FEEDS_ROLE + tree = _tree() + description = json.loads(tree[_A_LOAD_CIRCUIT]["$description"]) + description["nodes"][node]["properties"][prop] = { + "datatype": "enum", + "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED", + } + tree[_A_LOAD_CIRCUIT]["$description"] = json.dumps(description) + tree[_A_LOAD_CIRCUIT][f"{node}/{prop}"] = "LOADS" + baseline = _snapshot_fields(_snapshot(tree)) + tree[_A_LOAD_CIRCUIT][f"{node}/{prop}"] = "SOLAR" + after = _snapshot_fields(_snapshot(tree)) + + moved = {path for path, value in after.items() if baseline.get(path) != value} + assert moved == {f"circuits@{_A_LOAD_CIRCUIT}.feeds_role"} + assert _FEEDS_ROLE in _CONSUMED_WITHOUT_A_ROW + + +_ANOTHER_LOAD_CIRCUIT = "d3724e0d660ba506aa79c1cafe5d1181" + + +@pytest.mark.parametrize( + ("declaration", "field"), + [(_METER_SHARED_WITH, "meter_shared_with"), (_SWITCH_SHARED_WITH, "relay_shared_with")], +) +def test_shared_with_moves_the_snapshot_on_a_circuit_that_declares_it(declaration: Declaration, field: str) -> None: + """The experiment above, run on a circuit given the declaration the capture lacks.""" + _type, node, prop = declaration + tree = _tree() + description = json.loads(tree[_A_LOAD_CIRCUIT]["$description"]) + description["nodes"][node]["properties"][prop] = {"datatype": "string"} + tree[_A_LOAD_CIRCUIT]["$description"] = json.dumps(description) + tree[_A_LOAD_CIRCUIT][f"{node}/{prop}"] = "probe-value" + baseline = _snapshot_fields(_snapshot(tree)) + tree[_A_LOAD_CIRCUIT][f"{node}/{prop}"] = _ANOTHER_LOAD_CIRCUIT + after = _snapshot_fields(_snapshot(tree)) + + moved = {path for path, value in after.items() if baseline.get(path) != value} + assert moved == {f"circuits@{_A_LOAD_CIRCUIT}.{field}"} + assert declaration in _CONSUMED_WITHOUT_A_ROW + + def test_no_addressed_entry_duplicates_a_metadata_row() -> None: """The four tables partition the addressed set; they do not overlap. diff --git a/tests/test_schema_one_evse_lock.py b/tests/test_schema_one_evse_lock.py new file mode 100644 index 00000000..8a5da89f --- /dev/null +++ b/tests/test_schema_one_evse_lock.py @@ -0,0 +1,57 @@ +"""The EVSE lock as a control target, present only where the lock is settable. + +A charger whose `switch/lock-state` declaration carries `settable: true` gets +`SpanEvseSnapshot.lock_control`, addressing `…/switch/lock-state/set` on the +charger's own device and observed on the same property. A lock declared without +it, or not declared at all, has no target. +""" + +from __future__ import annotations + +from conftest import flat_schema +from reference_payloads.schema_one import replay +from reference_payloads.synthetic_trees import PANEL_ID, SyntheticDevice, evse, panel, tree +from span_panel_api.models import ControlTarget, SpanEvseSnapshot +from span_panel_api_schema_0 import SchemaZeroAdapter + + +def _charger(device: SyntheticDevice) -> SpanEvseSnapshot: + (charger,) = replay(tree(panel(), device), PANEL_ID).build_snapshot().evse.values() + return charger + + +def test_a_settable_lock_has_a_control_target() -> None: + assert _charger(evse("evse-a")).lock_control == ControlTarget( + topic="ebus/5/evse-a/switch/lock-state/set", + device_id="evse-a", + node_id="switch", + property_id="lock-state", + ) + + +def test_a_lock_that_is_not_settable_has_none() -> None: + assert _charger(evse("evse-a", lock_settable=False)).lock_control is None + + +def test_a_charger_with_no_lock_has_none() -> None: + base = evse("evse-a") + unlocked = SyntheticDevice( + device_id=base.device_id, + device_type=base.device_type, + name=base.name, + nodes={node: props for node, props in base.nodes.items() if node != "switch"}, + values={path: value for path, value in base.values.items() if not path.startswith("switch/")}, + ) + + assert _charger(unlocked).lock_control is None + + +def test_a_flat_panel_offers_no_lock_control() -> None: + snapshot = SchemaZeroAdapter(serial_number="sim-40t-001", schema=flat_schema(40)).build_snapshot() + + assert all(charger.lock_control is None for charger in snapshot.evse.values()) + + +def test_the_declared_lock_states_are_reported() -> None: + assert _charger(evse("evse-a")).lock_state_options == ("UNLOCKED", "LOCKED") + assert _charger(evse("evse-a", lock_settable=False)).lock_state_options == ("UNLOCKED", "LOCKED") diff --git a/tests/test_schema_one_feeds_role.py b/tests/test_schema_one_feeds_role.py new file mode 100644 index 00000000..d226df24 --- /dev/null +++ b/tests/test_schema_one_feeds_role.py @@ -0,0 +1,65 @@ +"""Each circuit's declared feeds role, as `SpanCircuitSnapshot.feeds_role`. + +`connection/feeds-role` says what a circuit feeds when that is not itself a +device on the tree. The role is reported as declared and changes nothing else: +a circuit whose role is solar is still a circuit, and no inverter is made up +for it. A value outside the role set, or none at all, reads as `None`. +""" + +from __future__ import annotations + +from typing import get_args + +import pytest + +from conftest import flat_schema +from reference_payloads.schema_one import replay +from reference_payloads.synthetic_trees import PANEL_ID, hosted_circuit, panel, tree, without_values +from span_panel_api import FEEDS_ROLES, FeedsRole, SpanPanelSnapshot +from span_panel_api_schema_0 import SchemaZeroAdapter + + +def _snapshot(role: str | None) -> SpanPanelSnapshot: + return replay(tree(panel(), hosted_circuit("c-1", (1,), feeds_role=role)), PANEL_ID).build_snapshot() + + +def test_the_role_set_is_the_literal() -> None: + assert set(FEEDS_ROLES) == set(get_args(FeedsRole.__value__)) + assert len(FEEDS_ROLES) == len(set(FEEDS_ROLES)) + + +@pytest.mark.parametrize("role", FEEDS_ROLES) +def test_a_declared_role_is_reported_as_published(role: FeedsRole) -> None: + assert _snapshot(role).circuits["c-1"].feeds_role == role + + +@pytest.mark.parametrize("role", ["NOT_A_ROLE", "solar", ""]) +def test_a_value_outside_the_role_set_reads_none(role: str) -> None: + assert _snapshot(role).circuits["c-1"].feeds_role is None + + +def test_an_undeclared_role_reads_none() -> None: + assert _snapshot(None).circuits["c-1"].feeds_role is None + + +def test_a_declared_role_not_yet_published_reads_none() -> None: + circuit = without_values(hosted_circuit("c-1", (1,), feeds_role="LOADS"), "connection/feeds-role") + snapshot = replay(tree(panel(), circuit), PANEL_ID).build_snapshot() + + assert snapshot.circuits["c-1"].feeds_role is None + + +@pytest.mark.spec_only +def test_a_solar_role_keeps_the_circuit_a_circuit() -> None: + """The role travels in `feeds_role`; `device_type` stays as published and no inverter appears.""" + snapshot = _snapshot("SOLAR") + + assert snapshot.circuits["c-1"].feeds_role == "SOLAR" + assert snapshot.circuits["c-1"].device_type == "circuit" + assert snapshot.pv_inverters == {} + + +def test_a_flat_panel_reports_no_role() -> None: + snapshot = SchemaZeroAdapter(serial_number="sim-40t-001", schema=flat_schema(40)).build_snapshot() + + assert all(circuit.feeds_role is None for circuit in snapshot.circuits.values()) diff --git a/tests/test_schema_one_other_models.py b/tests/test_schema_one_other_models.py new file mode 100644 index 00000000..008309cf --- /dev/null +++ b/tests/test_schema_one_other_models.py @@ -0,0 +1,589 @@ +"""Tree shapes that panel models other than MAIN 32 publish. + +Built from the capture, reshaped the way those models differ: circuit device ids +are `circuit-`, a remote current transformer is a circuit-class device +carrying only a meter, no PV device exists and the circuit feeding the solar +says so through `connection/feeds-role`, and `info/model` may read `UNKNOWN`. +""" + +from __future__ import annotations + +import json +import logging +from pathlib import Path + +import pytest + +from conftest import flat_schema +from reference_payloads.schema_one import RetainedTopicTree, device_from_topics, other_model_tree, parent_child_tree +from span_panel_api.models import FieldMetadata, SpanPanelSnapshot, SpanPVSnapshot, V2HomieSchema, is_discovery_path +from span_panel_api_schema_0 import SchemaZeroAdapter +from span_panel_api_schema_1 import SchemaOneAdapter +from span_panel_api_schema_1.const import TYPE_CIRCUIT +from span_panel_api_schema_1.field_metadata import build_field_metadata +from span_panel_api_schema_1.panel import PanelFields, panel_model_drift, panel_size_from_model +from span_panel_api_schema_1.snapshot import build_snapshot + +PANEL = "example-40t-001" + +_CIRCUIT_IDS = { + "0ab966b95f92a6a51ec548485aa85f54": "circuit-1", + "d3724e0d660ba506aa79c1cafe5d1181": "circuit-2", + "62d0e03897b337b57101aae82f1e9ba2": "circuit-3", + "fe8b85c15bc9610c1b8b4ebc6f82488d": "circuit-4", + "acf35888f35522c721501d35e66503e6": "circuit-5", + "573066aaddd7b75114c4563ce3af18c4": "circuit-6", +} +KITCHEN = "circuit-1" +SOLAR = "circuit-6" +GARAGE_DRIVE = "circuit-3" +"""Feeds `evse` in the capture.""" +REMOTE_CT = "remote-ct-1" + +_FEEDS_ROLE = {"datatype": "enum", "format": "LOADS,SUBPANEL,SOLAR,STORAGE,GENERATOR,MIXED,UNUSED"} + + +def _meter_only(meter_node: dict[str, object]) -> str: + return json.dumps( + { + "homie": "5.0", + "version": 1, + "type": TYPE_CIRCUIT, + "name": "Remote CT", + "nodes": {"meter": meter_node}, + "root": PANEL, + "parent": PANEL, + } + ) + + +def _tree() -> dict[str, dict[str, str]]: + """The capture reshaped as a panel model other than MAIN 32 publishes it.""" + source = parent_child_tree() + tree: dict[str, dict[str, str]] = {} + for device_id, topics in source.items(): + if device_id == "pv": + continue + tree[_CIRCUIT_IDS.get(device_id, device_id)] = dict(topics) + + solar = tree[SOLAR] + del solar["connection/feeds-device-id"] + description = json.loads(solar["$description"]) + description["nodes"]["connection"]["properties"]["feeds-role"] = _FEEDS_ROLE + solar["$description"] = json.dumps(description) + solar["connection/feeds-role"] = "SOLAR" + + kitchen_meter = json.loads(tree[KITCHEN]["$description"])["nodes"]["meter"] + tree[REMOTE_CT] = { + "$description": _meter_only(kitchen_meter), + "$state": "ready", + "meter/active-power": "250.0", + "meter/current": "2.1", + "meter/exported-energy": "0.0", + "meter/imported-energy": "900.0", + } + + panel = json.loads(tree[PANEL]["$description"]) + panel["children"] = [child for child in tree if child != PANEL] + tree[PANEL]["$description"] = json.dumps(panel) + return tree + + +def _snapshot(tree: RetainedTopicTree) -> SpanPanelSnapshot: + panel = device_from_topics(PANEL, tree[PANEL]) + children = [device_from_topics(device_id, topics) for device_id, topics in tree.items() if device_id != PANEL] + return build_snapshot(panel, children) + + +def _adapter(tree: RetainedTopicTree) -> SchemaOneAdapter: + schema = V2HomieSchema( + firmware_version="spanos2/r202639/01", types_schema_hash="sha256:test", types={}, data_model_version="1.0" + ) + adapter = SchemaOneAdapter(PANEL, schema) + for device_id in [PANEL, *[d for d in tree if d != PANEL]]: + topics = tree[device_id] + adapter.handle_message(f"ebus/5/{device_id}/$description", topics["$description"]) + adapter.handle_message(f"ebus/5/{device_id}/$state", topics.get("$state", "ready")) + for topic, payload in topics.items(): + if not topic.startswith("$"): + adapter.handle_message(f"ebus/5/{device_id}/{topic}", payload) + return adapter + + +@pytest.fixture(name="snapshot") +def _built() -> SpanPanelSnapshot: + return _snapshot(_tree()) + + +# --- circuit- ids -------------------------------------------------------- + + +def test_circuits_are_keyed_by_their_device_id_as_published(snapshot: SpanPanelSnapshot) -> None: + real = {cid for cid in snapshot.circuits if not cid.startswith("unmapped_tab_")} + + assert real == {*_CIRCUIT_IDS.values(), REMOTE_CT} + assert snapshot.circuits[KITCHEN].circuit_id == KITCHEN + assert snapshot.circuits[KITCHEN].name == "Kitchen Lights" + + +def test_the_controls_address_a_circuit_by_its_device_id() -> None: + adapter = _adapter(_tree()) + + target = adapter.set_circuit_relay_target(KITCHEN) + + assert target is not None + assert target.device_id == KITCHEN + assert KITCHEN in target.topic + + +# --- a remote current transformer ------------------------------------------- + + +def test_a_meter_only_circuit_reports_its_reading(snapshot: SpanPanelSnapshot) -> None: + ct = snapshot.circuits[REMOTE_CT] + + assert ct.instant_power_w == 250.0 + assert ct.current_a == 2.1 + assert ct.consumed_energy_wh == 900.0 + assert ct.tabs == [] + assert ct.name == "" + assert ct.device_type == "circuit" + + +def test_a_circuit_without_declared_spaces_is_not_negated_or_swapped(snapshot: SpanPanelSnapshot) -> None: + """A remote CT reads into the panel already: positive and imported-energy on import.""" + tree = _tree() + tree[REMOTE_CT].update( + {"meter/active-power": "-1200.0", "meter/imported-energy": "900.0", "meter/exported-energy": "300.0"} + ) + ct = _snapshot(tree).circuits[REMOTE_CT] + + assert ct.instant_power_w == -1200.0 + assert ct.consumed_energy_wh == 900.0 + assert ct.produced_energy_wh == 300.0 + # An ordinary circuit in the same tree is still negated and swapped. + kitchen = _snapshot(tree).circuits[KITCHEN] + raw = float(tree[KITCHEN]["meter/active-power"]) + assert kitchen.instant_power_w == (0.0 if raw == 0.0 else -raw) + assert kitchen.consumed_energy_wh == float(tree[KITCHEN]["meter/exported-energy"]) + + +def test_a_named_circuit_without_declared_spaces_still_measures_outside_the_panel() -> None: + """A later firmware may name the remote CT; without `info/spaces` it is still outside.""" + tree = _tree() + description = json.loads(tree[REMOTE_CT]["$description"]) + description["nodes"]["info"] = {"properties": {"name": {"datatype": "string"}}} + tree[REMOTE_CT]["$description"] = json.dumps(description) + tree[REMOTE_CT]["info/name"] = "Service" + ct = _snapshot(tree).circuits[REMOTE_CT] + + assert ct.measures_outside_panel is True + assert ct.name == "Service" + assert ct.instant_power_w == 250.0 + + +def test_a_branch_that_declares_spaces_without_a_value_is_still_a_branch() -> None: + """The declaration decides, not the value: an unpublished `info/spaces` is still loading.""" + tree = _tree() + del tree[KITCHEN]["info/spaces"] + kitchen = _snapshot(tree).circuits[KITCHEN] + + assert kitchen.measures_outside_panel is False + raw = float(tree[KITCHEN]["meter/active-power"]) + assert kitchen.instant_power_w == (0.0 if raw == 0.0 else -raw) + + +def test_only_the_remote_ct_measures_outside_the_panel(snapshot: SpanPanelSnapshot) -> None: + assert {cid for cid, c in snapshot.circuits.items() if c.measures_outside_panel} == {REMOTE_CT} + + +def test_no_main_32_circuit_measures_outside_the_panel() -> None: + reference = _snapshot(parent_child_tree()) + assert not any(c.measures_outside_panel for c in reference.circuits.values()) + + +def test_a_meter_only_circuit_has_no_relay_to_control_or_shed(snapshot: SpanPanelSnapshot) -> None: + """No `switch` node is not a switch that omits `relay-controllable`.""" + ct = snapshot.circuits[REMOTE_CT] + + assert ct.is_user_controllable is False + assert ct.is_sheddable is False + assert ct.always_on is False + assert ct.relay_state == "UNKNOWN" + assert ct.relay_requester == "UNKNOWN" + assert ct.relay_state_target is None + assert ct.priority == "UNKNOWN" + assert ct.priority_target is None + assert ct.is_never_backup is True + + +def test_a_meter_only_circuit_refuses_both_controls() -> None: + adapter = _adapter(_tree()) + + assert adapter.has_circuit(REMOTE_CT) + assert adapter.set_circuit_relay_target(REMOTE_CT) is None + assert adapter.set_circuit_priority_target(REMOTE_CT) is None + + +def test_a_meter_only_circuit_is_not_waited_on_for_a_name() -> None: + """It declares no `info/name`, so the wait would always time out.""" + assert REMOTE_CT not in _adapter(_tree()).circuit_nodes_missing_names() + + +# --- solar with no PV device ------------------------------------------------ + + +def test_a_circuit_whose_feeds_role_is_solar_is_labeled_pv(snapshot: SpanPanelSnapshot) -> None: + assert snapshot.circuits[SOLAR].device_type == "pv" + assert snapshot.circuits[SOLAR].instant_power_w == -8500.0 + assert snapshot.circuits[KITCHEN].device_type == "circuit" + + +def test_no_pv_device_leaves_the_pv_snapshot_empty(snapshot: SpanPanelSnapshot) -> None: + assert snapshot.pv == SpanPVSnapshot() + assert snapshot.pv_inverters == {} + + +@pytest.mark.parametrize("role", ["LOADS", "SUBPANEL", "STORAGE", "GENERATOR", "MIXED", "UNUSED", "solar", ""]) +def test_no_other_role_is_mapped(role: str) -> None: + tree = _tree() + tree[SOLAR]["connection/feeds-role"] = role + + assert _snapshot(tree).circuits[SOLAR].device_type == "circuit" + + +def test_feeds_device_id_is_authoritative_over_feeds_role() -> None: + tree = _tree() + del tree[GARAGE_DRIVE]["connection/feeds-device-id"] + tree[SOLAR]["connection/feeds-device-id"] = "evse" + + assert _snapshot(tree).circuits[SOLAR].device_type == "evse" + + +def test_a_feeds_device_id_naming_no_der_is_not_overridden_by_the_role() -> None: + tree = _tree() + tree[SOLAR]["connection/feeds-device-id"] = "something-else" + + assert _snapshot(tree).circuits[SOLAR].device_type == "circuit" + + +# --- whether a panel publishes solar roles structurally --------------------- + +_FLAT_WIRE = Path(__file__).parent / "fixtures" / "flat_wire.json" +_FLAT_SERIAL = "sim-40t-001" + + +def _other_model_snapshot() -> SpanPanelSnapshot: + return _shipped() + + +def _parent_child_snapshot() -> SpanPanelSnapshot: + return _snapshot(parent_child_tree()) + + +def _flat_snapshot() -> SpanPanelSnapshot: + """The flat capture replayed the way the retained store delivers it.""" + capture: dict[str, dict[str, str]] = json.loads(_FLAT_WIRE.read_text()) + adapter = SchemaZeroAdapter(serial_number=_FLAT_SERIAL, schema=flat_schema(40)) + for device in sorted(capture): + for key in sorted(capture[device]): + adapter.handle_message(f"ebus/5/{device}/{key}", capture[device][key]) + return adapter.build_snapshot() + + +def test_a_panel_that_declares_feeds_role_publishes_solar_roles() -> None: + assert _other_model_snapshot().publishes_solar_roles is True + assert _snapshot(_tree()).publishes_solar_roles is True + + +def test_main_32_and_the_flat_schema_do_not() -> None: + assert _parent_child_snapshot().publishes_solar_roles is False + assert _flat_snapshot().publishes_solar_roles is False + + +@pytest.mark.parametrize("role", [None, "LOADS"]) +def test_the_declaration_decides_not_the_value(role: str | None) -> None: + """A declared role with no value yet, or naming no solar, still marks the panel.""" + tree = _tree() + if role is None: + del tree[SOLAR]["connection/feeds-role"] + else: + tree[SOLAR]["connection/feeds-role"] = role + + assert _snapshot(tree).publishes_solar_roles is True + + +# --- info/model UNKNOWN ----------------------------------------------------- + + +def _unknown_model_tree() -> dict[str, dict[str, str]]: + tree = _tree() + description = json.loads(tree[PANEL]["$description"]) + description["nodes"]["info"]["properties"]["model"]["format"] = "MAIN_16,MLO_24,MAIN_32,MAIN_40,MLO_48,UNKNOWN" + tree[PANEL]["$description"] = json.dumps(description) + tree[PANEL]["info/model"] = "UNKNOWN" + return tree + + +def test_an_unknown_model_sizes_nothing_without_warning(caplog: pytest.LogCaptureFixture) -> None: + with caplog.at_level(logging.WARNING): + snapshot = _snapshot(_unknown_model_tree()) + + assert snapshot.panel_size == 0 + assert not [cid for cid in snapshot.circuits if cid.startswith("unmapped_tab_")] + assert not caplog.records + assert panel_size_from_model("UNKNOWN") == 0 + + +def test_an_unknown_model_reads_as_absent_so_a_consumer_falls_back() -> None: + tree = _unknown_model_tree() + panel = device_from_topics(PANEL, tree[PANEL]) + + assert PanelFields(panel=panel, upstream_lugs=None, downstream_lugs=None, mid=None).model is None + assert _snapshot(tree).model is None + + +def test_unknown_in_the_model_enum_is_not_drift(caplog: pytest.LogCaptureFixture) -> None: + panel = device_from_topics(PANEL, _unknown_model_tree()[PANEL]) + + with caplog.at_level(logging.WARNING): + assert panel_model_drift(panel) == () + assert not caplog.records + + +# --- properties only these models declare ----------------------------------- + +_UNION = { + "busbar-current": {"datatype": "float", "unit": "A"}, + "frequency": {"datatype": "float", "unit": "Hz"}, + "nominal-voltage": {"datatype": "float", "unit": "V"}, + "protection-functions": {"datatype": "enum", "format": "OVERCURRENT,SHORT_CIRCUIT,GROUND_FAULT,ARC_FAULT"}, + "shared-with-device-ids": {"datatype": "string"}, +} +"""Declarations as the union schema states them.""" + +_SITE = { + "name": {"datatype": "string"}, + "address-lines": {"datatype": "string"}, + "locality": {"datatype": "string"}, + "region": {"datatype": "string"}, + "country-code": {"datatype": "string"}, + "latitude": {"datatype": "float"}, + "longitude": {"datatype": "float"}, + "utility-meter-serial-number": {"datatype": "string"}, +} +_BACKED_UP = {"datatype": "enum", "format": "BACKED_UP,NOT_BACKED_UP,UNKNOWN"} +_CIRCUIT_ONLY = { + ("info", "tags"): {"datatype": "string"}, + ("info", "locations"): {"datatype": "string"}, + ("info", "dedicated"): {"datatype": "boolean"}, + ("connection", "fed-by-device-id"): {"datatype": "string"}, + ("connection", "fed-by-device-type"): {"datatype": "string"}, + ("connection", "fed-by-device-status"): {"datatype": "string"}, + ("connection", "backed-up"): _BACKED_UP, +} +_LUGS_ONLY = { + "backed-up": _BACKED_UP, + "feeds-role": _FEEDS_ROLE, + "service-rating": {"datatype": "integer", "unit": "A"}, + "overcurrent-protection": {"datatype": "integer", "unit": "A"}, +} +_UPSTREAM_LUGS = "lugs-upstream" + + +def _declare(tree: RetainedTopicTree, device_id: str, node: str, prop: str, definition: object, value: str) -> None: + description = json.loads(tree[device_id]["$description"]) + description["nodes"].setdefault(node, {"properties": {}})["properties"][prop] = definition + tree[device_id]["$description"] = json.dumps(description) + tree[device_id][f"{node}/{prop}"] = value + + +def _with_model_properties() -> dict[str, dict[str, str]]: + tree = _tree() + _declare(tree, PANEL, "meter", "busbar-current", _UNION["busbar-current"], "41.5") + _declare(tree, PANEL, "meter", "frequency", _UNION["frequency"], "60.01") + _declare(tree, KITCHEN, "info", "nominal-voltage", _UNION["nominal-voltage"], "120.0") + _declare(tree, KITCHEN, "breaker", "protection-functions", _UNION["protection-functions"], "GROUND_FAULT,ARC_FAULT") + shared = _UNION["shared-with-device-ids"] + _declare(tree, KITCHEN, "switch", "shared-with-device-ids", shared, "circuit-4,circuit-2") + _declare(tree, "circuit-2", "switch", "shared-with-device-ids", shared, "circuit-1,circuit-4") + _declare(tree, KITCHEN, "meter", "shared-with-device-ids", shared, f"{REMOTE_CT}, not-yet-seen,{KITCHEN},circuit-2") + return tree + + +def test_the_panel_meter_reads_busbar_current_and_frequency() -> None: + snapshot = _snapshot(_with_model_properties()) + + assert snapshot.busbar_current_a == 41.5 + assert snapshot.frequency_hz == 60.01 + + +def test_a_circuit_reads_its_nominal_voltage_and_protection_functions() -> None: + kitchen = _snapshot(_with_model_properties()).circuits[KITCHEN] + + assert kitchen.nominal_voltage_v == 120.0 + assert kitchen.protection_functions == ("GROUND_FAULT", "ARC_FAULT") + + +def test_shared_with_resolves_to_other_circuits_in_device_id_order() -> None: + """The circuit itself and an id naming no circuit in the snapshot are left out.""" + circuits = _snapshot(_with_model_properties()).circuits + + assert circuits[KITCHEN].relay_shared_with == ("circuit-2", "circuit-4") + assert circuits["circuit-2"].relay_shared_with == ("circuit-1", "circuit-4") + assert circuits[KITCHEN].meter_shared_with == ("circuit-2", REMOTE_CT) + + +def test_shared_with_orders_instance_numbers_numerically() -> None: + tree = _with_model_properties() + tree["circuit-10"] = {**tree["circuit-2"]} + tree[KITCHEN]["switch/shared-with-device-ids"] = "circuit-10,circuit-2" + + assert _snapshot(tree).circuits[KITCHEN].relay_shared_with == ("circuit-2", "circuit-10") + + +def test_a_shared_group_naming_no_known_circuit_is_still_shared() -> None: + tree = _with_model_properties() + tree[KITCHEN]["meter/shared-with-device-ids"] = "not-yet-seen" + + assert _snapshot(tree).circuits[KITCHEN].meter_shared_with == () + + +def test_every_model_property_is_none_where_not_published() -> None: + snapshot = _snapshot(_with_model_properties()) + unshared = snapshot.circuits["circuit-5"] + + assert unshared.nominal_voltage_v is None + assert unshared.protection_functions is None + assert unshared.relay_shared_with is None + assert unshared.meter_shared_with is None + assert snapshot.circuits["circuit-4"].relay_shared_with is None + + +def test_the_model_properties_carry_metadata_from_their_declarations() -> None: + tree = _with_model_properties() + metadata = build_field_metadata([device_from_topics(device_id, topics) for device_id, topics in tree.items()]) + + assert metadata["panel.busbar_current_a"] == FieldMetadata(unit="A", datatype="float") + assert metadata["panel.frequency_hz"] == FieldMetadata(unit="Hz", datatype="float") + assert metadata["circuit.nominal_voltage_v"] == FieldMetadata(unit="V", datatype="float") + assert metadata["circuit.protection_functions"] == FieldMetadata(unit=None, datatype="enum") + assert not [path for path in metadata if is_discovery_path(path) and path.split("/")[-1] in _UNION] + + +def test_the_model_properties_are_not_extension_properties() -> None: + rows = _snapshot(_with_model_properties()).extension_properties + + assert not [row for row in rows if row.property_id in _UNION] + + +def test_site_and_topology_properties_never_become_readings() -> None: + """`info` and `connection` resolve to the device card and the tree, never an entity.""" + tree = _with_model_properties() + for prop, definition in _SITE.items(): + _declare(tree, PANEL, "info", prop, definition, "1.5" if definition["datatype"] == "float" else "example") + for (node, prop), definition in _CIRCUIT_ONLY.items(): + _declare(tree, KITCHEN, node, prop, definition, "true" if definition["datatype"] == "boolean" else "UNKNOWN") + for prop, definition in _LUGS_ONLY.items(): + _declare( + tree, _UPSTREAM_LUGS, "connection", prop, definition, "200" if definition["datatype"] == "integer" else "LOADS" + ) + + snapshot = _snapshot(tree) + declared = set(_SITE) | {prop for _node, prop in _CIRCUIT_ONLY} | set(_LUGS_ONLY) + + assert not [row for row in snapshot.extension_properties if row.property_id in declared] + assert not [row for device in snapshot.adopted_devices for row in device.properties if row.property_id in declared] + + +def test_the_reference_main_32_publishes_none_of_them() -> None: + snapshot = _snapshot(parent_child_tree()) + metadata = build_field_metadata( + [device_from_topics(device_id, topics) for device_id, topics in parent_child_tree().items()] + ) + + assert snapshot.busbar_current_a is None + assert snapshot.frequency_hz is None + for circuit in snapshot.circuits.values(): + assert circuit.nominal_voltage_v is None + assert circuit.protection_functions is None + assert circuit.relay_shared_with is None + assert circuit.meter_shared_with is None + assert not { + "panel.busbar_current_a", + "panel.frequency_hz", + "circuit.nominal_voltage_v", + "circuit.protection_functions", + } & set(metadata) + + +# --- the shipped other-model reference tree --------------------------------- + +_OTHER_PANEL = "example-48t-001" + + +def _shipped() -> SpanPanelSnapshot: + tree = other_model_tree() + panel = device_from_topics(_OTHER_PANEL, tree[_OTHER_PANEL]) + return build_snapshot(panel, [device_from_topics(d, topics) for d, topics in tree.items() if d != _OTHER_PANEL]) + + +def _shipped_metadata() -> dict[str, FieldMetadata]: + return build_field_metadata([device_from_topics(d, topics) for d, topics in other_model_tree().items()]) + + +def test_the_shipped_tree_has_the_other_model_shape() -> None: + snapshot = _shipped() + real = {cid for cid in snapshot.circuits if not cid.startswith("unmapped_tab_")} + + assert snapshot.serial_number == _OTHER_PANEL + assert snapshot.model == "MLO_48" + assert snapshot.panel_size == 48 + assert snapshot.main_breaker_rating_a is None + assert real == {f"circuit-{n}" for n in range(1, 7)} | {"remote-ct-1", "remote-ct-2"} + assert snapshot.circuits["circuit-6"].device_type == "pv" + assert snapshot.circuits["circuit-3"].device_type == "evse" + assert snapshot.pv == SpanPVSnapshot() + assert snapshot.pv_inverters == {} + assert snapshot.busbar_current_a == 41.5 + assert snapshot.frequency_hz == 60.01 + assert snapshot.circuits["circuit-1"].relay_shared_with == ("circuit-2",) + assert snapshot.circuits["circuit-5"].relay_requester == "CIRCUIT_SCHEDULER" + + +def test_the_shipped_tree_remote_cts_are_meter_only() -> None: + snapshot = _shipped() + for ct_id in ("remote-ct-1", "remote-ct-2"): + ct = snapshot.circuits[ct_id] + assert ct.name == "" + assert ct.tabs == [] + assert ct.is_user_controllable is False + assert snapshot.circuits["remote-ct-2"].instant_power_w == 480.0 + + +def test_the_shipped_tree_resolves_every_mapped_row() -> None: + """Undeclared model-specific rows and the missing panel breaker are silent, not gaps.""" + metadata = _shipped_metadata() + + assert not [path for path, entry in metadata.items() if not entry.resolved] + assert "panel.main_breaker_rating_a" not in metadata + assert metadata["panel.busbar_current_a"] == FieldMetadata(unit="A", datatype="float") + + +def test_the_shipped_tree_reports_its_other_model_only_properties_as_discovered() -> None: + discovered = {path for path in _shipped_metadata() if is_discovery_path(path)} + + for prop in ("name", "latitude", "longitude", "address-lines", "utility-meter-serial-number"): + assert f"discovered.distribution-enclosure/info/{prop}" in discovered + for path in ("info/tags", "info/locations", "info/dedicated", "connection/backed-up"): + assert f"discovered.circuit/{path}" in discovered + for prop in ("service-rating", "overcurrent-protection", "feeds-role"): + assert f"discovered.lugs/connection/{prop}" in discovered + + +def test_the_shipped_tree_raises_no_reading_for_site_location() -> None: + snapshot = _shipped() + site = set(_SITE) + + assert not [row for row in snapshot.extension_properties if row.property_id in site] + assert snapshot.adopted_devices == () diff --git a/tests/test_schema_one_panel.py b/tests/test_schema_one_panel.py index 71491d85..e63f23bb 100644 --- a/tests/test_schema_one_panel.py +++ b/tests/test_schema_one_panel.py @@ -342,17 +342,19 @@ def test_an_assertion_outside_the_enum_is_not_an_answer() -> None: assert resolve_islanding_state(mid, panel) == "OFF_GRID" -def test_no_mid_reads_grid_power_and_never_asserts_off_grid() -> None: - """Tier 3, and the error worth keeping a test on. - - An earlier draft reasoned that no MID means no islanding authority means on-grid. - A missing MID means *SPAN* is not the authority and says nothing about whether the - site is islanded — a generator-fed island is the counterexample. Grid power flowing - is positive evidence of being on-grid; its absence is not evidence of the opposite. +def test_no_mid_is_on_grid_whatever_grid_power_reads() -> None: + """Tier 3. A panel with no MID cannot island, so a panel that is publishing is on-grid. + + This read `power-flows/grid` until 2026-10-13 and answered on-grid only above 1 W. + A sub-panel whose net draw sits near zero then lost the answer on every sample that + read `0.0` and regained it on the next, which an automation saw as the grid coming + back (SpanPanel/span-panel-api#215). Grid power is a measurement of how much is + flowing, and the amount says nothing about where it comes from. """ - assert resolve_islanding_state(None, _synthetic(PANEL, power_flows__grid="2400.0")) == "ON_GRID" - assert resolve_islanding_state(None, _synthetic(PANEL, power_flows__grid="0.0")) is None - assert resolve_islanding_state(None, _synthetic(PANEL)) is None + for grid_power in ("2400.0", "8.7", "0.0", "-0.4", "-3100.0"): + panel = _synthetic(PANEL, power_flows__grid=grid_power) + assert resolve_islanding_state(None, panel) == "ON_GRID", grid_power + assert resolve_islanding_state(None, _synthetic(PANEL)) == "ON_GRID" def test_run_config_names_the_forming_device_rather_than_guessing_it() -> None: diff --git a/tests/test_schema_one_panel_properties.py b/tests/test_schema_one_panel_properties.py new file mode 100644 index 00000000..ff470cb2 --- /dev/null +++ b/tests/test_schema_one_panel_properties.py @@ -0,0 +1,168 @@ +"""Panel and circuit readings, and the site properties that never become readings. + +The panel's busbar current and line frequency, the upstream lugs' overcurrent +protection rating, and each circuit's nominal voltage and protection functions +are read where the panel declares them and are `None` where it does not, or +has not published them. Their field metadata comes from the declarations, and +an undeclared one is absent rather than a gap. + +The site's name, address, coordinates and utility meter serial never become an +extension or adopted reading, on whatever node a device declares them. +""" + +from __future__ import annotations + +from typing import get_args + +import pytest + +from conftest import flat_schema +from reference_payloads.schema_one import devices_from_tree, replay +from reference_payloads.synthetic_trees import ( + PANEL_ID, + PropertyDeclaration, + SyntheticDevice, + hosted_circuit, + lugs, + panel, + tree, + without_values, +) +from span_panel_api import PROTECTION_FUNCTIONS, ProtectionFunction, SpanPanelSnapshot +from span_panel_api.models import FieldMetadata +from span_panel_api_schema_0 import SchemaZeroAdapter +from span_panel_api_schema_1.const import SITE_PROPERTIES +from span_panel_api_schema_1.field_metadata import build_field_metadata + +_STRING: PropertyDeclaration = {"name": "Site", "datatype": "string"} + + +def _snapshot(*children: SyntheticDevice, root: SyntheticDevice | None = None) -> SpanPanelSnapshot: + return replay(tree(root or panel(), *children), PANEL_ID).build_snapshot() + + +def test_the_protection_function_set_is_the_literal() -> None: + assert set(PROTECTION_FUNCTIONS) == set(get_args(ProtectionFunction.__value__)) + + +def test_the_panel_readings_are_read_where_declared() -> None: + snapshot = _snapshot( + lugs("UPSTREAM", overcurrent_protection_a=150), root=panel(busbar_current_a=41.5, frequency_hz=59.98) + ) + + assert (snapshot.busbar_current_a, snapshot.frequency_hz) == (41.5, 59.98) + assert snapshot.upstream_protection_rating_a == 150 + + +def test_the_panel_readings_are_none_where_undeclared() -> None: + snapshot = _snapshot(lugs("UPSTREAM"), lugs("DOWNSTREAM", overcurrent_protection_a=60)) + + assert (snapshot.busbar_current_a, snapshot.frequency_hz, snapshot.upstream_protection_rating_a) == ( + None, + None, + None, + ) + + +def test_the_panel_readings_are_none_until_published() -> None: + root = without_values(panel(busbar_current_a=41.5, frequency_hz=60.0), "meter/busbar-current", "meter/frequency") + upstream = without_values(lugs("UPSTREAM", overcurrent_protection_a=150), "connection/overcurrent-protection") + snapshot = _snapshot(upstream, root=root) + + assert (snapshot.busbar_current_a, snapshot.frequency_hz, snapshot.upstream_protection_rating_a) == ( + None, + None, + None, + ) + + +def test_a_circuit_reads_its_nominal_voltage_and_protection_functions() -> None: + circuit = _snapshot( + hosted_circuit("c-1", (1,), nominal_voltage_v=240.0, protection_functions=("ARC_FAULT", "OVERCURRENT")) + ).circuits["c-1"] + + assert circuit.nominal_voltage_v == 240.0 + assert circuit.protection_functions == ("ARC_FAULT", "OVERCURRENT") + + +def test_a_protection_function_outside_the_set_is_dropped() -> None: + circuit = _snapshot(hosted_circuit("c-1", (1,), protection_functions=("GROUND_FAULT", "NOT_A_FUNCTION"))).circuits["c-1"] + + assert circuit.protection_functions == ("GROUND_FAULT",) + + +def test_circuit_readings_are_none_where_undeclared_or_unpublished() -> None: + declared = hosted_circuit("c-2", (3,), nominal_voltage_v=120.0, protection_functions=("OVERCURRENT",)) + circuits = _snapshot( + hosted_circuit("c-1", (1,)), + without_values(declared, "info/nominal-voltage", "breaker/protection-functions"), + ).circuits + + for circuit_id in ("c-1", "c-2"): + assert (circuits[circuit_id].nominal_voltage_v, circuits[circuit_id].protection_functions) == (None, None) + + +def test_the_readings_carry_metadata_from_their_declarations() -> None: + metadata = build_field_metadata( + devices_from_tree( + tree( + panel(busbar_current_a=41.5, frequency_hz=60.0), + hosted_circuit("c-1", (1,), nominal_voltage_v=120.0, protection_functions=("OVERCURRENT",)), + ) + ) + ) + + assert metadata["panel.busbar_current_a"] == FieldMetadata(unit="A", datatype="float") + assert metadata["panel.frequency_hz"] == FieldMetadata(unit="Hz", datatype="float") + assert metadata["circuit.nominal_voltage_v"] == FieldMetadata(unit="V", datatype="float") + assert metadata["circuit.protection_functions"] == FieldMetadata(unit=None, datatype="enum") + + +def test_an_undeclared_reading_has_no_metadata_rather_than_a_gap() -> None: + metadata = build_field_metadata(devices_from_tree(tree(panel(), hosted_circuit("c-1", (1,))))) + + for path in ( + "panel.busbar_current_a", + "panel.frequency_hz", + "circuit.nominal_voltage_v", + "circuit.protection_functions", + ): + assert path not in metadata + + +@pytest.mark.parametrize("property_id", sorted(SITE_PROPERTIES)) +def test_a_site_property_on_any_node_never_becomes_a_reading(property_id: str) -> None: + """The identity node keeps them out where the panel declares them; this holds anywhere else.""" + base = panel() + root = SyntheticDevice( + device_id=base.device_id, + device_type=base.device_type, + name=base.name, + nodes={**base.nodes, "site": {property_id: _STRING}}, + values={**base.values, f"site/{property_id}": "example"}, + ) + vendor = SyntheticDevice( + device_id="vendor-a", + device_type="energy.ebus.device.example", + name="Vendor", + nodes={"site": {property_id: _STRING, "label": _STRING}}, + values={f"site/{property_id}": "example", "site/label": "example"}, + ) + snapshot = _snapshot(vendor, root=root) + + assert not [row for row in snapshot.extension_properties if row.property_id == property_id] + adopted = {row.property_id for device in snapshot.adopted_devices for row in device.properties} + assert adopted == {"label"} + + +def test_a_flat_panel_reports_none_of_them() -> None: + snapshot = SchemaZeroAdapter(serial_number="sim-40t-001", schema=flat_schema(40)).build_snapshot() + + assert (snapshot.busbar_current_a, snapshot.frequency_hz, snapshot.upstream_protection_rating_a) == ( + None, + None, + None, + ) + assert all( + (circuit.nominal_voltage_v, circuit.protection_functions) == (None, None) for circuit in snapshot.circuits.values() + ) diff --git a/tests/test_schema_one_positions.py b/tests/test_schema_one_positions.py new file mode 100644 index 00000000..04fcc96a --- /dev/null +++ b/tests/test_schema_one_positions.py @@ -0,0 +1,125 @@ +"""The panel's first and last breaker positions, and a model reported as `UNKNOWN`. + +The range comes from the reported model where the table knows it, and from the +occupied spaces where it does not. It only says which positions exist: nothing +is filled in over it and no circuit is made up for an empty position. A model +reported as `UNKNOWN` names no model: it reads as absent, sizes the panel 0 +and is neither warned about on every snapshot nor counted as drift. +""" + +from __future__ import annotations + +import logging + +import pytest + +from conftest import flat_schema +from reference_payloads.schema_one import device_from_topics, replay +from reference_payloads.synthetic_trees import PANEL_ID, hosted_circuit, panel, panel_with_positions, tree +from span_panel_api_schema_0 import SchemaZeroAdapter +from span_panel_api_schema_1.const import PANEL_POSITIONS_BY_MODEL, PANEL_SIZE_BY_MODEL +from span_panel_api_schema_1.panel import panel_model_drift + +_ADVERTISED = (*PANEL_SIZE_BY_MODEL, "UNKNOWN") + + +@pytest.mark.parametrize("model", sorted(PANEL_POSITIONS_BY_MODEL)) +def test_positions_follow_the_reported_model(model: str) -> None: + first, last = PANEL_POSITIONS_BY_MODEL[model] + snapshot = replay(panel_with_positions(model, (first, last)), PANEL_ID).build_snapshot() + + assert (snapshot.first_position, snapshot.last_position) == (first, last) + assert snapshot.panel_size == PANEL_SIZE_BY_MODEL[model] + + +def test_every_sized_model_has_a_range_as_long_as_its_size() -> None: + assert set(PANEL_POSITIONS_BY_MODEL) == set(PANEL_SIZE_BY_MODEL) + for model, (first, last) in PANEL_POSITIONS_BY_MODEL.items(): + assert last - first + 1 == PANEL_SIZE_BY_MODEL[model], model + + +def test_an_occupied_space_outside_the_model_range_keeps_the_range_and_warns_once( + caplog: pytest.LogCaptureFixture, +) -> None: + """The table's range stands, and the disagreement is reported once per panel.""" + model, (first, last) = next((model, span) for model, span in PANEL_POSITIONS_BY_MODEL.items() if span[0] > 1) + adapter = replay(panel_with_positions(model, (first - 1, last)), PANEL_ID) + + with caplog.at_level(logging.WARNING): + snapshots = [adapter.build_snapshot(), adapter.build_snapshot()] + + assert {(snapshot.first_position, snapshot.last_position) for snapshot in snapshots} == {(first, last)} + warnings = [record.getMessage() for record in caplog.records if "breaker positions" in record.getMessage()] + assert len(warnings) == 1 + assert all(part in warnings[0] for part in (model, f"{first}-{last}", f"{first - 1}-{last}")) + + +def test_a_panel_inside_its_model_range_is_not_reported(caplog: pytest.LogCaptureFixture) -> None: + with caplog.at_level(logging.WARNING): + replay(panel_with_positions("MAIN_32", (1, 32)), PANEL_ID).build_snapshot() + + assert not [record for record in caplog.records if "breaker positions" in record.getMessage()] + + +def test_an_unknown_model_takes_its_range_from_occupied_spaces_and_size_zero(caplog: pytest.LogCaptureFixture) -> None: + occupied = tree( + panel(model="UNKNOWN", advertised_models=_ADVERTISED), + hosted_circuit("c-12", (12, 14)), + hosted_circuit("c-3", (3,)), + ) + with caplog.at_level(logging.WARNING): + snapshot = replay(occupied, PANEL_ID).build_snapshot() + + assert (snapshot.first_position, snapshot.last_position) == (3, 14) + assert snapshot.panel_size == 0 + assert snapshot.model is None + assert not caplog.records + + +def test_an_unknown_model_with_nothing_occupied_has_no_range() -> None: + snapshot = replay(tree(panel(model="UNKNOWN", advertised_models=_ADVERTISED)), PANEL_ID).build_snapshot() + + assert (snapshot.first_position, snapshot.last_position) == (None, None) + + +def test_a_model_the_table_cannot_size_still_warns_and_takes_the_occupied_range( + caplog: pytest.LogCaptureFixture, +) -> None: + with caplog.at_level(logging.WARNING): + snapshot = replay(panel_with_positions("MAIN_64", (5, 7)), PANEL_ID).build_snapshot() + + assert (snapshot.first_position, snapshot.last_position, snapshot.panel_size) == (5, 7, 0) + assert snapshot.model == "MAIN_64" + assert any("MAIN_64" in record.getMessage() for record in caplog.records) + + +def test_no_position_is_synthesised() -> None: + snapshot = replay(panel_with_positions("MAIN_32", (2, 9)), PANEL_ID).build_snapshot() + + assert set(snapshot.circuits) == {"c-2", "c-9"} + + +def test_drift_ignores_unknown(caplog: pytest.LogCaptureFixture) -> None: + device = device_from_topics(PANEL_ID, tree(panel(model="MAIN_32", advertised_models=_ADVERTISED))[PANEL_ID]) + + with caplog.at_level(logging.WARNING): + assert panel_model_drift(device) == () + assert not caplog.records + + +@pytest.mark.parametrize("role", ["LOADS", "SOLAR"]) +def test_a_declared_feeds_role_marks_a_panel_that_publishes_solar_roles(role: str) -> None: + snapshot = replay(tree(panel(), hosted_circuit("c-1", (1,), feeds_role=role)), PANEL_ID).build_snapshot() + + assert snapshot.publishes_solar_roles is True + + +def test_a_panel_whose_circuits_declare_no_role_does_not() -> None: + assert replay(panel_with_positions("MAIN_32", (1,)), PANEL_ID).build_snapshot().publishes_solar_roles is False + + +def test_a_flat_panel_reports_no_range_and_no_roles() -> None: + snapshot = SchemaZeroAdapter(serial_number="sim-40t-001", schema=flat_schema(40)).build_snapshot() + + assert (snapshot.first_position, snapshot.last_position) == (None, None) + assert snapshot.publishes_solar_roles is False diff --git a/tests/test_schema_one_service_entrance.py b/tests/test_schema_one_service_entrance.py index 4985ac52..da826115 100644 --- a/tests/test_schema_one_service_entrance.py +++ b/tests/test_schema_one_service_entrance.py @@ -25,6 +25,8 @@ from __future__ import annotations +import json + import pytest from reference_payloads.schema_one import ( @@ -51,6 +53,18 @@ def _mutable_tree() -> dict[str, dict[str, str]]: return {device_id: dict(topics) for device_id, topics in parent_child_tree().items()} +def _without_a_declared_feed(tree: dict[str, dict[str, str]]) -> dict[str, dict[str, str]]: + """The upstream lugs with their `fed-by-*` record undeclared, so nothing can arrive.""" + description = json.loads(tree[UPSTREAM_LUGS]["$description"]) + properties = description["nodes"][NODE_CONNECTION]["properties"] + del properties[PROP_FED_BY_DEVICE_ID] + del properties[PROP_FED_BY_DEVICE_STATUS] + tree[UPSTREAM_LUGS]["$description"] = json.dumps(description) + del tree[UPSTREAM_LUGS][FED_BY_ID_TOPIC] + del tree[UPSTREAM_LUGS][FED_BY_STATUS_TOPIC] + return tree + + def _snapshot(tree: RetainedTopicTree) -> SpanPanelSnapshot: panel = device_from_topics(PANEL, tree[PANEL]) children = [device_from_topics(device_id, topics) for device_id, topics in tree.items() if device_id != PANEL] @@ -78,11 +92,23 @@ def test_a_panel_with_nothing_ahead_of_its_lugs_is_at_the_service_entrance() -> that always answered `True` would pass this and fail everything above it, and one that always answered `False` would do the reverse. """ + tree = _without_a_declared_feed(_mutable_tree()) + + assert _snapshot(tree).lugs_at_service_entrance is True + + +def test_a_declared_feed_with_no_value_yet_leaves_it_unknown() -> None: + """Declared and unvalued is not an answer. + + The lugs say they have a feed record and have not published it, so the feed + may yet name a device. `True` here would tell a panel behind a battery that + its lugs reading is the grid, until the value lands. + """ tree = _mutable_tree() del tree[UPSTREAM_LUGS][FED_BY_ID_TOPIC] del tree[UPSTREAM_LUGS][FED_BY_STATUS_TOPIC] - assert _snapshot(tree).lugs_at_service_entrance is True + assert _snapshot(tree).lugs_at_service_entrance is None @pytest.mark.parametrize( @@ -128,9 +154,7 @@ def test_the_grid_reading_itself_is_unchanged_either_way() -> None: become a reason to withhold or alter the value -- only to say what it is. """ behind = _mutable_tree() - plain = _mutable_tree() - del plain[UPSTREAM_LUGS][FED_BY_ID_TOPIC] - del plain[UPSTREAM_LUGS][FED_BY_STATUS_TOPIC] + plain = _without_a_declared_feed(_mutable_tree()) assert _snapshot(behind).lugs_at_service_entrance != _snapshot(plain).lugs_at_service_entrance assert _snapshot(behind).instant_grid_power_w == _snapshot(plain).instant_grid_power_w diff --git a/tests/test_schema_one_shared_meters.py b/tests/test_schema_one_shared_meters.py new file mode 100644 index 00000000..2a6bb96d --- /dev/null +++ b/tests/test_schema_one_shared_meters.py @@ -0,0 +1,115 @@ +"""Circuits that share a meter or a relay name each other. + +`meter/` and `switch/shared-with-device-ids` list the other devices one meter +measures or one relay switches. They are resolved to the circuit ids of the +snapshot: the circuit itself and ids naming no circuit are dropped, and the +rest are ordered by device id with instance numbers compared as numbers. +Undeclared or not yet published reads `None`; declared with no known peer reads +`()`. `shared_meter_groups` groups the circuits one meter measures; nothing is +summed. +""" + +from __future__ import annotations + +from conftest import flat_schema +from reference_payloads.schema_one import parent_child_tree, replay +from reference_payloads.synthetic_trees import ( + PANEL_ID, + SyntheticDevice, + hosted_circuit, + panel, + shared_pair, + tree, + without_values, +) +from span_panel_api import SpanPanelSnapshot, shared_meter_groups +from span_panel_api.models import device_id_order +from span_panel_api_schema_0 import SchemaZeroAdapter + +_REFERENCE_PANEL = "example-40t-001" + + +def _snapshot(*circuits: SyntheticDevice) -> SpanPanelSnapshot: + return replay(tree(panel(), *circuits), PANEL_ID).build_snapshot() + + +def test_a_shared_pair_names_each_other_for_meter_and_relay() -> None: + circuits = _snapshot(*shared_pair("c-1", "c-2")).circuits + + assert (circuits["c-1"].meter_shared_with, circuits["c-1"].relay_shared_with) == (("c-2",), ("c-2",)) + assert (circuits["c-2"].meter_shared_with, circuits["c-2"].relay_shared_with) == (("c-1",), ("c-1",)) + + +def test_the_circuit_itself_and_unknown_ids_are_dropped() -> None: + circuits = _snapshot( + hosted_circuit("c-1", (1,), meter_shared_with=("c-1", "ghost", "c-2"), relay_shared_with=("ghost",)), + hosted_circuit("c-2", (3,)), + ).circuits + + assert circuits["c-1"].meter_shared_with == ("c-2",) + assert circuits["c-1"].relay_shared_with == () + + +def test_instance_numbers_are_ordered_as_numbers() -> None: + circuits = _snapshot( + hosted_circuit("c-1", (1,), meter_shared_with=("c-10", "c-9")), + hosted_circuit("c-9", (3,)), + hosted_circuit("c-10", (5,)), + ).circuits + + assert circuits["c-1"].meter_shared_with == ("c-9", "c-10") + assert sorted(["c-10", "c-9", "c-1", "meter-a"], key=device_id_order) == ["c-1", "c-9", "c-10", "meter-a"] + + +def test_undeclared_shared_with_reads_none() -> None: + circuit = _snapshot(hosted_circuit("c-1", (1,))).circuits["c-1"] + + assert (circuit.meter_shared_with, circuit.relay_shared_with) == (None, None) + + +def test_declared_shared_with_not_yet_published_reads_none() -> None: + first, second = shared_pair("c-1", "c-2") + unpublished = without_values(first, "meter/shared-with-device-ids", "switch/shared-with-device-ids") + snapshot = _snapshot(unpublished, second) + + assert (snapshot.circuits["c-1"].meter_shared_with, snapshot.circuits["c-1"].relay_shared_with) == (None, None) + + +def test_declared_with_no_known_peer_reads_empty_and_has_no_group() -> None: + snapshot = _snapshot(hosted_circuit("c-1", (1,), meter_shared_with=("ghost",))) + + assert snapshot.circuits["c-1"].meter_shared_with == () + assert shared_meter_groups(snapshot.circuits) == {} + + +def test_groups_are_keyed_by_their_first_member() -> None: + snapshot = _snapshot(*shared_pair("c-10", "c-9", space=1), *shared_pair("c-2", "c-3", space=3)) + + assert shared_meter_groups(snapshot.circuits) == {"c-2": ("c-2", "c-3"), "c-9": ("c-9", "c-10")} + + +def test_a_group_holds_every_circuit_one_meter_measures() -> None: + """Named by any member, a circuit is in the group, even where its own list has not arrived.""" + snapshot = _snapshot( + hosted_circuit("c-1", (1,), meter_shared_with=("c-2",)), + hosted_circuit("c-2", (1,), meter_shared_with=("c-3",)), + hosted_circuit("c-3", (1,)), + ) + + assert shared_meter_groups(snapshot.circuits) == {"c-1": ("c-1", "c-2", "c-3")} + + +def test_the_reference_tree_shares_nothing() -> None: + snapshot = replay(parent_child_tree(), _REFERENCE_PANEL).build_snapshot() + + assert all( + (circuit.meter_shared_with, circuit.relay_shared_with) == (None, None) for circuit in snapshot.circuits.values() + ) + assert shared_meter_groups(snapshot.circuits) == {} + + +def test_a_flat_panel_shares_nothing() -> None: + snapshot = SchemaZeroAdapter(serial_number="sim-40t-001", schema=flat_schema(40)).build_snapshot() + + assert all(circuit.meter_shared_with is None for circuit in snapshot.circuits.values()) + assert shared_meter_groups(snapshot.circuits) == {} diff --git a/tests/test_schema_one_snapshot.py b/tests/test_schema_one_snapshot.py index 46182efd..64387509 100644 --- a/tests/test_schema_one_snapshot.py +++ b/tests/test_schema_one_snapshot.py @@ -117,6 +117,28 @@ class is recoverable from the tree. assert snapshot.current_run_config == "PANEL_ON_GRID" +def test_a_panel_with_no_mid_keeps_its_grid_answers_through_a_zero_grid_reading() -> None: + """Both entities hold steady while grid power passes through zero. + + A panel with no MID has no battery either, so the tree here is the reference one + without those two devices. The readings are the samples around one drop reported in + SpanPanel/span-panel-api#215, where each `0.0` turned both answers unknown for one + update. + """ + children = [device for device in _children() if device.device_id not in ("bess", "bess-mid")] + assert TreeRoles(children).mid is None + + for grid_power in ("11.2", "0.0", "8.7"): + panel = _device(PANEL) + panel.update_property("power-flows", "grid", grid_power) + + snapshot = build_snapshot(panel, children) + + assert snapshot.power_flow_grid == float(grid_power) + assert snapshot.dsm_state == "DSM_ON_GRID", grid_power + assert snapshot.current_run_config == "PANEL_ON_GRID", grid_power + + def test_an_unsizable_panel_reports_no_size_and_keeps_its_circuits() -> None: """A panel whose model we cannot size reports no total rather than a guess, and its circuits do not depend on the total.""" diff --git a/tests/test_schema_one_space_less_meters.py b/tests/test_schema_one_space_less_meters.py new file mode 100644 index 00000000..fd0a4215 --- /dev/null +++ b/tests/test_schema_one_space_less_meters.py @@ -0,0 +1,175 @@ +"""A circuit-typed device that declares no breaker space measures outside the panel. + +It is classified by declaration, never by value: a device whose `$description` +declares no `info/spaces` is a meter outside the panel however its values read, +and one that declares spaces stays hosted while its values have not arrived. + +Its power stays import-positive (positive = flowing into the panel), consumed is +imported energy and produced is exported energy, so consumed minus produced is +net import. It has no relay, no breaker and no shed priority, so it offers no +control and no voltage, and it is never waited on for a name it does not +declare. A hosted circuit keeps the panel's load frame exactly as before. +""" + +from __future__ import annotations + +import math + +import pytest + +from reference_payloads.schema_one import parent_child_tree, replay +from reference_payloads.synthetic_trees import ( + METER_READING, + PANEL_ID, + MeterReading, + SyntheticDevice, + discovered, + hosted_circuit, + panel, + space_less_meter, + tree, + without_values, +) +from span_panel_api.models import SpanCircuitSnapshot +from span_panel_api_schema_1 import SchemaOneAdapter +from span_panel_api_schema_1.circuits import relay_is_settable + +_REFERENCE_PANEL = "example-40t-001" + +_IMPORTING = MeterReading(active_power_w=13.5, current_a=0.1, imported_energy_wh=1200.5, exported_energy_wh=75.25) +"""Power flowing into the panel through the meter.""" + + +def _adapter(*children: SyntheticDevice) -> SchemaOneAdapter: + return replay(tree(panel(), *children), PANEL_ID) + + +def _circuit(device: SyntheticDevice) -> SpanCircuitSnapshot: + return _adapter(device).build_snapshot().circuits[device.device_id] + + +@pytest.mark.parametrize("reading", [_IMPORTING, METER_READING], ids=["importing", "exporting"]) +def test_a_space_less_meter_reads_its_wire_values_import_positive(reading: MeterReading) -> None: + meter = _circuit(space_less_meter("meter-a", reading=reading)) + + assert meter.measures_outside_panel is True + assert meter.instant_power_w == pytest.approx(reading.active_power_w) + assert meter.consumed_energy_wh == pytest.approx(reading.imported_energy_wh) + assert meter.produced_energy_wh == pytest.approx(reading.exported_energy_wh) + assert meter.current_a == pytest.approx(reading.current_a) + assert meter.tabs == [] + + +def test_a_space_less_meter_reading_zero_reads_positive_zero() -> None: + """A published `-0.0` is a zero reading, and is reported as `0.0`.""" + meter = _circuit(space_less_meter("meter-a", reading=MeterReading(-0.0, 0.0, 10.0, 5.0))) + + assert meter.instant_power_w == 0.0 + assert meter.instant_power_w is not None and math.copysign(1.0, meter.instant_power_w) == 1.0 + + +def test_a_space_less_meter_has_no_controls_and_is_never_waited_on() -> None: + adapter = _adapter(space_less_meter("meter-a")) + + meter = adapter.build_snapshot().circuits["meter-a"] + + assert (meter.is_user_controllable, meter.always_on, meter.is_sheddable) == (False, False, False) + assert adapter.set_circuit_relay_target("meter-a") is None + assert adapter.set_circuit_priority_target("meter-a") is None + assert meter.relay_state_target is None and meter.priority_target is None + assert meter.is_240v is None + assert meter.breaker_rating_a is None + assert "meter-a" not in adapter.circuit_nodes_missing_names() + + +def test_an_unvalued_space_less_meter_is_still_outside_the_panel() -> None: + """Declared and not yet valued: outside the panel, every reading unknown.""" + adapter = _adapter(without_values(space_less_meter("meter-a"))) + + meter = adapter.build_snapshot().circuits["meter-a"] + + assert meter.measures_outside_panel is True + assert (meter.instant_power_w, meter.consumed_energy_wh, meter.produced_energy_wh, meter.current_a) == ( + None, + None, + None, + None, + ) + assert meter.is_user_controllable is False + assert adapter.circuit_nodes_missing_names() == [] + + +def test_a_hosted_circuit_with_no_value_yet_counts_as_hosted() -> None: + """It declares its spaces before it values them, and the declaration decides.""" + adapter = _adapter(without_values(hosted_circuit("c-1", (1,)))) + + circuit = adapter.build_snapshot().circuits["c-1"] + + assert circuit.measures_outside_panel is False + assert circuit.tabs == [] + assert circuit.instant_power_w is None + assert circuit.is_user_controllable is True + assert "c-1" in adapter.circuit_nodes_missing_names() + + +def test_a_hosted_circuit_keeps_the_panel_load_frame() -> None: + """Negated power, exported energy as consumed: unchanged by the meter rule.""" + circuit = _circuit(hosted_circuit("c-1", (1,))) + + assert circuit.measures_outside_panel is False + assert circuit.instant_power_w == pytest.approx(-METER_READING.active_power_w) + assert circuit.consumed_energy_wh == pytest.approx(METER_READING.exported_energy_wh) + assert circuit.produced_energy_wh == pytest.approx(METER_READING.imported_energy_wh) + assert circuit.tabs == [1] + + +@pytest.mark.parametrize(("spaces", "is_240v"), [((1,), False), ((1, 3), True)]) +def test_a_hosted_circuit_reports_its_voltage_from_its_poles(spaces: tuple[int, ...], is_240v: bool) -> None: + assert _circuit(hosted_circuit("c-1", spaces)).is_240v is is_240v + + +def test_a_breaker_whose_pole_count_has_not_arrived_reports_no_voltage() -> None: + assert _circuit(without_values(hosted_circuit("c-1", (1, 3)), "breaker/poles")).is_240v is None + + +# --------------------------------------------------------------------------- +# Controllability follows the `switch` node, whatever the spaces +# --------------------------------------------------------------------------- + + +def test_a_hosted_circuit_without_a_switch_node_is_not_controllable() -> None: + """No relay to command, and none locked on: neither controllable nor always on.""" + device = hosted_circuit("c-1", (1,), relay=False) + adapter = _adapter(device) + + circuit = adapter.build_snapshot().circuits["c-1"] + + assert circuit.measures_outside_panel is False + assert (circuit.is_user_controllable, circuit.always_on, circuit.is_sheddable) == (False, False, False) + assert relay_is_settable(discovered(device)) is False + assert adapter.set_circuit_relay_target("c-1") is None + + +def test_an_unvalued_relay_controllable_on_a_switch_node_is_controllable() -> None: + """The property marks the exception, so a declared relay without it is controllable.""" + device = without_values(hosted_circuit("c-1", (1,)), "switch/relay-controllable") + adapter = _adapter(device) + + circuit = adapter.build_snapshot().circuits["c-1"] + + assert (circuit.is_user_controllable, circuit.always_on, circuit.is_sheddable) == (True, False, True) + assert relay_is_settable(discovered(device)) is True + assert adapter.set_circuit_relay_target("c-1") is not None + + +# --------------------------------------------------------------------------- +# The reference panel hosts every circuit +# --------------------------------------------------------------------------- + + +def test_the_reference_panel_has_no_space_less_meter() -> None: + """Every circuit of the reference tree declares its spaces, its relay and its breaker.""" + circuits = replay(parent_child_tree(), _REFERENCE_PANEL).build_snapshot().circuits + + assert circuits + assert not any(circuit.measures_outside_panel for circuit in circuits.values()) diff --git a/tests/test_schema_one_transport.py b/tests/test_schema_one_transport.py index 52cecebe..b7d3b827 100644 --- a/tests/test_schema_one_transport.py +++ b/tests/test_schema_one_transport.py @@ -147,6 +147,78 @@ def test_rerecording_a_pattern_replaces_it_and_moves_it_to_most_recent() -> None first.assert_not_called() +def test_recency_decides_an_overlap_rather_than_specificity() -> None: + """The tests above cannot tell the two rules apart. + + In each of them the more recent route is also the more specific one, so a + matcher that simply returns the most specific filter passes them. Recorded + the other way round, only recency gives the broad route the message. + """ + routes = ControllerRoutes() + narrow = MagicMock(name="device") + broad = MagicMock(name="wildcard") + routes.subscribe("ebus/5/child-a/$state", narrow) + routes.subscribe("ebus/5/+/$state", broad) + + routes.dispatch("ebus/5/child-a/$state", "ready") + + broad.assert_called_once() + narrow.assert_not_called() + + +def test_unsubscribing_a_route_leaves_its_sibling_routing() -> None: + """Routes that share a prefix share it in the matcher too, so removing + one must leave the other where it was.""" + routes = ControllerRoutes() + state = MagicMock(name="state") + description = MagicMock(name="description") + routes.subscribe("ebus/5/child-a/$state", state) + routes.subscribe("ebus/5/child-a/$description", description) + + routes.unsubscribe("ebus/5/child-a/$description") + routes.dispatch("ebus/5/child-a/$state", "ready") + routes.dispatch("ebus/5/child-a/$description", "{}") + + state.assert_called_once_with("ebus/5/child-a/$state", b"ready") + description.assert_not_called() + assert routes.held == 1 + + +def test_unsubscribing_a_route_leaves_a_longer_one_through_it_routing() -> None: + """The SDK's own shape: a device's `+/+/$target` extends its `+/+`.""" + routes = ControllerRoutes() + values = MagicMock(name="values") + targets = MagicMock(name="targets") + routes.subscribe("ebus/5/child-a/+/+", values) + routes.subscribe("ebus/5/child-a/+/+/$target", targets) + + routes.unsubscribe("ebus/5/child-a/+/+") + routes.dispatch("ebus/5/child-a/switch/relay/$target", "OPEN") + routes.dispatch("ebus/5/child-a/meter/active-power", "1.0") + + targets.assert_called_once_with("ebus/5/child-a/switch/relay/$target", b"OPEN") + values.assert_not_called() + assert routes.held == 1 + + +def test_a_route_recorded_again_after_it_was_dropped_routes_again() -> None: + """A device the SDK drops and later re-adopts: what arrived in between is + held, released to the returning route, and later messages reach it.""" + routes = ControllerRoutes() + callback = MagicMock() + routes.subscribe("ebus/5/child-a/+/+", callback) + routes.unsubscribe("ebus/5/child-a/+/+") + routes.dispatch("ebus/5/child-a/meter/active-power", "1.0") + + routes.subscribe("ebus/5/child-a/+/+", callback) + routes.dispatch("ebus/5/child-a/meter/active-power", "2.0") + + assert [call.args for call in callback.call_args_list] == [ + ("ebus/5/child-a/meter/active-power", b"1.0"), + ("ebus/5/child-a/meter/active-power", b"2.0"), + ] + + # --------------------------------------------------------------------------- # Arrival order # @@ -231,3 +303,45 @@ def test_held_messages_stop_accumulating_at_the_ceiling() -> None: callback = MagicMock() routes.subscribe("ebus/5/device-0/+/+", callback) callback.assert_called_once_with("ebus/5/device-0/meter/active-power", b"2.0") + + +def test_a_clear_takes_back_the_held_value_and_is_not_held_itself() -> None: + """A zero-length payload deletes the retained message, so the broker would replay nothing. + + Releasing the older value would bring back a reading the panel withdrew, + and holding the clear would hand the SDK an empty payload it stores as an + empty value. + """ + routes = ControllerRoutes() + callback = MagicMock() + + routes.dispatch("ebus/5/child-a/meter/active-power", "-3500.0") + routes.dispatch("ebus/5/child-a/meter/active-power", "") + routes.dispatch("ebus/5/child-a/meter/current", "") + + assert routes.held == 0 + routes.subscribe("ebus/5/child-a/+/+", callback) + callback.assert_not_called() + + +def test_a_routed_clear_is_still_delivered() -> None: + """Only the hold changes. A `$state` clear is the SDK's device removal, and it must arrive.""" + routes = ControllerRoutes() + callback = MagicMock() + routes.subscribe("ebus/5/child-a/$state", callback) + + routes.dispatch("ebus/5/child-a/$state", "") + + callback.assert_called_once_with("ebus/5/child-a/$state", b"") + + +def test_a_value_after_a_clear_is_held_and_delivered() -> None: + """Last message wins: a value published after the clear is what the broker retains.""" + routes = ControllerRoutes() + callback = MagicMock() + + routes.dispatch("ebus/5/child-a/meter/active-power", "") + routes.dispatch("ebus/5/child-a/meter/active-power", "-3400.0") + routes.subscribe("ebus/5/child-a/+/+", callback) + + callback.assert_called_once_with("ebus/5/child-a/meter/active-power", b"-3400.0") diff --git a/tests/test_schema_one_tree_export.py b/tests/test_schema_one_tree_export.py new file mode 100644 index 00000000..690b185b --- /dev/null +++ b/tests/test_schema_one_tree_export.py @@ -0,0 +1,2201 @@ +"""The masked export: each device's placeholder, and the document built with them. + +Each property runs over every vendored capture, the two main32 fixtures and the +reference tree, and selects what to check by what each tree declares. The +expected masks are restated here from the design rather than read from the +module, so a rule changed there fails here. +""" + +from __future__ import annotations + +from collections import Counter +from collections.abc import Mapping +from dataclasses import dataclass +import hashlib +from importlib.metadata import PackageNotFoundError, version +import json +from pathlib import Path +import re +import time + +from ebus_panel_sim.capture import definition_from_tree, tree_from_snapshot +from ebus_sdk.homie import DiscoveredDevice +import pytest + +from span_panel_api.models import MaskedTree, MaskedTreeDevice, SpanPanelSnapshot +from span_panel_api.protocol import TreeExportingAdapter +from span_panel_api_schema_0 import SchemaZeroAdapter +from span_panel_api_schema_1 import SchemaOneAdapter, adapter as schema_one_adapter +from span_panel_api_schema_1.tree_export import export_masked_tree, natural_key, placeholder_ids + +from conftest import flat_schema, parent_child_schema +from reference_payloads.captures import CAPTURES, capture_adapter, capture_path, capture_tree, capture_tree_from_document +from reference_payloads.reidentify import reidentify, rename_devices +from reference_payloads.schema_one import RetainedTopicTree, devices_from_tree, parent_child_tree, replay +from reference_payloads.synthetic_trees import SyntheticDevice, panel, tree + +_FIXTURES = Path(__file__).parent / "fixtures" +_MAIN32_FIXTURES = ("main32-tree-v1.json", "main32_r202639-tree-v1.json") +_REFERENCE_ROOT = "example-40t-001" +_NEW_ROOT = "synthetic-root-0001" +_SPACES = "info/spaces" +_DIRECTION = "info/direction" +_TYPE_CIRCUIT = "energy.ebus.device.circuit" +_TYPE_LUGS = "energy.ebus.device.lugs" +_TYPE_MID = "energy.ebus.device.mid" +_GENERATOR_IDS = [f"g-{n}" for n in range(2, 12)] + + +@dataclass(frozen=True) +class Case: + name: str + topics: RetainedTopicTree + root_id: str + source: Path | None = None + """The `tree-v1` file the case was read from; None for the retained-topic reference tree.""" + + def __repr__(self) -> str: + return self.name + + +def _main32_case(file_name: str) -> Case: + document: object = json.loads((_FIXTURES / file_name).read_text(encoding="utf-8")) + assert isinstance(document, dict) + captured = capture_tree_from_document(document, file_name) + return Case(file_name, captured.retained(), captured.root_id, _FIXTURES / file_name) + + +def _cases() -> list[Case]: + captures = [ + Case(stem, capture_tree(stem).retained(), capture_tree(stem).root_id, capture_path(stem)) for stem in CAPTURES + ] + return [ + *captures, + *(_main32_case(name) for name in _MAIN32_FIXTURES), + Case("reference", parent_child_tree(), _REFERENCE_ROOT), + ] + + +CASES = _cases() +every_tree = pytest.mark.parametrize("case", CASES, ids=repr) + + +def _ids_of(adapter: SchemaOneAdapter, root_id: str) -> dict[str, str]: + root = adapter._controller.get_root(root_id) + assert root is not None + return placeholder_ids(root, adapter._children()) + + +def _placeholders(topics: RetainedTopicTree, root_id: str) -> dict[str, str]: + return _ids_of(replay(topics, root_id), root_id) + + +def _value(device: DiscoveredDevice, topic: str) -> str | None: + node, _, prop = topic.partition("/") + value = device.properties.get(node, {}).get(prop) + return None if value is None else str(value) + + +def _of_type(case: Case, device_type: str) -> list[DiscoveredDevice]: + return [ + device + for device in devices_from_tree(case.topics) + if device.description is not None and device.description.get("type") == device_type + ] + + +@every_tree +def test_every_placeholder_is_prefixed(case: Case) -> None: + ids = _placeholders(case.topics, case.root_id) + assert set(ids) == set(case.topics) + assert all(placeholder.startswith("masked-") for placeholder in ids.values()) + assert len(set(ids.values())) == len(ids) + + +@every_tree +def test_circuits_are_numbered_by_first_breaker_space(case: Case) -> None: + ids = _placeholders(case.topics, case.root_id) + hosted = [ + (min(int(space) for space in re.findall(r"[0-9]+", spaces)), device.device_id) + for device in _of_type(case, _TYPE_CIRCUIT) + if (spaces := _value(device, _SPACES)) + ] + assert hosted, "no circuit publishes info/spaces" + in_space_order = [device_id for _, device_id in sorted(hosted, key=lambda entry: (entry[0], natural_key(entry[1])))] + assert [ids[device_id] for device_id in in_space_order] == [f"masked-circuit-{n}" for n in range(1, len(hosted) + 1)] + + +@every_tree +def test_lugs_take_their_direction(case: Case) -> None: + ids = _placeholders(case.topics, case.root_id) + lugs = {_value(device, _DIRECTION): device.device_id for device in _of_type(case, _TYPE_LUGS)} + assert {"UPSTREAM", "DOWNSTREAM"} <= lugs.keys() + assert ids[lugs["UPSTREAM"]] == "masked-lugs-upstream" + assert ids[lugs["DOWNSTREAM"]] == "masked-lugs-downstream" + + +def _generators(ids: list[str]) -> RetainedTopicTree: + return tree( + panel(), + *( + SyntheticDevice( + device_id=device_id, device_type="energy.ebus.device.generator", name="Generator", nodes={}, values={} + ) + for device_id in ids + ), + ) + + +@pytest.mark.parametrize("case", [*CASES, Case("many-generators", _generators(_GENERATOR_IDS), "panel-a")], ids=repr) +def test_placeholders_survive_an_id_change(case: Case) -> None: + rank = {device_id: position for position, device_id in enumerate(sorted(case.topics, key=natural_key), start=1)} + + def new_id(old: str) -> str: + return _NEW_ROOT if old == case.root_id else f"{_NEW_ROOT}-renamed-{rank[old]}" + + renamed, new_root = rename_devices(case.topics, case.root_id, new_id) + before = _placeholders(case.topics, case.root_id) + after = _placeholders(renamed, new_root) + assert {new_id(old): placeholder for old, placeholder in before.items()} == after + + +def test_natural_order_compares_numbers() -> None: + ids = ["g-1", "g-2", "g-3", "g-10", "g-11"] + placeholders = _placeholders(_generators(list(reversed(ids))), "panel-a") + assert [placeholders[device_id] for device_id in ids] == [f"masked-generator-{n}" for n in range(1, 6)] + + +def test_an_undescribed_device_is_named_as_such() -> None: + topics = parent_child_tree() + withheld = "pv" + adapter = replay(topics, _REFERENCE_ROOT, withhold_description_of=withheld) + ids = _ids_of(adapter, _REFERENCE_ROOT) + assert ids[withheld] == "masked-undescribed-1" + assert len(set(ids.values())) == len(ids) + assert not any("pv" in placeholder for placeholder in ids.values()) + + +def test_lugs_without_a_usable_direction_are_numbered() -> None: + topics = {device_id: dict(values) for device_id, values in parent_child_tree().items()} + topics["lugs-downstream"]["info/direction"] = "UPSTREAM" + topics["lugs-upstream"].pop("info/direction") + ids = _placeholders(topics, _REFERENCE_ROOT) + assert ids["lugs-downstream"] == "masked-lugs-upstream" + assert ids["lugs-upstream"] == "masked-lugs-1" + + +def test_a_second_lugs_claiming_a_taken_direction_is_numbered() -> None: + topics = {device_id: dict(values) for device_id, values in parent_child_tree().items()} + topics["lugs-downstream"]["info/direction"] = "UPSTREAM" + ids = _placeholders(topics, _REFERENCE_ROOT) + assert ids["lugs-downstream"] == "masked-lugs-upstream" + assert ids["lugs-upstream"] == "masked-lugs-1" + assert len(set(ids.values())) == len(ids) + + +def _retyped_placeholders(declared: str, replacement: str) -> dict[str, str]: + """The reference tree's placeholders with every device declaring exactly `declared` declaring `replacement`.""" + topics = {device_id: dict(values) for device_id, values in parent_child_tree().items()} + for values in topics.values(): + description = json.loads(values["$description"]) + if description.get("type") == declared: + description["type"] = replacement + values["$description"] = json.dumps(description) + return _placeholders(topics, _REFERENCE_ROOT) + + +@pytest.mark.parametrize("declared", [_TYPE_CIRCUIT, _TYPE_LUGS]) +def test_a_subtyped_circuit_or_lugs_is_placed_as_its_class(declared: str) -> None: + """A `circuit.` is numbered by breaker space and a `lugs.` takes its direction (#228).""" + assert _retyped_placeholders(declared, f"{declared}.hybrid") == _placeholders(parent_child_tree(), _REFERENCE_ROOT) + + +@pytest.mark.parametrize("declared", [_TYPE_CIRCUIT, _TYPE_LUGS]) +def test_a_look_alike_of_a_circuit_or_lugs_is_numbered_by_its_own_type(declared: str) -> None: + """`circuitfoo` and `lugsfoo` are other classes: numbered per short type, like any other device.""" + base_short = declared.removeprefix("energy.ebus.device.") + retyped = sorted( + device_id + for device_id, placeholder in _placeholders(parent_child_tree(), _REFERENCE_ROOT).items() + if placeholder.startswith(f"masked-{base_short}-") + ) + assert retyped, f"precondition: the reference tree carries a {declared} device" + + ids = _retyped_placeholders(declared, f"{declared}foo") + assert sorted(ids[device_id] for device_id in retyped) == sorted( + f"masked-{base_short}foo-{n}" for n in range(1, len(retyped) + 1) + ) + + +def test_ids_tied_in_natural_order_are_named_the_same_in_any_input_order() -> None: + tied = ["g-1", "g-01", "G-1", "g-2"] + assert len({natural_key(device_id) for device_id in tied[:3]}) == 1 + devices = devices_from_tree(_generators(tied)) + root, children = devices[0], devices[1:] + forward = placeholder_ids(root, children) + assert placeholder_ids(root, list(reversed(children))) == forward + assert placeholder_ids(root, children[1:] + children[:1]) == forward + assert len(set(forward.values())) == len(forward) + + +# The document. Masks and kept values as the design states them (§4.3). + +_PRODUCER = "span-panel-api-schema-1 0.0.0" +_SERIAL = "info/serial-number" +_NAME = "info/name" +_MASKED_PANEL = "Masked Panel" +_SITE_MASKS: Mapping[str, str] = { + "info/utility-meter-serial-number": "MASKED-METER", + "status/wifi-ssid": "masked-ssid", + "status/postal-code": "00000", + "info/address-lines": "Masked Address", + "info/locality": "Masked City", + "info/region": "Masked Region", + "info/latitude": "0.0", + "info/longitude": "0.0", + "status/time-zone": "UTC", + "info/country-code": "ZZ", +} +_FEEDS = "connection/feeds-device-id" +_FED_BY = "connection/fed-by-device-id" +_GRID_FORMING = "grid/grid-forming-entity" +_SHARED_WITH = "meter/shared-with-device-ids" +_LIST_SUFFIX = "/shared-with-device-ids" +_NUMERIC = ("integer", "float") +_MISSING = re.compile(r"masked-missing-[1-9][0-9]*") +_SEEDED_SITE: Mapping[str, tuple[str, str]] = { + "info/utility-meter-serial-number": ("SEEDED-METER-77", "string"), + "status/wifi-ssid": ("seeded-network", "string"), + "status/postal-code": ("98000", "string"), + "info/address-lines": ("4821 Seeded Lane", "string"), + "info/locality": ("Seededville", "string"), + "info/region": ("ZQ", "string"), + "info/latitude": ("47.6", "float"), + "info/longitude": ("-122.3", "float"), + _NAME: ("Seeded Residence", "string"), + "info/country-code": ("QZ", "string"), + "status/time-zone": ("Etc/GMT+9", "string"), +} +_SEEDED_LABEL = "Seeded Lugs Label" + + +def _object(value: object) -> dict[str, object]: + assert isinstance(value, dict) + return {str(key): item for key, item in value.items()} + + +def _description_of(topics: Mapping[str, str]) -> dict[str, object]: + return _object(json.loads(topics["$description"])) + + +def _declared(description: Mapping[str, object]) -> dict[str, str]: + """`node/property` -> declared datatype, for every property the description declares.""" + return { + f"{node_id}/{property_id}": str(_object(definition).get("datatype")) + for node_id, node in _object(description.get("nodes")).items() + for property_id, definition in _object(_object(node).get("properties")).items() + } + + +def _published(topics: Mapping[str, str]) -> dict[str, str]: + """The retained values of one device, without its `$` attributes or `$target`s.""" + return {topic: value for topic, value in topics.items() if not topic.startswith("$") and "/$" not in topic} + + +def _type_of(topics: Mapping[str, str]) -> str: + return str(_description_of(topics).get("type")) + + +def _declaring(topics: RetainedTopicTree, topic: str, device_type: str | None = None) -> list[str]: + """Devices that declare `topic`, optionally of one type, in natural id order.""" + return [ + device_id + for device_id in sorted(topics, key=natural_key) + if topic in _declared(_description_of(topics[device_id])) + and (device_type is None or _type_of(topics[device_id]) == device_type) + ] + + +def _copy(topics: RetainedTopicTree) -> dict[str, dict[str, str]]: + return {device_id: dict(values) for device_id, values in topics.items()} + + +def _export(adapter: SchemaOneAdapter, root_id: str, *, tree_complete: bool = True) -> MaskedTree: + root = adapter._controller.get_root(root_id) + assert root is not None + return export_masked_tree(root, adapter._children(), producer=_PRODUCER, tree_complete=tree_complete) + + +def _exported(topics: RetainedTopicTree, root_id: str) -> tuple[MaskedTree, dict[str, str]]: + adapter = replay(topics, root_id) + return _export(adapter, root_id), _ids_of(adapter, root_id) + + +def _valued(entry: MaskedTreeDevice) -> dict[str, str]: + """Every value the export carries for a described device; the three maps never share a key.""" + maps = (entry["properties"], entry["numeric_properties"], entry["undeclared_properties"]) + merged = {topic: value for values in maps for topic, value in values.items()} + assert len(merged) == sum(len(values) for values in maps) + return merged + + +def _is_reference(topic: str) -> bool: + return topic in (_FEEDS, _FED_BY, _GRID_FORMING) or topic.endswith(_LIST_SUFFIX) + + +def _named(topic: str, value: str) -> list[str]: + """The ids an id-valued property names as published: list elements trimmed, the grid itself none.""" + if topic.endswith(_LIST_SUFFIX): + return [part.strip() for part in value.split(",") if part.strip()] + if topic == _GRID_FORMING and value.strip().upper() == "GRID": + return [] + return [value] if value else [] + + +def _assert_resolves(topic: str, published: str, exported: str, ids: Mapping[str, str], missing: dict[str, str]) -> None: + """Each id the value names is its device's placeholder, or one `masked-missing-` per absent id.""" + named = _named(topic, published) + if topic == _GRID_FORMING and not named: + assert exported == published + return + placeholders = exported.split(",") if topic.endswith(_LIST_SUFFIX) and exported else [exported] if exported else [] + assert len(placeholders) == len(named), (topic, published, exported) + for original, placeholder in zip(named, placeholders, strict=True): + if original in ids: + assert placeholder == ids[original], (topic, original) + else: + assert _MISSING.fullmatch(placeholder), (topic, original, placeholder) + assert missing.setdefault(original, placeholder) == placeholder + + +def _property_id(topic: str) -> str: + return topic.partition("/")[2] + + +_SERIAL_ID = _property_id(_SERIAL) +_MASKS_BY_PROPERTY: Mapping[str, str] = {_property_id(topic): mask for topic, mask in _SITE_MASKS.items()} +"""The site masks by property id: they apply on whichever node publishes the property.""" +_SEEDED_BY_PROPERTY: Mapping[str, tuple[str, str]] = { + **{_property_id(topic): seeded for topic, seeded in _SEEDED_SITE.items() if _property_id(topic) in _MASKS_BY_PROPERTY}, + _SERIAL_ID: ("SEEDSN00001", "string"), +} +"""A seeded value and datatype for every property id masked on any node.""" + + +def _label(name: object, ids: Mapping[str, str]) -> object: + """A description `name` as exported: one that is a device id is that device's placeholder, any other as published. + + The captures name many devices by their id, and the sweep finds the id. + """ + return ids.get(name, name) if isinstance(name, str) else name + + +def _assert_masked( + topic: str, + published: str, + exported: str, + *, + owner: str, + root_id: str, + ids: Mapping[str, str], + missing: dict[str, str], +) -> None: + """The exported value is the published one with the design's masks applied, and nothing else changed.""" + if published == "": + assert exported == "" + elif owner == root_id and topic == _NAME: + assert exported == _MASKED_PANEL + elif _property_id(topic) == _SERIAL_ID: + assert exported == ids[owner].upper() + elif _property_id(topic) in _MASKS_BY_PROPERTY: + assert exported == _MASKS_BY_PROPERTY[_property_id(topic)] + elif _is_reference(topic): + _assert_resolves(topic, published, exported, ids, missing) + else: + assert exported == published, topic + + +def _declare(description: dict[str, object], topic: str, datatype: str) -> None: + """Add `topic` to a description's declarations unless it is already declared.""" + node_id, _, property_id = topic.partition("/") + nodes = description.setdefault("nodes", {}) + assert isinstance(nodes, dict) + node = nodes.setdefault(node_id, {"name": node_id, "type": f"energy.ebus.capability.{node_id}", "properties": {}}) + assert isinstance(node, dict) + declared = node.setdefault("properties", {}) + assert isinstance(declared, dict) + declared.setdefault(property_id, {"name": property_id, "datatype": datatype}) + + +def _seeded(case: Case) -> tuple[dict[str, dict[str, str]], str]: + """The tree with every masked and kept property declared and valued with a seeded value. + + Every device declares and publishes a distinct serial; the panel declares + and publishes every site property and a seeded `$description` name; one + device that is neither the panel nor a circuit declares and publishes an + `info/name` of its own, returned beside the tree. + """ + topics = _copy(case.topics) + labelled = next( + device_id + for device_id in sorted(topics, key=natural_key) + if device_id != case.root_id and _type_of(topics[device_id]) != _TYPE_CIRCUIT + ) + for number, device_id in enumerate(sorted(topics, key=natural_key), start=1): + description = _description_of(topics[device_id]) + _declare(description, _SERIAL, "string") + topics[device_id][_SERIAL] = f"SEEDSN{number:05d}" + if device_id == case.root_id: + for topic, (value, datatype) in _SEEDED_SITE.items(): + _declare(description, topic, datatype) + topics[device_id][topic] = value + description["name"] = _SEEDED_SITE[_NAME][0] + if device_id == labelled: + _declare(description, _NAME, "string") + topics[device_id][_NAME] = _SEEDED_LABEL + topics[device_id]["$description"] = json.dumps(description) + return topics, labelled + + +_TREE_V1_CASES = [case for case in CASES if case.source is not None] + + +@pytest.mark.parametrize("case", _TREE_V1_CASES, ids=repr) +def test_split_matches_the_captures(case: Case) -> None: + assert case.source is not None + export, ids = _exported(case.topics, case.root_id) + devices = _object(_object(json.loads(case.source.read_text(encoding="utf-8")))["devices"]) + assert set(export["devices"]) == {ids[device_id] for device_id in devices} + for device_id, body in devices.items(): + entry = export["devices"][ids[device_id]] + assert set(entry["properties"]) == set(_object(_object(body)["properties"])), device_id + assert set(entry["numeric_properties"]) == set(_object(_object(body)["numeric_properties"])), device_id + + +@every_tree +def test_nothing_is_lost(case: Case) -> None: + export, ids = _exported(case.topics, case.root_id) + assert export["metadata"] == {"schema": "tree-v1", "masked": True, "producer": _PRODUCER, "tree_complete": True} + assert export["undescribed_devices"] == {} + assert set(export["devices"]) == {ids[device_id] for device_id in case.topics} + missing: dict[str, str] = {} + for device_id, topics in case.topics.items(): + entry = export["devices"][ids[device_id]] + declared = _declared(_description_of(topics)) + assert _declared(entry["description"]) == declared + published = _published(topics) + exported = _valued(entry) + assert exported.keys() == published.keys(), device_id + for topic, value in published.items(): + _assert_masked(topic, value, exported[topic], owner=device_id, root_id=case.root_id, ids=ids, missing=missing) + assert set(entry["numeric_properties"]) == {topic for topic in published if declared.get(topic) in _NUMERIC} + assert set(entry["undeclared_properties"]) == published.keys() - declared.keys() + assert entry["targets"] == {} + assert entry.get("state") == topics.get("$state", "ready") + assert len(set(missing.values())) == len(missing) + + +@every_tree +def test_descriptions_are_published_with_their_references_mapped(case: Case) -> None: + export, ids = _exported(case.topics, case.root_id) + for device_id, topics in case.topics.items(): + expected = _description_of(topics) + for key in ("parent", "root"): + if key in expected: + expected[key] = ids[str(expected[key])] + children = expected.get("children") + if isinstance(children, list): + expected["children"] = [ids[str(child)] for child in children] + if device_id == case.root_id and "name" in expected: + expected["name"] = _MASKED_PANEL + elif "name" in expected: + expected["name"] = _label(expected["name"], ids) + assert export["devices"][ids[device_id]]["description"] == expected, device_id + + +@every_tree +def test_the_export_leaves_the_tree_as_it_was(case: Case) -> None: + adapter = replay(case.topics, case.root_id) + root = adapter._controller.get_root(case.root_id) + assert root is not None + devices = [root, *adapter._children()] + + def state() -> str: + return json.dumps( + [(device.description, device.properties, device.property_targets, device.state) for device in devices] + ) + + before = state() + export_masked_tree(root, devices[1:], producer=_PRODUCER, tree_complete=True) + assert state() == before + + +@every_tree +def test_the_document_does_not_depend_on_discovery_order(case: Case) -> None: + adapter = replay(case.topics, case.root_id) + root = adapter._controller.get_root(case.root_id) + assert root is not None + children = adapter._children() + forward = export_masked_tree(root, children, producer=_PRODUCER, tree_complete=True) + backward = export_masked_tree(root, list(reversed(children)), producer=_PRODUCER, tree_complete=True) + assert json.dumps(backward) == json.dumps(forward) + + +@every_tree +def test_an_empty_value_stays_empty(case: Case) -> None: + topics = _copy(case.topics) + declared = _declared(_description_of(topics[case.root_id])) + plain = [ + topic + for topic in sorted(declared) + if _property_id(topic) not in {*_MASKS_BY_PROPERTY, _SERIAL_ID} and topic != _NAME and not _is_reference(topic) + ] + text = next(topic for topic in plain if declared[topic] not in _NUMERIC) + number = next(topic for topic in plain if declared[topic] in _NUMERIC) + topics[case.root_id][text] = "" + topics[case.root_id][number] = "" + export, _ = _exported(topics, case.root_id) + entry = export["devices"]["masked-panel"] + assert entry["properties"][text] == "" + assert entry["numeric_properties"][number] == "" + + +def test_an_empty_masked_or_referencing_value_stays_empty() -> None: + topics = _copy(parent_child_tree()) + circuit = _declaring(topics, _FEEDS, _TYPE_CIRCUIT)[0] + for topic in (_SERIAL, "status/postal-code", "status/wifi-ssid"): + topics[_REFERENCE_ROOT][topic] = "" + topics[circuit][_FEEDS] = "" + export, ids = _exported(topics, _REFERENCE_ROOT) + panel_values = _valued(export["devices"]["masked-panel"]) + assert {topic: panel_values[topic] for topic in (_SERIAL, "status/postal-code", "status/wifi-ssid")} == { + _SERIAL: "", + "status/postal-code": "", + "status/wifi-ssid": "", + } + assert _valued(export["devices"][ids[circuit]])[_FEEDS] == "" + + +@every_tree +def test_an_undeclared_value_is_kept_apart(case: Case) -> None: + topics = _copy(case.topics) + topics[case.root_id]["vendor/extra"] = "seeded-extra" + export, _ = _exported(topics, case.root_id) + entry = export["devices"]["masked-panel"] + assert entry["undeclared_properties"] == {"vendor/extra": "seeded-extra"} + assert "vendor/extra" not in entry["properties"] + assert "vendor/extra" not in entry["numeric_properties"] + + +def test_an_undeclared_value_is_masked_by_its_name() -> None: + topics = _copy(parent_child_tree()) + circuit = _declaring(topics, _FEEDS, _TYPE_CIRCUIT)[0] + root_declares = _declared(_description_of(topics[_REFERENCE_ROOT])) + circuit_declares = _declared(_description_of(topics[circuit])) + assert "info/address-lines" not in root_declares + assert _SERIAL not in circuit_declares + assert _FED_BY not in circuit_declares + topics[_REFERENCE_ROOT]["info/address-lines"] = "4821 Seeded Lane" + topics[circuit][_SERIAL] = "SEEDSN00001" + topics[circuit][_FED_BY] = "bess" + export, ids = _exported(topics, _REFERENCE_ROOT) + assert export["devices"]["masked-panel"]["undeclared_properties"] == {"info/address-lines": "Masked Address"} + assert export["devices"][ids[circuit]]["undeclared_properties"] == { + _SERIAL: ids[circuit].upper(), + _FED_BY: ids["bess"], + } + + +@every_tree +def test_references_resolve(case: Case) -> None: + export, ids = _exported(case.topics, case.root_id) + missing: dict[str, str] = {} + for device_id, topics in case.topics.items(): + exported = _valued(export["devices"][ids[device_id]]) + for topic, value in _published(topics).items(): + if _is_reference(topic) and value: + _assert_resolves(topic, value, exported[topic], ids, missing) + assert len(set(missing.values())) == len(missing) + assert not set(missing.values()) & set(ids.values()) + + +def test_every_kind_of_reference_is_exercised() -> None: + """`test_references_resolve` checks what each tree publishes; across them, every kind is published.""" + named = [ + (topic, original, case.topics) + for case in CASES + for topics in case.topics.values() + for topic, value in _published(topics).items() + if _is_reference(topic) + for original in _named(topic, value) + ] + kinds = {_LIST_SUFFIX if topic.endswith(_LIST_SUFFIX) else topic for topic, _, _ in named} + assert {_FEEDS, _FED_BY, _LIST_SUFFIX} <= kinds + assert any(original not in topics for _, original, topics in named), "no tree publishes a dangling reference" + + +def test_a_dangling_reference_is_masked_missing() -> None: + topics = _copy(parent_child_tree()) + circuits = _declaring(topics, _FEEDS, _TYPE_CIRCUIT)[:2] + for circuit in circuits: + topics[circuit][_FEEDS] = "absent-device-1" + export, ids = _exported(topics, _REFERENCE_ROOT) + assert [_valued(export["devices"][ids[circuit]])[_FEEDS] for circuit in circuits] == ["masked-missing-1"] * 2 + + +def test_dangling_references_are_numbered_in_placeholder_order() -> None: + topics = _copy(parent_child_tree()) + ids = _placeholders(topics, _REFERENCE_ROOT) + first, second, third = sorted(_declaring(topics, _FEEDS, _TYPE_CIRCUIT), key=lambda device: natural_key(ids[device]))[:3] + topics[first][_FEEDS] = "absent-device-2" + topics[second][_FEEDS] = "absent-device-1" + topics[third][_FEEDS] = "absent-device-2" + export, ids = _exported(topics, _REFERENCE_ROOT) + assert [_valued(export["devices"][ids[circuit]])[_FEEDS] for circuit in (first, second, third)] == [ + "masked-missing-1", + "masked-missing-2", + "masked-missing-1", + ] + + +def _a_reference(case: Case) -> tuple[str, str, str] | None: + """The first published connection id naming a device of the tree other than the panel.""" + for device_id in sorted(case.topics, key=natural_key): + for topic, value in sorted(_published(case.topics[device_id]).items()): + if topic in (_FEEDS, _FED_BY) and value in case.topics and value != case.root_id: + return device_id, topic, value + return None + + +_REFERRING_CASES = [case for case in CASES if _a_reference(case) is not None] + + +@pytest.mark.parametrize("case", _REFERRING_CASES, ids=repr) +def test_a_reference_to_an_undescribed_device_resolves(case: Case) -> None: + reference = _a_reference(case) + assert reference is not None + referrer, topic, target = reference + adapter = replay(case.topics, case.root_id, withhold_description_of=target) + ids = _ids_of(adapter, case.root_id) + export = _export(adapter, case.root_id, tree_complete=False) + assert ids[target].startswith("masked-undescribed-") + assert ids[target] in export["undescribed_devices"] + assert _valued(export["devices"][ids[referrer]])[topic] == ids[target] + + +_SHARING_CASES = [case for case in CASES if len(_declaring(case.topics, _SHARED_WITH)) >= 3] + + +@pytest.mark.parametrize("case", _SHARING_CASES, ids=repr) +def test_shared_with_lists_are_trimmed(case: Case) -> None: + topics = _copy(case.topics) + listed, emptied, gapped = _declaring(topics, _SHARED_WITH)[:3] + a, b = [device_id for device_id in sorted(topics, key=natural_key) if device_id not in (listed, emptied, gapped)][:2] + topics[listed][_SHARED_WITH] = f"{a}, {b}" + topics[emptied][_SHARED_WITH] = "" + topics[gapped][_SHARED_WITH] = f" {b},, {a} ," + export, ids = _exported(topics, case.root_id) + assert _valued(export["devices"][ids[listed]])[_SHARED_WITH] == f"{ids[a]},{ids[b]}" + assert _valued(export["devices"][ids[emptied]])[_SHARED_WITH] == "" + assert _valued(export["devices"][ids[gapped]])[_SHARED_WITH] == f"{ids[b]},{ids[a]}" + + +_MID_CASES = [case for case in CASES if _declaring(case.topics, _GRID_FORMING, _TYPE_MID)] + + +@pytest.mark.parametrize("case", _MID_CASES, ids=repr) +def test_the_grid_forming_entity_is_the_grid_or_a_device(case: Case) -> None: + mid = _declaring(case.topics, _GRID_FORMING, _TYPE_MID)[0] + parent = str(_description_of(case.topics[mid])["parent"]) + for published, expected in (("GRID", "GRID"), (" Grid", " Grid"), (parent, None)): + topics = _copy(case.topics) + topics[mid][_GRID_FORMING] = published + export, ids = _exported(topics, case.root_id) + assert _valued(export["devices"][ids[mid]])[_GRID_FORMING] == (ids[parent] if expected is None else expected) + + +def test_targets_are_kept_and_masked_like_values() -> None: + topics = _copy(parent_child_tree()) + circuit = _declaring(topics, "switch/relay", _TYPE_CIRCUIT)[0] + mid = _declaring(topics, _GRID_FORMING, _TYPE_MID)[0] + parent = str(_description_of(topics[mid])["parent"]) + topics[circuit]["switch/relay/$target"] = "OPEN" + topics[mid][f"{_GRID_FORMING}/$target"] = parent + export, ids = _exported(topics, _REFERENCE_ROOT) + assert export["devices"][ids[circuit]]["targets"] == {"switch/relay": "OPEN"} + assert export["devices"][ids[mid]]["targets"] == {_GRID_FORMING: ids[parent]} + + +@every_tree +def test_site_values_are_masked(case: Case) -> None: + topics, _ = _seeded(case) + export, ids = _exported(topics, case.root_id) + entry = export["devices"]["masked-panel"] + values = _valued(entry) + assert {topic: values[topic] for topic in _SITE_MASKS} == _SITE_MASKS + assert values[_NAME] == _MASKED_PANEL + assert entry["description"]["name"] == _MASKED_PANEL + assert entry["numeric_properties"]["info/latitude"] == "0.0" + assert entry["numeric_properties"]["info/longitude"] == "0.0" + for device_id in topics: + assert _valued(export["devices"][ids[device_id]])[_SERIAL] == ids[device_id].upper(), device_id + + +@every_tree +def test_kept_values_are_published(case: Case) -> None: + topics, labelled = _seeded(case) + export, ids = _exported(topics, case.root_id) + panel_values = _valued(export["devices"]["masked-panel"]) + label = export["devices"][ids[labelled]] + assert _valued(label)[_NAME] == _SEEDED_LABEL + assert label["description"]["name"] == _label(_description_of(topics[labelled])["name"], ids) + circuits = _declaring(topics, _NAME, _TYPE_CIRCUIT) + assert circuits + for circuit in circuits: + entry = export["devices"][ids[circuit]] + assert _valued(entry)[_NAME] == topics[circuit][_NAME] + assert entry["description"]["name"] == _label(_description_of(topics[circuit])["name"], ids) + + +def _identity_free(snapshot: SpanPanelSnapshot) -> dict[str, object]: + """The snapshot fields that carry no identity, with id-keyed collections as multisets of values.""" + return { + "circuit count": len(snapshot.circuits), + "circuits": Counter( + (circuit.name, tuple(circuit.tabs), circuit.instant_power_w, circuit.relay_state, circuit.priority) + for circuit in snapshot.circuits.values() + ), + "battery.present": snapshot.battery.present, + "battery.soe_percentage": snapshot.battery.soe_percentage, + "battery.power_w": snapshot.battery.power_w, + "pv_inverters": len(snapshot.pv_inverters), + "evse": len(snapshot.evse), + "mid": snapshot.mid is not None, + "lugs_at_service_entrance": snapshot.lugs_at_service_entrance, + "instant_grid_power_w": snapshot.instant_grid_power_w, + "power_flow_pv": snapshot.power_flow_pv, + "power_flow_battery": snapshot.power_flow_battery, + "power_flow_grid": snapshot.power_flow_grid, + "power_flow_site": snapshot.power_flow_site, + "firmware_version": snapshot.firmware_version, + "panel_size": snapshot.panel_size, + } + + +@every_tree +def test_it_replays(case: Case) -> None: + export, _ = _exported(case.topics, case.root_id) + captured = capture_tree_from_document(_object(json.loads(json.dumps(export))), "export") + assert captured.root_id == "masked-panel" + original = replay(case.topics, case.root_id) + again = replay(captured.retained(), captured.root_id) + assert again.is_ready() + assert _identity_free(again.build_snapshot()) == _identity_free(original.build_snapshot()) + + +@every_tree +def test_partial_tree_exports(case: Case) -> None: + withheld = _declaring(case.topics, _SPACES, _TYPE_CIRCUIT)[0] + adapter = replay(case.topics, case.root_id, withhold_description_of=withheld) + complete = adapter._controller.is_tree_complete(case.root_id) + assert complete is False + export = _export(adapter, case.root_id, tree_complete=complete) + ids = _ids_of(adapter, case.root_id) + placeholder = ids[withheld] + assert export["metadata"]["tree_complete"] is False + assert placeholder not in export["devices"] + assert set(export["undescribed_devices"]) == {placeholder} + entry = export["undescribed_devices"][placeholder] + published = _published(case.topics[withheld]) + assert entry["values"].keys() == published.keys() + missing: dict[str, str] = {} + for topic, value in published.items(): + _assert_masked(topic, value, entry["values"][topic], owner=withheld, root_id=case.root_id, ids=ids, missing=missing) + assert entry["targets"] == {} + assert "state" not in entry + + +def test_an_undescribed_device_is_masked_by_the_same_rules() -> None: + topics = _copy(parent_child_tree()) + topics["pv"][_SERIAL] = "SEEDSN00001" + topics["pv"]["status/postal-code"] = "98000" + topics["pv"][_FEEDS] = "evse" + topics["pv"][f"{_FED_BY}/$target"] = "absent-device-1" + adapter = replay(topics, _REFERENCE_ROOT, withhold_description_of="pv") + ids = _ids_of(adapter, _REFERENCE_ROOT) + entry = _export(adapter, _REFERENCE_ROOT, tree_complete=False)["undescribed_devices"][ids["pv"]] + assert {topic: entry["values"][topic] for topic in (_SERIAL, "status/postal-code", _FEEDS)} == { + _SERIAL: ids["pv"].upper(), + "status/postal-code": "00000", + _FEEDS: ids["evse"], + } + assert entry["targets"] == {_FED_BY: "masked-missing-1"} + + +@pytest.mark.parametrize("payload", ["[1, 2]", '"a string"'], ids=["list", "string"]) +def test_a_description_that_is_not_an_object_is_undescribed(payload: str) -> None: + """Valid JSON that is not an object describes nothing: the device is undescribed, its values masked. + + Built from the devices directly rather than replayed: the eBus SDK (0.22.0) + raises on such a description itself, in `children_ids`, so no adapter can be + replayed into this state; the exporter is still total over it. + """ + topics = _copy(parent_child_tree()) + topics["pv"]["$description"] = payload + topics["pv"][_SERIAL] = "SEEDSN00001" + devices = devices_from_tree(topics) + root = next(device for device in devices if device.device_id == _REFERENCE_ROOT) + children = [device for device in devices if device is not root] + ids = placeholder_ids(root, children) + export = export_masked_tree(root, children, producer=_PRODUCER, tree_complete=False) + assert ids["pv"] == "masked-undescribed-1" + assert len(set(ids.values())) == len(ids) + assert ids["pv"] not in export["devices"] + entry = export["undescribed_devices"][ids["pv"]] + assert entry["values"][_SERIAL] == "MASKED-UNDESCRIBED-1" + assert entry["values"].keys() == _published(topics["pv"]).keys() + assert entry["state"] == "ready" + children_named = export["devices"]["masked-panel"]["description"]["children"] + assert isinstance(children_named, list) + assert ids["pv"] in children_named + + +@pytest.mark.parametrize("node", ["site", "vendor"]) +def test_site_and_serial_values_are_masked_on_any_node(node: str) -> None: + """A site or serial property is masked by its id, whichever node declares or publishes it.""" + topics = _copy(parent_child_tree()) + circuit = _declaring(topics, _FEEDS, _TYPE_CIRCUIT)[0] + description = _description_of(topics[_REFERENCE_ROOT]) + planted = {f"{node}/{property_id}": value for property_id, (value, _) in _SEEDED_BY_PROPERTY.items()} + for topic, value in planted.items(): + _declare(description, topic, _SEEDED_BY_PROPERTY[_property_id(topic)][1]) + topics[_REFERENCE_ROOT][topic] = value + topics[_REFERENCE_ROOT]["$description"] = json.dumps(description) + kept = {f"{node}/name": "Seeded Site Label"} + topics[_REFERENCE_ROOT].update(kept) + topics[circuit][f"{node}/serial-number"] = "SEEDSN00002" + export, ids = _exported(topics, _REFERENCE_ROOT) + panel_values = _valued(export["devices"]["masked-panel"]) + assert {topic: panel_values[topic] for topic in planted} == { + f"{node}/{property_id}": _MASKS_BY_PROPERTY.get(property_id, "MASKED-PANEL") for property_id in _SEEDED_BY_PROPERTY + } + assert {topic: panel_values[topic] for topic in kept} == kept + assert _valued(export["devices"][ids[circuit]])[f"{node}/serial-number"] == ids[circuit].upper() + + +def _typed(device_id: str, short_type: str) -> SyntheticDevice: + return SyntheticDevice( + device_id=device_id, device_type=f"energy.ebus.device.{short_type}", name=device_id, nodes={}, values={} + ) + + +def test_a_device_typed_missing_is_not_a_dangling_reference() -> None: + topics = _copy(tree(panel(), _typed("m-1", "missing"), _typed("t-1", "type-missing"), _typed("g-1", "generator"))) + topics["g-1"][_FEEDS] = "absent-device-1" + topics["g-1"][_FED_BY] = "m-1" + export, ids = _exported(topics, "panel-a") + dangling = _valued(export["devices"][ids["g-1"]])[_FEEDS] + assert dangling == "masked-missing-1" + assert dangling not in ids.values() + assert _valued(export["devices"][ids["g-1"]])[_FED_BY] == ids["m-1"] + assert not ids["m-1"].startswith("masked-missing-") + assert ids["m-1"] == "masked-type-missing-1" + assert len(set(ids.values())) == len(ids) + + +def test_a_device_typed_undescribed_is_not_an_undescribed_device() -> None: + topics = tree(panel(), _typed("u-1", "undescribed"), _typed("g-1", "generator")) + adapter = replay(topics, "panel-a", withhold_description_of="g-1") + ids = _ids_of(adapter, "panel-a") + export = _export(adapter, "panel-a", tree_complete=False) + assert ids["g-1"] == "masked-undescribed-1" + assert not ids["u-1"].startswith("masked-undescribed-") + assert len(set(ids.values())) == len(ids) + assert set(export["devices"]) == {"masked-panel", ids["u-1"]} + assert set(export["undescribed_devices"]) == {ids["g-1"]} + + +# The sweep (§4.3). The captures are masked upstream, so every leak test plants +# its own identifiers first: `reidentify` gives each device id, serial and site +# value a new, seeded one, and the export must carry none of them. + +_SEED = 337 +_SITE_PROPERTIES = frozenset(_MASKS_BY_PROPERTY) + + +def _identifying(topics: RetainedTopicTree, root_id: str) -> set[str]: + """Every valued serial and masked site value the tree publishes, and the panel's two names.""" + found = { + value + for device_topics in topics.values() + for topic, value in _published(device_topics).items() + if value and _property_id(topic) in {_SERIAL_ID, *_SITE_PROPERTIES} + } + panel_topics = topics[root_id] + names = (panel_topics.get(_NAME, ""), str(_description_of(panel_topics).get("name", ""))) + return found | {name for name in names if name} + + +@every_tree +def test_reidentification_plants_every_identifier(case: Case) -> None: + """A leak test is only as good as what it plants: every id, serial and site value is new, and planted.""" + reidentified = reidentify(case.topics, case.root_id, seed=_SEED) + topics = reidentified.tree + assert reidentified.root_id in topics + assert set(topics).isdisjoint(case.topics) + published = _identifying(topics, reidentified.root_id) + assert published.isdisjoint(_identifying(case.topics, case.root_id)) + assert reidentified.planted == set(topics) | published + assert len({value.casefold() for value in reidentified.planted}) == len(reidentified.planted) + assert reidentify(case.topics, case.root_id, seed=_SEED) == reidentified + original = replay(case.topics, case.root_id).build_snapshot() + assert _identity_free(replay(topics, reidentified.root_id).build_snapshot()) == _identity_free(original) + + +@every_tree +def test_no_planted_identifier_survives(case: Case) -> None: + reidentified = reidentify(case.topics, case.root_id, seed=_SEED) + export, _ = _exported(reidentified.tree, reidentified.root_id) + text = json.dumps(export).casefold() + assert [value for value in sorted(reidentified.planted) if value.casefold() in text] == [] + + +_TYPE_BESS = "energy.ebus.device.bess" +_TYPE_EVSE = "energy.ebus.device.evse" +_NOTE = "vendor/note" + + +def _first_of(topics: RetainedTopicTree, device_type: str) -> str: + return next(device_id for device_id in sorted(topics, key=natural_key) if _type_of(topics[device_id]) == device_type) + + +def _reidentified_reference() -> tuple[dict[str, dict[str, str]], str]: + """The reference tree re-identified, as a copy to plant in, and its new root id.""" + reidentified = reidentify(parent_child_tree(), _REFERENCE_ROOT, seed=_SEED) + return _copy(reidentified.tree), reidentified.root_id + + +def _rename(topics: dict[str, dict[str, str]], device_id: str, name: str) -> None: + """Set a device's `$description` `name`.""" + description = _description_of(topics[device_id]) + description["name"] = name + topics[device_id]["$description"] = json.dumps(description) + + +def test_the_sweep_catches_what_no_rule_names() -> None: + topics, root = _reidentified_reference() + assert topics[root][_SERIAL] == root, "the panel's serial is its id" + bess, evse = _first_of(topics, _TYPE_BESS), _first_of(topics, _TYPE_EVSE) + circuit, named = _declaring(topics, _FEEDS, _TYPE_CIRCUIT)[:2] + ghost, phantom = f"{root}-ghost", f"{root}-phantom" + assert not {ghost, phantom} & set(topics) + topics[root][_NOTE] = topics[bess][_SERIAL] + topics[root]["vendor/peer"] = evse + topics[root]["vendor/ghost"] = phantom + topics[circuit][_FEEDS] = ghost + _rename(topics, named, circuit) + export, ids = _exported(topics, root) + panel_values = export["devices"]["masked-panel"]["undeclared_properties"] + assert panel_values[_NOTE] == ids[bess].upper() + assert panel_values["vendor/peer"] == ids[evse] + assert export["devices"][ids[named]]["description"]["name"] == ids[circuit] + assert panel_values["vendor/ghost"] == "masked-panel-phantom" + dangling = _valued(export["devices"][ids[circuit]])[_FEEDS] + assert _MISSING.fullmatch(dangling) + assert root.casefold() not in json.dumps(export).casefold() + + +def test_the_sweep_reaches_inside_json() -> None: + """A `json` value is a wire string: the sweep reads it as text, so an identifier inside it is masked.""" + topics, root = _reidentified_reference() + bess = _first_of(topics, _TYPE_BESS) + serial = topics[bess][_SERIAL] + description = _description_of(topics[root]) + _declare(description, "vendor/state", "json") + topics[root]["$description"] = json.dumps(description) + topics[root]["vendor/state"] = json.dumps({"owner": serial, "peers": [serial.upper(), "kept"]}) + export, ids = _exported(topics, root) + exported = export["devices"]["masked-panel"]["properties"]["vendor/state"] + assert json.loads(exported) == {"owner": ids[bess].upper(), "peers": [ids[bess].upper(), "kept"]} + + +def test_a_shared_serial_masks_consistently() -> None: + """One serial on two devices: each device's own serial is its own mask; anywhere else, the first owner's.""" + topics, root = _reidentified_reference() + bess, mid = _first_of(topics, _TYPE_BESS), _first_of(topics, _TYPE_MID) + assert sorted((bess, mid)) == [mid, bess], "the seed must order the ids against their placeholders" + shared = topics[bess][_SERIAL] + topics[mid][_SERIAL] = shared + for device_id in (root, mid, bess): + topics[device_id][_NOTE] = shared + labelled = _first_of(topics, "energy.ebus.device.pv") + _rename(topics, labelled, f"gateway {shared}") + export, ids = _exported(topics, root) + first = min((bess, mid), key=lambda device_id: natural_key(ids[device_id])) + assert first == bess + assert _valued(export["devices"][ids[bess]])[_SERIAL] == ids[bess].upper() + assert _valued(export["devices"][ids[mid]])[_SERIAL] == ids[mid].upper() + for device_id in (root, mid, bess): + assert _valued(export["devices"][ids[device_id]])[_NOTE] == ids[first].upper(), device_id + assert export["devices"][ids[labelled]]["description"]["name"] == f"gateway {ids[first].upper()}" + + +def test_longest_identifier_wins() -> None: + """An id that embeds the panel serial maps to its own placeholder, not the panel's with a suffix. + + Longest first, not priority first: the PV's placeholder sorts after the + panel's, so the panel's id is the one tried first without the length order. + """ + topics, root = _reidentified_reference() + upstream, pv = f"{root}-lugs-up", _first_of(topics, "energy.ebus.device.pv") + assert upstream in topics + assert pv.startswith(f"{root}-") + topics[root][_NOTE] = f"fed from {upstream}; {pv.upper()} reports" + export, ids = _exported(topics, root) + assert (ids[upstream], ids[pv]) == ("masked-lugs-upstream", "masked-pv-1") + assert natural_key(ids[pv]) > natural_key("masked-panel") + assert ( + export["devices"]["masked-panel"]["undeclared_properties"][_NOTE] + == "fed from masked-lugs-upstream; masked-pv-1 reports" + ) + + +def test_the_sweep_leaves_unrelated_text() -> None: + """Site values are not swept, and an id matches only where no letter or digit adjoins it.""" + case = next(case for case in CASES if {"circuit-1", "circuit-12"} <= set(case.topics)) + topics = _copy(case.topics) + statuses = [ + (device_id, topic) + for device_id, device_topics in topics.items() + for topic, value in _published(device_topics).items() + if value == "OK" + ] + assert any(topic == "connection/feeds-device-status" for _, topic in statuses) + unrelated = "spare circuit-120, subcircuit-12, circuit-1a" + assert not {"circuit-120", "circuit-1a"} & set(topics) + topics[case.root_id]["info/region"] = "OK" + topics[case.root_id][_NOTE] = "circuit-12" + topics[case.root_id]["vendor/spare"] = unrelated + export, ids = _exported(topics, case.root_id) + for device_id, topic in statuses: + assert _valued(export["devices"][ids[device_id]])[topic] == "OK", (device_id, topic) + panel_values = _valued(export["devices"]["masked-panel"]) + assert panel_values["info/region"] == "Masked Region" + assert panel_values[_NOTE] == ids["circuit-12"] + assert ids["circuit-12"] != ids["circuit-1"] + assert panel_values["vendor/spare"] == unrelated + + +def test_a_short_identifier_is_matched_only_whole() -> None: + """`bess` and `pv` are shorter than six characters: a whole value is swept, a word inside one or a key is not.""" + topics = _copy(parent_child_tree()) + assert {"bess", "pv"} <= set(topics) + topics[_REFERENCE_ROOT]["vendor/peer"] = "bess" + topics[_REFERENCE_ROOT]["vendor/peer-shouted"] = "BESS" + _rename(topics, "bess", "Example BESS") + export, ids = _exported(topics, _REFERENCE_ROOT) + panel = export["devices"]["masked-panel"] + assert panel["undeclared_properties"]["vendor/peer"] == ids["bess"] + assert panel["undeclared_properties"]["vendor/peer-shouted"] == ids["bess"] + assert export["devices"][ids["bess"]]["description"]["name"] == "Example BESS" + declaring_pv = [ids[device_id] for device_id in _declaring(topics, "power-flows/pv")] + assert declaring_pv + for placeholder in declaring_pv: + flows = _object(_object(export["devices"][placeholder]["description"]["nodes"])["power-flows"]) + assert "pv" in _object(flows["properties"]) + assert "power-flows/pv" in _valued(export["devices"][placeholder]) + + +@every_tree +def test_the_sweep_leaves_exporter_output_alone(case: Case) -> None: + """Placeholders and masks are the exporter's own text, never swept. + + The captures' ids (`circuit-3`, `lugs-upstream`) lie inside their own + placeholders at a `-` boundary, so a sweep over the finished document would + rewrite `masked-circuit-3` into `masked-masked-circuit-`. + """ + topics, _ = _seeded(case) + circuit = _declaring(topics, _SPACES, _TYPE_CIRCUIT)[0] + topics[circuit][_FEEDS] = "absent-device-1" + export, ids = _exported(topics, case.root_id) + assert set(export["devices"]) == set(ids.values()) + for device_id, device_topics in topics.items(): + entry = export["devices"][ids[device_id]] + published = _description_of(device_topics) + for key in ("parent", "root"): + if key in published: + assert entry["description"][key] == ids[str(published[key])], (device_id, key) + children = published.get("children") + if isinstance(children, list): + assert entry["description"]["children"] == [ids[str(child)] for child in children], device_id + assert _valued(entry)[_SERIAL] == ids[device_id].upper(), device_id + panel = export["devices"]["masked-panel"] + assert {topic: _valued(panel)[topic] for topic in _SITE_MASKS} == _SITE_MASKS + assert (_valued(panel)[_NAME], panel["description"]["name"]) == (_MASKED_PANEL, _MASKED_PANEL) + assert _valued(export["devices"][ids[circuit]])[_FEEDS] == "masked-missing-1" + + +def test_an_id_spelt_like_exporter_output_does_not_rewrite_it() -> None: + """Device ids that spell another device's placeholder, a mask and a dangling placeholder. + + The sweep replaces each where the panel published it, and leaves alone the + same text where the exporter wrote it. + """ + spelt = ["masked-generator-1", "masked-missing-1", "masked-ssid"] + topics = _copy(_generators(["g-1", *spelt])) + topics["panel-a"]["status/wifi-ssid"] = "seeded-network" + topics["panel-a"][_NOTE] = "masked-generator-1" + topics["g-1"][_FEEDS] = "absent-device-1" + export, ids = _exported(topics, "panel-a") + assert [ids[device_id] for device_id in ["g-1", *spelt]] == [f"masked-generator-{n}" for n in range(1, 5)] + assert set(export["devices"]) == {"masked-panel", *(f"masked-generator-{n}" for n in range(1, 5))} + panel_values = _valued(export["devices"]["masked-panel"]) + assert panel_values["status/wifi-ssid"] == "masked-ssid" + assert panel_values[_NOTE] == ids["masked-generator-1"] + assert _valued(export["devices"][ids["g-1"]])[_FEEDS] == "masked-missing-1" + assert export["devices"]["masked-panel"]["description"]["children"] == [ids[device_id] for device_id in ["g-1", *spelt]] + + +def test_a_serial_published_as_a_target_is_swept_too() -> None: + """A serial a device publishes only as a `$target`, beside a different value, is still one of its identifiers.""" + topics = _copy(parent_child_tree()) + target_serial = "TGTARGET00001" + assert topics["bess"][_SERIAL] != target_serial + topics["bess"][f"{_SERIAL}/$target"] = target_serial + topics[_REFERENCE_ROOT][_NOTE] = target_serial + export, ids = _exported(topics, _REFERENCE_ROOT) + assert export["devices"][ids["bess"]]["targets"][_SERIAL] == ids["bess"].upper() + assert export["devices"]["masked-panel"]["undeclared_properties"][_NOTE] == ids["bess"].upper() + + +def test_a_key_naming_a_device_is_swept_alike_where_declared_and_valued() -> None: + """A property id that embeds a serial is swept in the description and the value's key, so the value stays declared.""" + topics, root = _reidentified_reference() + bess = _first_of(topics, _TYPE_BESS) + topic = f"vendor/battery-{topics[bess][_SERIAL]}" + description = _description_of(topics[root]) + _declare(description, topic, "string") + topics[root]["$description"] = json.dumps(description) + topics[root][topic] = "seeded-reading" + export, ids = _exported(topics, root) + swept = f"vendor/battery-{ids[bess].upper()}" + panel = export["devices"]["masked-panel"] + assert panel["properties"][swept] == "seeded-reading" + assert swept not in panel["undeclared_properties"] + assert swept in _declared(panel["description"]) + + +def test_a_state_is_swept() -> None: + topics, root = _reidentified_reference() + pv, evse = _first_of(topics, "energy.ebus.device.pv"), _first_of(topics, _TYPE_EVSE) + topics[pv]["$state"] = evse + export, ids = _exported(topics, root) + assert export["devices"][ids[pv]].get("state") == ids[evse] + + +def test_a_tree_of_short_identifiers_exports() -> None: + """With no identifier long enough to match inside text, the sweep matches whole values only, and nothing else.""" + short = {"panel-a": "p", "g-1": "g1", "g-2": "g2"} + topics, root = rename_devices(_generators(["g-1", "g-2"]), "panel-a", short.__getitem__) + planted = _copy(topics) + planted[root][_SERIAL] = root + planted[root][_NOTE] = "G1" + planted[root]["vendor/text"] = "g1 -- g2 stay" + export, ids = _exported(planted, root) + panel_values = export["devices"]["masked-panel"]["undeclared_properties"] + assert panel_values == {_NOTE: ids["g1"], "vendor/text": "g1 -- g2 stay"} + + +_METER_SERIAL = "info/utility-meter-serial-number" +_SEEDED_METER_SERIAL = _SEEDED_SITE[_METER_SERIAL][0] + + +def test_the_meter_serial_is_swept_as_an_identifier() -> None: + """A utility meter serial is a serial number, not free text: found anywhere else, it is `MASKED-METER` (§4.3).""" + assert any(_SEEDED_METER_SERIAL in reidentify(case.topics, case.root_id, seed=_SEED).planted for case in CASES) + topics, root = _reidentified_reference() + description = _description_of(topics[root]) + _declare(description, _METER_SERIAL, "string") + _declare(description, "vendor/meter", "json") + topics[root]["$description"] = json.dumps(description) + topics[root][_METER_SERIAL] = _SEEDED_METER_SERIAL + topics[root][_NOTE] = f"meter {_SEEDED_METER_SERIAL}" + topics[root]["vendor/meter"] = json.dumps({"meter": _SEEDED_METER_SERIAL.lower()}) + export, _ = _exported(topics, root) + panel = export["devices"]["masked-panel"] + assert panel["properties"][_METER_SERIAL] == "MASKED-METER" + assert panel["undeclared_properties"][_NOTE] == "meter MASKED-METER" + assert json.loads(panel["properties"]["vendor/meter"]) == {"meter": "MASKED-METER"} + assert _SEEDED_METER_SERIAL.casefold() not in json.dumps(export).casefold() + + +def test_an_identifier_after_a_json_escape_is_swept() -> None: + """An identifier after an escape in a `json` value is masked: the value is swept literal by literal, decoded. + + Only a literal that changed is written again (`ensure_ascii=False`, so its + `\u00b0` becomes `°`); the keys around it stay byte for byte. + """ + topics, root = _reidentified_reference() + bess, evse = _first_of(topics, _TYPE_BESS), _first_of(topics, _TYPE_EVSE) + serial = topics[bess][_SERIAL].upper() + lines = { + escape: f"{before}{evse}|{before}{serial}" + for escape, before in (("newline", "one\n"), ("tab", "a\t"), ("quote", 'say "'), ("unicode", "°")) + } + published = json.dumps(lines) + assert all(escape in published for escape in ("\\n", "\\t", '\\"', "\\u00b0")) + description = _description_of(topics[root]) + _declare(description, "vendor/log", "json") + topics[root]["$description"] = json.dumps(description) + topics[root]["vendor/log"] = published + export, ids = _exported(topics, root) + exported = export["devices"]["masked-panel"]["properties"]["vendor/log"] + swept = {escape: line.replace(evse, ids[evse]).replace(serial, ids[bess].upper()) for escape, line in lines.items()} + literals = (f"{json.dumps(escape)}: {json.dumps(line, ensure_ascii=False)}" for escape, line in swept.items()) + assert exported == "{" + ", ".join(literals) + "}" + assert json.loads(exported) == swept + assert evse not in exported + assert serial not in exported + + +def test_a_dangling_id_reads_the_same_everywhere() -> None: + """An id the panel publishes for a device it does not hold is one `masked-missing-`, at a reference and in free text. + + Built from the devices directly: replayed, a child the panel declares + becomes an undescribed device rather than a dangling one. + """ + topics, root = _reidentified_reference() + referring, named = _declaring(topics, _FEEDS, _TYPE_CIRCUIT)[:2] + ghost, absent_child = f"{root}-ghost", f"{root}-absent-child" + assert not {ghost, absent_child} & set(topics) + assert all(len(dangling) >= 6 and re.search(r"[0-9]", dangling) for dangling in (ghost, absent_child)) + topics[referring][_FEEDS] = ghost + panel_description = _description_of(topics[root]) + children = panel_description["children"] + assert isinstance(children, list) + panel_description["children"] = [*children, absent_child] + topics[root]["$description"] = json.dumps(panel_description) + topics[root][_NOTE] = f"waiting for {ghost} and {absent_child}" + _rename(topics, named, ghost) + devices = devices_from_tree(topics) + panel_device = next(device for device in devices if device.device_id == root) + others = [device for device in devices if device is not panel_device] + ids = placeholder_ids(panel_device, others) + export = export_masked_tree(panel_device, others, producer=_PRODUCER, tree_complete=True) + missing = _valued(export["devices"][ids[referring]])[_FEEDS] + panel_children = export["devices"]["masked-panel"]["description"]["children"] + assert isinstance(panel_children, list) + missing_child = panel_children[-1] + assert isinstance(missing_child, str) + assert _MISSING.fullmatch(missing) and _MISSING.fullmatch(missing_child) and missing != missing_child + assert export["devices"]["masked-panel"]["undeclared_properties"][_NOTE] == f"waiting for {missing} and {missing_child}" + assert export["devices"][ids[named]]["description"]["name"] == missing + assert ghost not in json.dumps(export) + assert absent_child not in json.dumps(export) + + +def test_an_undescribed_device_is_swept_in_free_text() -> None: + """A device that has not described itself still has an id and a serial, and both are found wherever they appear.""" + partial = _copy(parent_child_tree()) + del partial["evse"]["$description"] + reidentified = reidentify(partial, _REFERENCE_ROOT, seed=_SEED) + topics, root = _copy(reidentified.tree), reidentified.root_id + undescribed = next(device_id for device_id, device_topics in topics.items() if "$description" not in device_topics) + serial = topics[undescribed][_SERIAL] + assert serial in reidentified.planted + topics[root][_NOTE] = f"{undescribed} reports {serial}" + adapter = replay(topics, root, withhold_description_of=undescribed) + ids = _ids_of(adapter, root) + export = _export(adapter, root, tree_complete=False) + assert ids[undescribed] == "masked-undescribed-1" + assert ids[undescribed] in export["undescribed_devices"] + expected = f"{ids[undescribed]} reports {ids[undescribed].upper()}" + assert export["devices"]["masked-panel"]["undeclared_properties"][_NOTE] == expected + assert [value for value in (undescribed, serial) if value.casefold() in json.dumps(export).casefold()] == [] + + +@pytest.mark.parametrize("word", ["UNKNOWN", "NONE", "BACKUP"]) +def test_a_word_at_a_reference_site_is_not_swept_elsewhere(word: str) -> None: + """A dangling reference that is a word rather than an id reads `masked-missing-` there, and nowhere else. + + Only a dangling value of six characters or more with a digit in it is swept + beyond its reference: `UNKNOWN` is also a reading and an enum member, and + `NONE` every relay requester's reading. + """ + topics = _copy(parent_child_tree()) + mid = _declaring(topics, _GRID_FORMING, _TYPE_MID)[0] + topics[_REFERENCE_ROOT]["vendor/status"] = word + as_grid = _copy(topics) + as_grid[mid][_GRID_FORMING] = "GRID" + topics[mid][_GRID_FORMING] = word + export, ids = _exported(topics, _REFERENCE_ROOT) + baseline, _ = _exported(as_grid, _REFERENCE_ROOT) + assert _MISSING.fullmatch(_valued(export["devices"][ids[mid]])[_GRID_FORMING]) + export["devices"][ids[mid]]["properties"].pop(_GRID_FORMING) + baseline["devices"][ids[mid]]["properties"].pop(_GRID_FORMING) + assert word in json.dumps(export) + assert export == baseline + + +@pytest.mark.parametrize("placeholder", ["0", "N/A", "unknown"]) +def test_a_placeholder_serial_is_masked_at_its_property_only(placeholder: str) -> None: + """A serial that does not read as an id is masked where it is published and swept nowhere else. + + A panel that has no serial for a device publishes a placeholder there. Only + a serial of six characters or more with a digit in it joins the sweep, so + `0`, `N/A` and `unknown` are masked at their own `serial-number` and + `utility-meter-serial-number` properties and leave every equal value, and + a description's equal number, as published. A real serial is still swept + everywhere. + """ + topics, root = _reidentified_reference() + bess, evse = _first_of(topics, _TYPE_BESS), _first_of(topics, _TYPE_EVSE) + evse_serial = topics[evse][_SERIAL] + topics[bess][_SERIAL] = placeholder + description = _description_of(topics[root]) + _declare(description, _METER_SERIAL, "string") + description["vendor-zero"] = 0 + description["vendor-status"] = placeholder + topics[root]["$description"] = json.dumps(description) + topics[root][_METER_SERIAL] = placeholder + topics[root]["vendor/status"] = placeholder + topics[root]["vendor/text"] = f"status {placeholder} for {evse_serial}" + export, ids = _exported(topics, root) + panel = export["devices"]["masked-panel"] + assert _valued(export["devices"][ids[bess]])[_SERIAL] == ids[bess].upper() + assert panel["properties"][_METER_SERIAL] == "MASKED-METER" + assert panel["undeclared_properties"]["vendor/status"] == placeholder + assert panel["undeclared_properties"]["vendor/text"] == f"status {placeholder} for {ids[evse].upper()}" + assert panel["description"]["vendor-zero"] == 0 + assert panel["description"]["vendor-status"] == placeholder + assert evse_serial.casefold() not in json.dumps(export).casefold() + + +def test_an_identifier_never_starts_inside_a_json_escape() -> None: + """A match may start after a complete escape, never on an escape's own letter, which would split the escape.""" + topics, root = _reidentified_reference() + assert root.startswith("n") + cases = { + "split": "\n" + root[1:], + "escaped-backslash-then-split": "\\\n" + root[1:], + "after-escaped-backslash": "\\" + root, + "after-newline": "\n" + root, + } + description = _description_of(topics[root]) + for name, text in cases.items(): + _declare(description, f"vendor/{name}", "json") + topics[root][f"vendor/{name}"] = json.dumps({"n": text}) + topics[root]["$description"] = json.dumps(description) + export, _ = _exported(topics, root) + exported = export["devices"]["masked-panel"]["properties"] + for name in ("split", "escaped-backslash-then-split"): + assert exported[f"vendor/{name}"] == topics[root][f"vendor/{name}"], name + for name, text in cases.items(): + assert json.loads(exported[f"vendor/{name}"]) == {"n": text.replace(root, "masked-panel")}, name + + +def test_an_identifier_after_a_literal_backslash_is_swept() -> None: + """A backslash in plain text, or in a decoded description string, is a boundary like any other character.""" + topics, root = _reidentified_reference() + bess = _first_of(topics, _TYPE_BESS) + circuit = _declaring(topics, _FEEDS, _TYPE_CIRCUIT)[0] + serial = topics[bess][_SERIAL].upper() + topics[root]["vendor/path"] = f"C:\\{serial}" + topics[root]["vendor/log"] = f"logs\\{serial}\\x" + topics[root]["vendor/circuit"] = f"\\{circuit}" + description = _description_of(topics[root]) + description["vendor-path"] = f"C:\\{serial}" + topics[root]["$description"] = json.dumps(description) + export, ids = _exported(topics, root) + panel = export["devices"]["masked-panel"] + mask = ids[bess].upper() + assert {topic: panel["undeclared_properties"][topic] for topic in ("vendor/path", "vendor/log", "vendor/circuit")} == { + "vendor/path": f"C:\\{mask}", + "vendor/log": f"logs\\{mask}\\x", + "vendor/circuit": f"\\{ids[circuit]}", + } + assert panel["description"]["vendor-path"] == f"C:\\{mask}" + + +def test_an_identifier_after_an_escape_in_plain_text_is_swept() -> None: + """In text outside any JSON literal, a JSON-style escape before an identifier is a boundary, as a backslash alone already is. + + Written as `\\n`, the escape's letter would otherwise adjoin the identifier + and hide it. The rule only adds matches: a backslash before an identifier + is still a boundary, an all-digit identifier keeps its decimal rule after + an escape, and text holding no identifier keeps its bytes. + """ + topics, root = _reidentified_reference() + bess, lugs = _first_of(topics, _TYPE_BESS), _first_of(topics, _TYPE_LUGS) + serial = topics[bess][_SERIAL].upper() + meter = "45123987" + assert root.startswith("n") and lugs.startswith(root) + description = _description_of(topics[root]) + _declare(description, _METER_SERIAL, "string") + topics[root]["$description"] = json.dumps(description) + topics[root][_METER_SERIAL] = meter + kept = 'log:\\n kept \\u00b0 \\t "quoted" \\q done' + planted = { + "vendor/log": "log:\\n" + serial, + "vendor/after-literal": 'a"b" \\n' + serial, + "vendor/unicode": "\\u00b0" + serial, + "vendor/tab-root": "\\t" + root, + "vendor/newline-root": "\\n" + root, + "vendor/newline-lugs": "\\n" + lugs, + "vendor/path": "C:\\" + serial, + "vendor/newline-meter": "\\n" + meter, + "vendor/newline-reading": "\\n0." + meter, + "vendor/newline-fraction": "\\n" + meter + ".5", + "vendor/kept": kept, + } + topics[root].update(planted) + export, ids = _exported(topics, root) + values = export["devices"]["masked-panel"]["undeclared_properties"] + mask = ids[bess].upper() + assert values == { + "vendor/log": "log:\\n" + mask, + "vendor/after-literal": 'a"b" \\n' + mask, + "vendor/unicode": "\\u00b0" + mask, + "vendor/tab-root": "\\tmasked-panel", + "vendor/newline-root": "\\nmasked-panel", + "vendor/newline-lugs": "\\n" + ids[lugs], + "vendor/path": "C:\\" + mask, + "vendor/newline-meter": "\\nMASKED-METER", + "vendor/newline-reading": "\\n0." + meter, + "vendor/newline-fraction": "\\n" + meter + ".5", + "vendor/kept": kept, + } + assert serial not in json.dumps(export) + assert root not in json.dumps(export) + + +def test_a_short_identifier_after_an_escape_in_plain_text_is_not_swept() -> None: + """An escape is a boundary, not a whole value: a short id after one is still matched only as the entire string.""" + topics = _copy(parent_child_tree()) + assert "bess" in topics + topics[_REFERENCE_ROOT]["vendor/short"] = "\\nbess" + topics[_REFERENCE_ROOT]["vendor/whole"] = "bess" + export, ids = _exported(topics, _REFERENCE_ROOT) + values = export["devices"]["masked-panel"]["undeclared_properties"] + assert values["vendor/short"] == "\\nbess" + assert values["vendor/whole"] == ids["bess"] + + +def test_an_identifier_spelt_with_an_escape_is_swept() -> None: + """An identifier written with a `\\u` escape in a `json` value is found once the literal is decoded.""" + topics, root = _reidentified_reference() + assert root.startswith("n") + published = '{"n": "\\u006e' + root[1:] + '", "kept": "\\u00b0"}' + assert json.loads(published) == {"n": root, "kept": "°"} + topics[root]["vendor/raw"] = published + export, _ = _exported(topics, root) + exported = export["devices"]["masked-panel"]["undeclared_properties"]["vendor/raw"] + assert exported == '{"n": "masked-panel", "kept": "\\u00b0"}' + + +def test_every_string_literal_is_swept_whatever_surrounds_it() -> None: + """A JSON string literal is a whole string value wherever it stands, and an object key is a key. + + On the reference tree `bess` is a short id: a literal equal to it is swept + in an object, an array, a JSON string scalar and text that only looks like + JSON (a trailing comma), while a key literal (`"bess":`) is kept. The text + around the literals stays byte for byte. + """ + topics = _copy(parent_child_tree()) + serial = topics["bess"][_SERIAL] + planted = { + "vendor/object": '{"peer": "bess", "bess": 1}', + "vendor/array": '["BESS", "kept"]', + "vendor/broken": '{"peer": "bess", "serial": "' + serial + '",}', + "vendor/scalar": '"bess"', + "vendor/prose": 'the "bess" unit, and bess', + } + topics[_REFERENCE_ROOT].update(planted) + export, ids = _exported(topics, _REFERENCE_ROOT) + values = export["devices"]["masked-panel"]["undeclared_properties"] + assert values == { + "vendor/object": '{"peer": "' + ids["bess"] + '", "bess": 1}', + "vendor/array": '["' + ids["bess"] + '", "kept"]', + "vendor/broken": '{"peer": "' + ids["bess"] + '", "serial": "' + ids["bess"].upper() + '",}', + "vendor/scalar": '"' + ids["bess"] + '"', + "vendor/prose": 'the "' + ids["bess"] + '" unit, and bess', + } + + +def test_a_number_equal_to_an_identifier_is_swept_and_the_value_still_parses() -> None: + """An identifier published as a JSON number is swept; in an object or array it becomes a string literal. + + The number token is swept as text (`-` is a boundary, so the sign stays) + and written as a JSON string, so the value parses as it did. A bare value + that is only the number is a whole value and is replaced as plain text, as + every other whole value is, and so is a number in text that does not parse + (a trailing comma), which nothing could parse before. + """ + topics, root = _reidentified_reference() + meter = "45123987" + description = _description_of(topics[root]) + _declare(description, _METER_SERIAL, "string") + topics[root]["$description"] = json.dumps(description) + topics[root][_METER_SERIAL] = meter + planted = { + "vendor/object": '{"meter": ' + meter + "}", + "vendor/array": "[" + meter + ", 1]", + "vendor/negative": '{"m": -' + meter + "}", + "vendor/bare": meter, + "vendor/broken": "[" + meter + ", 1,]", + } + topics[root].update(planted) + export, _ = _exported(topics, root) + values = export["devices"]["masked-panel"]["undeclared_properties"] + assert values == { + "vendor/object": '{"meter": "MASKED-METER"}', + "vendor/array": '["MASKED-METER", 1]', + "vendor/negative": '{"m": "-MASKED-METER"}', + "vendor/bare": "MASKED-METER", + "vendor/broken": "[MASKED-METER, 1,]", + } + for topic in ("vendor/object", "vendor/array", "vendor/negative"): + assert isinstance(json.loads(values[topic]), (dict, list)), topic + assert meter not in json.dumps(export) + + +def test_an_identifier_after_an_escape_is_swept_in_any_text() -> None: + """A string literal is decoded and swept wherever it stands: a JSON string scalar, or text that does not parse. + + A literal JSON would refuse (an escape it does not define, a raw tab) is + decoded leniently and, once changed, written again with standard escapes. + """ + topics, root = _reidentified_reference() + bess = _first_of(topics, _TYPE_BESS) + serial = topics[bess][_SERIAL].upper() + escaped = json.dumps("\n" + serial) + assert escaped == '"\\n' + serial + '"' + planted = { + "vendor/scalar": escaped, + "vendor/trailing-comma": '{"n": ' + escaped + ",}", + "vendor/leading-nbsp": ' {"n": ' + escaped + "}", + "vendor/undefined-escape": '{"n": "\\q ' + serial + '"}', + "vendor/raw-tab": '{"n": "\t' + serial + '"}', + } + for topic, text in planted.items(): + if topic != "vendor/scalar": + with pytest.raises(ValueError): + json.loads(text) + topics[root].update(planted) + export, ids = _exported(topics, root) + values = export["devices"]["masked-panel"]["undeclared_properties"] + mask = ids[bess].upper() + expected = {topic: text.replace(serial, mask) for topic, text in planted.items()} + expected["vendor/undefined-escape"] = '{"n": "\\\\q ' + mask + '"}' + expected["vendor/raw-tab"] = '{"n": "\\t' + mask + '"}' + assert values == expected + assert json.loads(values["vendor/undefined-escape"]) == {"n": "\\q " + mask} + assert json.loads(values["vendor/raw-tab"]) == {"n": "\t" + mask} + assert serial not in json.dumps(export) + + +def test_json_inside_a_string_is_swept() -> None: + """A literal whose content is itself JSON is swept as JSON, in a `json` value and in a `$description` string.""" + topics, root = _reidentified_reference() + bess = _first_of(topics, _TYPE_BESS) + serial = topics[bess][_SERIAL].upper() + inner = json.dumps({"a": "\n" + serial}) + published = json.dumps({"inner": inner}) + assert published == '{"inner": "{\\"a\\": \\"\\\\n' + serial + '\\"}"}' + description = _description_of(topics[root]) + _declare(description, "vendor/nested", "json") + description["vendor-nested"] = published + topics[root]["$description"] = json.dumps(description) + topics[root]["vendor/nested"] = published + export, ids = _exported(topics, root) + panel = export["devices"]["masked-panel"] + expected = json.dumps({"inner": json.dumps({"a": "\n" + ids[bess].upper()})}) + assert panel["properties"]["vendor/nested"] == expected + assert panel["description"]["vendor-nested"] == expected + assert serial not in json.dumps(export) + + +def test_a_changed_literal_with_a_lone_surrogate_stays_encodable() -> None: + """A swept literal holding a lone-surrogate escape is written escaped, so the export still encodes as UTF-8.""" + topics, root = _reidentified_reference() + bess = _first_of(topics, _TYPE_BESS) + serial = topics[bess][_SERIAL].upper() + topics[root]["vendor/surrogate"] = '{"k": "\\ud800 ' + serial + '"}' + export, ids = _exported(topics, root) + exported = export["devices"]["masked-panel"]["undeclared_properties"]["vendor/surrogate"] + assert exported == '{"k": "\\ud800 ' + ids[bess].upper() + '"}' + assert exported.encode("utf-8") + assert json.loads(exported) == {"k": "\ud800 " + ids[bess].upper()} + assert json.dumps(export).encode("utf-8") + + +def test_a_flawed_literal_is_decoded_leniently() -> None: + """A literal with an undefined escape or a raw control character is still decoded, so a valid escape beside the flaw hides nothing. + + Swept plain, `\\n` before the serial would glue its `n` to it. A flawed + literal that holds no identifier keeps its bytes. + """ + topics, root = _reidentified_reference() + bess = _first_of(topics, _TYPE_BESS) + serial = topics[bess][_SERIAL].upper() + planted = { + "vendor/undefined-escape": '{"n": "\\q \\n' + serial + '"}', + "vendor/raw-tab-before": '{"n": "\t\\n' + serial + '"}', + "vendor/raw-tab-after": '{"n": "\\n' + serial + '\t"}', + "vendor/flawed-neighbour": '{"n": "\\n' + serial + '", "bad": "\\q"}', + } + for text in planted.values(): + with pytest.raises(ValueError): + json.loads(text) + topics[root].update(planted) + export, ids = _exported(topics, root) + values = export["devices"]["masked-panel"]["undeclared_properties"] + mask = ids[bess].upper() + assert values == { + "vendor/undefined-escape": '{"n": "\\\\q \\n' + mask + '"}', + "vendor/raw-tab-before": '{"n": "\\t\\n' + mask + '"}', + "vendor/raw-tab-after": '{"n": "\\n' + mask + '\\t"}', + "vendor/flawed-neighbour": '{"n": "\\n' + mask + '", "bad": "\\q"}', + } + for topic in ("vendor/undefined-escape", "vendor/raw-tab-before", "vendor/raw-tab-after"): + assert isinstance(json.loads(values[topic]), dict), topic + assert serial not in json.dumps(export) + + +def _wrapped(innermost: Mapping[str, str], wraps: int) -> str: + """`innermost` as a JSON object text carried inside a string `wraps` times, each level JSON in a string.""" + level: dict[str, str] = dict(innermost) + for _ in range(wraps): + level = {"inner": json.dumps(level)} + return json.dumps(level) + + +def test_a_literal_at_the_nesting_bound_is_masked_whole_or_kept() -> None: + """A literal decoded four levels down is replaced whole where it may hide an identifier and kept otherwise. + + The wire string is depth 0, a literal decoded from it depth 1: two wraps + put the innermost object's strings at depth 3, three wraps at depth 4. + """ + topics, root = _reidentified_reference() + bess = _first_of(topics, _TYPE_BESS) + serial = topics[bess][_SERIAL].upper() + planted = { + "vendor/depth-3": _wrapped({"serial": serial}, 2), + "vendor/depth-4": _wrapped({"serial": serial}, 3), + "vendor/depth-4-plain": _wrapped({"note": "kept"}, 3), + } + topics[root].update(planted) + export, ids = _exported(topics, root) + values = export["devices"]["masked-panel"]["undeclared_properties"] + mask = ids[bess].upper() + assert values == { + "vendor/depth-3": _wrapped({"serial": mask}, 2), + "vendor/depth-4": _wrapped({"serial": "masked-nested-value"}, 3), + "vendor/depth-4-plain": planted["vendor/depth-4-plain"], + } + assert serial not in json.dumps(export) + + +def test_a_short_identifier_filling_a_literal_at_the_bound_is_masked_whole() -> None: + """At the bound a short identifier counts where it would anywhere, as the whole of a value literal.""" + topics = _copy(parent_child_tree()) + assert "bess" in topics + topics[_REFERENCE_ROOT]["vendor/depth-3"] = _wrapped({"peer": "bess"}, 2) + topics[_REFERENCE_ROOT]["vendor/depth-4"] = _wrapped({"peer": "bess"}, 3) + export, ids = _exported(topics, _REFERENCE_ROOT) + values = export["devices"]["masked-panel"]["undeclared_properties"] + assert values["vendor/depth-3"] == _wrapped({"peer": ids["bess"]}, 2) + assert values["vendor/depth-4"] == _wrapped({"peer": "masked-nested-value"}, 3) + + +def _enclosed(innermost: str, depth: int) -> str: + """`innermost` as a JSON string literal nested `depth` deep, each level spelt with `\\u` escapes so the text stays small.""" + text = innermost + for _ in range(depth): + text = '"' + text.replace("\\", "\\u005c").replace('"', "\\u0022") + '"' + return text + + +def _unwrapped(text: str, depth: int) -> object: + """`text` decoded as a JSON string literal `depth` times.""" + decoded: object = text + for _ in range(depth): + assert isinstance(decoded, str) + decoded = json.loads(decoded) + return decoded + + +def test_deep_nesting_exports_in_bounded_size_and_time() -> None: + """A serial nested 24 literals deep is masked, and the export grows by at most a constant factor. + + Every level written again doubles the escapes inside it, so an unbounded + sweep would write megabytes for this three-kilobyte value. At depth four of + this spelling the serial is glued to a digit of `\\u0022`, so only the + quote in the content tells the bound to mask the literal. + """ + topics, root = _reidentified_reference() + bess = _first_of(topics, _TYPE_BESS) + serial = topics[bess][_SERIAL].upper() + deep = _enclosed(serial, 24) + assert len(deep) < 4_000 + topics[root]["vendor/deep"] = deep + start = time.perf_counter() + export, _ = _exported(topics, root) + elapsed = time.perf_counter() - start + exported = export["devices"]["masked-panel"]["undeclared_properties"]["vendor/deep"] + assert len(exported) <= 4 * len(deep) + assert elapsed < 1.0 + assert serial not in json.dumps(export) + assert _unwrapped(exported, 4) == "masked-nested-value" + + +def test_deeply_nested_strings_do_not_exhaust_the_stack() -> None: + """A string nested five hundred literals deep exports without a `RecursionError`.""" + topics, root = _reidentified_reference() + deep = _enclosed("x", 500) + assert len(deep) < 2_000_000 + topics[root]["vendor/deep"] = deep + export, _ = _exported(topics, root) + exported = export["devices"]["masked-panel"]["undeclared_properties"]["vendor/deep"] + assert _unwrapped(exported, 4) == "masked-nested-value" + + +def test_an_unclosed_quote_is_scanned_in_linear_time() -> None: + """Text of quotes that never close is swept in linear time, and an identifier after them is still found. + + A backslash before a newline must not end the scan of a literal either: + every escaped quote behind it would then open a scan of its own. The + unclosed literal's content is decoded and swept as a literal's is, so where + it changed it is written again with standard escapes: the stray backslash + before the serial is doubled by each level that writes it, and the raw + newline becomes `\\n`. Where nothing changed the bytes stay. + """ + topics, root = _reidentified_reference() + bess = _first_of(topics, _TYPE_BESS) + serial = topics[bess][_SERIAL].upper() + unclosed = '"\\' * 32_000 + assert len(unclosed) == 64_000 + newline = '"' + '\\"' * 16_000 + "\\\n" + topics[root]["vendor/unclosed"] = unclosed + topics[root]["vendor/unclosed-then-serial"] = unclosed + " " + serial + topics[root]["vendor/unclosed-newline"] = newline + serial + start = time.perf_counter() + export, ids = _exported(topics, root) + elapsed = time.perf_counter() - start + values = export["devices"]["masked-panel"]["undeclared_properties"] + mask = ids[bess].upper() + # The content decodes to 31,999 quotes, a backslash, a space and the serial: 15,999 empty literals, then a + # quote that opens an unclosed literal of its own, whose content `\ ` is swept and written again. + inner = '"' + json.dumps("\\ " + mask)[1:-1] + assert values["vendor/unclosed"] == unclosed + assert values["vendor/unclosed-then-serial"] == '"' + json.dumps('"' * 31_998 + inner)[1:-1] + assert values["vendor/unclosed-newline"] == '"' + json.dumps('"' * 16_000 + "\\\n" + mask)[1:-1] + assert serial not in json.dumps(export) + assert elapsed < 1.0 + + +def test_an_identifier_after_an_escape_in_an_unclosed_literal_is_swept() -> None: + """A quote that never closes still opens a literal: its content is decoded and swept, and written again without a closing quote. + + Swept as plain text, the `n` of `\\n` would adjoin the root id and hide it. + The content is the text after the quote less a lone backslash at the end, + which stays as it was; an unclosed literal holding no identifier keeps its + bytes, its `\\u00b0` not written as `°`. + """ + topics, root = _reidentified_reference() + bess = _first_of(topics, _TYPE_BESS) + serial = topics[bess][_SERIAL].upper() + planted = { + "vendor/newline": '{"n": "abc\\n' + root, + "vendor/tab": '{"n": "abc\\t' + root, + "vendor/trailing-backslash": '{"n": "\\n' + serial + "\\", + "vendor/kept": '{"n": "abc\\n kept', + "vendor/kept-backslash": '{"n": "abc\\n kept\\', + "vendor/kept-escape": '{"n": "\\u00b0 kept', + } + topics[root].update(planted) + export, ids = _exported(topics, root) + values = export["devices"]["masked-panel"]["undeclared_properties"] + assert values == { + "vendor/newline": '{"n": "abc\\nmasked-panel', + "vendor/tab": '{"n": "abc\\tmasked-panel', + "vendor/trailing-backslash": '{"n": "\\n' + ids[bess].upper() + "\\", + "vendor/kept": planted["vendor/kept"], + "vendor/kept-backslash": planted["vendor/kept-backslash"], + "vendor/kept-escape": planted["vendor/kept-escape"], + } + assert root not in json.dumps(export) + assert serial not in json.dumps(export) + + +def _unclosed_enclosed(innermost: str, depth: int) -> str: + """`innermost` behind `depth` quotes that never close, each level's content spelt with `\\u` escapes so the text stays small.""" + text = innermost + for _ in range(depth): + text = '"' + text.replace("\\", "\\u005c").replace('"', "\\u0022") + return text + + +def test_deeply_nested_unclosed_literals_export_in_bounded_size_and_time() -> None: + """A serial behind five hundred unclosed quotes exports without exhausting the stack, and in bounded size. + + Each unclosed literal's content is swept one level deeper, so the chain + stops at the bound: the content there holds a quote and is masked whole, + and the three levels outside it are written again around that. + """ + topics, root = _reidentified_reference() + bess = _first_of(topics, _TYPE_BESS) + serial = topics[bess][_SERIAL].upper() + deep = _unclosed_enclosed(serial, 500) + assert len(deep) < 2_000_000 + topics[root]["vendor/deep"] = deep + start = time.perf_counter() + export, _ = _exported(topics, root) + elapsed = time.perf_counter() - start + expected = '"masked-nested-value' + for _ in range(3): + expected = '"' + json.dumps(expected)[1:-1] + assert export["devices"]["masked-panel"]["undeclared_properties"]["vendor/deep"] == expected + assert elapsed < 1.0 + assert serial not in json.dumps(export) + + +def _nested(innermost: object, depth: int) -> object: + """`innermost` under `depth` objects, each the one key `a`; the outermost is a description value at depth 0.""" + value = innermost + for _ in range(depth): + value = {"a": value} + return value + + +def _listed(innermost: object, depth: int) -> object: + """`innermost` under `depth` one-element lists; the outermost is a description value at depth 0.""" + value = innermost + for _ in range(depth): + value = [value] + return value + + +_DESCRIPTION_BOUND = 32 +"""How deep a description's containers are swept inside; restated from the design, so a changed bound fails here.""" + + +def _unwrapped_objects(kept: object, copied: object, depth: int) -> tuple[object, object]: + """Both values walked `depth` levels down through the one key `a`.""" + for _ in range(depth): + assert isinstance(kept, dict) and isinstance(copied, dict) + kept, copied = kept["a"], copied["a"] + return kept, copied + + +def test_a_description_container_at_the_nesting_bound_is_masked_whole_or_kept() -> None: + """A description's containers are swept thirty-two deep; one at the bound is masked whole where a leaf in it would change and copied otherwise. + + A description's top-level values are depth 0 and real descriptions reach + depth 3 (`nodes//properties/`), so no real description is + near the bound. At the bound the decision is made on the parsed leaves, not + on serialised text: a container is masked whole where a key, a string or a + number in it would be swept, whatever lies below it, and one whose leaves + would all stay, strings among them, is copied, not shared with the SDK's + tree. + """ + topics, root = _reidentified_reference() + bess = _first_of(topics, _TYPE_BESS) + serial = topics[bess][_SERIAL].upper() + meter = "45123987" + numbers = [1, 2.5, True, None] + text = {"note": "kept", "list": ["a", 1]} + description = _description_of(topics[root]) + _declare(description, _METER_SERIAL, "string") + bound = _DESCRIPTION_BOUND + description["vendor-below"] = _nested({"serial": serial}, bound - 1) + description["vendor-at"] = _nested({"serial": serial}, bound) + description["vendor-beyond"] = _nested({"serial": serial}, bound + 1) + description["vendor-at-key"] = _nested({serial: 1}, bound) + description["vendor-at-text"] = _nested(text, bound) + description["vendor-at-meter"] = _nested([int(meter), 1], bound) + description["vendor-at-numbers"] = _nested(numbers, bound) + topics[root]["$description"] = json.dumps(description) + topics[root][_METER_SERIAL] = meter + adapter = replay(topics, root) + export = _export(adapter, root) + ids = _ids_of(adapter, root) + exported = export["devices"]["masked-panel"]["description"] + mask = ids[bess].upper() + assert exported["vendor-below"] == _nested({"serial": mask}, bound - 1) + assert exported["vendor-at"] == _nested("masked-nested-value", bound) + assert exported["vendor-beyond"] == _nested("masked-nested-value", bound) + assert exported["vendor-at-key"] == _nested("masked-nested-value", bound) + assert exported["vendor-at-text"] == _nested(text, bound) + assert exported["vendor-at-meter"] == _nested("masked-nested-value", bound) + assert exported["vendor-at-numbers"] == _nested(numbers, bound) + assert meter not in json.dumps(export) + assert serial not in json.dumps(export) + sdk_root = adapter._controller.get_root(root) + assert sdk_root is not None and sdk_root.description is not None + for name in ("vendor-at-text", "vendor-at-numbers"): + kept, copied = _unwrapped_objects(sdk_root.description[name], exported[name], bound) + assert copied == kept, name + assert copied is not kept, name + if isinstance(kept, dict) and isinstance(copied, dict): + assert copied["list"] is not kept["list"], name + + +def test_a_description_container_below_the_bound_is_swept_inside() -> None: + """A description container five or six deep is read like a shallower one: swept inside, and kept as published where nothing in it is an identifier. + + Real descriptions reach depth 3; a vendor's property definition that + nests an object a level or two deeper must not be masked whole for it. + """ + topics, root = _reidentified_reference() + bess = _first_of(topics, _TYPE_BESS) + serial = topics[bess][_SERIAL].upper() + plain = {"note": "kept", "range": [0, 100], "unit": "W", "flags": {"on": True, "off": None}} + description = _description_of(topics[root]) + description["vendor-depth-5"] = _nested(plain, 5) + description["vendor-depth-6"] = _nested(plain, 6) + description["vendor-depth-6-serial"] = _nested({"serial": serial, "note": "kept"}, 6) + topics[root]["$description"] = json.dumps(description) + export, ids = _exported(topics, root) + exported = export["devices"]["masked-panel"]["description"] + assert exported["vendor-depth-5"] == _nested(plain, 5) + assert exported["vendor-depth-6"] == _nested(plain, 6) + assert exported["vendor-depth-6-serial"] == _nested({"serial": ids[bess].upper(), "note": "kept"}, 6) + assert serial not in json.dumps(export) + + +def test_a_short_numeric_identifier_in_a_description_list_is_masked_above_and_at_the_bound() -> None: + """A short all-digit id published as a number in a list is masked just above the bound and at it alike. + + Above the bound each number is held to the whole-value rule; at the bound + the same rule decides for the list, so the id cannot be kept there while + it is masked one level up. + """ + short = "12345" + topics, root = rename_devices(_generators(["g-1"]), "panel-a", {"panel-a": "panel-a", "g-1": short}.__getitem__) + planted = _copy(topics) + description = _description_of(planted[root]) + bound = _DESCRIPTION_BOUND + description["vendor-above"] = _nested([int(short), 1], bound - 1) + description["vendor-at"] = _nested([int(short), 1], bound) + description["vendor-at-text"] = _nested([short], bound) + description["vendor-at-other"] = _nested([int(short) + 1, 1], bound) + planted[root]["$description"] = json.dumps(description) + export, ids = _exported(planted, root) + exported = export["devices"]["masked-panel"]["description"] + assert exported["vendor-above"] == _nested([ids[short], 1], bound - 1) + assert exported["vendor-at"] == _nested("masked-nested-value", bound) + assert exported["vendor-at-text"] == _nested("masked-nested-value", bound) + assert exported["vendor-at-other"] == _nested([int(short) + 1, 1], bound) + assert short not in json.dumps(export) + + +_DESCRIPTION_COPY_LIMIT = 64 +"""How deep a kept description subtree may reach before it is masked whole; restated from the design.""" + + +def test_a_deeply_nested_description_exports_within_the_bound() -> None: + """A description nested four hundred containers deep exports without exhausting the stack, and the export still serialises indented. + + A serial at the bottom is gone. A subtree holding no identifier is copied + as published while it stays within sixty-four levels, and masked whole + beyond them: a consumer writes the export with `json.dumps(indent=2)`, + which a deeper document would make raise. + """ + topics, root = _reidentified_reference() + bess = _first_of(topics, _TYPE_BESS) + serial = topics[bess][_SERIAL].upper() + plain = ["kept", 1, None] + description = _description_of(topics[root]) + description["vendor-deep"] = _nested(serial, 400) + description["vendor-deep-list"] = _listed(serial, 400) + description["vendor-deep-plain"] = _nested(plain, 400) + description["vendor-plain-50"] = _nested(plain, 50) + description["vendor-plain-at-limit"] = _nested(plain, _DESCRIPTION_COPY_LIMIT) + description["vendor-plain-past-limit"] = _nested(plain, _DESCRIPTION_COPY_LIMIT + 1) + topics[root]["$description"] = json.dumps(description) + export, _ = _exported(topics, root) + exported = export["devices"]["masked-panel"]["description"] + assert exported["vendor-deep"] == _nested("masked-nested-value", _DESCRIPTION_BOUND) + assert exported["vendor-deep-list"] == _listed("masked-nested-value", _DESCRIPTION_BOUND) + assert exported["vendor-deep-plain"] == _nested("masked-nested-value", _DESCRIPTION_BOUND) + assert exported["vendor-plain-50"] == _nested(plain, 50) + assert exported["vendor-plain-at-limit"] == _nested(plain, _DESCRIPTION_COPY_LIMIT) + assert exported["vendor-plain-past-limit"] == _nested("masked-nested-value", _DESCRIPTION_BOUND) + assert serial not in json.dumps(export) + assert json.dumps(export, indent=2) + + +def test_a_number_in_a_description_equal_to_an_identifier_is_masked() -> None: + """A serial published as a JSON number in a description is the text of one in a `json` value, and reads the same mask, as a string. + + The sign is a published byte outside the identifier and stays, inside the + string, as it does in a `json` value. Any other number is itself. + """ + topics, root = _reidentified_reference() + meter = "45123987" + description = _description_of(topics[root]) + _declare(description, _METER_SERIAL, "string") + description["vendor-meter"] = {"meter": int(meter), "negative": -int(meter), "count": 1, "reading": 0.5} + topics[root]["$description"] = json.dumps(description) + topics[root][_METER_SERIAL] = meter + export, _ = _exported(topics, root) + assert export["devices"]["masked-panel"]["description"]["vendor-meter"] == { + "meter": "MASKED-METER", + "negative": "-MASKED-METER", + "count": 1, + "reading": 0.5, + } + assert meter not in json.dumps(export) + + +def test_a_boolean_in_a_description_is_never_an_identifier() -> None: + """A boolean is not a number: on a tree whose device id is `true`, a description's `true` stays a boolean, at the bound too.""" + topics, root = rename_devices(_generators(["g-1"]), "panel-a", {"panel-a": "panel-a", "g-1": "true"}.__getitem__) + planted = _copy(topics) + description = _description_of(planted[root]) + description["vendor-flags"] = {"on": True, "off": False} + description["vendor-flags-at-bound"] = _nested({"on": True, "off": False}, _DESCRIPTION_BOUND) + planted[root]["$description"] = json.dumps(description) + planted[root][_NOTE] = "TRUE" + export, ids = _exported(planted, root) + panel = export["devices"]["masked-panel"] + assert panel["undeclared_properties"][_NOTE] == ids["true"] + assert panel["description"]["vendor-flags"] == {"on": True, "off": False} + assert panel["description"]["vendor-flags-at-bound"] == _nested({"on": True, "off": False}, _DESCRIPTION_BOUND) + + +def test_an_all_digit_identifier_is_not_found_inside_a_decimal() -> None: + """An identifier made only of digits is not found where a decimal point joins it to another digit; anywhere else it is. + + A meter serial of `123456` lies inside the reading `0.123456`, the version + `1.123456` and the fraction `123456.5`; after `meter 123456.` it is the + serial. A dangling id that starts with the serial is still the longer + match, whatever boundaries each is tried with. + """ + topics, root = _reidentified_reference() + meter = "123456" + ghost = f"{meter}-ghost" + circuit = _declaring(topics, _FEEDS, _TYPE_CIRCUIT)[0] + description = _description_of(topics[root]) + _declare(description, _METER_SERIAL, "string") + description["vendor-reading"] = 0.123456 + topics[root]["$description"] = json.dumps(description) + topics[root][_METER_SERIAL] = meter + topics[circuit][_FEEDS] = ghost + planted = { + "vendor/reading": "0.123456", + "vendor/version": "1.123456", + "vendor/fraction": "123456.5", + "vendor/sentence": "meter 123456.", + "vendor/object": '{"v": 0.123456, "m": 123456}', + "vendor/bare": meter, + "vendor/ghost": ghost, + } + topics[root].update(planted) + export, ids = _exported(topics, root) + panel = export["devices"]["masked-panel"] + dangling = _valued(export["devices"][ids[circuit]])[_FEEDS] + assert _MISSING.fullmatch(dangling) + assert panel["properties"][_METER_SERIAL] == "MASKED-METER" + assert panel["undeclared_properties"] == { + "vendor/reading": "0.123456", + "vendor/version": "1.123456", + "vendor/fraction": "123456.5", + "vendor/sentence": "meter MASKED-METER.", + "vendor/object": '{"v": 0.123456, "m": "MASKED-METER"}', + "vendor/bare": "MASKED-METER", + "vendor/ghost": dangling, + } + assert panel["description"]["vendor-reading"] == 0.123456 + + +def _json_containers(values: Mapping[str, str]) -> dict[str, str]: + """The values that parse as a JSON object or array.""" + found: dict[str, str] = {} + for topic, value in values.items(): + try: + parsed: object = json.loads(value) + except ValueError: + continue + if isinstance(parsed, (dict, list)): + found[topic] = value + return found + + +@every_tree +def test_every_json_value_still_parses(case: Case) -> None: + """Every published JSON object or array, captured or planted with escapes and identifiers, still parses exported.""" + reidentified = reidentify(case.topics, case.root_id, seed=_SEED) + topics, root = _copy(reidentified.tree), reidentified.root_id + other = next(device_id for device_id in sorted(topics) if device_id != root) + topics[root]["vendor/escaped"] = json.dumps( + {"split": "\n" + root[1:], "after": f"\n{root}", "backslash": f"C:\\{other}", other: ["\u00b0" + root, "\\"]} + ) + export, ids = _exported(topics, root) + published = {ids[device_id]: _json_containers(_published(device_topics)) for device_id, device_topics in topics.items()} + assert published["masked-panel"] + for placeholder, containers in published.items(): + values = _valued(export["devices"][placeholder]) + for topic in containers: + exported: object = json.loads(values[topic]) + assert isinstance(exported, (dict, list)), (placeholder, topic) + assert json.loads(_valued(export["devices"]["masked-panel"])["vendor/escaped"]) == { + "split": "\n" + root[1:], + "after": "\nmasked-panel", + "backslash": f"C:\\{ids[other]}", + ids[other]: ["\u00b0masked-panel", "\\"], + } + + +def test_the_adapter_offers_the_export() -> None: + assert isinstance(capture_adapter(CAPTURES[0]), TreeExportingAdapter) + assert not isinstance(SchemaZeroAdapter("sim-40t-001", flat_schema(40)), TreeExportingAdapter) + + +def test_the_adapter_exports_before_the_tree_is_ready() -> None: + adapter = replay(parent_child_tree(), _REFERENCE_ROOT, withhold_description_of="pv") + assert adapter.is_ready() is False + export = adapter.export_masked_tree() + assert export is not None + assert export["metadata"]["tree_complete"] is False + + +def test_no_export_before_the_root_describes_itself() -> None: + assert SchemaOneAdapter(_REFERENCE_ROOT, parent_child_schema()).export_masked_tree() is None + + +def test_the_adapter_names_its_distribution_and_a_complete_tree() -> None: + """An export from a replayed capture names the installed distribution and version, and says the tree is whole.""" + export = capture_adapter(CAPTURES[0]).export_masked_tree() + assert export is not None + assert export["metadata"] == { + "schema": "tree-v1", + "masked": True, + "producer": f"span-panel-api-schema-1 {version('span-panel-api-schema-1')}", + "tree_complete": True, + } + + +def test_the_producer_is_unknown_where_the_distribution_is_not_installed(monkeypatch: pytest.MonkeyPatch) -> None: + """Without its dist-info (a checkout on `sys.path`) the adapter still exports, naming its version `unknown`.""" + + def absent(distribution: str) -> str: + raise PackageNotFoundError(distribution) + + monkeypatch.setattr(schema_one_adapter, "version", absent) + export = capture_adapter(CAPTURES[0]).export_masked_tree() + assert export is not None + assert export["metadata"]["producer"] == "span-panel-api-schema-1 unknown" + + +@every_tree +def test_upstream_reads_the_export(case: Case) -> None: + export = replay(case.topics, case.root_id).export_masked_tree() + assert export is not None + tree = tree_from_snapshot(export) + assert tree.keys() == export["devices"].keys() + for device_id, device in export["devices"].items(): + values = {**device["properties"], **device["numeric_properties"]} + assert tree[device_id].properties == values + definition_from_tree(tree) diff --git a/tests/test_schema_one_undeclared_devices.py b/tests/test_schema_one_undeclared_devices.py index af864580..b928a3a8 100644 --- a/tests/test_schema_one_undeclared_devices.py +++ b/tests/test_schema_one_undeclared_devices.py @@ -65,7 +65,7 @@ def _upgraded_tree(stale_state: str | None) -> dict[str, dict[str, str]]: **tree[SOLAR_CIRCUIT], "connection/feeds-device-id": SECOND_PV, "info/name": "Garage Solar", - "info/spaces": "5,7", + "info/spaces": "13,15", } if stale_state is not None: tree[STALE_PV] = {**pv, "$state": stale_state, "info/model": STALE_MODEL} diff --git a/tests/test_shared_meters_captures.py b/tests/test_shared_meters_captures.py new file mode 100644 index 00000000..553f1b3a --- /dev/null +++ b/tests/test_shared_meters_captures.py @@ -0,0 +1,60 @@ +"""Shared meters and relays, over every reference capture. + +Each circuit's peers and each group are compared with what the capture's own +`shared-with-device-ids` values list. +""" + +from __future__ import annotations + +import pytest + +from reference_payloads.captures import CAPTURES, CaptureTree, capture_adapter, capture_snapshot, capture_tree +from span_panel_api import shared_meter_groups +from span_panel_api.models import device_id_order, is_discovery_path + +_SHARED_WITH = ("meter/shared-with-device-ids", "switch/shared-with-device-ids") + + +def _declared_peers(tree: CaptureTree, circuit_id: str, topic: str) -> tuple[str, ...] | None: + published = tree.value(circuit_id, topic) + if published is None: + return None + circuits = set(tree.circuits()) + listed = {peer.strip() for peer in published.split(",") if peer.strip()} + return tuple(sorted((listed & circuits) - {circuit_id}, key=device_id_order)) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_each_circuit_names_the_peers_its_capture_lists(stem: str) -> None: + tree, circuits = capture_tree(stem), capture_snapshot(stem).circuits + for circuit_id in tree.circuits(): + circuit = circuits[circuit_id] + assert circuit.meter_shared_with == _declared_peers(tree, circuit_id, _SHARED_WITH[0]), circuit_id + assert circuit.relay_shared_with == _declared_peers(tree, circuit_id, _SHARED_WITH[1]), circuit_id + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_shared_meters_group_exactly_their_declared_peers(stem: str) -> None: + tree = capture_tree(stem) + members: set[frozenset[str]] = set() + for circuit_id in tree.circuits(): + peers = _declared_peers(tree, circuit_id, _SHARED_WITH[0]) + if peers: + members.add(frozenset({circuit_id, *peers})) + expected = {group[0]: group for group in (tuple(sorted(member, key=device_id_order)) for member in members)} + + assert shared_meter_groups(capture_snapshot(stem).circuits) == expected + + +def test_the_captures_hold_shared_meters() -> None: + assert any(shared_meter_groups(capture_snapshot(stem).circuits) for stem in CAPTURES) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_shared_with_is_neither_discovered_nor_an_extension_reading(stem: str) -> None: + adapter = capture_adapter(stem) + discovered = [path for path in adapter.build_field_metadata() if is_discovery_path(path)] + extension = {f"{row.node_id}/{row.property_id}" for row in adapter.build_snapshot().extension_properties} + + assert not [path for path in discovered if path.endswith(tuple(f"/{topic}" for topic in _SHARED_WITH))] + assert not extension & set(_SHARED_WITH) diff --git a/tests/test_space_less_meters_captures.py b/tests/test_space_less_meters_captures.py new file mode 100644 index 00000000..591b6709 --- /dev/null +++ b/tests/test_space_less_meters_captures.py @@ -0,0 +1,64 @@ +"""A circuit-typed device that declares no breaker space, over every reference capture. + +It is a meter outside the panel, classified by declaration, never by value. Its +power stays import-positive (positive = flowing into the panel), consumed is +imported energy and produced is exported energy, it has no relay and no shed +priority to command, and it is never waited on for a name. +""" + +from __future__ import annotations + +import pytest + +from reference_payloads.captures import CAPTURES, capture_adapter, capture_snapshot, capture_tree, space_less_meters +from reference_payloads.schema_one import parent_child_tree, replay + +_REFERENCE_PANEL = "example-40t-001" + + +def _reads(wire: float | None) -> object: + """What the snapshot must hold for a wire value: the number, or None where it is unvalued.""" + return None if wire is None else pytest.approx(wire) + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_a_space_less_meter_reads_its_wire_values_import_positive(stem: str) -> None: + tree, snapshot = capture_tree(stem), capture_snapshot(stem) + for meter_id in space_less_meters(tree): + meter = snapshot.circuits[meter_id] + assert meter.measures_outside_panel is True + assert meter.instant_power_w == _reads(tree.number(meter_id, "meter/active-power")) + assert meter.consumed_energy_wh == _reads(tree.number(meter_id, "meter/imported-energy")) + assert meter.produced_energy_wh == _reads(tree.number(meter_id, "meter/exported-energy")) + assert meter.tabs == [] + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_a_space_less_meter_has_no_controls_and_is_never_waited_on(stem: str) -> None: + tree, snapshot, adapter = capture_tree(stem), capture_snapshot(stem), capture_adapter(stem) + for meter_id in space_less_meters(tree): + meter = snapshot.circuits[meter_id] + assert (meter.is_user_controllable, meter.is_sheddable, meter.always_on) == (False, False, False) + assert adapter.set_circuit_relay_target(meter_id) is None + assert adapter.set_circuit_priority_target(meter_id) is None + assert meter.relay_state_target is None and meter.priority_target is None + assert meter.is_240v is None + assert meter_id not in adapter.circuit_nodes_missing_names() + + +@pytest.mark.parametrize("stem", CAPTURES) +def test_every_hosted_circuit_stays_inside_the_panel(stem: str) -> None: + tree, snapshot = capture_tree(stem), capture_snapshot(stem) + meters = set(space_less_meters(tree)) + + assert all(circuit.measures_outside_panel is (circuit_id in meters) for circuit_id, circuit in snapshot.circuits.items()) + + +def test_the_captures_hold_space_less_meters() -> None: + assert any(space_less_meters(capture_tree(stem)) for stem in CAPTURES) + + +def test_the_reference_tree_has_no_space_less_meter() -> None: + snapshot = replay(parent_child_tree(), _REFERENCE_PANEL).build_snapshot() + + assert not any(circuit.measures_outside_panel for circuit in snapshot.circuits.values()) diff --git a/tests/test_synthetic_trees.py b/tests/test_synthetic_trees.py new file mode 100644 index 00000000..e95f004f --- /dev/null +++ b/tests/test_synthetic_trees.py @@ -0,0 +1,295 @@ +"""The synthetic tree builders, and the adapter's replay of what they build. + +Each builder stands for a shape the reference payloads do not carry. These tests +pin two things: what each builder declares and values, which is the contract a +test written against it relies on, and that every tree the builders make passes +through the adapter's real discovery path without raising. What the adapter +makes of each shape belongs to the tests of that behaviour, not to these. +""" + +from __future__ import annotations + +import json + +import pytest + +from reference_payloads.schema_one import RetainedTopicTree, replay +from reference_payloads.synthetic_trees import ( + PANEL_ID, + battery, + circuit_fed_battery, + discovered, + evse, + hosted_circuit, + lugs, + panel, + panel_with_positions, + shared_pair, + space_less_meter, + tree, + without_values, +) + +_CIRCUIT_TYPE = "energy.ebus.device.circuit" + + +def _description(topics: RetainedTopicTree, device_id: str) -> dict[str, object]: + description: object = json.loads(topics[device_id]["$description"]) + assert isinstance(description, dict) + return description + + +def _nodes(topics: RetainedTopicTree, device_id: str) -> dict[str, dict[str, dict[str, object]]]: + """The device's declared nodes: node id -> property id -> declaration.""" + nodes = _description(topics, device_id)["nodes"] + assert isinstance(nodes, dict) + declared: dict[str, dict[str, dict[str, object]]] = {} + for node, body in nodes.items(): + assert isinstance(node, str) and isinstance(body, dict) + properties = body["properties"] + assert isinstance(properties, dict) + declared[node] = {} + for prop, declaration in properties.items(): + assert isinstance(prop, str) and isinstance(declaration, dict) + declared[node][prop] = {str(key): value for key, value in declaration.items()} + return declared + + +def _declared(topics: RetainedTopicTree, device_id: str) -> set[str]: + """Every `node/property` the device's description declares.""" + return {f"{node}/{prop}" for node, properties in _nodes(topics, device_id).items() for prop in properties} + + +def _valued(topics: RetainedTopicTree, device_id: str) -> set[str]: + return {topic for topic in topics[device_id] if not topic.startswith("$")} + + +def _circuit_ids(topics: RetainedTopicTree) -> set[str]: + return {device_id for device_id in topics if _description(topics, device_id)["type"] == _CIRCUIT_TYPE} + + +_TREES: dict[str, RetainedTopicTree] = { + "panel alone": tree(panel()), + "meter without a breaker space": tree(panel(), space_less_meter()), + "unvalued meter without a breaker space": tree(panel(), without_values(space_less_meter())), + "occupied positions": panel_with_positions("MAIN_32", (1, 2, 7)), + "occupied positions, unsized model": panel_with_positions("UNKNOWN", (9, 10)), + "declared feeds role": tree(panel(), hosted_circuit("c-1", (1,), feeds_role="LOADS")), + "out-of-set feeds role": tree(panel(), hosted_circuit("c-1", (1,), feeds_role="NOT_A_ROLE")), + "shared meter and relay": tree(panel(), *shared_pair()), + "shared-with lists naming the circuit itself and an unknown id": tree( + panel(), + hosted_circuit("c-1", (1,), meter_shared_with=("c-1", "c-9"), relay_shared_with=("c-9",)), + ), + "circuit without a relay": tree(panel(), hosted_circuit("c-1", (1,), relay=False)), + "panel and circuit readings": tree( + panel(busbar_current_a=12.5, frequency_hz=60.02), + lugs("UPSTREAM", overcurrent_protection_a=150), + lugs("DOWNSTREAM"), + hosted_circuit("c-1", (1, 3), nominal_voltage_v=240.0, protection_functions=("OVERCURRENT", "ARC_FAULT")), + ), + "settable charger lock": tree(panel(), evse()), + "battery fed by a circuit": tree(panel(), *circuit_fed_battery()), +} + + +@pytest.mark.parametrize("topics", list(_TREES.values()), ids=list(_TREES)) +def test_every_tree_replays_through_the_adapter(topics: RetainedTopicTree) -> None: + adapter = replay(topics, PANEL_ID) + + assert adapter.is_ready() + snapshot = adapter.build_snapshot() + adapter.build_field_metadata() + assert snapshot.serial_number == PANEL_ID + assert _circuit_ids(topics) <= set(snapshot.circuits) + + +@pytest.mark.spec_only +def test_a_solar_role_circuit_replays_through_the_adapter() -> None: + """The catalog's `connection/feeds-role` `SOLAR`, which no reference capture + publishes on a circuit.""" + topics = tree(panel(), hosted_circuit("c-1", (1, 3), feeds_role="SOLAR")) + + adapter = replay(topics, PANEL_ID) + + assert adapter.is_ready() + assert "c-1" in adapter.build_snapshot().circuits + + +def test_a_meter_without_a_breaker_space_declares_only_a_meter() -> None: + topics = tree(panel(), space_less_meter("meter-a")) + + assert _description(topics, "meter-a")["type"] == _CIRCUIT_TYPE + assert _declared(topics, "meter-a") == { + "meter/active-power", + "meter/current", + "meter/imported-energy", + "meter/exported-energy", + } + assert _valued(topics, "meter-a") == _declared(topics, "meter-a") + + +def test_without_values_keeps_the_declaration_and_drops_every_value() -> None: + topics = tree(panel(), without_values(space_less_meter("meter-a"))) + + assert _declared(topics, "meter-a") == _declared(tree(panel(), space_less_meter("meter-a")), "meter-a") + assert _valued(topics, "meter-a") == set() + + +def test_without_values_drops_only_the_properties_it_names() -> None: + topics = tree(panel(), without_values(space_less_meter("meter-a"), "meter/active-power")) + + assert _valued(topics, "meter-a") == {"meter/current", "meter/imported-energy", "meter/exported-energy"} + + +def test_without_values_refuses_a_property_the_device_does_not_declare() -> None: + with pytest.raises(ValueError, match="info/spaces"): + without_values(space_less_meter(), "info/spaces") + + +def test_a_hosted_circuit_publishes_its_spaces_and_a_controllable_relay() -> None: + topics = tree(panel(), hosted_circuit("c-1", (5, 7))) + + assert topics["c-1"]["info/spaces"] == "5,7" + assert topics["c-1"]["breaker/poles"] == "2" + assert topics["c-1"]["switch/relay-controllable"] == "true" + nodes = _nodes(topics, "c-1") + assert nodes["switch"]["relay"]["settable"] is True + assert "connection" not in nodes + assert "shared-with-device-ids" not in nodes["meter"] + + +def test_a_circuit_without_a_relay_declares_no_switch_node() -> None: + topics = tree(panel(), hosted_circuit("c-1", (1,), relay=False)) + + assert "switch" not in _nodes(topics, "c-1") + assert topics["c-1"]["info/spaces"] == "1" + + +def test_a_relay_cannot_be_shared_by_a_circuit_without_one() -> None: + with pytest.raises(ValueError, match="c-1"): + hosted_circuit("c-1", (1,), relay=False, relay_shared_with=("c-2",)) + + +def test_shared_with_lists_are_published_as_given() -> None: + """The circuit's own id and an id no device has are published, not filtered: + dropping them is the adapter's job.""" + topics = tree(panel(), hosted_circuit("c-1", (1,), meter_shared_with=("c-1", "c-9"), relay_shared_with=("c-9",))) + + assert topics["c-1"]["meter/shared-with-device-ids"] == "c-1,c-9" + assert topics["c-1"]["switch/shared-with-device-ids"] == "c-9" + + +def test_a_declared_feeds_role_is_valued_as_given() -> None: + topics = tree(panel(), hosted_circuit("c-1", (1,), feeds_role="NOT_A_ROLE")) + + assert topics["c-1"]["connection/feeds-role"] == "NOT_A_ROLE" + + +def test_a_shared_pair_names_each_other_on_one_space() -> None: + first, second = shared_pair("c-1", "c-2", space=4) + topics = tree(panel(), first, second) + + for member, peer in (("c-1", "c-2"), ("c-2", "c-1")): + assert topics[member]["meter/shared-with-device-ids"] == peer + assert topics[member]["switch/shared-with-device-ids"] == peer + assert topics[member]["info/spaces"] == "4" + meter = ("meter/active-power", "meter/current", "meter/imported-energy", "meter/exported-energy") + assert [topics["c-1"][topic] for topic in meter] == [topics["c-2"][topic] for topic in meter] + + +def test_the_readings_are_declared_only_where_given() -> None: + plain = tree(panel(), lugs("UPSTREAM"), hosted_circuit("c-1", (1,))) + read = tree( + panel(busbar_current_a=12.5, frequency_hz=60.02), + lugs("UPSTREAM", overcurrent_protection_a=150), + hosted_circuit("c-1", (1,), nominal_voltage_v=120.0, protection_functions=("OVERCURRENT", "GROUND_FAULT")), + ) + readings = { + PANEL_ID: {"meter/busbar-current", "meter/frequency"}, + "lugs-upstream": {"connection/overcurrent-protection"}, + "c-1": {"info/nominal-voltage", "breaker/protection-functions"}, + } + + for device_id, paths in readings.items(): + assert not paths & _declared(plain, device_id) + assert paths <= _declared(read, device_id) & _valued(read, device_id) + assert read[PANEL_ID]["meter/frequency"] == "60.02" + assert read["lugs-upstream"]["connection/overcurrent-protection"] == "150" + assert read["c-1"]["breaker/protection-functions"] == "OVERCURRENT,GROUND_FAULT" + + +def test_the_panel_advertises_the_model_it_reports_unless_told_otherwise() -> None: + def model_format(device_id: str, topics: RetainedTopicTree) -> object: + return _nodes(topics, device_id)["info"]["model"]["format"] + + assert model_format(PANEL_ID, tree(panel(model="MAIN_32"))) == "MAIN_32" + advertised = tree(panel(model="UNKNOWN", advertised_models=("UNKNOWN", "MAIN_32"))) + assert model_format(PANEL_ID, advertised) == "UNKNOWN,MAIN_32" + assert advertised[PANEL_ID]["info/model"] == "UNKNOWN" + + +def test_panel_with_positions_hosts_one_circuit_per_position() -> None: + topics = panel_with_positions("MAIN_32", (2, 9)) + + assert topics[PANEL_ID]["info/model"] == "MAIN_32" + assert {device_id: topics[device_id]["info/spaces"] for device_id in _circuit_ids(topics)} == {"c-2": "2", "c-9": "9"} + + +def test_the_charger_lock_is_settable_unless_told_otherwise() -> None: + def lock_declaration(topics: RetainedTopicTree) -> dict[str, object]: + return _nodes(topics, "evse-a")["switch"]["lock-state"] + + assert lock_declaration(tree(panel(), evse("evse-a")))["settable"] is True + assert "settable" not in lock_declaration(tree(panel(), evse("evse-a", lock_settable=False))) + + +def test_a_circuit_fed_battery_is_named_by_its_circuit() -> None: + circuit, fed = circuit_fed_battery("c-1", "battery-a", status="LOST") + topics = tree(panel(), circuit, fed) + + assert topics["c-1"]["connection/feeds-device-id"] == "battery-a" + assert topics["c-1"]["connection/feeds-device-type"] == _description(topics, "battery-a")["type"] + assert topics["c-1"]["connection/feeds-device-status"] == "LOST" + + +def test_the_tree_links_every_device_to_its_parent() -> None: + standalone = battery("battery-a") + child = without_values(space_less_meter("meter-a")) + topics = tree(panel(), standalone, hosted_circuit("c-1", (1,)), child) + + assert _description(topics, PANEL_ID)["children"] == ["battery-a", "c-1", "meter-a"] + assert "parent" not in _description(topics, PANEL_ID) + for device_id in ("battery-a", "c-1", "meter-a"): + assert _description(topics, device_id)["parent"] == PANEL_ID + assert _description(topics, device_id)["root"] == PANEL_ID + + +def test_dropping_values_never_changes_the_description() -> None: + circuit = hosted_circuit("c-1", (1,), name="Workshop") + + before = tree(panel(), circuit) + after = tree(panel(), without_values(circuit)) + + assert after["c-1"]["$description"] == before["c-1"]["$description"] + assert _description(after, "c-1")["name"] == "Workshop" + + +@pytest.mark.parametrize("topics", list(_TREES.values()), ids=list(_TREES)) +def test_no_description_names_a_device_by_its_id(topics: RetainedTopicTree) -> None: + """A device id posing as a name would mask every name fallback under test.""" + for device_id in topics: + assert _description(topics, device_id)["name"] != device_id + + +def test_the_tree_refuses_a_device_id_twice() -> None: + with pytest.raises(ValueError, match="c-1"): + tree(panel(), hosted_circuit("c-1", (1,)), hosted_circuit("c-1", (2,))) + + +def test_a_device_rebuilt_alone_reads_its_values() -> None: + device = discovered(hosted_circuit("c-1", (3,), name="Workshop")) + + assert device.device_id == "c-1" + assert device.get_property("info", "name") == "Workshop" + assert device.get_property("info", "spaces") == "3" diff --git a/tests/test_tree_export_protocol.py b/tests/test_tree_export_protocol.py new file mode 100644 index 00000000..5cb1552c --- /dev/null +++ b/tests/test_tree_export_protocol.py @@ -0,0 +1,23 @@ +"""The masked-tree export is an optional adapter capability, not a required one. + +`adapters._REQUIRED_MEMBERS` is derived from `SchemaAdapter`, so a member added +there would be demanded of every built adapter wheel. The export lives in a +protocol of its own, which an adapter satisfies or not. +""" + +from __future__ import annotations + +from span_panel_api import MaskedTree, TreeExportingAdapter, adapters + + +def test_export_is_not_required_of_every_adapter() -> None: + assert "export_masked_tree" not in adapters._REQUIRED_MEMBERS + + +def test_an_object_with_the_method_satisfies_the_protocol() -> None: + class _Exporter: + def export_masked_tree(self) -> MaskedTree | None: + return None + + assert isinstance(_Exporter(), TreeExportingAdapter) + assert not isinstance(object(), TreeExportingAdapter) diff --git a/uv.lock b/uv.lock index 44440c60..e1e1cc6c 100644 --- a/uv.lock +++ b/uv.lock @@ -310,15 +310,15 @@ wheels = [ [[package]] name = "ebus-panel-sim" -version = "0.8.0" +version = "0.9.0" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "ebus-sdk" }, { name = "pyyaml" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/c8/e3/8c8804ec873fe17d9f55084d7eef7fe06e9dcbe485c8db4ee40de4544448/ebus_panel_sim-0.8.0.tar.gz", hash = "sha256:f6ee87bf5739b0709b009ea31c09d9f6ab6a0ea198bbd5f481d15cd78d8ceec3", size = 188102, upload-time = "2026-08-27T05:02:56.194Z" } +sdist = { url = "https://files.pythonhosted.org/packages/a4/b6/dcb40e681a5e5e6abe16e10b76644c62d163d967735e922dc8309d4b1a78/ebus_panel_sim-0.9.0.tar.gz", hash = "sha256:5683e232f7b7a57bffc8e28699f14cf87782edbc0e44ad347bddf91853a78df8", size = 244010, upload-time = "2026-10-06T20:06:01.287Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/b5/02/cf373b5a2e5aee9fa4801e2f946fbe666596868473b186018a8de42ee020/ebus_panel_sim-0.8.0-py3-none-any.whl", hash = "sha256:d1d1a5bce715a81b6c10932911bee93673b0db14fdae0129ef67512b1b9ef990", size = 97663, upload-time = "2026-08-27T05:02:54.577Z" }, + { url = "https://files.pythonhosted.org/packages/71/2d/a3c69f3d4615a780842214281fe39ef2d6611eae80cdc0aa92f962eed5f7/ebus_panel_sim-0.9.0-py3-none-any.whl", hash = "sha256:253275ccabdb7ac09c0fcf135c67399127608be72802a8608ff59a2aa796e8d3", size = 120633, upload-time = "2026-10-06T20:05:59.742Z" }, ] [[package]] @@ -974,7 +974,7 @@ wheels = [ [[package]] name = "span-panel-api" -version = "3.7.0b1" +version = "3.8.0" source = { editable = "." } dependencies = [ { name = "httpx" }, @@ -1028,7 +1028,7 @@ dev = [ { name = "black" }, { name = "coverage" }, { name = "cryptography", specifier = ">=50.0.0" }, - { name = "ebus-panel-sim", specifier = "==0.8.0" }, + { name = "ebus-panel-sim", specifier = "==0.9.0" }, { name = "mypy" }, { name = "pre-commit" }, { name = "pylint" }, @@ -1046,7 +1046,7 @@ dev = [ [[package]] name = "span-panel-api-schema-0" -version = "1.3.0b1" +version = "1.3.0" source = { editable = "packages/schema-0" } dependencies = [ { name = "span-panel-api" }, @@ -1057,7 +1057,7 @@ requires-dist = [{ name = "span-panel-api", editable = "." }] [[package]] name = "span-panel-api-schema-1" -version = "1.3.0b1" +version = "1.4.0" source = { editable = "packages/schema-1" } dependencies = [ { name = "ebus-sdk" },