Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/schema-1/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ 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]

### Changed

- The shipped reference tree is recaptured with `ebus-panel-sim` 0.11.0, which publishes readings in the panel's number forms, nets each lug leg's current by the panel's row layout, reads `200.0` for an unset requested import limit and publishes the
off-grid import limit only where a panel commissions it, as the reference panel now does.

## [1.5.0]

Requires `span-panel-api` **3.9.0 or newer**, whose snapshots carry the fields this parser now fills.
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,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.9.0",
"ebus-panel-sim==0.11.0",
"pytest>=9.0.2",
"pytest-asyncio>=1.3.0",
"pytest-cov",
Expand Down
21 changes: 21 additions & 0 deletions scripts/capture_parent_child_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,26 @@ def evse_instances(profile: Profile) -> list[DeviceInstance]:
return instances


_OFF_GRID_IMPORT_LIMIT_KEYS: tuple[tuple[str, str], ...] = (
("off_grid_import_limit_enablement", "off-grid-import-limit-enablement"),
("off_grid_import_limit_a", "off-grid-import-limit-a"),
)


def off_grid_import_limit(profile: Profile) -> dict[str, str]:
"""The off-grid import limit as the panel commissions it (DIVERGENCE 4), in the emitter's keys.

Passed through as written, never defaulted: a key the manifest omits is a limit the
panel did not commission, which the emitter publishes as nothing, and the emitter
validates the enablement and requires the limit while it is ENABLED.
"""
return {
emitter_key: str(profile.panel[manifest_key])
for manifest_key, emitter_key in _OFF_GRID_IMPORT_LIMIT_KEYS
if manifest_key in profile.panel
}


def manifest(profile: Profile) -> DeviceManifest:
"""The commissioned panel this capture describes."""
total_tabs = int(_decimal(profile.panel, "total_tabs", 40))
Expand All @@ -352,6 +372,7 @@ def manifest(profile: Profile) -> DeviceManifest:
"service-voltage-v": str(_decimal(profile.panel, "service_voltage_v", 240.0)),
"line-voltage-v": str(_decimal(profile.panel, "line_voltage_v", 120.0)),
"islandable": _bool_str(_flag(profile.panel, "islandable")),
**off_grid_import_limit(profile),
},
),
DeviceInstance("lugs", "lugs-upstream", "Upstream lugs", {"direction": "upstream"}),
Expand Down
14 changes: 13 additions & 1 deletion scripts/reference_panel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 three kinds.
# is marked ==> below. There are four kinds.
#
# ==> DIVERGENCE 1: shed priorities.
# The emitter's example commissions the two ordinary loads as `NICE_TO_HAVE`. That is
Expand All @@ -36,6 +36,15 @@
# 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.
#
# ==> DIVERGENCE 4: the off-grid import limit.
# From ebus-panel-sim 0.10.0 the emitter publishes `pcs/off-grid-import-limit`,
# `-enablement` and `-active` only as a panel commissions the limit, and the example
# commissions none, so a capture taken from it publishes none of the three. This
# library reads all three, and real panels publish them: the emitter's own reference
# captures include panels with the limit ENABLED and a value. The limit here is
# commissioned ENABLED with a synthetic value, so the capture publishes all three. On
# grid, `-active` reads `false`, as it does on those panels.

panel_config:
serial_number: example-40t-001
Expand All @@ -53,6 +62,9 @@ panel_config:
service_voltage_v: 240.0
line_voltage_v: 120.0
wifi_ssid: example-wifi
# ==> DIVERGENCE 4. The off-grid import limit, commissioned.
off_grid_import_limit_enablement: ENABLED
off_grid_import_limit_a: 66.5

