Compare commits
No commits in common. "1c38c61fbc9d50a35d3cf0614b8418a91496f9c6" and "7f88f87722aa05768a11fd3df72fc13e29fa0860" have entirely different histories.
1c38c61fbc
...
7f88f87722
@ -1,47 +0,0 @@
|
||||
from json import dumps
|
||||
|
||||
|
||||
|
||||
from json import dumps
|
||||
|
||||
class ManageController:
|
||||
def __init__(self, producer, topic='commands'):
|
||||
self.valve_state = "closed"
|
||||
self.heater_state = "off"
|
||||
self.producer = producer
|
||||
self.topic = topic
|
||||
|
||||
def toggle_device(self, device, request_id, greenhouse_id):
|
||||
|
||||
|
||||
if device == 'valve':
|
||||
|
||||
if self.valve_state == 'closed':
|
||||
self.valve_state = 'open'
|
||||
print("Valve opened")
|
||||
else:
|
||||
self.valve_state = 'closed'
|
||||
print("Valve closed")
|
||||
|
||||
elif device == 'heater':
|
||||
|
||||
if self.heater_state == 'off':
|
||||
self.heater_state = 'on'
|
||||
print("Heater turned on")
|
||||
else:
|
||||
self.heater_state = 'off'
|
||||
print("Heater turned off")
|
||||
|
||||
|
||||
self.send_status(request_id, greenhouse_id)
|
||||
|
||||
def send_status(self, request_id, greenhouse_id):
|
||||
|
||||
status = {
|
||||
'request_id': request_id,
|
||||
'greenhouse_id': greenhouse_id,
|
||||
'valve_state': self.valve_state,
|
||||
'heater_state': self.heater_state
|
||||
}
|
||||
self.producer.send(self.topic, value=status)
|
||||
print(f"Sent device status: {status}")
|
Loading…
Reference in New Issue
Block a user