Live power APIs: detail/load/EMS queries + power module + host_probe8
This commit is contained in:
1 parent
c11188dd0b
commit
f15ae42db7
5 files changed
+393
No files matched your search
@@ -0,0 +1,44 @@
|
||||
"""Offline tests for live-power extraction (no radio/hardware needed)."""
|
||||
|
||||
import unittest
|
||||
|
||||
from franklinwh_agate_client.power import (
|
||||
ems_load_watts,
|
||||
extract_power,
|
||||
)
|
||||
|
||||
|
||||
class TestExtractPower(unittest.TestCase):
|
||||
def test_total_power_wins(self):
|
||||
reply = {"cmdType": 1301,
|
||||
"dataArea": {"apowerCount": 2, "totalPower": 1872.5}}
|
||||
out = extract_power(reply)
|
||||
self.assertEqual(out["value"], 1872.5)
|
||||
self.assertEqual(out["source"], "totalPower")
|
||||
|
||||
def test_switch_power_fallback(self):
|
||||
reply = {"dataArea": {"index": 1, "Sw1Volt": 120.1,
|
||||
"SW1Curr": 3.2, "SW1ExpPower": 384.0}}
|
||||
out = extract_power(reply)
|
||||
self.assertEqual(out["value"], 384.0)
|
||||
self.assertEqual(out["source"], "SW1ExpPower")
|
||||
|
||||
def test_missing_power(self):
|
||||
out = extract_power({"dataArea": {"result": 1, "reason": -1}})
|
||||
self.assertIsNone(out["value"])
|
||||
self.assertIsNone(out["source"])
|
||||
|
||||
def test_ems_load_watts_math(self):
|
||||
reply = {"dataArea": {"gridVol1": 120.4, "gridVol2": 120.5,
|
||||
"loadCurr1": 7.8, "loadCurr2": 7.8,
|
||||
"gridLineVol": 2410}}
|
||||
watts = ems_load_watts(reply)
|
||||
self.assertAlmostEqual(watts, 15.6 * 120.45, places=1)
|
||||
|
||||
def test_ems_load_watts_missing(self):
|
||||
self.assertIsNone(ems_load_watts({"dataArea": {}}))
|
||||
self.assertIsNone(ems_load_watts({}))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user