def test_check_change_status_device(self): # Create device dev = accessdb.create_device("dev1", "dev1") self.assertEqual(dev is None, False) # Check status device. Default of device status is OFF status = controldev.get_device_status(dev.id) self.assertEqual(status, "OFF") # Update status device ret = accessdb.update_status_device_input_obj(dev, status) # Because status default is OFF, update new status is OFF. Return False self.assertEqual(ret, False) # Change status status = "ON" ret = accessdb.update_status_device_input_obj(dev, status) self.assertEqual(ret, True) # Get list alarm by time for device which just insert to db alarm_list = accessdb.get_alarm_time_list_from_device_pk(dev.id) for row in alarm_list: log = "%s %s" % (row.dev.dev_name, row.timer) logger.debug(log) self.assertEqual(alarm_list is None, False) self.assertEqual(len(alarm_list), 0) # Get list alarm by temp for device alarm_by_temp = accessdb.get_alarm_by_temp(dev.id) self.assertEqual(alarm_by_temp is None, False) self.assertEqual(alarm_by_temp.dev.dev_name, dev.dev_name) # Get device status dev_test = accessdb.get_device_from_pk(dev.id) self.assertEqual(dev_test is None, False) self.assertEqual(dev_test.status, "ON") # Create History now_time = apitimer.get_now_time_with_second() from_status = "OFF" to_status = "ON" ret = accessdb.insert_history_device_status(dev, from_status, to_status) self.assertEqual(ret, True) # Get list device history_list = accessdb.get_list_history_device_status(dev.id) self.assertEqual(len(history_list), 1)
# Reset list temp for next_time data = [] next_time = next_time + timedelta(minutes=1) data.append(temp_value) # Thread run video def threaded_function(cmd): commands.getoutput(cmd) # Update status of device when raspi was booted dev_list = accessdb.get_device_list() for dev in dev_list: status = controldev.get_device_status(dev.id) # Update status of device controldev.update_status_device(dev.id, status) # Reset alarm by tem when raspi was booted. accessdb.reset_count_alarm_by_temp_object(dev) isOn = False thread = None while True: # Check cam to write to file ret = controldev.check_exist_raspivid_process() if ret is False: