def update(self, id=None): """ Handle PUT requests for scenes/reload API """ from lib.scene import Scenes self.scenes = Scenes.get_instance() if id == 'all': result = self.scenes.reload_scenes() return json.dumps(result) else: return json.dumps(False)
def read(self, id=None): """ Handle GET requests for scenes API """ if self.items == None: self.items = Items.get_instance() from lib.scene import Scenes get_param_func = getattr(Scenes, "get_instance", None) if callable(get_param_func): supported = True self.scenes = Scenes.get_instance() scene_list = [] if self.scenes is not None: scene_list = self.scenes.get_loaded_scenes() disp_scene_list = [] for scene in scene_list: scene_dict = {} scene_dict['path'] = scene # scene_dict['name'] = str(self._sh.return_item(scene)) scene_dict['name'] = str(self.items.return_item(scene)) action_list = self.scenes.get_scene_actions(scene) scene_dict['value_list'] = action_list # scene_dict[scene] = action_list disp_action_list = [] for value in action_list: action_dict = {} action_dict['action'] = value action_dict[ 'action_name'] = self.scenes.get_scene_action_name( scene, value) action_list = self.scenes.return_scene_value_actions( scene, value) for action in action_list: if not isinstance(action[0], str): action[0] = action[0].id() action_dict['action_list'] = action_list disp_action_list.append(action_dict) scene_dict['values'] = disp_action_list self.logger.debug( "scenes_html: disp_action_list for scene {} = {}".format( scene, disp_action_list)) disp_scene_list.append(scene_dict) else: supported = False return json.dumps(disp_scene_list)
def update(self, id=None): """ Handle PUT requests for scenes/reload API """ from lib.scene import Scenes self.scenes = Scenes.get_instance() from lib.userfunctions import reload from lib.userfunctions import reload_all if id == 'all': #result = self.scenes.reload_scenes() result = reload_all() return json.dumps(result) else: result = reload(id) return json.dumps(result)
def scenes_html(self): from lib.scene import Scenes get_param_func = getattr(Scenes, "get_instance", None) if callable(get_param_func): supported = True self.scenes = Scenes.get_instance() scene_list = self.scenes.get_loaded_scenes() disp_scene_list = [] for scene in scene_list: scene_dict = {} scene_dict['path'] = scene scene_dict['name'] = str(self._sh.return_item(scene)) action_list = self.scenes.get_scene_actions(scene) scene_dict['value_list'] = action_list scene_dict[scene] = action_list disp_action_list = [] for value in action_list: action_dict = {} action_dict['action'] = value action_dict[ 'action_name'] = self.scenes.get_scene_action_name( scene, value) action_list = self.scenes.return_scene_value_actions( scene, value) for action in action_list: if not isinstance(action[0], str): action[0] = action[0].id() action_dict['action_list'] = action_list disp_action_list.append(action_dict) scene_dict['values'] = disp_action_list self.logger.info( "scenes_html: disp_action_list for scene {} = {}".format( scene, disp_action_list)) disp_scene_list.append(scene_dict) else: supported = False return self.render_template('scenes.html', supported=supported, scene_list=disp_scene_list)