mirror of
https://github.com/pommi/python-itho-wpu.git
synced 2025-07-13 01:45:44 +02:00
feat(itho-wpu): getsettings support
A loop around getsetting based on the settings available in the database to retrieve all settings from the WPU. Example usage: > ./itho-wpu.py --action getsettings > 0. Niet Gebruikt: 0 (min: 0, max: 65535, step: 1) > 1. Hardware Configuratie: 70 (min: 0, max: 65535, step: 1) > 2. Jaar Inbedrijfstelling: 2010 (min: 2004, max: 2099, step: 1)
This commit is contained in:
29
itho-wpu.py
29
itho-wpu.py
@ -34,7 +34,7 @@ def parse_args():
|
||||
"--action",
|
||||
nargs="?",
|
||||
required=True,
|
||||
choices=actions.keys(),
|
||||
choices=list(actions.keys()) + ["getsettings"],
|
||||
help="Execute an action",
|
||||
)
|
||||
parser.add_argument(
|
||||
@ -157,6 +157,20 @@ class IthoWPU:
|
||||
return datalog
|
||||
return datalog
|
||||
|
||||
def get_settings(self):
|
||||
listversion = self.get_listversion_from_nodeid()
|
||||
parameterlist_version = self.heatpump_db.execute(
|
||||
f"SELECT parameterlist FROM versiebeheer WHERE version = {listversion}"
|
||||
)[0]["parameterlist"]
|
||||
if parameterlist_version is None or not type(parameterlist_version) == int:
|
||||
logger.error(f"Parameterlist not found in database for version {listversion}")
|
||||
return None
|
||||
settings = self.heatpump_db.execute(
|
||||
"SELECT id, name, min, max, def, title, description, unit "
|
||||
+ f"FROM parameterlijst_v{parameterlist_version}"
|
||||
)
|
||||
return settings
|
||||
|
||||
def get_setting_by_id(self, settingid):
|
||||
listversion = self.get_listversion_from_nodeid()
|
||||
parameterlist_version = self.heatpump_db.execute(
|
||||
@ -339,6 +353,14 @@ def process_setting(response, wpu):
|
||||
)
|
||||
|
||||
|
||||
def process_settings(wpu, args):
|
||||
settings = wpu.get_settings()
|
||||
for setting in settings:
|
||||
response = wpu.get("getsetting", int(setting["id"]))
|
||||
if response is not None:
|
||||
process_response("getsetting", response, args, wpu)
|
||||
|
||||
|
||||
def format_datatype(name, m, dt):
|
||||
"""
|
||||
Transform a list of bytes to a readable number based on the datatype.
|
||||
@ -423,6 +445,11 @@ def main():
|
||||
return
|
||||
|
||||
wpu = IthoWPU(args.master_only, args.slave_only, args.slave_timeout, args.no_cache)
|
||||
|
||||
if args.action == "getsettings":
|
||||
process_settings(wpu, args)
|
||||
return
|
||||
|
||||
response = wpu.get(args.action, args.settingid)
|
||||
if response is not None:
|
||||
process_response(args.action, response, args, wpu)
|
||||
|
Reference in New Issue
Block a user