def get_device_ids(): """Get each device from the designated spreadsheet.""" values = input_from_sheets("{}!A2:B2".format(SHEET)) print("get_device_ids() values: {}".format(values)) device_ids = [] for x in values: device_id = x[0] locate_now(device_id) device_ids.append(device_id) return device_ids
def report_light_threshold_values(init_data=""): """Grab light reading and report it. Light Threshold: | C col .......................|....... Time Checked: | D col .......................|....... Time Checked: | E col .......................|....... Last Unit Report Time: | F col .......................|....... Time Since Last Report:| G col """ i = ROW_ITER_START light_threshold_status = {} now_status = {} report_status = {} diff_status = {} data = {} if init_data is "": data = input_from_sheets(RANGE_NAME) else: data = init_data for row in data: device_id = row[0] time_diff = 0 config = get_config_for_device(device_id) status = get_status_for_device(device_id) if config and status: print("got config and status") s = update_unit_status(status, config, time_diff, i) else: print("didn't get config and status") s = update_unit_status_failure(i) light_threshold_status = s.light_threshold_status now_status = s.now_status report_status = s.report_status diff_status = s.diff_status update_sheet_status(light_threshold_status=light_threshold_status, now_status=now_status, report_status=report_status, diff_status=diff_status) if len(data) < 6: print("sleeping for 10 to avoid too quick a response") time.sleep(10) time.sleep(math.floor(100 / 24)) i += 1 print("Finished running report of threshold values.")
def report_light_readings(): """Grab light reading and report it. Time Checked: | D col .......................|....... Last Unit Report Time: | F col .......................|....... Light Reading: | H col """ # Get all data data = input_from_sheets(RANGE_NAME) now_status = report_status = current_light_reading = {} i = ROW_ITER_START for row in data: device_id = row[0] light_time = compile_light_time(device_id) now = light_time.get('now') status_time = light_time.get('time') light_reading = light_time.get('light_reading') light_reading_or_batt = get_light_value_or_no_battery( status_time, now, light_reading) now_status['value'] = now now_status['cell'] = "D{}".format(str(i)) report_status['value'] = status_time report_status['cell'] = "F{}".format(str(i)) current_light_reading['value'] = light_reading_or_batt current_light_reading['cell'] = "H{}".format(str(i)) update_sheet_status( now_status=now_status, report_status=report_status, current_light_reading=current_light_reading, ) i += 1 time.sleep(math.floor(100 / 24)) print("finished running report_light_readings")
def update_device_light_thresholds(test=False): """ Get PT unit ID. Desired Light Sensor Value, and current light sensor value. """ data = input_from_sheets(RANGE_NAME) i = ROW_ITER_START light_threshold_status = {} now_status = {} report_status = {} diff_status = {} current_light_reading = {} for row in data: device_id = row[0] """Process a location stamp.""" time.sleep(math.floor(100 / 24)) # set up the write range for updating sheet light_time = compile_light_time(device_id) # fetch the current light sensor value and timestamp desired_threshold_value = row[1] light_threshold_status['value'] = light_time.get('light') light_threshold_status['cell'] = "C{}".format(str(i)) now_status['value'] = light_time.get('now') now_status['cell'] = "D{}".format(str(i)) report_status['value'] = light_time.get('time') report_status['cell'] = "F{}".format(str(i)) diff_minutes = light_time.get('time difference') pretty_time = get_pretty_time(diff_minutes) diff_status['value'] = "{}".format(pretty_time) diff_status['cell'] = "G{}".format(str(i)) current_light_reading['value'] = light_time.get('light_reading') current_light_reading['cell'] = "H{}".format(str(i)) update_sheet_status( light_threshold_status=light_threshold_status, now_status=now_status, report_status=report_status, diff_status=diff_status, current_light_reading=current_light_reading, ) time.sleep(math.floor(100 / 24)) # compare current light value with desired light value # desired_threshold = input_from_sheets("B{}".format(str(i)), '') analysis = analyze_thresholds({ 'desired': int(desired_threshold_value), 'current': int(light_threshold_status['value']) }) # get a timestamp now = datetime.datetime.utcnow() attempt_or_verify_time = now.strftime("%Y-%m-%d %H:%M:%S") cell = 'E{}'.format(str(i)) print("DIFF MINUTES\n\n\n\n\n\n\n\n{}".format(diff_minutes)) # if different, update to desired light value if diff_minutes > 32: update_sheet_status(check_battery={ 'value': 'CHECK BATTERY', 'cell': cell }) else: print('''\n\n\n\n\n ANALYSIS for {device} with light threshold of {threshold} where {desired} is desired: {analysis} \n\n\n\n\n\n\n'''.format( device=device_id, analysis=analysis, threshold=light_threshold_status['value'], desired=desired_threshold_value)) time.sleep(1) if not analysis: update_light_value(device_id, desired_threshold_value) update_sheet_status( light_update={ 'value': 'attempted {}'.format(attempt_or_verify_time), 'cell': cell }) else: update_sheet_status( light_update={ 'value': 'verified {}'.format(attempt_or_verify_time), 'cell': cell }) # finally, update the increment var print('''\n\n\n\n\n\n\n\n\n\n\n let's take a breather... \n\n\n\n\n\n\n\n\n\n\n ''') time.sleep(math.floor(100 / 24)) print("back to work!") i += 1 return {'data': data, 'time': report_status['value']}
def test_write_to_cell(self): write_to_cell("Hello, from test_connections!", SHEET, "E17") test_ = input_from_sheets("{}!E17".format(SHEET)) self.assertEqual(test_, [["Hello, from test_connections!"]])