def test_apply_instruction(self):
     temperature_probes._last_master_reading = 24.565
     brew_logic.configuration.set_instruction_interval_seconds(0.1)
     brew_logic.configuration.set_control_temperature_interval_seconds(0.5)                
     brew_logic.start_instruction_thread()
     brew_logic.start_temperature_control_thread()        
     instruction = Instruction(1, 10, time.time(), time.time() + 600, 'Test Instruction')        
     brew_logic.store_instruction_for_unique_time(instruction)
     time.sleep(1)
     assert(brew_logic.freezer_state)
     assert(not brew_logic.heater_state)
     temperature_probes._last_master_reading = 9.4  # now devices should stop
     time.sleep(1)        
     assert(not brew_logic.freezer_state)
     assert(brew_logic.heater_state)
     temperature_probes._last_master_reading = 10.5  # now devices should stop
     time.sleep(1)
     assert(not brew_logic.freezer_state)
     assert(not brew_logic.heater_state)
 def test_set_and_remove_device_override(self):
     """ when the brew logic is handling the device and we override it, after we remove the override it should continue doing what it was """
     brew_logic.configuration.set_instruction_interval_seconds(0.1)
     brew_logic.configuration.set_control_temperature_interval_seconds(0.5)  
     brew_logic.start_instruction_thread()
     brew_logic.start_temperature_control_thread()        
     json = '{ "description" : "Instruction created from web API", "target_temperature_C" : "15.5", "from_timestamp" : "10", "to_timestamp" : "2397162478" }'        
     response = self._call_POST_with_credentials_and_body('http://localhost:8080/chestfreezer/api/instruction', json, 'application/json')[0]
     assert(response.status == 201)
     time.sleep(0.5)
     # the instruction takes over
     assert(brew_logic.get_actual_target_temperature_C() == 15.5)
     # we manually override
     response = self._call_POST_with_credentials_and_body('http://localhost:8080/chestfreezer/api/temperature/target', '{"target_temperature_C": -5.1}', 'application/json')[0]
     assert(response.status == 204)
     time.sleep(0.5)
     assert(brew_logic.get_actual_target_temperature_C() == -5.1)
     # we remove our override
     time.sleep(0.5) 
     response = self._call_POST_with_credentials_and_body('http://localhost:8080/chestfreezer/api/temperature/target', '{"override": "false" }', 'application/json')[0]
     assert(response.status == 204)
     # the instruction temperature should be used again
     time.sleep(0.5)         
     assert(brew_logic.get_actual_target_temperature_C() == 15.5)
def start_threads():
    """ starts a thread that stored the temperature readings every second, and the other 2 temperature controlling threads """
    temperature_probes.start_temperature_recording_thread()
    logic.start_instruction_thread()
    logic.start_temperature_control_thread()
    logic.start_beer_monitoring_thread()