Example #1
0
def _should_reverse_device_state():
    ''' checks the config, if the normal relay state is OPEN then all the device states should be reversed '''
    value = configuration.normal_relay_state()
    if value == 'open': return True
    elif value == 'false': return False
    else: raise Exception('Relay normal state is neither "open" nor "closed", instead is "' + str(value) + '". Pin will not trigger.')
def start_web_interface(server_type = "paste"):        
    """ starts the bottle.py server """            
    print 'Starting web interface...\n'        
    api.start(server_type)
        
if __name__ == "__main__":
    check_and_init_database()     
    check_hardware()
    check_internet_connectivity()    
    start_threads()
    start_web_interface()
    
    try:
        while True:
            pass
    except KeyboardInterrupt:
        print '\nInterrupted, shutting down...'
        # stop threads, cleanup, etc?         
        normal_boolean_state = configuration.normal_relay_state() == 'open'
        brew_logic._set_heater(normal_boolean_state)
        print 'Heater returned to default state...'
        brew_logic._set_freezer(normal_boolean_state)
        print 'Freezer returned to default state...'
        chestfreezer_gpio.cleanup()        
        print 'Goodbye!'
        os._exit(0)
    except Exception as e:
        print 'Exception: ' + str(e)
        
 def test_default_relay_state_is_open(self):
     print configuration.normal_relay_state()
     assert(configuration.normal_relay_state() == 'open')