def set_procedure(procedure): statuses = {} db_save = True expire_delta = 120 if procedure == "lights_on": statuses = {"865": True, "led": True, "led_rgb": True} elif procedure == "lights_off": statuses = {"865": False, "led": False, "led_rgb": False} elif procedure == "movie": expire_delta = 150 statuses = {"865": False, "led": False, "led_rgb": True} elif procedure == "schimb_apa": statuses = {"865": False, "led": True, "led_rgb": True, "pompa": False, "incalzitor": False} elif procedure == "feed": expire_delta = 10 statuses = {"pompa": False} elif procedure == "reset": db_save = False TempCommands.clear_all() statuses = get_statuses() if db_save: TempCommands.add_entry(statuses, expire_delta) IO.set_pins(statuses) return procedure
def get_statuses(): status = {pin_id: True for pin_id in config.NI_pins} current = datetime.now().replace(second=0, microsecond=0) for light in config.lights: start = current.replace(hour=light.on_hour, minute=light.on_minute) finish = current.replace(hour=light.off_hour, minute=light.off_minute) status.setdefault(light.id, False) if start < current < finish: status[light.id] = True obj = TempCommands.get() if obj is not None: status.update(obj.statuses) return status
def close_pin(pin_id): obj = TempCommands.add_entry({pin_id: False}) IO.close(pin_id) return "<h1 style='color:blue'>Hello There, {}</h1>".format(pin_id)
def open_pin(pin_id): obj = TempCommands.add_entry({pin_id: True}) IO.open(pin_id) return "<h1 style='color:blue'>Hello There, {}</h1>".format(pin_id)