Commit 53ad9125 authored by Jiahang Chen's avatar Jiahang Chen
Browse files

change dt to thing

parent 40a5b9fe
Pipeline #354940 passed with stage
in 14 seconds
......@@ -2,6 +2,7 @@
from ml.app_logger import APP_LOGGER
from ml.tools import remove_namespace
"""
from ml.thing import Thing
from ml.ml40.features.properties.associations.composite import Composite
......@@ -165,7 +166,6 @@
from ml.fml40.features.functionalities.supports_felling import SupportsFelling
from ml.fml40.features.functionalities.transports_logs import TransportsLogs
# TODO: Get rid of this global variable
# TODO: automatically get all classes in modul
DT_FACTORY = {}
......@@ -176,6 +176,7 @@
for member in clsmembers:
DT_FACTORY[member[0]] = member[1]
def build_sub_features(feature_ins, feature):
sub_features = feature.get("subFeatures", [])
......@@ -200,7 +201,7 @@ def build_sub_features(feature_ins, feature):
def build_sub_thing(feature_ins, json_feature):
json_sub_things = json_feature.get("targets", [])
for json_sub_thing in json_sub_things:
sub_thing_ref = create_dt_ref(model={"attributes": json_sub_thing})
sub_thing_ref = create_thing(model={"attributes": json_sub_thing})
sub_thing_name = json_sub_thing.get("name", None)
feature_ins.targets[sub_thing_name] = sub_thing_ref
......@@ -225,7 +226,7 @@ def build_role(role):
role_obj = DT_FACTORY.get(remove_namespace(role_class_name), None)
if role_obj is None:
APP_LOGGER.critical("Roles: %s is missing" % role_class_name)
role_instance = None
role_instance = None
else:
APP_LOGGER.debug("Adding roles: %s" % role_class_name)
role_instance = role_obj()
......@@ -265,9 +266,9 @@ def add_function_impl_obj(thing, impl_obj, feature_name):
thing.features[feature_name] = impl_obj(feature_name)
def create_dt_ref(model, grant_type="password",
secret="", username=None, password=None,
is_broker_rest=False, is_broker=False, is_repo=False):
def create_thing(model, grant_type="password",
secret="", username=None, password=None,
is_broker_rest=False, is_broker=False, is_repo=False):
attributes = model.get("attributes", None)
if attributes is None:
......@@ -281,9 +282,9 @@ def create_dt_ref(model, grant_type="password",
thing_name = attributes.get("name", "")
APP_LOGGER.debug("Build digital twin {} with id {}".format(thing_name, model.get("thingId", "")))
d_t = DT_FACTORY.get(thing_type)
_thing = DT_FACTORY.get(thing_type)
thing_ref = d_t(
thing_ref = _thing(
model=model,
grant_type=grant_type,
client_secret=secret,
......
......@@ -320,13 +320,13 @@ def make_feature_config(class_name, identifier="", name="", subFeatures=""):
return config_json
def make_thing_config(dt_id, name, roles, features=[], config_path=""):
def make_thing_config(thing_id, name, roles, features=[], config_path=""):
if not config_path:
config_path = os.path.join("__file__", "configs")
config_file = {
"thingId": dt_id,
"policyId": dt_id,
"thingId": thing_id,
"policyId": thing_id,
"attributes": {
"class": "ml40::Thing",
"name": name,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment