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/LocationTagGroup.json' )) tgr.register_tag_groups_from_uri( get_abs_file_uri( 'definitions/TagGroup/com.adlinktech.example/DistanceTagGroup.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( get_abs_file_uri( 'definitions/ThingClass/com.adlinktech.example/DistanceServiceThingClass.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)
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)
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)
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) # Register Gen2 sensor tag groups tag_groups.Temperature_register_with_datariver(self._dr) # 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/TemperatureDashboardThingClass.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 ThingEx(self._dr.create_thing(tp))
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/SensorStateTagGroup.json' ) tgr.register_tag_groups_from_uri( 'file://definitions/TagGroup/com.adlinktech.example/FuelLevelTagGroup.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/FuelLevelSensorThingClass.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)