def _fromDict(obj): """ Returns a CurrentState for the given dict. """ prefix = Prefix.from_str(obj['prefix']) stateName = obj['stateName'] paramSet = list(map(lambda p: Parameter._fromDict(p), obj['paramSet'])) return CurrentState(prefix, stateName, paramSet)
def _fromDict(obj): """ Returns a ControlCommand for the given dict. """ typ = obj["_type"] source = Prefix.from_str(obj['source']) commandName = CommandName(obj['commandName']) maybeObsId = obj['maybeObsId'] if 'maybeObsId' in obj else "" paramSet = list(map(lambda p: Parameter._fromDict(p), obj['paramSet'])) assert (typ in {"Setup", "Observe"}) if typ == 'Setup': return Setup(source, commandName, maybeObsId, paramSet) else: return Observe(source, commandName, maybeObsId, paramSet)
def _fromDict(obj): """ Returns a Event for the given dict. """ typ = obj['_type'] assert (typ in {"SystemEvent", "ObserveEvent"}) paramSet = list( map(lambda p: Parameter._fromDict(p, True), obj['paramSet'])) eventTime = EventTime._fromDict(obj['eventTime']) prefix = Prefix.from_str(obj['source']) eventName = EventName(obj['eventName']) eventId = obj['eventId'] if typ == 'SystemEvent': return SystemEvent(prefix, eventName, paramSet, eventTime, eventId) else: return ObserveEvent(prefix, eventName, paramSet, eventTime, eventId)
def test_location_service_models(self): testDir = pathlib.Path(__file__).parent.absolute() with open(f"{testDir}/location-models.json") as json_file: data = json.load(json_file) for p in data['ComponentType']: assert (ComponentType[p].name == p) for p in data['Connection']: connectionInfo = ConnectionInfo.from_dict(p) self.log.debug(f"Connection: {connectionInfo}") assert (connectionInfo.to_dict() == p) for p in data['Registration']: regType = p['_type'] if regType == "HttpRegistration": registration = HttpRegistration.from_dict(p) elif regType == "TcpRegistration": registration = TcpRegistration.from_dict(p) elif regType == "AkkaRegistration": registration = AkkaRegistration.from_dict(p) assert (registration.to_dict() == p) for p in data['ComponentId']: componentId = ComponentId.from_dict(p) self.log.debug(f"ComponentId: {componentId}") assert (componentId.to_dict() == p) for p in data['Prefix']: prefix = Prefix.from_str(p) assert (str(prefix) == p) for p in data['ConnectionType']: assert (ConnectionType(p).value == p) for p in data['Subsystem']: assert (Subsystems[p].name == p) for p in data['Location']: locType = p['_type'] if locType == "AkkaLocation": loc = AkkaLocation.from_dict(p) elif locType == "HttpLocation": loc = HttpLocation.from_dict(p) elif locType == "TcpLocation": loc = TcpLocation.from_dict(p) self.log.debug(f"Location: {loc}") assert (loc.to_dict() == p)
def from_str(class_object, eventKeyStr: str): i = eventKeyStr.rindex('.') return EventKey(Prefix.from_str(eventKeyStr[:i]), EventName(eventKeyStr[i + 1:]))