def create_device(args): global g_devices (instance_name, client, engine, update_callback, context, params) = args sorted_class_names = sort_by_suffix(params["functions"]) C = compose_class( sorted_class_names ) # Create a composite device class from all the given class names d = C(instance_name, engine.get_now(), engine, update_callback, context, params["functions"]) # Instantiate it client.add_device(d.properties["$id"], engine.get_now(), d.properties) if "stop_at" in params: at_time = conftime.richTime(params["stop_at"]) engine.register_event_at(at_time, stop_device, (engine, d), None) the_id = d.properties["$id"] if the_id in g_devices_dict: logging.error("FATAL: Attempt to create duplicate device " + str(d.properties["$id"])) exit(-1) g_devices.append(d) g_devices_dict[the_id] = d return d
def set_end_time_str(self,timeString): """<timeString> can be: None (for never end) 'now' to end when simulation reaches current time (i.e. current time when simulation was run - otherwise it gets hard to e.g. schedule events for end time!) 'when_done' to end when no further events are pending or else an ISO8601 absolute or relative time""" if timeString in [None, "when_done"]: self.end_time = timeString elif timeString == "now": self.end_time = time.time() else: self.end_time = richTime(timeString)
def change_property_action(params): def set_it(d): if params.get("is_attribute", False): d.__dict__[params["property_name"]] = params["property_value"] logging.info("Set attribute "+str(params["property_name"])+" on device "+d.get_property("$id")+" to "+str(params["property_value"])) else: d.set_property(params["property_name"], params["property_value"], timestamp=ts) logging.info("Set property "+str(params["property_name"])+" on device "+d.get_property("$id")+" to "+str(params["property_value"])) d = device_factory.get_devices_by_property( params["identity_property"], params["identity_value"]) logging.info("change property acting on "+str(len(d))+" matching devices") if "$ts" in params: ts = conftime.richTime(params["$ts"]) else: ts = None logging.info("change_property "+str(params)) for the_d in d: set_it(the_d)
def set_start_time_str(self, timeString): t = richTime(timeString) self.start_time = t self.set_now(t)
def set_now_str(self,timeString): self.set_time(richTime(timeString))
def set_now_str(self, timeString): self.set_time( richTime(timeString) ) # ??? doesn't seem to exist, is this function ever called?