修复BUG
This commit is contained in:
@@ -365,34 +365,40 @@ class JackeryDataCoordinator:
|
|||||||
# Merge logic
|
# Merge logic
|
||||||
# Type 101: Sub-device full data
|
# Type 101: Sub-device full data
|
||||||
if msg_code == 101 and isinstance(body, dict):
|
if msg_code == 101 and isinstance(body, dict):
|
||||||
# Expect "plug": [ ... ]
|
# Normalize sub-device payloads for plugs/sockets/CTs
|
||||||
# Normalize to "plugs" and "cts" for internal usage
|
raw_plugs = body.get("plug") or body.get("plugs") or body.get("socket") or body.get("sockets") or []
|
||||||
raw_plugs = body.get("plug", [])
|
raw_cts = body.get("ct") or body.get("cts") or []
|
||||||
if raw_plugs:
|
|
||||||
# Separate CTs (devType=2?) and Plugs (others?)
|
current_cts = []
|
||||||
# User said CTs (2) and Plugs (6). Protocol example shows devType in item.
|
current_plugs = []
|
||||||
|
|
||||||
# Update "plugs" list (containing all sub-devices or just plugs?)
|
# Combine all sub-devices into a single list for discovery
|
||||||
# Let's keep "plugs" as the raw list of all sub-devices for _check_for_new_plugs to scan
|
combined = []
|
||||||
# Or better, separate them now.
|
if isinstance(raw_plugs, list):
|
||||||
|
|
||||||
current_cts = []
|
|
||||||
current_plugs = []
|
|
||||||
|
|
||||||
for item in raw_plugs:
|
for item in raw_plugs:
|
||||||
|
if isinstance(item, dict) and item.get("devType") is None:
|
||||||
|
item = {**item, "devType": 6}
|
||||||
|
combined.append(item)
|
||||||
|
if isinstance(raw_cts, list):
|
||||||
|
for item in raw_cts:
|
||||||
|
if isinstance(item, dict) and item.get("devType") is None:
|
||||||
|
item = {**item, "devType": 2}
|
||||||
|
combined.append(item)
|
||||||
|
|
||||||
|
if combined:
|
||||||
|
for item in combined:
|
||||||
|
if not isinstance(item, dict):
|
||||||
|
continue
|
||||||
dt = item.get("devType")
|
dt = item.get("devType")
|
||||||
# Assuming devType 2 is CT based on "Poll Sub-devices ... CTs (2)"
|
|
||||||
if dt == 2:
|
if dt == 2:
|
||||||
# Map keys for CT calculator: TphasePw -> gridBuy, TnphasePw -> gridSell ?
|
|
||||||
# Or just pass item as is. _calculate_energy_flow expects item in "cts" list.
|
|
||||||
current_cts.append(item)
|
current_cts.append(item)
|
||||||
else:
|
else:
|
||||||
current_plugs.append(item)
|
current_plugs.append(item)
|
||||||
|
|
||||||
self._data_cache["cts"] = current_cts
|
self._data_cache["cts"] = current_cts
|
||||||
# We store all in "plugs" for JackeryPlugSensor to find itself by SN
|
# Store all in "plugs" for JackeryPlugSensor to find itself by SN
|
||||||
self._data_cache["plugs"] = raw_plugs
|
self._data_cache["plugs"] = combined
|
||||||
self._data_cache["plug"] = raw_plugs # Keep original key too
|
self._data_cache["plug"] = combined # Keep original key too
|
||||||
|
|
||||||
# Type 25 or Status: Main device data
|
# Type 25 or Status: Main device data
|
||||||
elif isinstance(body, dict):
|
elif isinstance(body, dict):
|
||||||
@@ -420,6 +426,8 @@ class JackeryDataCoordinator:
|
|||||||
# Check both keys
|
# Check both keys
|
||||||
plugs = data.get("plugs") or data.get("plug")
|
plugs = data.get("plugs") or data.get("plug")
|
||||||
if not plugs or not isinstance(plugs, list):
|
if not plugs or not isinstance(plugs, list):
|
||||||
|
plugs = data.get("cts") if isinstance(data.get("cts"), list) else None
|
||||||
|
if not plugs:
|
||||||
return
|
return
|
||||||
|
|
||||||
new_entities = []
|
new_entities = []
|
||||||
|
|||||||
Reference in New Issue
Block a user