Exemple #1
0
 def set_force_on(object_id, value):
     db_client = helper.get_database_mongo()
     db_client.relays.update({
         '_id': ObjectId(object_id)}, {
         '$set': {
             'force_on': value
         }}, upsert=False)
     Log.debug("Set Force on =" + str(value) + " Relay id=" + object_id)
Exemple #2
0
    def switch_checker(self, relay):
        current_relay_state = relay.get_state()
        if self.DEBUG:
            print("Relay state = " + str(current_relay_state))
            print("State = " + str(relay.force_on) + " state = " + str(current_relay_state))

        if relay.force_on == Relay.FORCE_ON:
            if current_relay_state == Relay.OFF:
                Log.debug(relay.name + " has turn on by user")
                relay.turn_on()
        else:
            if current_relay_state == Relay.ON:
                Log.debug(relay.name + " has turn off by user")

                relay.turn_off()
Exemple #3
0
    def switch_checker(self, relay):
        current_relay_state = relay.get_state()
        if self.DEBUG:
            print("Relay state = " + str(current_relay_state))
            print("State = " + str(relay.force_on) + " state = " +
                  str(current_relay_state))

        if relay.force_on == Relay.FORCE_ON:
            if current_relay_state == Relay.OFF:
                Log.debug(relay.name + " has turn on by user")
                relay.turn_on()
        else:
            if current_relay_state == Relay.ON:
                Log.debug(relay.name + " has turn off by user")

                relay.turn_off()
Exemple #4
0
    def timer_checker(self, relay):
        # get current time
        flags = FlagsDay()
        today = datetime.date.today()
        day = today.strftime("%a")
        for timer in relay.time:
            flags.asByte = timer["day"]
            time_checker = getattr(flags, day) == 1 and helper.time_in_range(
                parser.parse(timer["time_on"]).time(),
                parser.parse(timer["time_off"]).time())
            current_relay_state = relay.get_state()
            if self.DEBUG:
                print("Relay state = " + str(current_relay_state))
                print(relay.name + "  checker is " + str(time_checker))
                print("State = " + str(relay.force_on) + " state = " +
                      str(current_relay_state))

            if time_checker or relay.force_on == Relay.FORCE_ON:
                if relay.force_on == Relay.FORCE_OFF and current_relay_state == Relay.ON:
                    Log.debug(relay.name + " has turn by Force turn off")
                    print("Force Off")
                    relay.turn_off()
                elif current_relay_state == Relay.OFF and not relay.force_on == Relay.FORCE_OFF:
                    Log.debug(relay.name + " has turn by timer")
                    relay.turn_on()

            else:
                if current_relay_state == Relay.ON:
                    Log.debug(relay.name + " has turnoff by timer")
                    relay.turn_off()
Exemple #5
0
    def timer_checker(self, relay):
        # get current time
        flags = FlagsDay()
        today = datetime.date.today()
        day = today.strftime("%a")
        for timer in relay.time:
            flags.asByte = timer["day"]
            time_checker = getattr(flags, day) == 1 and helper.time_in_range(
                parser.parse(timer["time_on"]).time(),
                parser.parse(timer["time_off"]).time())
            current_relay_state = relay.get_state()
            if self.DEBUG:
                print("Relay state = " + str(current_relay_state))
                print(relay.name + "  checker is " + str(time_checker))
                print("State = " + str(relay.force_on) + " state = " + str(current_relay_state))

            if time_checker or relay.force_on == Relay.FORCE_ON:
                if relay.force_on == Relay.FORCE_OFF and current_relay_state == Relay.ON:
                    Log.debug(relay.name + " has turn by Force turn off")
                    print("Force Off")
                    relay.turn_off()
                elif current_relay_state == Relay.OFF and not relay.force_on == Relay.FORCE_OFF:
                    Log.debug(relay.name + " has turn by timer")
                    relay.turn_on()

            else:
                if current_relay_state == Relay.ON:
                    Log.debug(relay.name + " has turnoff by timer")
                    relay.turn_off()