-
Notifications
You must be signed in to change notification settings - Fork 0
/
AirCleanerController.py
78 lines (60 loc) · 2.3 KB
/
AirCleanerController.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
import utime
import Settings
class AirCleanerController:
def __init__(self, read_sensors_callback, settings_controller: Settings):
self.settings = settings_controller
self.settings.load_settings()
self.set_speed = self.settings.settings['set_speed']
self.manual_speed = self.settings.settings['manual_speed']
self.mode = self.settings.settings['mode']
self.read_sensors_callback = read_sensors_callback
self.sensors_values = {}
self.last_senor_read = 0
def save_settings(self):
self.settings.save_settings()
return True
def read_sensors(self):
if (utime.ticks_ms() - self.last_senor_read) > 1000:
self.sensors_values = self.read_sensors_callback(self.sensors_values)
self.last_senor_read = utime.ticks_ms()
def fan_speed(self):
if self.settings.settings['mode'] == 'M':
return self.settings.settings['manual_speed']
else:
return int(self.settings.settings['set_speed'] * self.sensors_values["dust_level"] / 20)
@property
def temperature(self):
return self.sensors_values["temperature"]
@property
def humidity(self):
return self.sensors_values["humidity"]
@property
def air_pressure(self):
return self.sensors_values["air_pressure"]
@property
def dust_level(self):
return self.sensors_values["dust_level"]
@property
def fan_power(self):
if self.settings.settings['mode'] == 'M':
return self.settings.settings['manual_speed']
else:
return self.settings.settings['set_speed']
@property
def temperature_str(self):
return "{:.2f}°C".format(self.sensors_values["temperature"])
@property
def humidity_str(self):
return "{:.2f}%".format(self.sensors_values["humidity"])
@property
def air_pressure_str(self):
return self.sensors_values["air_pressure"]
@property
def dust_level_str(self):
return "{:.2f}ug/m3".format(self.sensors_values["dust_level"])
@property
def fan_power_str(self):
if self.settings.settings['mode'] == 'M':
return "{}%".format(self.settings.settings['manual_speed'])
else:
return "{}%".format(self.settings.settings['set_speed'])