Example #1
0
def load_tag_groups(dr: DataRiver, tag_group_dir: str):
    tgr = JSonTagGroupRegistry()

    for entry in os.scandir(tag_group_dir):
        if entry.is_file() and entry.path.endswith('.json'):
            log.info(f'Loading tag group: {entry.path}')
            try:
                tgr.register_tag_groups_from_uri(f'file://{entry.path}')
            except Exception as e:
                log.error(f'Unable to load tag group: {entry.path} : {e}')
                pass
    dr.add_tag_group_registry(tgr)
Example #2
0
    def create_thing(self):
        # Create and Populate the TagGroup registry with JSON resource files.
        tgr = JSonTagGroupRegistry()
        tgr.register_tag_groups_from_uri(get_abs_file_uri('definitions/TagGroup/com.adlinktech.example/TemperatureTagGroup.json'))
        self._dr.add_tag_group_registry(tgr) 
 
        # Create and Populate the ThingClass registry with JSON resource files.
        tcr = JSonThingClassRegistry()
        tcr.register_thing_classes_from_uri(get_abs_file_uri('definitions/ThingClass/com.adlinktech.example/TemperatureDisplayThingClass.json'))
        self._dr.add_thing_class_registry(tcr)
 
        # Create a Thing based on properties specified in a JSON resource file.
        tp = JSonThingProperties()
        tp.read_properties_from_uri(self._thing_properties_uri)
        return self._dr.create_thing(tp)
Example #3
0
   def create_thing(self):
       # Create and Populate the TagGroup registry with JSON resource files.
       tgr = JSonTagGroupRegistry()
       tgr.register_tag_groups_from_uri('file://definitions/TagGroup/com.adlinktech.example/RotationalSpeedTagGroup.json')
       self._datariver.add_tag_group_registry(tgr) 
 
       # Create and Populate the ThingClass registry with JSON resource files.
       tcr = JSonThingClassRegistry()
       tcr.register_thing_classes_from_uri('file://definitions/ThingClass/com.adlinktech.example/RotationalSpeedSensorThingClass.json')
       self._datariver.add_thing_class_registry(tcr)
 
       # Create a Thing based on properties specified in a JSON resource file.
       tp = JSonThingProperties()
       tp.read_properties_from_uri(self._thing_properties_uri)
       
       return self._datariver.create_thing(tp)
Example #4
0
def register_tag_groups(dr: DataRiver, tag_group_dir: str,
                        tag_groups: List[str]):
    '''
    For each of the Tag Groups listed in tag_groups and whose definition is in tag_groups_dir register them with
    the provided instance of the Data River; dr.

    The tag_groups list should be the name of the file without the .json extension
    '''
    tgr = JSonTagGroupRegistry()

    for tg in tag_groups:
        logging.info(f'Loading Tag Group: {tg}.json from {tag_group_dir}')
        tgr.register_tag_groups_from_uri(
            get_abs_file_uri(str(os.path.join(tag_group_dir, f'{tg}.json'))))

    dr.add_tag_group_registry(tgr)