Search in sources :

Example 1 with Thing

use of io.openems.api.thing.Thing in project openems by OpenEMS.

the class ThermalPowerStationTest method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    ess = new UnitTestAsymmetricEssNature("ess0");
    meter = new UnitTestSymmetricMeterNature("meter0");
    controller = new ThermalPowerStationController();
    outputChannel = new UnitTestWriteChannel<>("0", new Thing() {

        @Override
        public String id() {
            return "output0";
        }

        @Override
        public ThingStateChannels getStateChannel() {
            return null;
        }
    });
    essThingMap = new Ess(ess);
    meterThingMap = new Meter(meter);
    controller.ess.updateValue(essThingMap, true);
    List<Meter> meters = new ArrayList<>();
    meters.add(meterThingMap);
    controller.meters.updateValue(meters, true);
    controller.outputChannelOpt = Optional.of(outputChannel);
    controller.productionLimit.updateValue(1000L, true);
    controller.limitTimeRange.updateValue(1L, true);
    controller.minSoc.updateValue(15L, true);
    controller.maxSoc.updateValue(95L, true);
    controller.invertOutput.updateValue(false, true);
}
Also used : Ess(io.openems.impl.controller.thermalpowerstation.Ess) ThermalPowerStationController(io.openems.impl.controller.thermalpowerstation.ThermalPowerStationController) Meter(io.openems.impl.controller.thermalpowerstation.Meter) ArrayList(java.util.ArrayList) UnitTestAsymmetricEssNature(io.openems.test.utils.devicenatures.UnitTestAsymmetricEssNature) UnitTestSymmetricMeterNature(io.openems.test.utils.devicenatures.UnitTestSymmetricMeterNature) Thing(io.openems.api.thing.Thing) BeforeClass(org.junit.BeforeClass)

Example 2 with Thing

use of io.openems.api.thing.Thing in project openems by OpenEMS.

the class AsymmetricSymmetricCombinationEssNature method loadEss.

private void loadEss() {
    String essId;
    try {
        essId = ess.value();
        // remove old ess
        if (essNature != null) {
            gridMode.removeChannel(essNature.gridMode());
            soc.removeChannel(essNature.soc());
            allowedApparent.removeChannel(essNature.allowedApparent());
            allowedCharge.removeChannel(essNature.allowedCharge());
            allowedDischarge.removeChannel(essNature.allowedDischarge());
            systemState.removeChannel(essNature.systemState());
            capacity.removeChannel(essNature.capacity());
            maxNominalPower.removeChannel(essNature.maxNominalPower());
            activePowerL1.removeChannel(essNature.activePowerL1());
            activePowerL1.removeChannel(essNature.activePowerL2());
            activePowerL1.removeChannel(essNature.activePowerL3());
            activePowerL2.removeChannel(essNature.activePowerL1());
            activePowerL2.removeChannel(essNature.activePowerL2());
            activePowerL2.removeChannel(essNature.activePowerL3());
            activePowerL3.removeChannel(essNature.activePowerL1());
            activePowerL3.removeChannel(essNature.activePowerL2());
            activePowerL3.removeChannel(essNature.activePowerL3());
            activePower.removeChannel(essNature.activePowerL1());
            activePower.removeChannel(essNature.activePowerL2());
            activePower.removeChannel(essNature.activePowerL3());
            reactivePowerL1.removeChannel(essNature.reactivePowerL1());
            reactivePowerL1.removeChannel(essNature.reactivePowerL2());
            reactivePowerL1.removeChannel(essNature.reactivePowerL3());
            reactivePowerL2.removeChannel(essNature.reactivePowerL1());
            reactivePowerL2.removeChannel(essNature.reactivePowerL2());
            reactivePowerL2.removeChannel(essNature.reactivePowerL3());
            reactivePowerL3.removeChannel(essNature.reactivePowerL1());
            reactivePowerL3.removeChannel(essNature.reactivePowerL2());
            reactivePowerL3.removeChannel(essNature.reactivePowerL3());
            reactivePower.removeChannel(essNature.reactivePowerL1());
            reactivePower.removeChannel(essNature.reactivePowerL2());
            reactivePower.removeChannel(essNature.reactivePowerL3());
            setActivePowerL1.removeChannel(essNature.setActivePowerL1());
            setActivePowerL1.removeChannel(essNature.setActivePowerL2());
            setActivePowerL1.removeChannel(essNature.setActivePowerL3());
            setActivePowerL2.removeChannel(essNature.setActivePowerL1());
            setActivePowerL2.removeChannel(essNature.setActivePowerL2());
            setActivePowerL2.removeChannel(essNature.setActivePowerL3());
            setActivePowerL3.removeChannel(essNature.setActivePowerL1());
            setActivePowerL3.removeChannel(essNature.setActivePowerL2());
            setActivePowerL3.removeChannel(essNature.setActivePowerL3());
            setReactivePowerL1.removeChannel(essNature.setReactivePowerL1());
            setReactivePowerL1.removeChannel(essNature.setReactivePowerL2());
            setReactivePowerL1.removeChannel(essNature.setReactivePowerL3());
            setReactivePowerL2.removeChannel(essNature.setReactivePowerL1());
            setReactivePowerL2.removeChannel(essNature.setReactivePowerL2());
            setReactivePowerL2.removeChannel(essNature.setReactivePowerL3());
            setReactivePowerL3.removeChannel(essNature.setReactivePowerL1());
            setReactivePowerL3.removeChannel(essNature.setReactivePowerL2());
            setReactivePowerL3.removeChannel(essNature.setReactivePowerL3());
            setWorkState.removeChannel(essNature.setWorkState());
            power = null;
            nativeAsymmetricPower = null;
        }
        essNature = null;
        if (essId != null) {
            Optional<Thing> nature = repo.getThingById(essId);
            if (nature.isPresent()) {
                if (nature.get() instanceof AsymmetricEssNature) {
                    AsymmetricEssNature ess = (AsymmetricEssNature) nature.get();
                    essNature = ess;
                    // Add channels to functionalChannels
                    if (essNature != null) {
                        gridMode.setChannel(essNature.gridMode());
                        soc.setChannel(essNature.soc());
                        allowedApparent.setChannel(essNature.allowedApparent());
                        allowedDischarge.setChannel(essNature.allowedDischarge());
                        allowedCharge.setChannel(essNature.allowedCharge());
                        systemState.setChannel(essNature.systemState());
                        capacity.setChannel(essNature.capacity());
                        maxNominalPower.setChannel(essNature.maxNominalPower());
                        activePowerL1.addChannel(essNature.activePowerL1());
                        activePowerL1.addChannel(essNature.activePowerL2());
                        activePowerL1.addChannel(essNature.activePowerL3());
                        activePowerL2.addChannel(essNature.activePowerL1());
                        activePowerL2.addChannel(essNature.activePowerL2());
                        activePowerL2.addChannel(essNature.activePowerL3());
                        activePowerL3.addChannel(essNature.activePowerL1());
                        activePowerL3.addChannel(essNature.activePowerL2());
                        activePowerL3.addChannel(essNature.activePowerL3());
                        activePower.addChannel(essNature.activePowerL1());
                        activePower.addChannel(essNature.activePowerL2());
                        activePower.addChannel(essNature.activePowerL3());
                        reactivePowerL1.addChannel(essNature.reactivePowerL1());
                        reactivePowerL1.addChannel(essNature.reactivePowerL2());
                        reactivePowerL1.addChannel(essNature.reactivePowerL3());
                        reactivePowerL2.addChannel(essNature.reactivePowerL1());
                        reactivePowerL2.addChannel(essNature.reactivePowerL2());
                        reactivePowerL2.addChannel(essNature.reactivePowerL3());
                        reactivePowerL3.addChannel(essNature.reactivePowerL1());
                        reactivePowerL3.addChannel(essNature.reactivePowerL2());
                        reactivePowerL3.addChannel(essNature.reactivePowerL3());
                        reactivePower.addChannel(essNature.reactivePowerL1());
                        reactivePower.addChannel(essNature.reactivePowerL2());
                        reactivePower.addChannel(essNature.reactivePowerL3());
                        setActivePowerL1.addChannel(essNature.setActivePowerL1());
                        setActivePowerL1.addChannel(essNature.setActivePowerL2());
                        setActivePowerL1.addChannel(essNature.setActivePowerL3());
                        setActivePowerL2.addChannel(essNature.setActivePowerL1());
                        setActivePowerL2.addChannel(essNature.setActivePowerL2());
                        setActivePowerL2.addChannel(essNature.setActivePowerL3());
                        setActivePowerL3.addChannel(essNature.setActivePowerL1());
                        setActivePowerL3.addChannel(essNature.setActivePowerL2());
                        setActivePowerL3.addChannel(essNature.setActivePowerL3());
                        setReactivePowerL1.addChannel(essNature.setReactivePowerL1());
                        setReactivePowerL1.addChannel(essNature.setReactivePowerL2());
                        setReactivePowerL1.addChannel(essNature.setReactivePowerL3());
                        setReactivePowerL2.addChannel(essNature.setReactivePowerL1());
                        setReactivePowerL2.addChannel(essNature.setReactivePowerL2());
                        setReactivePowerL2.addChannel(essNature.setReactivePowerL3());
                        setReactivePowerL3.addChannel(essNature.setReactivePowerL1());
                        setReactivePowerL3.addChannel(essNature.setReactivePowerL2());
                        setReactivePowerL3.addChannel(essNature.setReactivePowerL3());
                        setWorkState.addChannel(essNature.setWorkState());
                        power = new SymmetricPowerProxy(essNature.maxNominalPower().value(), getParent().getBridge());
                        nativeAsymmetricPower = new AsymmetricPower(essNature.allowedDischarge().required(), essNature.allowedCharge().required(), essNature.allowedApparent().required(), essNature.setActivePowerL1().required(), essNature.setActivePowerL2().required(), essNature.setActivePowerL3().required(), essNature.setReactivePowerL1().required(), essNature.setReactivePowerL2().required(), essNature.setReactivePowerL3().required());
                    }
                } else {
                    log.error("ThingID: " + essId + " is no AsymmetricEss!");
                }
            } else {
                log.warn("meter: " + essId + " not found!");
            }
        }
    } catch (InvalidValueException e) {
        log.error("esss value is invalid!", e);
    }
}
Also used : InvalidValueException(io.openems.api.exception.InvalidValueException) AsymmetricPower(io.openems.core.utilities.AsymmetricPower) SymmetricPowerProxy(io.openems.core.utilities.power.symmetric.SymmetricPowerProxy) Thing(io.openems.api.thing.Thing) AsymmetricEssNature(io.openems.api.device.nature.ess.AsymmetricEssNature)

Example 3 with Thing

use of io.openems.api.thing.Thing in project openems by OpenEMS.

the class MeterClusterNature method loadMeter.

private void loadMeter() {
    JsonArray meterIds;
    try {
        meterIds = meter.value();
        // remove old ess
        synchronized (symmetricMeterList) {
            synchronized (asymmetricMeterList) {
                symmetricMeterList.clear();
                for (AsymmetricMeterNature meter : asymmetricMeterList) {
                    this.thingState.removeChangeListener(meter.getStateChannel());
                }
                asymmetricMeterList.clear();
                if (meterIds != null) {
                    for (JsonElement id : meterIds) {
                        Optional<Thing> nature = repo.getThingById(id.getAsString());
                        if (nature.isPresent()) {
                            if (nature.get() instanceof AsymmetricMeterNature) {
                                AsymmetricMeterNature meter = (AsymmetricMeterNature) nature.get();
                                asymmetricMeterList.add(meter);
                            } else if (nature.get() instanceof SymmetricMeterNature) {
                                SymmetricMeterNature meter = (SymmetricMeterNature) nature.get();
                                symmetricMeterList.add(meter);
                            } else {
                                log.error("ThingID: " + id.getAsString() + " is no Meter!");
                            }
                        } else {
                            log.warn("meter: " + id.getAsString() + " not found!");
                        }
                    }
                }
            }
        }
    } catch (InvalidValueException e) {
        log.error("meter value is invalid!", e);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) InvalidValueException(io.openems.api.exception.InvalidValueException) SymmetricMeterNature(io.openems.api.device.nature.meter.SymmetricMeterNature) AsymmetricMeterNature(io.openems.api.device.nature.meter.AsymmetricMeterNature) JsonElement(com.google.gson.JsonElement) Thing(io.openems.api.thing.Thing)

Example 4 with Thing

use of io.openems.api.thing.Thing in project openems by OpenEMS.

the class SimulatorAsymmetricEss method getCharger.

private void getCharger() {
    if (chargerList != null) {
        for (ChargerNature charger : chargerList) {
            soc.removeChannel(charger.getActualPower());
        }
        chargerList.clear();
        if (charger.valueOptional().isPresent()) {
            JsonArray ids = charger.valueOptional().get();
            for (JsonElement e : ids) {
                Optional<Thing> t = repo.getThingById(e.getAsString());
                if (t.isPresent()) {
                    if (t.get() instanceof ChargerNature) {
                        ChargerNature charger = (ChargerNature) t.get();
                        chargerList.add(charger);
                        soc.addChannel(charger.getActualPower());
                    }
                }
            }
        }
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) ChargerNature(io.openems.api.device.nature.charger.ChargerNature) Thing(io.openems.api.thing.Thing)

Example 5 with Thing

use of io.openems.api.thing.Thing in project openems by OpenEMS.

the class Config method getJson.

/**
 * Gets the Config as Json in the given format
 *
 * @param format
 * @return
 * @throws NotImplementedException
 */
public synchronized JsonObject getJson(ConfigFormat format, Role role, String language) throws NotImplementedException {
    JsonObject jConfig = new JsonObject();
    if (format == ConfigFormat.FILE) {
        /*
			 * Prepare Json in format for config.json file
			 */
        // Bridge
        jConfig.add("things", getBridgesJson(format, role));
        // Scheduler
        jConfig.add("scheduler", getSchedulerJson(format, role));
        // Persistence
        jConfig.add("persistence", getPersistenceJson(format, role));
        // Users
        jConfig.add("users", getUsersJson());
    } else {
        /*
			 * Prepare Json in format for OpenEMS UI
			 */
        // things...
        JsonObject jThings = new JsonObject();
        Set<Thing> things = ThingRepository.getInstance().getThings();
        for (Thing thing : things) {
            JsonObject jThing = (JsonObject) ConfigUtils.getAsJsonElement(thing, format, role);
            jThings.add(thing.id(), jThing);
        }
        jConfig.add("things", jThings);
        // meta...
        JsonObject jMeta = new JsonObject();
        try {
            Iterable<ThingDoc> availableThings = ClassRepository.getInstance().getAvailableThings();
            for (ThingDoc availableThing : availableThings) {
                jMeta.add(availableThing.getClazz().getName(), availableThing.getAsJsonObject());
            }
        } catch (ReflectionException e) {
            log.error(e.getMessage());
            e.printStackTrace();
        }
        jConfig.add("meta", jMeta);
    }
    return jConfig;
}
Also used : ReflectionException(io.openems.api.exception.ReflectionException) JsonObject(com.google.gson.JsonObject) Thing(io.openems.api.thing.Thing) ThingDoc(io.openems.api.doc.ThingDoc)

Aggregations

Thing (io.openems.api.thing.Thing)17 JsonArray (com.google.gson.JsonArray)6 JsonElement (com.google.gson.JsonElement)5 JsonObject (com.google.gson.JsonObject)5 ConfigChannel (io.openems.api.channel.ConfigChannel)4 ThingDoc (io.openems.api.doc.ThingDoc)4 ReflectionException (io.openems.api.exception.ReflectionException)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Channel (io.openems.api.channel.Channel)3 ReadChannel (io.openems.api.channel.ReadChannel)3 ThingMap (io.openems.api.controller.ThingMap)3 Device (io.openems.api.device.Device)3 ChannelDoc (io.openems.api.doc.ChannelDoc)3 Field (java.lang.reflect.Field)3 Bridge (io.openems.api.bridge.Bridge)2 ThingStateChannel (io.openems.api.channel.ThingStateChannel)2 WriteChannel (io.openems.api.channel.WriteChannel)2 DeviceNature (io.openems.api.device.nature.DeviceNature)2 ChargerNature (io.openems.api.device.nature.charger.ChargerNature)2