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 (bits4–5 and, if present, bits0–1).
    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 == []

