예제 #1
0
    def load_struct_definitions(self, etc_dir):

        # --------------------------------------------------------------------
        # Read in all struct definitions before reading item definitions
        #
        # structs are merged into the item tree in lib.config
        #
        # structs are read in from metadata file of plugins while loading plugins
        # and from ../etc/struct.yaml
        #
        # Read in item structs from ../etc/struct.yaml
        struct_definitions = shyaml.yaml_load(os.path.join(
            etc_dir, 'struct.yaml'),
                                              ordered=True,
                                              ignore_notfound=True)
        if struct_definitions is not None:
            if isinstance(struct_definitions, collections.OrderedDict):
                for key in struct_definitions:
                    self.add_struct_definition('', key,
                                               struct_definitions[key])
            else:
                self.logger.error(
                    "load_itemdefinitions(): Invalid content in struct.yaml: struct_definitions = '{}'"
                    .format(struct_definitions))

        self.fill_nested_structs()

        # for Testing: Save structure of joined item structs
        self.logger.info(
            "load_itemdefinitions(): For testing the joined item structs are saved to {}"
            .format(os.path.join(etc_dir, 'structs_joined.yaml')))
        shyaml.yaml_save(os.path.join(etc_dir, 'structs_joined.yaml'),
                         self._struct_definitions)
예제 #2
0
파일: structs.py 프로젝트: stoepf/smarthome
    def load_struct_definitions(self, etc_dir):

        # --------------------------------------------------------------------
        # Read in all struct definitions before reading item definitions
        #
        # structs are merged into the item tree in lib.config
        #
        # - plugin-structs are read in from metadata file of plugins while loading plugins
        # - other structs are read in from ../etc/struct.yaml by this procedure
        # - further structs are read in from ../etc/struct_<prefix>.yaml by this procedure
        #
        self.load_struct_definitions_from_file(etc_dir, 'struct.yaml', '')

        # look for further struct files
        fl = os.listdir(etc_dir)
        for fn in fl:
            if fn.startswith('struct_') and fn.endswith('.yaml'):
                key_prefix = 'my.' + fn[7:-5]
                self.load_struct_definitions_from_file(etc_dir, fn, key_prefix)

        # Resolve struct references in structs and fill in the content of the struct
        self.fill_nested_structs()

        # for Testing: Save structure of joined item structs
        self.logger.info("load_itemdefinitions(): For testing the joined item structs are saved to {}".format(os.path.join(etc_dir, 'structs_joined.yaml')))
        shyaml.yaml_save(os.path.join(etc_dir, 'structs_joined.yaml'), self._struct_definitions)
예제 #3
0
파일: scene.py 프로젝트: ThomasCr/smarthome
 def _save_learned_values(self, scene):
     """
     Save learned values for the scene to a file to make them persistant
     """
     logger.info("Saving learned values for scene {}:".format(scene))
     learned_dict = {}
     for key in self._learned_values:
         lvalue = self._learned_values[key]
         kl = key.split('#')
         fkey = kl[1]+'#'+kl[2]
         learned_dict[fkey] = lvalue
         logger.debug(" - Saving value {} for state/ditem {}".format(lvalue, fkey))
     scene_learnfile = os.path.join(self._scenes_dir, scene+'_learned')
     yaml.yaml_save(scene_learnfile+'.yaml', learned_dict)
     return
예제 #4
0
 def _save_learned_values(self, scene):
     """
     Save learned values for the scene to a file to make them persistant
     """
     logger.info("Saving learned values for scene {}:".format(scene))
     learned_dict = {}
     for key in self._learned_values:
         lvalue = self._learned_values[key]
         kl = key.split('#')
         fkey = kl[1] + '#' + kl[2]
         learned_dict[fkey] = lvalue
         logger.debug(" - Saving value {} for state/ditem {}".format(
             lvalue, fkey))
     scene_learnfile = os.path.join(self._scenes_dir, scene + '_learned')
     yaml.yaml_save(scene_learnfile + '.yaml', learned_dict)
     return