Пример #1
0
 def on_message(self, text):
     dict_key = self.kwargs.get("key", "name")
     if text != "Назад":
         self.deferred.callback(
             ActivityReturn(ActivityReturn.ReturnType.OK, {dict_key: text}))
         return
     Activity.on_message(self, text)
Пример #2
0
 def render(self):
     type = self.types[self.kwargs["selected_item"]]
     field_value = None
     if type == StaticFieldValue:
         res = yield self.manager.start_activity(self.chat_id, InputValue,
                                                 **self.kwargs)
         if res.type == ActivityReturn.ReturnType.OK:
             value = res.data["value"]
             field_value = StaticFieldValue(value)
     elif type == LocalFieldValue:
         res = yield self.manager.start_activity(
             self.chat_id, [DevicesActivity, DeviceInfoActivity],
             **self.kwargs)
         if res.type == ActivityReturn.ReturnType.OK:
             dev_id = res.data["dev_id"]
             field_name = res.data["field_name"]
             field_value = LocalFieldValue(dev_id, field_name)
     elif type == RemoteFieldValue:
         res = yield self.manager.start_activity(
             self.chat_id, [DevicesActivity, DeviceInfoActivity],
             **self.kwargs)
         if res.type == ActivityReturn.ReturnType.OK:
             dev_id = res.data["dev_id"]
             field_name = res.data["field_name"]
             field_value = RemoteFieldValue(dev_id, field_name)
     if field_value is not None:
         self.kwargs = {}
         self.deferred.callback(
             ActivityReturn(ActivityReturn.ReturnType.OK,
                            {"field_value": field_value}))
Пример #3
0
 def item_selected(self, name, field_type):
     self.deferred.callback(
         ActivityReturn(
             ActivityReturn.ReturnType.OK, {
                 "dev_name": self.dev_name,
                 "field_name": name,
                 "field_type": field_type
             }))
Пример #4
0
 def gen_text(self):
     self.text = "Создание скрипта..."
     name = self.kwargs["script_name"]
     trigger = self.kwargs["trigger"]
     action = self.kwargs["action"]
     self.deferred.callback(
         ActivityReturn(ActivityReturn.ReturnType.OK,
                        {"script": Script(trigger, action, name)}))
     yield None
Пример #5
0
 def on_message(self, text):
     field_type = self.kwargs.get("field_type", "str")
     if text != "Назад":
         value = None
         if field_type == "str":
             value = text
         elif field_type == "int" and FieldEdit.is_int(text):
             value = int(text)
         elif field_type == "bool" and FieldEdit.is_bool(text):
             value = {"Да": True, "Нет": False}[text]
         if value is not None:
             self.deferred.callback(
                 ActivityReturn(ActivityReturn.ReturnType.OK,
                                {"value": value}))
             return
     Activity.on_message(self, text)
Пример #6
0
 def render(self):
     trigger_type = TriggerRouterActivity.types[
         self.kwargs["selected_item"]]
     trigger = None
     if trigger_type == ValueTrigger:
         res = yield self.manager.start_activity(
             self.chat_id, [
                 DevicesActivity, DeviceInfoActivity, SelectItem,
                 FieldValueCreateActivity
             ],
             text="Выберите тип изменения",
             list=["GREATER", "LESS", "EQUAL", "NOTEQUAL"])
         if res.type == ActivityReturn.ReturnType.OK:
             dev_id = res.data["dev_id"]
             field_name = res.data["field_name"]
             change_type = res.data["selected_item"]
             field_value = res.data["field_value"]
             trigger = ValueTrigger(dev_id, field_name, change_type,
                                    field_value)
     elif trigger_type == ANDTrigger or trigger_type == ORTrigger:
         if trigger_type == ANDTrigger:
             self.send_message("Создание И триггера.", [[]])
         elif trigger_type == ORTrigger:
             self.send_message("Создание ИЛИ триггера.", [[]])
         res = yield self.manager.start_activity(
             self.chat_id,
             WizardActivity,
             steps=[TriggerCreateActivity, TriggerCreateActivity])
         if res.type == ActivityReturn.ReturnType.OK:
             trigger1 = res.data["data"][0]["trigger"]
             trigger2 = res.data["data"][1]["trigger"]
             trigger = trigger_type(trigger1, trigger2)
     if trigger is not None:
         self.deferred.callback(
             ActivityReturn(ActivityReturn.ReturnType.OK,
                            {"trigger": trigger}))
Пример #7
0
 def render(self):
     action_type = self.types[self.kwargs["selected_item"]]
     action = None
     if action_type == ChangeFieldAction:
         res = yield self.manager.start_activity(
             self.chat_id, [
                 DevicesActivity, DeviceInfoActivity,
                 FieldValueCreateActivity
             ],
             text="Выберите тип изменения",
             list=["GREATER", "LESS", "EQUAL", "NOTEQUAL"],
             writable=True)
         if res.type == ActivityReturn.ReturnType.OK:
             dev_id = res.data["dev_id"]
             field_name = res.data["field_name"]
             field_value = res.data["field_value"]
             action = ChangeFieldAction(dev_id, field_name, field_value)
     elif action_type == MethodAction:
         pass
     if action is not None:
         self.deferred.callback(
             ActivityReturn(ActivityReturn.ReturnType.OK,
                            {"action": action}))
     pass
Пример #8
0
 def item_selected(self, dev_id, name):
     self.deferred.callback(
         ActivityReturn(ActivityReturn.ReturnType.OK,
                        {"dev_id": int(dev_id)}))
Пример #9
0
 def final_call(self, res):
     self.deferred.callback(ActivityReturn(ActivityReturn.ReturnType.OK))
Пример #10
0
 def item_selected(self, server_id, name):
     self.deferred.callback(
         ActivityReturn(ActivityReturn.ReturnType.OK,
                        {"server": self.servers[int(server_id)]}))
Пример #11
0
 def item_selected(self, id, name):
     self.deferred.callback(
         ActivityReturn(ActivityReturn.ReturnType.OK,
                        {"selected_item": name}))
Пример #12
0
 def remove_script(self, message):
     yield self.manager.serv.remove_script(self.kwargs["script"].id,
                                           self.kwargs["password"])
     self.deferred.callback(ActivityReturn(ActivityReturn.ReturnType.BACK))
Пример #13
0
 def go_to_devices(self, m):
     self.manager.start_activity(
         self.chat_id, [DevicesActivity, DeviceInfoActivity, FieldEdit],
         wizard_completed=lambda res: ActivityReturn(ActivityReturn.
                                                     ReturnType.BACK),
         writable=True)
Пример #14
0
 def field_updated(self, res):
     self.deferred.callback(ActivityReturn(ActivityReturn.ReturnType.OK))