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)
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}))
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 }))
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
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)
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}))
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
def item_selected(self, dev_id, name): self.deferred.callback( ActivityReturn(ActivityReturn.ReturnType.OK, {"dev_id": int(dev_id)}))
def final_call(self, res): self.deferred.callback(ActivityReturn(ActivityReturn.ReturnType.OK))
def item_selected(self, server_id, name): self.deferred.callback( ActivityReturn(ActivityReturn.ReturnType.OK, {"server": self.servers[int(server_id)]}))
def item_selected(self, id, name): self.deferred.callback( ActivityReturn(ActivityReturn.ReturnType.OK, {"selected_item": name}))
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))
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)
def field_updated(self, res): self.deferred.callback(ActivityReturn(ActivityReturn.ReturnType.OK))