Add SoftAP battery PoC (apower/BMS/EMS socket read) with docs and tests
Probes 10.100.1.1:9000,18000, sends 0x19/0x1D/0x1E envelopes, extracts currentBatterySoc/soc/avg(socArray). Includes offline extract_soc tests, BATTERY_POC docs, README usage, and empirical port-9000 RE notes.
This commit is contained in:
1 parent
4c0b9de3df
commit
2438a04ed5
6 files changed
+359
-3
No files matched your search
@@ -0,0 +1,39 @@
|
||||
"""Offline tests for battery SoC extraction (no radio/hardware needed)."""
|
||||
|
||||
import unittest
|
||||
|
||||
from franklinwh_agate_client.battery import extract_soc
|
||||
|
||||
|
||||
class TestExtractSoc(unittest.TestCase):
|
||||
def test_current_battery_soc_wins(self):
|
||||
reply = {"cmdType": 25, "data": {"currentBatterySoc": 78, "soc": 10}}
|
||||
out = extract_soc(reply)
|
||||
self.assertEqual(out["value"], 78)
|
||||
self.assertEqual(out["source"], "currentBatterySoc")
|
||||
|
||||
def test_soc_fallback(self):
|
||||
out = extract_soc({"data": {"soc": "55"}})
|
||||
self.assertEqual(out["value"], 55)
|
||||
self.assertEqual(out["source"], "soc")
|
||||
|
||||
def test_soc_array_averaged(self):
|
||||
out = extract_soc({"data": {"socArray": [80, 90]}})
|
||||
self.assertEqual(out["value"], 85)
|
||||
self.assertEqual(out["source"], "socArray(avg)")
|
||||
|
||||
def test_nested_data_string(self):
|
||||
import json
|
||||
|
||||
reply = {"data": json.dumps({"aPower": {"soc": 62}})}
|
||||
out = extract_soc(reply)
|
||||
self.assertEqual(out["value"], 62)
|
||||
|
||||
def test_missing_soc(self):
|
||||
out = extract_soc({"data": {"foo": 1}})
|
||||
self.assertIsNone(out["value"])
|
||||
self.assertIsNone(out["source"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user