"""Signed PV kanály Deye → agregovaná pv_power_w (kladné příspěvky jen)."""

from __future__ import annotations

import unittest

from services.telemetry_collector import aggregate_pv_production_w


class TestAggregatePvProductionW(unittest.TestCase):
    def test_daytime_typical(self) -> None:
        self.assertEqual(aggregate_pv_production_w(6000, 4000, 0), 10_000)

    def test_negative_gen_ignored_in_total(self) -> None:
        self.assertEqual(aggregate_pv_production_w(0, 0, -61), 0)

    def test_false_uint16_gen_becomes_small_negative(self) -> None:
        raw = 65472
        signed = raw - 65536 if raw > 32767 else raw
        self.assertEqual(signed, -64)
        self.assertEqual(aggregate_pv_production_w(0, 0, signed), 0)

    def test_false_uint16_pv1_like_grid_export_clamped(self) -> None:
        raw = 52038
        signed = raw - 65536 if raw > 32767 else raw
        self.assertEqual(signed, -13_498)
        self.assertEqual(aggregate_pv_production_w(signed, 0, 0), 0)

    def test_mixed_one_negative(self) -> None:
        self.assertEqual(aggregate_pv_production_w(8000, -100, 2000), 10_000)


if __name__ == "__main__":
    unittest.main()
