mirror of
https://github.com/pommi/python-itho-wpu.git
synced 2024-12-21 18:43:27 +01:00
feat: add support for reading counters
This commit is contained in:
parent
e02aa03459
commit
dfc78da5ba
25
README.md
25
README.md
@ -132,6 +132,31 @@ 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)
|
139. Blokkade Tijd Van Verwarmen Naar Koelen (uur): 48 (min: 0, max: 168, step: 1)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* Retrieve counters of the WPU
|
||||||
|
```
|
||||||
|
./itho-wpu.py --action getcounters
|
||||||
|
0. Bedrijf Cv Pomp (cnt_chpump): 5295 uur
|
||||||
|
1. Bedrijf Bron Pomp (cnt_source): 873 uur
|
||||||
|
2. Bedrijf Boiler Pomp (cnt_dhw): 56085 uur
|
||||||
|
3. Bedrijf Compressor (cnt_comp): 53066 uur
|
||||||
|
4. Bedrijf Elektrisch Element (cnt_elek): 45568 uur
|
||||||
|
5. Cv Bedrijf (cnt_chmode): 2869 uur
|
||||||
|
6. Boiler Bedrijf (cnt_dhwmode): 42518 uur
|
||||||
|
7. Vrijkoel Bedrijf (cnt_fcmode): 64098 uur
|
||||||
|
8. Bedrijf (cnt_run): 34559 uur
|
||||||
|
9. Cv Pomp Starts (cnt_chpstart): 65317
|
||||||
|
10. Bron Pomp Starts (cnt_srcpstart): 40672
|
||||||
|
11. Boiler Pomp Starts (cnt_dhwpstart): 30485
|
||||||
|
12. Compressor Starts (cnt_compstart): 62495
|
||||||
|
13. Elektrisch Element Start (cnt_elekstart): 44800
|
||||||
|
14. Cv Starts (cnt_chmstart): 9229
|
||||||
|
15. Boiler Starts (cnt_dhwmstart): 2069
|
||||||
|
16. Vrijkoel Starts (cnt_fcmstart): 62218
|
||||||
|
17. Systeem Starts (cnt_system): 61952
|
||||||
|
18. Bedrijf Dhw Element (cnt_dhwelement): 15616 uur
|
||||||
|
19. Dhw E-Element Starts (cnt_dhwestart): 0
|
||||||
|
```
|
||||||
|
|
||||||
* Retrieve a manual operation setting from the WPU
|
* Retrieve a manual operation setting from the WPU
|
||||||
```
|
```
|
||||||
# ./itho-wpu.py --loglevel info --action getmanual --id 0
|
# ./itho-wpu.py --loglevel info --action getmanual --id 0
|
||||||
|
@ -38,7 +38,9 @@ def convert(par_file, sqlite_db):
|
|||||||
|
|
||||||
tables = []
|
tables = []
|
||||||
for table_info in par_cur.tables(tableType="TABLE"):
|
for table_info in par_cur.tables(tableType="TABLE"):
|
||||||
if re.match("^(VersieBeheer|Data[Ll]abel|Parameterlijst|Handbed)", table_info.table_name):
|
if re.match(
|
||||||
|
"^(VersieBeheer|Data[Ll]abel|Parameterlijst|Handbed|Counters)", table_info.table_name
|
||||||
|
):
|
||||||
tables.append(table_info.table_name)
|
tables.append(table_info.table_name)
|
||||||
|
|
||||||
for t in sorted(tables):
|
for t in sorted(tables):
|
||||||
@ -69,6 +71,19 @@ def convert(par_file, sqlite_db):
|
|||||||
r.Eenheid_NL,
|
r.Eenheid_NL,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
if re.match("^Counters", t):
|
||||||
|
par_cur.execute(f"select Index, Naam, Tekst_NL, Tooltip_NL, Eenheid_NL from {t}")
|
||||||
|
rows = par_cur.fetchall()
|
||||||
|
for r in sorted(rows):
|
||||||
|
data.append(
|
||||||
|
(
|
||||||
|
r.Index,
|
||||||
|
r.Naam,
|
||||||
|
r.Tekst_NL,
|
||||||
|
r.Tooltip_NL,
|
||||||
|
r.Eenheid_NL,
|
||||||
|
)
|
||||||
|
)
|
||||||
if re.match("^Handbed", t):
|
if re.match("^Handbed", t):
|
||||||
par_cur.execute(
|
par_cur.execute(
|
||||||
"select Index, Naam, Naam_fabriek, Min, Max, Default, "
|
"select Index, Naam, Naam_fabriek, Min, Max, Default, "
|
||||||
@ -90,10 +105,12 @@ def convert(par_file, sqlite_db):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
if re.match("^VersieBeheer", t):
|
if re.match("^VersieBeheer", t):
|
||||||
par_cur.execute(f"select VersieNummer, DataLabel, ParameterLijst, Handbed from {t}")
|
par_cur.execute(
|
||||||
|
f"select VersieNummer, DataLabel, ParameterLijst, Handbed, Counters from {t}"
|
||||||
|
)
|
||||||
rows = par_cur.fetchall()
|
rows = par_cur.fetchall()
|
||||||
for r in sorted(rows):
|
for r in sorted(rows):
|
||||||
data.append((r.VersieNummer, r.DataLabel, r.ParameterLijst, r.Handbed))
|
data.append((r.VersieNummer, r.DataLabel, r.ParameterLijst, r.Handbed, r.Counters))
|
||||||
sqlite_db.insert(t.lower(), data)
|
sqlite_db.insert(t.lower(), data)
|
||||||
|
|
||||||
|
|
||||||
|
25
db.py
25
db.py
@ -44,6 +44,17 @@ class sqlite:
|
|||||||
);""".format(
|
);""".format(
|
||||||
t
|
t
|
||||||
)
|
)
|
||||||
|
elif t.startswith("counters"):
|
||||||
|
query = """
|
||||||
|
CREATE TABLE {} (
|
||||||
|
id real,
|
||||||
|
name text,
|
||||||
|
title text,
|
||||||
|
tooltip text,
|
||||||
|
unit text
|
||||||
|
);""".format(
|
||||||
|
t
|
||||||
|
)
|
||||||
elif t.startswith("handbed"):
|
elif t.startswith("handbed"):
|
||||||
query = """
|
query = """
|
||||||
CREATE TABLE {} (
|
CREATE TABLE {} (
|
||||||
@ -80,7 +91,8 @@ class sqlite:
|
|||||||
version integer primary key,
|
version integer primary key,
|
||||||
datalabel integer,
|
datalabel integer,
|
||||||
parameterlist integer,
|
parameterlist integer,
|
||||||
handbed integer
|
handbed integer,
|
||||||
|
counters interger
|
||||||
);""".format(
|
);""".format(
|
||||||
t
|
t
|
||||||
)
|
)
|
||||||
@ -102,6 +114,13 @@ class sqlite:
|
|||||||
""".format(
|
""".format(
|
||||||
t
|
t
|
||||||
)
|
)
|
||||||
|
elif t.startswith("counters"):
|
||||||
|
query = """
|
||||||
|
INSERT INTO {} (id, name, title, tooltip, unit)
|
||||||
|
VALUES (?, ?, ?, ?, ?);
|
||||||
|
""".format(
|
||||||
|
t
|
||||||
|
)
|
||||||
elif t.startswith("handbed"):
|
elif t.startswith("handbed"):
|
||||||
query = """
|
query = """
|
||||||
INSERT INTO {} (id, name, name_factory, min, max, def, title, tooltip, unit)
|
INSERT INTO {} (id, name, name_factory, min, max, def, title, tooltip, unit)
|
||||||
@ -111,8 +130,8 @@ class sqlite:
|
|||||||
)
|
)
|
||||||
elif t.startswith("versiebeheer"):
|
elif t.startswith("versiebeheer"):
|
||||||
query = """
|
query = """
|
||||||
INSERT INTO {} (version, datalabel, parameterlist, handbed)
|
INSERT INTO {} (version, datalabel, parameterlist, handbed, counters)
|
||||||
VALUES (?, ?, ?, ?);
|
VALUES (?, ?, ?, ?, ?);
|
||||||
""".format(
|
""".format(
|
||||||
t
|
t
|
||||||
)
|
)
|
||||||
|
34
itho-wpu.py
34
itho-wpu.py
@ -27,6 +27,7 @@ actions = {
|
|||||||
"setsetting": [0xA4, 0x10],
|
"setsetting": [0xA4, 0x10],
|
||||||
"getmanual": [0x40, 0x30],
|
"getmanual": [0x40, 0x30],
|
||||||
"setmanual": [0x40, 0x30],
|
"setmanual": [0x40, 0x30],
|
||||||
|
"getcounters": [0x42, 0x10],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -171,6 +172,19 @@ class IthoWPU:
|
|||||||
return datalog
|
return datalog
|
||||||
return datalog
|
return datalog
|
||||||
|
|
||||||
|
def get_counters(self):
|
||||||
|
listversion = self.get_listversion_from_nodeid()
|
||||||
|
counters_version = self.heatpump_db.execute(
|
||||||
|
f"SELECT counters FROM versiebeheer WHERE version = {listversion}"
|
||||||
|
)[0]["counters"]
|
||||||
|
if counters_version is None or not type(counters_version) == int:
|
||||||
|
logger.error(f"Counters not found in database for version {listversion}")
|
||||||
|
return None
|
||||||
|
settings = self.heatpump_db.execute(
|
||||||
|
"SELECT id, name, title, tooltip, unit " + f"FROM counters_v{counters_version}"
|
||||||
|
)
|
||||||
|
return settings
|
||||||
|
|
||||||
def get_settings(self):
|
def get_settings(self):
|
||||||
listversion = self.get_listversion_from_nodeid()
|
listversion = self.get_listversion_from_nodeid()
|
||||||
parameterlist_version = self.heatpump_db.execute(
|
parameterlist_version = self.heatpump_db.execute(
|
||||||
@ -294,6 +308,8 @@ def process_response(action, response, args, wpu):
|
|||||||
process_nodeid(response)
|
process_nodeid(response)
|
||||||
elif action == "getserial":
|
elif action == "getserial":
|
||||||
process_serial(response)
|
process_serial(response)
|
||||||
|
elif action == "getcounters":
|
||||||
|
process_counters(response, wpu)
|
||||||
|
|
||||||
|
|
||||||
def process_nodeid(response):
|
def process_nodeid(response):
|
||||||
@ -324,6 +340,24 @@ def process_serial(response):
|
|||||||
logger.info(f"Serial: {serial}")
|
logger.info(f"Serial: {serial}")
|
||||||
|
|
||||||
|
|
||||||
|
def process_counters(response, wpu):
|
||||||
|
counters = wpu.get_counters()
|
||||||
|
message = response[5:]
|
||||||
|
for c in counters:
|
||||||
|
index = int(c["id"]) * 2
|
||||||
|
num = format_datatype(c["name"], message[index : index + 2], 0x10) # noqa: E203
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
"{}. {} ({}): {}{}".format(
|
||||||
|
int(c["id"]),
|
||||||
|
c["title"].title(),
|
||||||
|
c["name"].lower(),
|
||||||
|
num,
|
||||||
|
" " + c["unit"] if c["unit"] is not None else "",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def process_datalog(response, wpu):
|
def process_datalog(response, wpu):
|
||||||
datalog = wpu.get_datalog_structure()
|
datalog = wpu.get_datalog_structure()
|
||||||
message = response[5:]
|
message = response[5:]
|
||||||
|
@ -21,6 +21,7 @@ actions = {
|
|||||||
"setsetting": [0xA4, 0x10],
|
"setsetting": [0xA4, 0x10],
|
||||||
"getmanual": [0x40, 0x30],
|
"getmanual": [0x40, 0x30],
|
||||||
"setmanual": [0x40, 0x30],
|
"setmanual": [0x40, 0x30],
|
||||||
|
"getcounters": [0x42, 0x10],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user