Added suport for in valve
This commit is contained in:
@@ -7,29 +7,50 @@ class Changer(object):
|
||||
self.local_state = local_state
|
||||
self.remote_state = remote_state
|
||||
GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme
|
||||
GPIO.setup(config.GPIO_PIN_VALVE, GPIO.OUT)
|
||||
GPIO.setup(config.GPIO_PIN_OUT_VALVE, GPIO.OUT)
|
||||
GPIO.setup(config.GPIO_PIN_IN_VALVE, GPIO.OUT)
|
||||
|
||||
self.states = {
|
||||
'opening': self.open_valve,
|
||||
'closing': self.close_valve,
|
||||
'open': self.open_valve,
|
||||
'closed': self.close_valve
|
||||
self.out_valve_states = {
|
||||
'opening': self.open_out_valve,
|
||||
'closing': self.close_out_valve,
|
||||
'open': self.open_out_valve,
|
||||
'closed': self.close_out_valve
|
||||
}
|
||||
|
||||
self.in_valve_states = {
|
||||
'opening': self.open_in_valve,
|
||||
'closing': self.close_in_valve,
|
||||
'open': self.open_in_valve,
|
||||
'closed': self.close_in_valve
|
||||
}
|
||||
|
||||
def process_change(self):
|
||||
self.validate_states()
|
||||
change = self.states.get(self.remote_state['out_valve'], None )
|
||||
if change is not None:
|
||||
change()
|
||||
|
||||
out_valve_change = self.out_valve_states.get(self.remote_state['out_valve'], None )
|
||||
if out_valve_change is not None:
|
||||
out_valve_change()
|
||||
|
||||
in_valve_change = self.in_valve_states.get(self.remote_state['in_valve'], None )
|
||||
if in_valve_change is not None:
|
||||
in_valve_change()
|
||||
|
||||
return self.local_state
|
||||
|
||||
def open_valve(self):
|
||||
GPIO.output(config.GPIO_PIN_VALVE, GPIO.HIGH)
|
||||
def open_in_valve(self):
|
||||
GPIO.output(config.GPIO_PIN_IN_VALVE, GPIO.HIGH)
|
||||
self.local_state['in_valve'] = 'open'
|
||||
|
||||
def close_in_valve(self):
|
||||
GPIO.output(config.GPIO_PIN_IN_VALVE, GPIO.LOW)
|
||||
self.local_state['in_valve'] = 'closed'
|
||||
|
||||
def open_out_valve(self):
|
||||
GPIO.output(config.GPIO_PIN_OUT_VALVE, GPIO.HIGH)
|
||||
self.local_state['out_valve'] = 'open'
|
||||
|
||||
def close_valve(self):
|
||||
GPIO.output(config.GPIO_PIN_VALVE, GPIO.LOW)
|
||||
def close_out_valve(self):
|
||||
GPIO.output(config.GPIO_PIN_OUT_VALVE, GPIO.LOW)
|
||||
self.local_state['out_valve'] = 'closed'
|
||||
|
||||
def validate_states(self):
|
||||
|
||||
Reference in New Issue
Block a user