-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathcmdline.py
executable file
·134 lines (117 loc) · 4.52 KB
/
cmdline.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
#!/usr/bin/env python3
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from pycalima.Calima import Calima,FindCalimas
import sys, getopt, time
def printHelp():
print("\nCommand control and monitoring tool for PAX Calima fan. Let the air flow!\n")
print("-h\tshow this help list")
print("-l\tScan and list all found Calimas")
print("-m MAC\tSpecify Calima MAC address")
print("-p PIN\tSpecify Calima Pincode")
print("-s\tScan all characteristics")
print("-b SEC\tEnable Boost mode for SEC seconds")
print("-t SPD\tSet trickle speed to SPD in all modes. Use max 2000.")
print("\tWarning: this will make fan run at at this speed all the time")
def main():
# Define vars
action = ""
mac_address = ""
pincode = ""
boostsecs = 0
tricklespeed = 950
try:
opts, args = getopt.getopt(sys.argv[1:], "hb:lsm:p:t:")
except getopt.GetoptError:
printHelp()
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
printHelp()
sys.exit()
elif opt == '-l':
print(FindCalimas())
sys.exit()
elif opt in ("-m"):
mac_address = arg
elif opt in ("-p"):
pincode = arg
elif opt in ("-s"):
action = "scan"
elif opt == '-b':
action = "startboost"
boostsecs= int(arg)
elif opt == '-t':
action = "settrickle"
tricklespeed= int(arg)
else:
usage()
sys.exit(2)
if pincode == "" or mac_address == "":
print("You need to set both mac address and pincode to connect\n")
print("Run me with -h to get some help\n")
sys.exit(2)
fan = Calima(mac_address, pincode)
if action == "startboost":
print("Setting Boost mode for {} seconds".format(boostsecs))
fan.setBoostMode(1,2250,boostsecs)
time.sleep(2)
print(fan.getBoostMode())
fan.disconnect()
elif action == "scan":
fan.scanCharacteristics()
#currentState = fan.getStateShort()
#for item in currentState._fields:
# print("{}={} ".format(item,getattr(currentState, item)),end='')
fan.disconnect()
elif action == "settrickle":
print("Setting tricklespeed to {} ".format(tricklespeed))
fan.setFanSpeedSettings(2250,975,tricklespeed)
time.sleep(2)
print(fan.getFanSpeedSettings())
fan.disconnect()
else:
print("Device Name: ", fan.getDeviceName())
print("Model Number: ", fan.getModelNumber())
print("Serial Number: ", fan.getSerialNumber())
print("Hardware Revision: ", fan.getHardwareRevision())
print("Firmware Revision: ", fan.getFirmwareRevision())
print("Software Revision: ", fan.getSoftwareRevision())
print("Manufacturer: ", fan.getManufacturer())
print("Alias: ", fan.getAlias())
print("Factory Settings Changed: ", fan.getFactorySettingsChanged())
print("Mode: ", fan.getMode())
print("Fan Speed Settings: ", fan.getFanSpeedSettings())
print("Sensors Sensitivity: ", fan.getSensorsSensitivity())
print("Light Sensor Settings: ", fan.getLightSensorSettings())
print("Heat Distributor: ", fan.getHeatDistributor())
print("Boost Mode: ", fan.getBoostMode())
print("Led: ", fan.getLed())
print("Automatic Cycles: ", fan.getAutomaticCycles())
print("Time: ", fan.getTime())
print("Silent Hours: ", fan.getSilentHours())
print("Trickle Days: ", fan.getTrickleDays())
while True:
try:
print(fan.getState())
time.sleep(2)
except Exception as e:
print(e)
fan.disconnect()
break
if __name__ == '__main__':
main()