-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
148 lines (140 loc) · 6.05 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python3
# author(s):
__author__ = "William van Beek"
__copyright__ = ""
__credits__ = ["William van Beek"]
__license__ = "GPL-3.0-only"
__version__ = "0.1"
__maintainer__ = "William van Beek"
__email__ = ""
__status__ = "Testing"
# Imports:
import argparse, time, sys, json
import DOHPC.readConfig as RC
import DOHPC.findIP as FI
import DOHPC.readHP as RH
import DOHPC.createDB as CDB
import DOHPC.sendHP as SH
import DOHPC.showHP as DHP
import DOHPC.mqtt as MQTT
def main():
# Get input form user
parser = argparse.ArgumentParser(
description='Daikin OpenSource HeatPump Controller - (DOHPC)'
)
parser.add_argument('-fip','--find-ip', nargs='+',
help='If you want to automatically find the IP by mDNS, Must come with a serial number!',
dest='findIP')
parser.add_argument('-ip','--ip', nargs='+',
help='You know your IP (nerd!), and want to just use it',
dest='IP')
parser.add_argument('-n','--number', nargs='+',
help='The ammount of daikin devices you have (need to be used with --ip or --fip)',
dest='number')
parser.add_argument('-f','--file',
help='The config file to use (./config.ini), this removes the need for other flags',
dest='file')
parser.add_argument('-d','--display', action='store_true',
help='Just display all the info dont change a thing',
dest='display')
parser.add_argument('-cdb','--create-database',
help='Creates a SQLITE database for you - takes filename as argument.(besure to update the config.ini)',
dest='cdataBase')
parser.add_argument('-db','--database',
help='SQLITE file location.(besure to update the config.ini)',
dest='dataBase')
parser.add_argument('-s','--send',
help='argument can be (T) for temperature or (S) for schedule bust be paired with -v',
dest='sendType')
parser.add_argument('-v','--value',
help='The value to send to the heatpump \n(int for temperature for schedule see DOCUMENTATION)',
dest='sendValue')
parser.add_argument('-r','--read', action='store_true',
help='Set me and I will read the pump and put it in the DB ',
dest='readFlag')
parser.add_argument('-m','--mqtt', action='store_true',
help='Set me and I will start a MQTT loop (BETA FEATURE)',
dest='mqtt')
args = parser.parse_args()
if args.cdataBase:
# we want to initialize a DB
#print(args.cdataBase)
CDB.createDatabase(args.cdataBase)
sys.exit(1)
if args.dataBase:
# database is over written.
daikinDataBase = args.dataBase
else:
daikinDataBase = ""
if args.file:
# User gave a config file
givenConfig = args.file
daikinSearch, daikinSerial, daikinIP, daikinDevices, daikinDataBase, daikinUrlError, daikinUrlBase, daikingUrlDisc, daikinMqttBroker, daikinMqttPublishTempTimeOut, daikinMqttPublishDataTimeOut, daikinMqttExitFile = RC.readConfig(givenConfig)
if daikinSearch == "True":
# ^- need to convert to booleans
DaikinIP = FI.findIP(daikinSerial)
elif daikinIP == "":
daikinIP = ""
elif daikinIP != "":
DaikinIP = daikinIP
else:
print("Error found in IP")
sys.exit(1)
else:
# Not pretty, but it works :)
if args.IP:
# You know the IP, no need to find it
daikinIP = args.IP[0]
if args.number:
daikinDevices = args.number[0]
else:
daikinDevices = ""
elif args.findIP:
# You want to find the ip
daikinSerial = args.findIP[0]
daikinIP = FI.findIP(daikinSerial)
if args.number:
daikinDevices = args.number[0]
else:
daikinDevices = ""
else:
daikinIP = ""
"""
From here we should have a IP to work with.
Time to do some actual work with the heatpump.
"""
# Read Heatpump values:
if daikinIP == "" or daikinDevices == "" or daikinDataBase == "":
print("There is no IP adress, or amount of devices specified, cannot read heatpump")
sys.exit(1)
elif daikinUrlError == "" or daikinUrlBase == "" or daikingUrlDisc == "":
# In case still no config file is being used :(
daikinUrlError = "/[0]/MNAE/"
daikinUrlBase = "/[0]/MNCSE-node/"
daikingUrlDisc = "/[0]/MNAE/0"
else:
# Read current settings from the heatpump
if args.readFlag:
RH.readHPDetails(daikinIP, daikinDataBase, daikinUrlError, daikinUrlBase, daikingUrlDisc, daikinDevices)
if args.display:
DHP.showHPDetails(daikinIP, daikinDataBase, daikinUrlError, daikinUrlBase, daikingUrlDisc, daikinDevices)
elif args.display:
DHP.showHPDetails(daikinIP, daikinDataBase, daikinUrlError, daikinUrlBase, daikingUrlDisc, daikinDevices)
# Run into a while loop here that does its magic.
#pass
elif args.mqtt:
# This will be a loop, And does not exit on its own, nneed to think about reasing / sending data
MQTT.startMQTT(daikinMqttBroker, daikinMqttPublishTempTimeOut, daikinMqttPublishDataTimeOut, daikinMqttExitFile, daikinIP, daikinDataBase, daikinUrlError, daikinUrlBase, daikingUrlDisc, daikinDevices)
"""
Now that we have the valeus, time to do send a new temperature, or schedule to the heatpump
"""
if args.sendType:
# we want to send a value
if args.sendValue:
SH.sendHPvalues(args.sendType, args.sendValue, daikinIP, daikinDataBase, daikinUrlError, daikinUrlBase, daikingUrlDisc, daikinDevices)
else:
print("No data to send")
sys.exit(1)
if __name__ == "__main__":
# Run program
main()