Printing of ESDL Objects

Sometimes it is convenient to print ESDL objects, but they all look the same: the class name and then a hexadecimal memory location, e.g. <esdl.esdl.WindTurbine object at 0x00000215AF0EE590>. This snippet makes them more useful, using the repr() functionality of Python:

esdl.InfluxDBProfile.__repr__ = lambda x: f"<{x.eClass.name} name={x.name}, measurement={x.measurement}, field={x.field}>"
esdl.Consumer.__repr__ = lambda x: f"<{x.eClass.name} name={x.name}, id={x.id}>"

As a Consumer is a super class, all subclasses (like HeatingDemand) will also be printed using this repr. Output will be like:

<InfluxDBProfile name=Profile1, measurement=profiles, field=profile1>
<HeatingDemand name=HeatDemand1, id=id1>

More advanced __repr__ is useful for Ports:

esdl.Port.__repr__ = lambda x: f'<{x.eClass.name}[{x.name}] of {x.eContainer().name if x.eContainer() else None}, id={x.id}>'

This will print also the name of the container object, e.g.:

<OutPort[Out] of WindTurbine_c53e, id=2040dfa0-bb51-4d57-9b11-9b0001429b71>