-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtemperature_profile.py
31 lines (27 loc) · 1.16 KB
/
temperature_profile.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
"""Model temperature profile that changes at a constant rate"""
from time import sleep
from threading import Thread
from threading import Lock
from threading import Event
from pyModbusTCP.client import ModbusClient
class TemperatureProfile(Thread):
"""Sets a fixed amount by which the temperature is incremented or decremented per second."""
temperature = 90 # Class instance
def __init__(self, identity, lock, event, dtemp, dtime):
"""Sets the rate of change for the temperature.
dtemp = number of degrees change each cycle
dtime = number of seconds between temperature changes"""
Thread.__init__(self)
self.dtemp = dtemp
self.dtime = dtime
self.identity = identity
self.lock = lock
self.event = event
def run(self):
"""Updates the class temperature instance from within its own thread"""
while True:
if TemperatureProfile.temperature is not None:
self.event.wait()
with self.lock: # Acquire the lock
TemperatureProfile.temperature = TemperatureProfile.temperature + self.dtemp
sleep(self.dtime)