Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds an optional default value for register values. #75

Merged
merged 3 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion SunGather/registers-sungrow.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 0.2.0
version: 0.2.1
vendor: Sungrow
registers:
- read:
Expand Down Expand Up @@ -1144,6 +1144,7 @@ registers:
value: "Restarting"
- response: 0x4000
value: "EMS Run"
default: "Unknown"
models: ["SH5K-20","SH3K6","SH4K6","SH5K-V13","SH5K-30","SH3K6-30","SH4K6-30","SH5.0RS","SH3.6RS","SH4.6RS","SH6.0RS","SH10RT","SH10RT-V112","SH8.0RT","SH6.0RT","SH5.0RT"]
- name: "running_state"
level: 2
Expand Down
10 changes: 7 additions & 3 deletions SunGather/sungather.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,18 @@ def load_registers(self, register_type, start, count=100):

# We convert a system response to a human value
if register.get('datarange'):
match = False
for value in register.get('datarange'):
if value['response'] == rr.registers[num]:
register_value = value['value']


match = True
if not match:
default = register.get('default')
logging.debug(f"No matching value for {register_value} in datarange of {register_name}, using default {default}")
register_value = default

if register.get('accuracy'):
register_value = round(register_value * register.get('accuracy'),2)
register_value = round(register_value * register.get('accuracy'), 2)

# Set the final register value with adjustments above included
self.latest_scrape[register_name] = register_value
Expand Down