Files
ems/backend/tests/test_drop_registers_matching_last_verified.py
Dusan Vojacek b66b0109b9
Some checks failed
CI and deploy / migration-check (push) Failing after 11s
CI and deploy / deploy (push) Has been skipped
fix cutoff a grid peak shaving register
2026-04-29 13:38:00 +02:00

25 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from services.control.exporter_monolith import (
REG178_PASSIVE,
_drop_registers_matching_last_verified,
)
def test_drop_registers_skips_reg178_when_mask_matches():
# last_verified contains extra bits; reg178 is a bit field and exporter uses RMW.
# We want to skip if the relevant bits match (bits45 and, if present, bits01).
last_verified = {178: 12030} # real-world example from home-01 (bits4-5 still == 0b11)
expected_rmw = (int(last_verified[178]) & ~0x0030) | int(REG178_PASSIVE)
registers = [(178, "control_board_special_1", int(expected_rmw))]
out, skipped = _drop_registers_matching_last_verified(registers, last_verified)
assert out == []
assert skipped == [178]
def test_drop_registers_keeps_reg178_when_mask_differs():
registers = [(178, "grid_peak_shaving_switch", REG178_PASSIVE)]
last_verified = {178: 32} # SELL mask 0b10
out, skipped = _drop_registers_matching_last_verified(registers, last_verified)
assert out == registers
assert skipped == []