bess:
enabled: true
Expand Down
2 changes: 1 addition & 1 deletion tests/test_schema_one_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def test_snapshot_is_built_from_the_discovered_tree(adapter: SchemaOneAdapter) -
assert snapshot.serial_number == PANEL
assert snapshot.panel_size == 40
assert snapshot.circuits[SOLAR_CIRCUIT].name == "Solar Inverter"
assert snapshot.battery.soe_percentage == pytest.approx(50.4104, rel=1e-4)
assert snapshot.battery.soe_percentage == pytest.approx(50.4)
# The tree's 6 circuits and nothing else: unoccupied positions are not circuits.
assert len(snapshot.circuits) == 6

Expand Down
6 changes: 3 additions & 3 deletions tests/test_schema_one_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def test_energy_accumulators_are_swapped_to_the_circuit_perspective(solar: Disco
*from* the circuit, which the circuit produced."""
circuit = build_circuit(solar)

assert solar.get_property("meter", "imported-energy") == "182.16666666666666"
assert circuit.produced_energy_wh == pytest.approx(182.166666, rel=1e-6)
assert solar.get_property("meter", "imported-energy") == "182.2"
assert circuit.produced_energy_wh == pytest.approx(182.2)
assert circuit.consumed_energy_wh == 0.0


Expand All @@ -118,7 +118,7 @@ def test_breaker_rating_and_current(kitchen: DiscoveredDevice) -> None:
circuit = build_circuit(kitchen)

assert circuit.breaker_rating_a == 15.0
assert circuit.current_a == pytest.approx(1.00833, rel=1e-4)
assert circuit.current_a == pytest.approx(1.0)


# ---------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions tests/test_schema_one_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def test_battery_state_of_charge_and_energy() -> None:

# Historically misnamed and kept that way: soe_percentage holds the
# percentage, soe_kwh the energy.
assert battery.soe_percentage == pytest.approx(50.4104, rel=1e-4)
assert battery.soe_kwh == pytest.approx(6.8054, rel=1e-4)
assert battery.soe_percentage == pytest.approx(50.4)
assert battery.soe_kwh == pytest.approx(6.8)
assert battery.nameplate_capacity_kwh == 13.5
assert battery.vendor_name == "Span"

Expand Down
14 changes: 7 additions & 7 deletions tests/test_schema_one_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,23 @@ def test_main_meter_energy_maps_imported_to_consumed(fields: PanelFields) -> Non
"""Opposite of a circuit: the panel imports from the grid, so imported
energy is what the house consumed."""
upstream = _device("lugs-upstream")
assert upstream.get_property("meter", "imported-energy") == "64.55"
assert upstream.get_property("meter", "imported-energy") == "64.6"

assert fields.main_meter_energy_consumed_wh == pytest.approx(64.55, rel=1e-4)
assert fields.main_meter_energy_produced_wh == pytest.approx(76.95, rel=1e-4)
assert fields.main_meter_energy_consumed_wh == pytest.approx(64.6)
assert fields.main_meter_energy_produced_wh == pytest.approx(77.0)


def test_per_phase_currents(fields: PanelFields) -> None:
"""Lugs expose `current-a`/`current-b`; circuits expose a single `current`.
Same capability type, different property set."""
assert fields.upstream_l1_current_a == pytest.approx(56.7166, rel=1e-4)
assert fields.upstream_l2_current_a == pytest.approx(46.4749, rel=1e-4)
assert fields.downstream_l1_current_a == pytest.approx(56.7166, rel=1e-4)
assert fields.upstream_l1_current_a == pytest.approx(23.3)
assert fields.upstream_l2_current_a == pytest.approx(15.1)
assert fields.downstream_l1_current_a == pytest.approx(23.3)


def test_feedthrough_comes_from_the_downstream_lugs(fields: PanelFields) -> None:
assert fields.feedthrough_power_w == -4617.0
assert fields.feedthrough_energy_consumed_wh == pytest.approx(64.55, rel=1e-4)
assert fields.feedthrough_energy_consumed_wh == pytest.approx(64.6)


def test_lugs_are_found_by_declared_direction_not_device_id() -> None:
Expand Down
88 changes: 56 additions & 32 deletions tests/test_schema_one_pcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
*participation*.

**The capture is a PCS that is switched off, and that shapes every test here.**
Every limit is `0.0`, every enablement `UNCONFIGURED`, every boolean `false`.
Uniform data makes an assertion cheap to satisfy for the wrong reason: a field
wired to the neighbouring property reports the identical value, and a parser
that returned a zero of its own would agree with the wire by accident. So no
test in this module rests on the captured values alone. Presence is asserted
against the capture, and every *reading* is proved by republishing a value that
differs from the captured one and from every sibling's, one property at a time,
with the other fifteen fields pinned to their baseline. A field that read the
wrong property moves when it should not, and that is what fails.
Every boolean is `false`, and the limits are `0.0` and `UNCONFIGURED` but for
two: the off-grid limit is commissioned, and the requested limit reads the
`200.0` a panel publishes for one nobody set. Near-uniform data makes
an assertion cheap to satisfy for the wrong reason: a field wired to the
neighbouring property often reports the identical value, and a parser that
returned a zero of its own would agree with the wire by accident. So no test in
this module rests on the captured values alone. Presence is asserted against
the capture, and every *reading* is proved by republishing a value that differs
from the captured one, one property at a time, with the other fifteen fields
pinned to their baseline. A field that read the wrong property does not move
when its own is republished, or moves when another is, and that is what fails.
"""

from __future__ import annotations
Expand Down Expand Up @@ -104,14 +106,18 @@ def _without_node(tree: dict[str, dict[str, str]], device_id: str = PANEL) -> di

# Every panel property the capability publishes, paired with the field that
# reads it and with a republished value chosen to be distinct from the captured
# one *and* from every sibling's. Distinctness is the whole apparatus: against a
# capture where all sixteen values are zeros, `false` and `UNCONFIGURED`, an
# assertion that a field equals what was published is satisfied by fifteen wrong
# wirings as easily as by the right one.
# one *and* from every other republished value of its kind. Distinctness is the
# whole apparatus: against a capture of mostly zeros, `false` and `UNCONFIGURED`,
# an assertion that a field equals what was published is satisfied by many wrong
# wirings as easily as by the right one. The first makes the field move when its
# own property is republished; the second lets the all-at-once test tell the
# families apart.
#
# The enablement enum has exactly four members and there are exactly four
# constraint classes, so each family gets a different one; the limits get
# unrelated decimals; and each boolean is flipped away from the captured value.
# constraint classes, so each family gets a different one, none its captured
# value (the off-grid limit's is `ENABLED`, the others' `UNCONFIGURED`); the
# limits get unrelated decimals; and each boolean is flipped away from the
# captured value.
_PANEL_READS: tuple[tuple[str, str, str, object], ...] = (
("enabled", "enabled", "true", True),
("active", "active", "true", True),
Expand All @@ -124,7 +130,7 @@ def _without_node(tree: dict[str, dict[str, str]], device_id: str = PANEL) -> di
("operator-import-limit-enablement", "operator_import_limit_enablement", "DISABLED", "DISABLED"),
("operator-import-limit-active", "operator_import_limit_active", "true", True),
("off-grid-import-limit", "off_grid_import_limit_a", "33.75", 33.75),
("off-grid-import-limit-enablement", "off_grid_import_limit_enablement", "UNSPECIFIED", "UNSPECIFIED"),
("off-grid-import-limit-enablement", "off_grid_import_limit_enablement", "UNCONFIGURED", "UNCONFIGURED"),
("off-grid-import-limit-active", "off_grid_import_limit_active", "true", True),
("requested-import-limit", "requested_import_limit_a", "44.125", 44.125),
(
Expand Down Expand Up @@ -163,19 +169,37 @@ def test_the_capture_is_a_pcs_that_is_switched_off() -> None:
"""The fact every test in this module is written around, asserted rather
than assumed.

Uniform data is the hazard here: a wrong wiring reports the same value as a
right one, so no reading below is proved by comparing against the capture.
Were the capture ever retaken with a configured PCS, this fails first and
says so, rather than the mutation tests continuing to pass while the weaker
assertions they replace quietly became meaningful.
Near-uniform data is the hazard here: a wrong wiring often reports the same
value as a right one, so no reading below is proved by comparing against the
capture. Were the capture ever retaken with a configured PCS, this fails
first and says so, rather than the mutation tests continuing to pass while
the weaker assertions they replace quietly became meaningful.

Two values break the uniformity, and both are a real panel's: the off-grid
limit is commissioned (`reference_panel.yaml`, DIVERGENCE 4) and, on grid,
not active; and the requested limit nobody set reads `200.0`, as every
public SPAN capture publishes it.
"""
pcs = _pcs(parent_child_tree())

assert pcs.enabled is False
assert pcs.active is False
assert pcs.binding_constraint == "NONE"
assert {value for name, value in _fields(pcs).items() if name.endswith("_limit_a")} == {0.0}
assert {value for name, value in _fields(pcs).items() if name.endswith("_enablement")} == {"UNCONFIGURED"}
assert _fields(pcs) == {
"enabled": False,
"active": False,
"import_limit_a": 0.0,
"binding_constraint": "NONE",
"feed_import_limit_a": 0.0,
"feed_import_limit_enablement": "UNCONFIGURED",
"feed_import_limit_active": False,
"operator_import_limit_a": 0.0,
"operator_import_limit_enablement": "UNCONFIGURED",
"operator_import_limit_active": False,
"off_grid_import_limit_a": 66.5,
"off_grid_import_limit_enablement": "ENABLED",
"off_grid_import_limit_active": False,
"requested_import_limit_a": 200.0,
"requested_import_limit_enablement": "UNCONFIGURED",
"requested_import_limit_active": False,
}


def test_the_catalog_constraint_classes_are_the_ones_the_panel_declares() -> None:
Expand Down Expand Up @@ -210,13 +234,13 @@ def test_the_catalog_constraint_classes_are_the_ones_the_panel_declares() -> Non
def test_republishing_one_property_moves_only_the_field_that_reads_it(
property_id: str, attribute: str, republished: str, expected: object
) -> None:
"""The load-bearing test of the module, and the answer to the uniform capture.
"""The load-bearing test of the module, and the answer to the near-uniform capture.

Two assertions, and the second is the one that bites. The first says the
field followed the wire. The second says *no other field did* — which is
what a field reading the neighbouring property fails, and what an assertion
against the captured zeros could never detect, since every sibling already
holds the value a wrong wiring would report.
against the captured values could rarely detect, since most siblings already
hold the value a wrong wiring would report.
"""
baseline = _fields(_pcs(parent_child_tree()))

Expand Down Expand Up @@ -338,9 +362,9 @@ def test_a_panel_with_no_pcs_node_carries_no_pcs_at_all() -> None:

def test_a_switched_off_pcs_is_still_a_pcs() -> None:
"""The distinction the node-presence gate exists to keep, and the reason it
cannot be a value gate: this capture publishes zeros throughout, and a
consumer that read those as absence would delete the entities of every panel
whose PCS is merely unconfigured."""
cannot be a value gate: this capture's PCS is switched off and publishes
mostly zeros, and a consumer that read those as absence would delete the
entities of every panel whose PCS is merely unconfigured."""
assert _snapshot(parent_child_tree()).pcs is not None


Expand Down
2 changes: 1 addition & 1 deletion tests/test_schema_one_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_a_circuit_feeding_a_der_reports_the_der_type(snapshot: SpanPanelSnapsho


def test_der_snapshots_are_populated(snapshot: SpanPanelSnapshot) -> None:
assert snapshot.battery.soe_percentage == pytest.approx(50.4104, rel=1e-4)
assert snapshot.battery.soe_percentage == pytest.approx(50.4)
assert snapshot.battery.connected is True
assert snapshot.pv.model == "IQ8PLUS-72-2-US"
assert snapshot.pv.feed_circuit_id == SOLAR_CIRCUIT
Expand Down
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading