mirror of
https://github.com/pommi/python-itho-wpu.git
synced 2024-11-21 13:52:15 +01:00
feat: add support for reading manual operations
This commit is contained in:
parent
381dd4c6ec
commit
63f06400ef
10
README.md
10
README.md
@ -101,7 +101,7 @@ See the [pislave](https://github.com/ootjersb/pislave#wiring) project
|
||||
|
||||
* Retrieve a single setting from the WPU
|
||||
```
|
||||
# ./itho-wpu.py --action getsetting --settingid 1
|
||||
# ./itho-wpu.py --action getsetting --id 1
|
||||
1. Hardware Configuratie: 70 (min: 0, max: 65535, step: 1)
|
||||
```
|
||||
|
||||
@ -123,7 +123,7 @@ See the [pislave](https://github.com/ootjersb/pislave#wiring) project
|
||||
|
||||
* Change a setting of the WPU
|
||||
```
|
||||
# ./itho-wpu.py --action setsetting --settingid 139 --value 48
|
||||
# ./itho-wpu.py --action setsetting --id 139 --value 48
|
||||
Current setting:
|
||||
139. Blokkade Tijd Van Verwarmen Naar Koelen (uur): 24 (min: 0, max: 168, step: 1)
|
||||
Setting `139` will be changed to `48`? [y/N] y
|
||||
@ -132,6 +132,12 @@ See the [pislave](https://github.com/ootjersb/pislave#wiring) project
|
||||
139. Blokkade Tijd Van Verwarmen Naar Koelen (uur): 48 (min: 0, max: 168, step: 1)
|
||||
```
|
||||
|
||||
* Retrieve a manual operation setting from the WPU
|
||||
```
|
||||
# ./itho-wpu.py --loglevel info --action getmanual --id 0
|
||||
0. Buitentemp (°C): 10.0
|
||||
```
|
||||
|
||||
# Exporting measurements
|
||||
|
||||
## InfluxDB
|
||||
|
@ -38,7 +38,7 @@ def convert(par_file, sqlite_db):
|
||||
|
||||
tables = []
|
||||
for table_info in par_cur.tables(tableType="TABLE"):
|
||||
if re.match("^(VersieBeheer|Data[Ll]abel|Parameterlijst)", table_info.table_name):
|
||||
if re.match("^(VersieBeheer|Data[Ll]abel|Parameterlijst|Handbed)", table_info.table_name):
|
||||
tables.append(table_info.table_name)
|
||||
|
||||
for t in sorted(tables):
|
||||
@ -69,11 +69,31 @@ def convert(par_file, sqlite_db):
|
||||
r.Eenheid_NL,
|
||||
)
|
||||
)
|
||||
if re.match("^VersieBeheer", t):
|
||||
par_cur.execute(f"select VersieNummer, DataLabel, ParameterLijst from {t}")
|
||||
if re.match("^Handbed", t):
|
||||
par_cur.execute(
|
||||
"select Index, Naam, Naam_fabriek, Min, Max, Default, "
|
||||
f"Tekst_NL, Tooltip_NL, Eenheid_NL from {t}"
|
||||
)
|
||||
rows = par_cur.fetchall()
|
||||
for r in sorted(rows):
|
||||
data.append((r.VersieNummer, r.DataLabel, r.ParameterLijst))
|
||||
data.append(
|
||||
(
|
||||
r.Index,
|
||||
r.Naam,
|
||||
r.Naam_fabriek,
|
||||
r.Min,
|
||||
r.Max,
|
||||
r.Default,
|
||||
r.Tekst_NL,
|
||||
r.Tooltip_NL,
|
||||
r.Eenheid_NL,
|
||||
)
|
||||
)
|
||||
if re.match("^VersieBeheer", t):
|
||||
par_cur.execute(f"select VersieNummer, DataLabel, ParameterLijst, Handbed from {t}")
|
||||
rows = par_cur.fetchall()
|
||||
for r in sorted(rows):
|
||||
data.append((r.VersieNummer, r.DataLabel, r.ParameterLijst, r.Handbed))
|
||||
sqlite_db.insert(t.lower(), data)
|
||||
|
||||
|
||||
|
29
db.py
29
db.py
@ -44,6 +44,21 @@ class sqlite:
|
||||
);""".format(
|
||||
t
|
||||
)
|
||||
elif t.startswith("handbed"):
|
||||
query = """
|
||||
CREATE TABLE {} (
|
||||
id real,
|
||||
name text,
|
||||
name_factory text,
|
||||
min real,
|
||||
max real,
|
||||
def real,
|
||||
title text,
|
||||
tooltip text,
|
||||
unit text
|
||||
);""".format(
|
||||
t
|
||||
)
|
||||
elif t.startswith("parameterlijst"):
|
||||
query = """
|
||||
CREATE TABLE {} (
|
||||
@ -64,7 +79,8 @@ class sqlite:
|
||||
CREATE TABLE {} (
|
||||
version integer primary key,
|
||||
datalabel integer,
|
||||
parameterlist integer
|
||||
parameterlist integer,
|
||||
handbed integer
|
||||
);""".format(
|
||||
t
|
||||
)
|
||||
@ -86,10 +102,17 @@ class sqlite:
|
||||
""".format(
|
||||
t
|
||||
)
|
||||
elif t.startswith("handbed"):
|
||||
query = """
|
||||
INSERT INTO {} (id, name, name_factory, min, max, def, title, tooltip, unit)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);
|
||||
""".format(
|
||||
t
|
||||
)
|
||||
elif t.startswith("versiebeheer"):
|
||||
query = """
|
||||
INSERT INTO {} (version, datalabel, parameterlist)
|
||||
VALUES (?, ?, ?);
|
||||
INSERT INTO {} (version, datalabel, parameterlist, handbed)
|
||||
VALUES (?, ?, ?, ?);
|
||||
""".format(
|
||||
t
|
||||
)
|
||||
|
61
itho-wpu.py
61
itho-wpu.py
@ -25,6 +25,7 @@ actions = {
|
||||
"getdatalog": [0xA4, 0x01],
|
||||
"getsetting": [0xA4, 0x10],
|
||||
"setsetting": [0xA4, 0x10],
|
||||
"getmanual": [0x40, 0x30],
|
||||
}
|
||||
|
||||
|
||||
@ -39,10 +40,10 @@ def parse_args():
|
||||
help="Execute an action",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--settingid",
|
||||
"--id",
|
||||
nargs="?",
|
||||
type=int,
|
||||
help="Setting identifier",
|
||||
help="Setting or manual identifier",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--value",
|
||||
@ -193,6 +194,22 @@ class IthoWPU:
|
||||
return None
|
||||
return setting_details[0]
|
||||
|
||||
def get_manual_by_id(self, manualid):
|
||||
listversion = self.get_listversion_from_nodeid()
|
||||
handbed_version = self.heatpump_db.execute(
|
||||
f"SELECT handbed FROM versiebeheer WHERE version = {listversion}"
|
||||
)[0]["handbed"]
|
||||
if handbed_version is None or not type(handbed_version) == int:
|
||||
logger.error(f"Handbed not found in database for version {listversion}")
|
||||
return None
|
||||
manual_details = self.heatpump_db.execute(
|
||||
"SELECT name, min, max, def, title, tooltip, unit "
|
||||
+ f"FROM handbed_v{handbed_version} WHERE id = {manualid}"
|
||||
)
|
||||
if len(manual_details) != 1:
|
||||
return None
|
||||
return manual_details[0]
|
||||
|
||||
|
||||
class IthoWPUCache:
|
||||
def __init__(self):
|
||||
@ -264,6 +281,8 @@ def process_response(action, response, args, wpu):
|
||||
export_to_influxdb(action, measurements)
|
||||
elif action == "getsetting":
|
||||
process_setting(response, wpu)
|
||||
elif action == "getmanual":
|
||||
process_manual(response, wpu)
|
||||
elif action == "getnodeid":
|
||||
process_nodeid(response)
|
||||
elif action == "getserial":
|
||||
@ -369,7 +388,7 @@ def process_settings(wpu, args):
|
||||
|
||||
def process_setsetting(wpu, args):
|
||||
logger.info("Current setting:")
|
||||
response = wpu.get("getsetting", int(args.settingid))
|
||||
response = wpu.get("getsetting", int(args.id))
|
||||
if response is None:
|
||||
return
|
||||
process_response("getsetting", response, args, wpu)
|
||||
@ -392,7 +411,7 @@ def process_setsetting(wpu, args):
|
||||
logger.debug(f"New setting (normalized): {normalized_value}")
|
||||
hex_list_value = [hex(v) for v in list(normalized_value.to_bytes(4, byteorder="big"))]
|
||||
logger.debug(f"New setting (hex): {hex_list_value}")
|
||||
parsed_value = format_datatype(args.settingid, hex_list_value, datatype)
|
||||
parsed_value = format_datatype(args.id, hex_list_value, datatype)
|
||||
logger.debug(f"New setting (parsed): {parsed_value}")
|
||||
|
||||
_, minimum, maximum, _ = parse_setting(response, wpu)
|
||||
@ -400,19 +419,41 @@ def process_setsetting(wpu, args):
|
||||
logger.error(f"New value `{parsed_value}` is not between `{minimum}` and `{maximum}`")
|
||||
return
|
||||
|
||||
sure = input(f"Setting `{args.settingid}` will be changed to `{parsed_value}`? [y/N] ")
|
||||
sure = input(f"Setting `{args.id}` will be changed to `{parsed_value}`? [y/N] ")
|
||||
if sure in ["y", "Y"]:
|
||||
logger.info(f"Updating setting {args.settingid} to `{parsed_value}`")
|
||||
logger.info(f"Updating setting {args.id} to `{parsed_value}`")
|
||||
else:
|
||||
logger.error("Aborted")
|
||||
return
|
||||
|
||||
response = wpu.get("setsetting", args.settingid, normalized_value)
|
||||
response = wpu.get("setsetting", args.id, normalized_value)
|
||||
if response is None:
|
||||
return
|
||||
process_response("getsetting", response, args, wpu)
|
||||
|
||||
|
||||
def process_manual(response, wpu):
|
||||
message = response[5:]
|
||||
|
||||
manualid = int(message[2], 0)
|
||||
manual = wpu.get_manual_by_id(manualid)
|
||||
if manual is None:
|
||||
logger.error(f"Manual '{manualid}' is invalid")
|
||||
return
|
||||
|
||||
datatype = message[3]
|
||||
value = format_datatype(manual["name"], message[4:6], datatype)
|
||||
|
||||
logger.info(
|
||||
"{}. {}{}: {}".format(
|
||||
manualid,
|
||||
manual["title"].title(),
|
||||
f' ({manual["unit"]})' if manual["unit"] is not None else "",
|
||||
value,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def format_datatype(name, m, dt):
|
||||
"""
|
||||
Transform a list of bytes to a readable number based on the datatype.
|
||||
@ -493,8 +534,8 @@ def main():
|
||||
logging.Formatter("%(asctime)-15s %(levelname)s: %(message)s")
|
||||
)
|
||||
|
||||
if args.action in ["getsetting", "setsetting"] and args.settingid is None:
|
||||
logger.error("`--settingid` is required with `--action getsetting`")
|
||||
if args.action in ["getsetting", "setsetting", "getmanual"] and args.id is None:
|
||||
logger.error(f"`--id` is required with `--action {args.action}`")
|
||||
return
|
||||
|
||||
wpu = IthoWPU(args.master_only, args.slave_only, args.slave_timeout, args.no_cache)
|
||||
@ -507,7 +548,7 @@ def main():
|
||||
process_setsetting(wpu, args)
|
||||
return
|
||||
|
||||
response = wpu.get(args.action, args.settingid)
|
||||
response = wpu.get(args.action, args.id)
|
||||
if response is not None:
|
||||
process_response(args.action, response, args, wpu)
|
||||
|
||||
|
11
itho_i2c.py
11
itho_i2c.py
@ -19,6 +19,7 @@ actions = {
|
||||
"getdatalog": [0xA4, 0x01],
|
||||
"getsetting": [0xA4, 0x10],
|
||||
"setsetting": [0xA4, 0x10],
|
||||
"getmanual": [0x40, 0x30],
|
||||
}
|
||||
|
||||
|
||||
@ -76,6 +77,16 @@ class I2CMaster:
|
||||
+ [0x00, 0x00, 0x00, 0x00] # step
|
||||
+ [0x00, identifier, 0x00]
|
||||
)
|
||||
elif action == "getmanual":
|
||||
byte_identifier = list(identifier.to_bytes(2, byteorder="big"))
|
||||
request = (
|
||||
[0x80]
|
||||
+ actions[action]
|
||||
+ [0x04, 0x04] # read, length
|
||||
+ [0x01] # bank
|
||||
+ byte_identifier
|
||||
+ [0x01] # 1 = manual
|
||||
)
|
||||
else:
|
||||
# 0x80 = source, 0x04 = msg_type, 0x00 = length
|
||||
request = [0x80] + actions[action] + [0x04, 0x00]
|
||||
|
Loading…
Reference in New Issue
Block a user