From 38d3bd722d013ab10febcd121f517a1db935009f Mon Sep 17 00:00:00 2001 From: Jarno Rankinen Date: Sun, 15 Jan 2023 14:44:00 +0200 Subject: [PATCH] EPingvincoils class, reads values from bus on init --- enervent-ctrl-python/.gitignore | 3 +- enervent-ctrl-python/src/EnerventCoils.py | 92 +++++++++++++++++++++ enervent-ctrl-python/src/enervent-logger.py | 6 +- 3 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 enervent-ctrl-python/src/EnerventCoils.py diff --git a/enervent-ctrl-python/.gitignore b/enervent-ctrl-python/.gitignore index 068b6b7..9e4c91c 100644 --- a/enervent-ctrl-python/.gitignore +++ b/enervent-ctrl-python/.gitignore @@ -1,5 +1,6 @@ +*/__pycache__/ bin/ include/ lib/ lib64 -share/ \ No newline at end of file +share/ diff --git a/enervent-ctrl-python/src/EnerventCoils.py b/enervent-ctrl-python/src/EnerventCoils.py new file mode 100644 index 0000000..5a6607c --- /dev/null +++ b/enervent-ctrl-python/src/EnerventCoils.py @@ -0,0 +1,92 @@ +import minimalmodbus + +class EnerventCoil(): + def __init__(self, symbol="", description="", reserved=True): + self.symbol = symbol + self.value = 0 + self.description = description + self.reserved = reserved + +class PingvinCoils(): + coils = [ + EnerventCoil("COIL_STOP", "Stop"), + EnerventCoil("COIL_AWAY", "Away mode"), + EnerventCoil("COIL_AWAY_L", "Away Long mode"), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil("COIL_MAX_H", "Max Heating"), + EnerventCoil("COIL_MAX_C", "Max Cooling"), + EnerventCoil("COIL_CO_BOOST_EN", "CO2 boost"), + EnerventCoil("COIL_RH_BOOST_EN", "Relative humidity boost"), + EnerventCoil("COIL_M_BOOST", "Manual boost 100%"), + EnerventCoil("COIL_TEMP_BOOST_EN", "Temperature boost"), + EnerventCoil("COIL_SNC", "Summer night cooling"), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil("COIL_AWAY_H", "Heating enabled/disabled in AWAY mode"), + EnerventCoil("COIL_AWAY_C", "Cooling enabled/disabled in AWAY mode"), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil("COIL_LTO_ON", "Heat recycler state (running=1, stopped = 0)"), + EnerventCoil(), + EnerventCoil("COIL_HEAT_ON", "After heater element state (On = 1, Off = 0)"), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil("COIL_TEMP_DECREASE", "Temperature decrease function"), + EnerventCoil("COIL_OVERTIME", "Programmatic equivalent of OVERTIME digital input"), + EnerventCoil(), + EnerventCoil(), + EnerventCoil("COIL_ECO_MODE", "Eco mode"), + EnerventCoil("COIL_ALARM_A", "Alarm of class A active"), + EnerventCoil("COIL_ALARM_B", "Alarm of class B active"), + EnerventCoil("COIL_CLK_PROG", "Clock program is currently active"), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil("COIL_SILENT_MODE", "Silent mode"), + EnerventCoil("COIL_STOP_SLP_COOLING", "Electrical heater cool-off function enabled when the machine has stopped"), + EnerventCoil("COIL_SERVICE_EN", "Service reminder"), + EnerventCoil(), + EnerventCoil(), + EnerventCoil("COIL_COOLING_EN", "Active cooling function enabled"), + EnerventCoil("COIL_LTO_EN"), + EnerventCoil("COIL_HEATING_EN", "Active heating function enabled"), + EnerventCoil("COIL_LTO_DEFROST_EN", "HRC defrosting function enabled during winter season"), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil(), + EnerventCoil() + ] + + def __init__(self, serialdevice='/dev/ttyS0', modbusaddr=1, debug=False): + self.pingvin = minimalmodbus.Instrument(serialdevice, modbusaddr) + self.pingvin.serial.timeout = 0.2 + self.pingvin.debug = debug + curvalues = self.pingvin.read_bits(0,71,1) + for i, coil in enumerate(self.coils): + self.coils[i].value = curvalues[i] + diff --git a/enervent-ctrl-python/src/enervent-logger.py b/enervent-ctrl-python/src/enervent-logger.py index e44479b..96987a0 100755 --- a/enervent-ctrl-python/src/enervent-logger.py +++ b/enervent-ctrl-python/src/enervent-logger.py @@ -1,17 +1,17 @@ #!/usr/bin/env python -import minimalmodbus import logging +from EnerventCoils import PingvinCoils VERSION = "0.0.1" ## Logging configuration log = logging.getLogger(__name__) logging.basicConfig( - level=logging.INFO, + level=logging.DEBUG, format='%(asctime)s %(message)s', datefmt='%y/%m/%d %H:%M:%S' ) if __name__ == "__main__": log.info(f"Starting enervent-logger {VERSION}") - \ No newline at end of file + pingvin = PingvinCoils('/dev/ttyS0',1,debug=True)