Skip to content

Commit

Permalink
feat: Add bit in dictionaries for enum
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Sep 29, 2024
1 parent 598cc43 commit 7648d7f
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 55 deletions.
12 changes: 6 additions & 6 deletions custom_components/solarman/inverter_definitions/deye_2mppt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -610,17 +610,17 @@ parameters:
registers: [0x0065, 0x0066]
icon: "mdi:alert-outline"
lookup:
- key: 0x0000
- key: 0
value: "OK"
- key: 0x0002
- bit: 1
value: "Fan failure"
- key: 0x0004
- bit: 2
value: "Grid phase failure"
- key: 0x0008
- bit: 3
value: "Meter communication failure"
- key: 0x40000000
- bit: 30
value: "Battery loss"
- key: 0x80000000
- bit: 31
value: "Parallel communication quality"
- key: "default"
value: "Error"
Expand Down
12 changes: 6 additions & 6 deletions custom_components/solarman/inverter_definitions/deye_4mppt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -747,17 +747,17 @@ parameters:
registers: [0x0065, 0x0066]
icon: "mdi:alert-outline"
lookup:
- key: 0x0000
- key: 0
value: "OK"
- key: 0x0002
- bit: 1
value: "Fan failure"
- key: 0x0004
- bit: 2
value: "Grid phase failure"
- key: 0x0008
- bit: 3
value: "Meter communication failure"
- key: 0x40000000
- bit: 30
value: "Battery loss"
- key: 0x80000000
- bit: 31
value: "Parallel communication quality"
- key: "default"
value: "Error"
Expand Down
12 changes: 6 additions & 6 deletions custom_components/solarman/inverter_definitions/deye_hybrid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -678,17 +678,17 @@ parameters:
registers: [0x0065, 0x0066]
icon: "mdi:alert-outline"
lookup:
- key: 0x0000
- key: 0
value: "OK"
- key: 0x0002
- bit: 1
value: "Fan failure"
- key: 0x0004
- bit: 2
value: "Grid phase failure"
- key: 0x0008
- bit: 3
value: "Meter communication failure"
- key: 0x40000000
- bit: 30
value: "Battery loss"
- key: 0x80000000
- bit: 31
value: "Parallel communication quality"
- key: "default"
value: "Error"
Expand Down
30 changes: 15 additions & 15 deletions custom_components/solarman/inverter_definitions/deye_sg01hp3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1690,17 +1690,17 @@ parameters:
registers: [0x0229, 0x022A]
icon: "mdi:alert-outline"
lookup:
- key: 0x0000
- key: 0
value: "OK"
- key: 0x0002
- bit: 1
value: "Fan failure"
- key: 0x0004
- bit: 2
value: "Grid phase failure"
- key: 0x0008
- bit: 3
value: "Meter communication failure"
- key: 0x40000000
- bit: 30
value: "Battery loss"
- key: 0x80000000
- bit: 31
value: "Parallel communication quality"
- key: "default"
value: "Error"
Expand All @@ -1712,23 +1712,23 @@ parameters:
registers: [0x22B, 0x022C, 0x022D, 0x022E]
icon: "mdi:message-alert-outline"
lookup:
- key: 0x0000
- key: 0
value: "OK"
- key: 0x0040
- bit: 6
value: "DC/DC Soft Start failure"
- key: 0x0200
- bit: 9
value: "Auxiliary power supply failure"
- key: 0x1000
- bit: 12
value: "Working mode changed"
- key: 0x00020000
- bit: 17
value: "AC Over-current failure"
- key: 0x00040000
- bit: 18
value: "Tz_Integ_Fault failure"
- key: 0x00080000
- bit: 19
value: "DC Over-current failure"
- key: 0x00400000
- bit: 22
value: "AC current leakage failure"
- key: 0x8000000000000000
- bit: 63
value: "Temperature is too high"
- key: "default"
value: "Error"
Expand Down
30 changes: 15 additions & 15 deletions custom_components/solarman/inverter_definitions/deye_sg04lp3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1655,17 +1655,17 @@ parameters:
registers: [0x0229, 0x022A]
icon: "mdi:alert-outline"
lookup:
- key: 0x0000
- key: 0
value: "OK"
- key: 0x0002
- bit: 1
value: "Fan failure"
- key: 0x0004
- bit: 2
value: "Grid phase failure"
- key: 0x0008
- bit: 3
value: "Meter communication failure"
- key: 0x40000000
- bit: 30
value: "Battery loss"
- key: 0x80000000
- bit: 31
value: "Parallel communication quality"
- key: "default"
value: "Error"
Expand All @@ -1677,23 +1677,23 @@ parameters:
registers: [0x22B, 0x022C, 0x022D, 0x022E]
icon: "mdi:message-alert-outline"
lookup:
- key: 0x0000
- key: 0
value: "OK"
- key: 0x0040
- bit: 6
value: "DC/DC Soft Start failure"
- key: 0x0200
- bit: 9
value: "Auxiliary power supply failure"
- key: 0x1000
- bit: 12
value: "Working mode changed"
- key: 0x00020000
- bit: 17
value: "AC Over-current failure"
- key: 0x00040000
- bit: 18
value: "Tz_Integ_Fault failure"
- key: 0x00080000
- bit: 19
value: "DC Over-current failure"
- key: 0x00400000
- bit: 22
value: "AC current leakage failure"
- key: 0x8000000000000000
- bit: 63
value: "Temperature is too high"
- key: "default"
value: "Error"
Expand Down
21 changes: 21 additions & 0 deletions custom_components/solarman/inverter_definitions/deye_string.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,27 @@ parameters:
- key: 0x0004
value: "Fault"

- name: "Device Alarm"
class: "enum"
rule: 3
registers: [0x0065, 0x0066]
icon: "mdi:alert-outline"
lookup:
- key: 0
value: "OK"
- bit: 1
value: "Fan failure"
- bit: 2
value: "Grid phase failure"
- bit: 3
value: "Meter communication failure"
- bit: 30
value: "Battery loss"
- bit: 31
value: "Parallel communication quality"
- key: "default"
value: "Error"

- group: PV
items:
- name: PV Power
Expand Down
18 changes: 11 additions & 7 deletions custom_components/solarman/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,17 @@ def in_range(self, value, definition):

def lookup_value(self, value, keyvaluepairs):
for o in keyvaluepairs:
key = o["key"]
if isinstance(key, list):
for k in key:
if k == value:
return o["value"]
elif key == value or "default" in o or key == "default":
return o["value"]
if "bit" in o:
if 1 << o["bit"] == value or "default":
return o["value"]
else:
key = o["key"]
if isinstance(key, list):
for k in key:
if k == value:
return o["value"]
elif key == value or "default" in o or key == "default":
return o["value"]

return keyvaluepairs[0]["value"]

Expand Down

0 comments on commit 7648d7f

Please sign in to comment.