mirror of
https://github.com/pommi/python-itho-wpu.git
synced 2024-12-22 18:53:28 +01:00
Compare commits
No commits in common. "dfc78da5ba2fa7179be9238a0b7601eae20b487d" and "71e776e09291462996f4b5edc5269ed9f6854bf4" have entirely different histories.
dfc78da5ba
...
71e776e092
25
README.md
25
README.md
@ -132,31 +132,6 @@ 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,9 +38,7 @@ 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(
|
if re.match("^(VersieBeheer|Data[Ll]abel|Parameterlijst|Handbed)", table_info.table_name):
|
||||||
"^(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):
|
||||||
@ -71,19 +69,6 @@ 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, "
|
||||||
@ -105,12 +90,10 @@ def convert(par_file, sqlite_db):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
if re.match("^VersieBeheer", t):
|
if re.match("^VersieBeheer", t):
|
||||||
par_cur.execute(
|
par_cur.execute(f"select VersieNummer, DataLabel, ParameterLijst, Handbed from {t}")
|
||||||
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, r.Counters))
|
data.append((r.VersieNummer, r.DataLabel, r.ParameterLijst, r.Handbed))
|
||||||
sqlite_db.insert(t.lower(), data)
|
sqlite_db.insert(t.lower(), data)
|
||||||
|
|
||||||
|
|
||||||
|
25
db.py
25
db.py
@ -44,17 +44,6 @@ 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 {} (
|
||||||
@ -91,8 +80,7 @@ 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
|
||||||
)
|
)
|
||||||
@ -114,13 +102,6 @@ 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)
|
||||||
@ -130,8 +111,8 @@ class sqlite:
|
|||||||
)
|
)
|
||||||
elif t.startswith("versiebeheer"):
|
elif t.startswith("versiebeheer"):
|
||||||
query = """
|
query = """
|
||||||
INSERT INTO {} (version, datalabel, parameterlist, handbed, counters)
|
INSERT INTO {} (version, datalabel, parameterlist, handbed)
|
||||||
VALUES (?, ?, ?, ?, ?);
|
VALUES (?, ?, ?, ?);
|
||||||
""".format(
|
""".format(
|
||||||
t
|
t
|
||||||
)
|
)
|
||||||
|
56
itho-wpu.py
56
itho-wpu.py
@ -27,7 +27,6 @@ actions = {
|
|||||||
"setsetting": [0xA4, 0x10],
|
"setsetting": [0xA4, 0x10],
|
||||||
"getmanual": [0x40, 0x30],
|
"getmanual": [0x40, 0x30],
|
||||||
"setmanual": [0x40, 0x30],
|
"setmanual": [0x40, 0x30],
|
||||||
"getcounters": [0x42, 0x10],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -93,13 +92,13 @@ class IthoWPU:
|
|||||||
self._q = queue.Queue()
|
self._q = queue.Queue()
|
||||||
self.no_cache = no_cache
|
self.no_cache = no_cache
|
||||||
self.cache = IthoWPUCache()
|
self.cache = IthoWPUCache()
|
||||||
self.nodeid = self.call("getnodeid")
|
self.nodeid = self.get("getnodeid")
|
||||||
self.datatype = self.call("getdatatype")
|
self.datatype = self.get("getdatatype")
|
||||||
self.heatpump_db = db.sqlite("heatpump.sqlite")
|
self.heatpump_db = db.sqlite("heatpump.sqlite")
|
||||||
|
|
||||||
def call(self, action, identifier=None, datatype=None, value=None, check=True):
|
def get(self, action, identifier=None, datatype=None, value=None, check=True):
|
||||||
if not self.no_cache:
|
if not self.no_cache:
|
||||||
response = self.cache.call(action.replace("get", ""))
|
response = self.cache.get(action.replace("get", ""))
|
||||||
if response is not None:
|
if response is not None:
|
||||||
logger.debug(f"Response (from cache): {response}")
|
logger.debug(f"Response (from cache): {response}")
|
||||||
return response
|
return response
|
||||||
@ -172,19 +171,6 @@ 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(
|
||||||
@ -259,7 +245,7 @@ class IthoWPUCache:
|
|||||||
logger.debug(f"Writing to local cache: {json.dumps(self._cache_data)}")
|
logger.debug(f"Writing to local cache: {json.dumps(self._cache_data)}")
|
||||||
json.dump(self._cache_data, cache_file)
|
json.dump(self._cache_data, cache_file)
|
||||||
|
|
||||||
def call(self, action):
|
def get(self, action):
|
||||||
if action not in ["nodeid", "serial", "datatype"]:
|
if action not in ["nodeid", "serial", "datatype"]:
|
||||||
logger.debug(f"Cache for '{action}' is not supported")
|
logger.debug(f"Cache for '{action}' is not supported")
|
||||||
return None
|
return None
|
||||||
@ -308,8 +294,6 @@ 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):
|
||||||
@ -340,24 +324,6 @@ 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:]
|
||||||
@ -422,14 +388,14 @@ def process_setting(response, wpu):
|
|||||||
def process_settings(wpu, args):
|
def process_settings(wpu, args):
|
||||||
settings = wpu.get_settings()
|
settings = wpu.get_settings()
|
||||||
for setting in settings:
|
for setting in settings:
|
||||||
response = wpu.call("getsetting", int(setting["id"]))
|
response = wpu.get("getsetting", int(setting["id"]))
|
||||||
if response is not None:
|
if response is not None:
|
||||||
process_response("getsetting", response, args, wpu)
|
process_response("getsetting", response, args, wpu)
|
||||||
|
|
||||||
|
|
||||||
def process_setsetting(wpu, args):
|
def process_setsetting(wpu, args):
|
||||||
logger.info("Current setting:")
|
logger.info("Current setting:")
|
||||||
response = wpu.call("getsetting", int(args.id))
|
response = wpu.get("getsetting", int(args.id))
|
||||||
if response is None:
|
if response is None:
|
||||||
return
|
return
|
||||||
process_response("getsetting", response, args, wpu)
|
process_response("getsetting", response, args, wpu)
|
||||||
@ -467,7 +433,7 @@ def process_setsetting(wpu, args):
|
|||||||
logger.error("Aborted")
|
logger.error("Aborted")
|
||||||
return
|
return
|
||||||
|
|
||||||
response = wpu.call("setsetting", args.id, None, normalized_value)
|
response = wpu.get("setsetting", args.id, None, normalized_value)
|
||||||
if response is None:
|
if response is None:
|
||||||
return
|
return
|
||||||
process_response("getsetting", response, args, wpu)
|
process_response("getsetting", response, args, wpu)
|
||||||
@ -497,7 +463,7 @@ def process_manual(response, wpu):
|
|||||||
|
|
||||||
def process_setmanual(wpu, args):
|
def process_setmanual(wpu, args):
|
||||||
logger.info("Current manual operation:")
|
logger.info("Current manual operation:")
|
||||||
response = wpu.call("getmanual", int(args.id))
|
response = wpu.get("getmanual", int(args.id))
|
||||||
if response is None:
|
if response is None:
|
||||||
return
|
return
|
||||||
process_response("getmanual", response, args, wpu)
|
process_response("getmanual", response, args, wpu)
|
||||||
@ -532,7 +498,7 @@ def process_setmanual(wpu, args):
|
|||||||
logger.error("Aborted")
|
logger.error("Aborted")
|
||||||
return
|
return
|
||||||
|
|
||||||
response = wpu.call("setmanual", args.id, int(datatype, 0), normalized_value, args.check)
|
response = wpu.get("setmanual", args.id, int(datatype, 0), normalized_value, args.check)
|
||||||
|
|
||||||
|
|
||||||
def format_datatype(name, m, dt):
|
def format_datatype(name, m, dt):
|
||||||
@ -633,7 +599,7 @@ def main():
|
|||||||
process_setmanual(wpu, args)
|
process_setmanual(wpu, args)
|
||||||
return
|
return
|
||||||
|
|
||||||
response = wpu.call(args.action, args.id)
|
response = wpu.get(args.action, args.id)
|
||||||
if response is not None:
|
if response is not None:
|
||||||
process_response(args.action, response, args, wpu)
|
process_response(args.action, response, args, wpu)
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ 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