mirror of
https://github.com/pommi/python-itho-wpu.git
synced 2024-12-21 18:43:27 +01:00
Compare commits
2 Commits
71e776e092
...
dfc78da5ba
Author | SHA1 | Date | |
---|---|---|---|
dfc78da5ba | |||
e02aa03459 |
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)
|
||||
```
|
||||
|
||||
* 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
|
||||
```
|
||||
# ./itho-wpu.py --loglevel info --action getmanual --id 0
|
||||
|
@ -38,7 +38,9 @@ def convert(par_file, sqlite_db):
|
||||
|
||||
tables = []
|
||||
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)
|
||||
|
||||
for t in sorted(tables):
|
||||
@ -69,6 +71,19 @@ def convert(par_file, sqlite_db):
|
||||
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):
|
||||
par_cur.execute(
|
||||
"select Index, Naam, Naam_fabriek, Min, Max, Default, "
|
||||
@ -90,10 +105,12 @@ def convert(par_file, sqlite_db):
|
||||
)
|
||||
)
|
||||
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()
|
||||
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)
|
||||
|
||||
|
||||
|
25
db.py
25
db.py
@ -44,6 +44,17 @@ class sqlite:
|
||||
);""".format(
|
||||
t
|
||||
)
|
||||
elif t.startswith("counters"):
|
||||
query = """
|
||||
CREATE TABLE {} (
|
||||
id real,
|
||||
name text,
|
||||
title text,
|
||||
tooltip text,
|
||||
unit text
|
||||
);""".format(
|
||||
t
|
||||
)
|
||||
elif t.startswith("handbed"):
|
||||
query = """
|
||||
CREATE TABLE {} (
|
||||
@ -80,7 +91,8 @@ class sqlite:
|
||||
version integer primary key,
|
||||
datalabel integer,
|
||||
parameterlist integer,
|
||||
handbed integer
|
||||
handbed integer,
|
||||
counters interger
|
||||
);""".format(
|
||||
t
|
||||
)
|
||||
@ -102,6 +114,13 @@ class sqlite:
|
||||
""".format(
|
||||
t
|
||||
)
|
||||
elif t.startswith("counters"):
|
||||
query = """
|
||||
INSERT INTO {} (id, name, title, tooltip, unit)
|
||||
VALUES (?, ?, ?, ?, ?);
|
||||
""".format(
|
||||
t
|
||||
)
|
||||
elif t.startswith("handbed"):
|
||||
query = """
|
||||
INSERT INTO {} (id, name, name_factory, min, max, def, title, tooltip, unit)
|
||||
@ -111,8 +130,8 @@ class sqlite:
|
||||
)
|
||||
elif t.startswith("versiebeheer"):
|
||||
query = """
|
||||
INSERT INTO {} (version, datalabel, parameterlist, handbed)
|
||||
VALUES (?, ?, ?, ?);
|
||||
INSERT INTO {} (version, datalabel, parameterlist, handbed, counters)
|
||||
VALUES (?, ?, ?, ?, ?);
|
||||
""".format(
|
||||
t
|
||||
)
|
||||
|
56
itho-wpu.py
56
itho-wpu.py
@ -27,6 +27,7 @@ actions = {
|
||||
"setsetting": [0xA4, 0x10],
|
||||
"getmanual": [0x40, 0x30],
|
||||
"setmanual": [0x40, 0x30],
|
||||
"getcounters": [0x42, 0x10],
|
||||
}
|
||||
|
||||
|
||||
@ -92,13 +93,13 @@ class IthoWPU:
|
||||
self._q = queue.Queue()
|
||||
self.no_cache = no_cache
|
||||
self.cache = IthoWPUCache()
|
||||
self.nodeid = self.get("getnodeid")
|
||||
self.datatype = self.get("getdatatype")
|
||||
self.nodeid = self.call("getnodeid")
|
||||
self.datatype = self.call("getdatatype")
|
||||
self.heatpump_db = db.sqlite("heatpump.sqlite")
|
||||
|
||||
def get(self, action, identifier=None, datatype=None, value=None, check=True):
|
||||
def call(self, action, identifier=None, datatype=None, value=None, check=True):
|
||||
if not self.no_cache:
|
||||
response = self.cache.get(action.replace("get", ""))
|
||||
response = self.cache.call(action.replace("get", ""))
|
||||
if response is not None:
|
||||
logger.debug(f"Response (from cache): {response}")
|
||||
return response
|
||||
@ -171,6 +172,19 @@ class IthoWPU:
|
||||
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):
|
||||
listversion = self.get_listversion_from_nodeid()
|
||||
parameterlist_version = self.heatpump_db.execute(
|
||||
@ -245,7 +259,7 @@ class IthoWPUCache:
|
||||
logger.debug(f"Writing to local cache: {json.dumps(self._cache_data)}")
|
||||
json.dump(self._cache_data, cache_file)
|
||||
|
||||
def get(self, action):
|
||||
def call(self, action):
|
||||
if action not in ["nodeid", "serial", "datatype"]:
|
||||
logger.debug(f"Cache for '{action}' is not supported")
|
||||
return None
|
||||
@ -294,6 +308,8 @@ def process_response(action, response, args, wpu):
|
||||
process_nodeid(response)
|
||||
elif action == "getserial":
|
||||
process_serial(response)
|
||||
elif action == "getcounters":
|
||||
process_counters(response, wpu)
|
||||
|
||||
|
||||
def process_nodeid(response):
|
||||
@ -324,6 +340,24 @@ def process_serial(response):
|
||||
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):
|
||||
datalog = wpu.get_datalog_structure()
|
||||
message = response[5:]
|
||||
@ -388,14 +422,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"]))
|
||||
response = wpu.call("getsetting", int(setting["id"]))
|
||||
if response is not None:
|
||||
process_response("getsetting", response, args, wpu)
|
||||
|
||||
|
||||
def process_setsetting(wpu, args):
|
||||
logger.info("Current setting:")
|
||||
response = wpu.get("getsetting", int(args.id))
|
||||
response = wpu.call("getsetting", int(args.id))
|
||||
if response is None:
|
||||
return
|
||||
process_response("getsetting", response, args, wpu)
|
||||
@ -433,7 +467,7 @@ def process_setsetting(wpu, args):
|
||||
logger.error("Aborted")
|
||||
return
|
||||
|
||||
response = wpu.get("setsetting", args.id, None, normalized_value)
|
||||
response = wpu.call("setsetting", args.id, None, normalized_value)
|
||||
if response is None:
|
||||
return
|
||||
process_response("getsetting", response, args, wpu)
|
||||
@ -463,7 +497,7 @@ def process_manual(response, wpu):
|
||||
|
||||
def process_setmanual(wpu, args):
|
||||
logger.info("Current manual operation:")
|
||||
response = wpu.get("getmanual", int(args.id))
|
||||
response = wpu.call("getmanual", int(args.id))
|
||||
if response is None:
|
||||
return
|
||||
process_response("getmanual", response, args, wpu)
|
||||
@ -498,7 +532,7 @@ def process_setmanual(wpu, args):
|
||||
logger.error("Aborted")
|
||||
return
|
||||
|
||||
response = wpu.get("setmanual", args.id, int(datatype, 0), normalized_value, args.check)
|
||||
response = wpu.call("setmanual", args.id, int(datatype, 0), normalized_value, args.check)
|
||||
|
||||
|
||||
def format_datatype(name, m, dt):
|
||||
@ -599,7 +633,7 @@ def main():
|
||||
process_setmanual(wpu, args)
|
||||
return
|
||||
|
||||
response = wpu.get(args.action, args.id)
|
||||
response = wpu.call(args.action, args.id)
|
||||
if response is not None:
|
||||
process_response(args.action, response, args, wpu)
|
||||
|
||||
|
@ -21,6 +21,7 @@ actions = {
|
||||
"setsetting": [0xA4, 0x10],
|
||||
"getmanual": [0x40, 0x30],
|
||||
"setmanual": [0x40, 0x30],
|
||||
"getcounters": [0x42, 0x10],
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user