class TestSubEntity(crest.Entity): state = current = crest.State() port_in = crest.Input(res, 111) port_in2 = crest.Input(res, 222) port_out = crest.Output(res, 11111) port_out2 = crest.Output(res, 22222)
def _pullup(portname, port): """Worker for pullup. Pulls up one individual port to a name""" if not isinstance(port, (crest.Input, crest.Output)): raise ValueError( f"Error during pullup. '{portname}' cannot be pulled up because it is not an Input or Output port." ) parent = get_parent(port) parents_parent = get_parent(parent) if parents_parent is None: raise ValueError( f"Error during pullup. Port {portname}'s parent entity is not a subentity. Cannot pull up." ) if hasattr(parents_parent, portname): raise ValueError( f"Error during pullup. There exists already an object called '{portname}'." ) connect_name = portname + "_connect" if hasattr(parents_parent, connect_name): raise ValueError( f"Error during pullup. Cannot create connection influence. Name '{connect_name}' already exists." ) if isinstance(port, crest.Input): newport = add(parents_parent, portname, crest.Input(port.resource, port.value)) add(parents_parent, connect_name, crest.Influence(source=newport, target=port)) else: newport = add(parents_parent, portname, crest.Output(port.resource, port.value)) add(parents_parent, connect_name, crest.Influence(source=port, target=newport))
class TestEntity(crest.Entity): port_in = crest.Input(res, 1234) port_out = crest.Output(res, 987) state = current = crest.State() influence = crest.Influence(source=port_in, target=port_out) def __init__(self): api.add(self, "port_out", crest.Output(res, 5555))
class TestEntity(crest.Entity): port_out = crest.Output(res, 987) state = current = crest.State() sub = SubEntity() influence = crest.Influence(source=sub.sub_out, target=port_out) def __init__(self): api.add(self, "sub", SubEntity())
class TestEntity(crest.Entity): port_out = crest.Output(res, 987) state = current = crest.State() update = crest.Update(state=state, target=port_out, function=(lambda self: 12345)) def __init__(self): api.add(self, "port_out", crest.Output(res, 7777))
class RootType(crest.Entity): stateA = current = crest.State() stateB = crest.State() inport = crest.Input(crest.Resource("watt", crest.REAL), 0) local = crest.Local(crest.Resource("watt", crest.REAL), 1234) local2 = crest.Local(crest.Resource("watt", crest.REAL), 1234) outport = crest.Output(crest.Resource("watt", crest.REAL), 3.14) trans = crest.Transition(source=stateA, target=stateB, guard=(lambda self: False)) inf = crest.Influence(source=inport, target=local, function=(lambda value: value * 2 + 15)) up = crest.Update(state=stateA, target=outport, function=(lambda self: 1337)) action = crest.Action(transition=trans, target=local2, function=(lambda self: self.local2 + 1))
class TestEntity(crest.Entity): port_out = crest.Output(res, 987) state = current = crest.State() second_state = crest.State() transition = crest.Transition(source=state, target=second_state, guard=(lambda self: True)) action = crest.Action(transition=transition, target=port_out, function=(lambda self: 12345)) def __init__(self): api.add(self, "port_out", crest.Output(res, 7777))
def __init__(self): api.add(self, "port_out", crest.Output(res, 7777))
class SubEntity(crest.Entity): state = current = crest.State() sub_out = crest.Output(res, 111)
class TestEntity(crest.Entity): port_out = crest.Output(res, 987) state = current = crest.State() def __init__(self): api.add(self, "state", newstate)
class Test(crest.Entity): in1 = crest.Input(resource=res, value=0) in2 = crest.Input(resource=res, value=0) local = crest.Local(resource=res, value=0) out = crest.Output(resource=res, value=0)
class TestSubEntity(crest.Entity): in1 = crest.Input(resource=testRes, value=3) in2 = crest.Input(resource=testRes, value=3) out1 = crest.Output(resource=testRes, value=3) out2 = crest.Output(resource=testRes, value=3)
class Subtype(self.basetype): outport = crest.Output(newres, 12)