コード例 #1
0
    def initialize(self):
        self.listen_state_handle_list = []

        self.app_switch = self.args["app_switch"]
        self.ishome = self.args["ishome"]
        self.input_booleans = self.args["input_booleans"].split(",")
        self.message = self.args["message"]

        if self.get_state(self.app_switch) == "on":
            for input_boolean in self.input_booleans:
                self.log("{} is {}".format(input_boolean,
                                           self.get_state(input_boolean)))
                self.listen_state_handle_list.append(
                    self.listen_state(self.state_change, input_boolean))
                if (self.get_state(input_boolean) == "on"
                        and self.get_state(self.ishome) == "off"):
                    self.turn_on(self.ishome)
                    self.log("Setting {} to on".format(self.ishome))
                if (self.get_state(input_boolean) == "off"
                        and self.get_state(self.ishome) == "on"):
                    if self.are_others_away(input_boolean):
                        self.turn_off(self.ishome)
                        self.log("Setting {} to off".format(self.ishome))
                        notify_message = globals.random_arg(self.message)
                        self.log("notify_messsage: {}".format(notify_message))
                        self.call_service("notify/group_notifications",
                                          message=notify_message)
コード例 #2
0
 def state_change(self, entity, attribute, old, new, kwargs):
     if self.get_state(self.app_switch) == "on":
         if new != "" and new != old:
             self.log("{} changed from {} to {}".format(entity, old, new))
             if new == "on":
                 self.turn_on(self.ishome)
                 self.log("Setting {} to on".format(self.ishome))
             if new == "off":
                 if self.are_others_away(entity):
                     self.turn_off(self.ishome)
                     self.log("Setting {} to off".format(self.ishome))
                     notify_message = globals.random_arg(self.message)
                     self.log("notify_messsage: {}".format(notify_message))
                     self.call_service("notify/group_notifications",
                                       message=notify_message)