示例#1
0
def predictor_loop():
    while True:
        try:
            cnx, cursor = DBFunctions.connect_to_DB()
            for curtain in DBFunctions.curtain_ids(cursor):
                if DBFunctions.event_predictor(cursor, curtain):
                    close_results = DBFunctions.close_events_for_day_for_last_four_weeks(
                        cursor, curtain)
                    close_event_times = create_event_objects(close_results)
                    predicted_events = predict_events(close_event_times)
                    set_events(cnx, cursor, curtain, predicted_events)

                    open_results = DBFunctions.non_close_events_for_day_for_last_four_weeks(
                        cursor, curtain)
                    open_event_times = create_event_objects(open_results)
                    predicted_events = predict_events(open_event_times)
                    set_events(cnx, cursor, curtain, predicted_events)

            cnx.close()
            if current_time_is_past_sleep_point():
                sleep_time = time_to_next_day()
            else:
                sleep_time = EVENT_PREDICTOR_SLEEP
            sleep(sleep_time)  # wait a day

        except Exception as error:
            try:
                import ErrorWriter
                ErrorWriter.write_error(error)
            except:
                pass
            sleep(ERROR_WAIT)
示例#2
0
def main():
    while True:
        try:
            # ———— CREATE OBJECTS ————
            # print("Creating Objects...", end="")  #TESTING
            calendar = GoogleCalendar.GoogleCalendar(CREDENTIAL_PATH,
                                                     PICKLE_PATH, SCOPES, 600)
            current_time = CustomTime.CurrentTime(24)
            ip_checkers = create_ip_checkers()
            hue_room = HueRoom.HueRoom(HUE_LIGHTS)
            weather = Weather.Weather(API_key, 76133, 600)
            # print("DONE")  #TESTING

            # ———— START OBJECT THREADS ————
            # print("Starting threaded programs...", end="")  #TESTING
            calendar.start()
            current_time.start()
            weather.start()
            for x in range(len(ip_checkers)):
                ip_checkers[x].start()
            # print("DONE")  #TESTING

            sleep(4)  # give objects time to retreive data
            update_screen_loop(ip_checkers, calendar, current_time, hue_room,
                               weather)

        except Exception as error:
            try:
                ErrorWriter.write_error(error)
            except:
                print("BAD")
        sleep(2)
示例#3
0
 def thread_loop(self):
     while self.has_not_ended:
         while datetime.now() < self.sleep_until_time:
             sleep(15)
         try:
             self.is_home = self.device_is_on_network()
         except Exception as error:
             ErrorWriter.write_error(error)
         sleep(self.wait)
示例#4
0
def sunrise_time():
	from astral import Astral

	astr_object = Astral()
	astr_object.solar_depression = "civil"
	try: return astr_object[CITY].sun(local=True)["sunrise"]
	except Exception as error:
		ErrorWriter.write_error(error)
		return None
示例#5
0
	def thread_loop(self):
		while self.has_not_ended:
			while datetime.now() < self.sleep_until_time: sleep(60)
			try:
				request_json = self.request()
				self.decode_request(request_json)
			except Exception as error:
				ErrorWriter.write_error(error)
				self.decode_request()
			sleep(self.wait)
示例#6
0
def start_connection():
	try:
		import mysql.connector
		cnx = mysql.connector.connect(	user=DB_USER, password=DB_PASSWD,
						                              host=DB_IP, port=DB_PORT,
						                              database=DB_NAME)
		return cnx
	except Exception as error:
		ErrorWriter.write_error(error)
		return None
示例#7
0
    def thread_loop(self):
        while self.has_not_ended:
            while datetime.now() < self.sleep_until_time:
                sleep(30)

            try:
                any_light_is_on = self.check_if_any_light_is_on()
            except Exception as error:
                ErrorWriter.write_error(error)

            sleep(self.wait)
 def thread_loop(self):
     while self.has_not_ended:
         while datetime.now() < self.sleep_until_time:
             sleep(60)
         try:
             if not self.creds.valid or self.creds.expired or self.creds.refresh_token:
                 self.revalidate_credentials()
             result_json = self.query()
             self.events = [EVENT(value) for value in result_json]
         except Exception as error:
             ErrorWriter.write_error(error)
             self.events = []
         sleep(self.wait)
示例#9
0
    def thread_loop(self):
        while self.has_not_ended:
            while datetime.now() < self.sleep_until_time:
                sleep(60)
            try:
                self.now = self.time_string()
                self.day = self.day_string()
                self.date = self.date_string()
            except Exception as error:
                ErrorWriter.write_error(error)
                self.now = "ERROR"
                self.day = "ERROR"
                self.date = "ERROR"

            sleep(59)
示例#10
0
def calibrate(cnx, cursor):
    try:
        import RPi.GPIO as GPIO
        from DBFunctions import direction, set_curtain_length

        GPIOUtility.enable_motor()
        closed_direction = direction(cursor)
        move_to_closed(closed_direction)
        step_count = count_steps_from_closed_to_open()
        set_curtain_length(cnx, cursor, step_count)  # write count to DB
        GPIOUtility.disable_motor()
    except Exception as error:
        try:
            GPIOUtility.disable_motor()
        except:
            pass
        ErrorWriter.write_error(error)
示例#11
0
def main():
    # program loop
    while True:
        try:
            threads = [
                Thread(target=AdafruitFeed.start_client_loop),
                Thread(target=DaytimeEvents.sunrise_loop),
                Thread(target=DaytimeEvents.sunset_loop),
                Thread(target=EventPredictor.predictor_loop)
            ]
            for thread in threads:
                thread.start()
            for thread in threads:
                thread.join()

        except Exception as error:
            try:
                ErrorWriter.write_error(
                    error)  # doubly protect main program loop
            except:
                print(error)
        sleep(ERROR_WAIT)  # something messed up; give it time to reset
示例#12
0
def main():
    # program loop
    while True:
        try:
            GPIOUtility.setup_GPIO()
            GPIOUtility.disable_motor(
            )  # on program start, allow for manual movement

            process_thread = threading.Thread(target=primary_curtain_process)
            manual_move_thread = threading.Thread(
                target=CalibrateCurtain.manual_move_end_setter)

            for thread in [process_thread, manual_move_thread]:
                thread.start()
                thread.join()

        except Exception as error:
            try:
                ErrorWriter.write_error(
                    error)  # doubly protect main program loop
                write_error(cnx, cursor, current, desired, error)
            except:
                print(error)
        sleep(ERROR_WAIT)  # something messed up; give it time to reset
示例#13
0
def main():
	# program loop
	while True:
		try:
			GPIOUtility.setup_GPIO()
			GPIOUtility.disable_motor()  # on program start, allow for manual movement

			threads =	[
							Thread(target=primary_process_loop),
							Thread(target=AdafruitFeed.start_client_loop),
							Thread(target=CalibrateCurtain.manual_move_loop),
							Thread(target=DaytimeEvents.sunrise_loop),
							Thread(target=DaytimeEvents.sunset_loop),
							Thread(target=EventPredictor.predictor_loop)
						]
			for thread in threads:
				thread.start()
			for thread in threads:
				thread.join()

		except Exception as error:
			try: ErrorWriter.write_error(error)  # doubly protect main program loop
			except: print(error)
		sleep(ERROR_WAIT)  # something messed up; give it time to reset