Search in sources :

Example 1 with DeviceNature

use of io.openems.api.device.nature.DeviceNature in project openems by OpenEMS.

the class SimulatorReadChannel method required.

@Override
public SimulatorReadChannel<T> required() {
    super.required();
    if (parent() instanceof DeviceNature) {
        DeviceNature parent = (DeviceNature) parent();
        parent.setAsRequired(this);
    }
    return this;
}
Also used : DeviceNature(io.openems.api.device.nature.DeviceNature)

Example 2 with DeviceNature

use of io.openems.api.device.nature.DeviceNature in project openems by OpenEMS.

the class EssClusterNature method loadEss.

private void loadEss() {
    Set<DeviceNature> natures = repo.getDeviceNatures();
    JsonArray essIds;
    try {
        essIds = esss.value();
        // remove old ess
        for (SymmetricEssNature ess : this.essList) {
            soc.removeChannel(ess.soc());
            gridMode.removeChannel(ess.gridMode());
            systemState.removeChannel(ess.systemState());
            allowedCharge.removeChannel(ess.allowedCharge());
            allowedDischarge.removeChannel(ess.allowedDischarge());
            allowedApparent.removeChannel(ess.allowedApparent());
            activePower.removeChannel(ess.activePower());
            reactivePower.removeChannel(ess.reactivePower());
            apparentPower.removeChannel(ess.apparentPower());
            maxNominalPower.removeChannel(ess.maxNominalPower());
            capacity.removeChannel(ess.capacity());
            setWorkState.removeChannel(ess.setWorkState());
            power.removeEss(ess);
        }
        essList.clear();
        if (essIds != null && isInitialized) {
            for (DeviceNature nature : natures) {
                if (nature instanceof SymmetricEssNature) {
                    if (essIds.toString().contains(nature.id())) {
                        SymmetricEssNature ess = (SymmetricEssNature) nature;
                        essList.add(ess);
                        soc.addChannel(ess.soc());
                        gridMode.addChannel(ess.gridMode());
                        systemState.addChannel(ess.systemState());
                        allowedCharge.addChannel(ess.allowedCharge());
                        allowedDischarge.addChannel(ess.allowedDischarge());
                        allowedApparent.addChannel(ess.allowedApparent());
                        activePower.addChannel(ess.activePower());
                        reactivePower.addChannel(ess.reactivePower());
                        apparentPower.addChannel(ess.apparentPower());
                        maxNominalPower.addChannel(ess.maxNominalPower());
                        capacity.addChannel(ess.capacity());
                        setWorkState.addChannel(ess.setWorkState());
                        power.addEss(ess);
                    }
                }
            }
        // capacity.channelUpdated(null, null);
        }
    } catch (InvalidValueException e) {
        log.error("esss value is invalid!", e);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) InvalidValueException(io.openems.api.exception.InvalidValueException) DeviceNature(io.openems.api.device.nature.DeviceNature) SystemDeviceNature(io.openems.impl.protocol.system.SystemDeviceNature) SymmetricEssNature(io.openems.api.device.nature.ess.SymmetricEssNature)

Example 3 with DeviceNature

use of io.openems.api.device.nature.DeviceNature in project openems by OpenEMS.

the class FeneconPersistence method addChannelValueToQueue.

/**
 * Add a channel value to the send queue
 *
 * @param channel
 * @param valueOpt
 */
private void addChannelValueToQueue(Channel channel, Optional<?> valueOpt) {
    // Ignore anything that is not a ReadChannel
    if (!(channel instanceof ReadChannel<?>)) {
        return;
    }
    ReadChannel<?> readChannel = (ReadChannel<?>) channel;
    // Ignore channels that shall not be persisted
    if (readChannel.isDoNotPersist()) {
        return;
    }
    // Read and format value from channel
    FieldValue<?> fieldValue;
    if (!valueOpt.isPresent()) {
        fieldValue = new NullFieldValue();
    } else {
        Object value = valueOpt.get();
        if (value instanceof Number) {
            fieldValue = new NumberFieldValue((Number) value);
        } else if (value instanceof String) {
            fieldValue = new StringFieldValue((String) value);
        } else if (value instanceof Inet4Address) {
            fieldValue = new StringFieldValue(((Inet4Address) value).getHostAddress());
        } else if (value instanceof Boolean) {
            fieldValue = new NumberFieldValue(((Boolean) value) ? 1 : 0);
        } else if (value instanceof ChannelEnum) {
            fieldValue = new NumberFieldValue(((ChannelEnum) value).getValue());
        } else if (value instanceof DeviceNature || value instanceof JsonElement || value instanceof Map || value instanceof Set || value instanceof List || value instanceof ThingMap) {
            // ignore
            return;
        } else {
            log.warn("FENECON Persistence for value type [" + value.getClass().getName() + "] of channel [" + channel.address() + "] is not implemented.");
            return;
        }
    }
    // Add timestamp + value to queue
    synchronized (queue) {
        queue.put(readChannel.address(), fieldValue);
    }
}
Also used : Inet4Address(java.net.Inet4Address) Set(java.util.Set) NumberFieldValue(io.openems.common.types.NumberFieldValue) ReadChannel(io.openems.api.channel.ReadChannel) NullFieldValue(io.openems.common.types.NullFieldValue) StringFieldValue(io.openems.common.types.StringFieldValue) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) DeviceNature(io.openems.api.device.nature.DeviceNature) List(java.util.List) ThingMap(io.openems.api.controller.ThingMap) ChannelEnum(io.openems.common.types.ChannelEnum) HashMap(java.util.HashMap) Map(java.util.Map) ThingMap(io.openems.api.controller.ThingMap)

Example 4 with DeviceNature

use of io.openems.api.device.nature.DeviceNature in project openems by OpenEMS.

the class KebaDevice method receive.

/**
 * Forward message to deviceNature
 */
public void receive(String message) {
    for (DeviceNature nature : this.getDeviceNatures()) {
        if (nature instanceof KebaDeviceNature) {
            KebaDeviceNature kebaNature = (KebaDeviceNature) nature;
            kebaNature.receive(message);
        }
    }
}
Also used : DeviceNature(io.openems.api.device.nature.DeviceNature)

Example 5 with DeviceNature

use of io.openems.api.device.nature.DeviceNature in project openems by OpenEMS.

the class ModbusReadChannel method required.

@Override
public ReadChannel<T> required() {
    super.required();
    if (parent() instanceof DeviceNature) {
        DeviceNature parent = (DeviceNature) parent();
        parent.setAsRequired(this);
    }
    return super.required();
}
Also used : DeviceNature(io.openems.api.device.nature.DeviceNature)

Aggregations

DeviceNature (io.openems.api.device.nature.DeviceNature)8 JsonObject (com.google.gson.JsonObject)2 Bridge (io.openems.api.bridge.Bridge)2 ReadChannel (io.openems.api.channel.ReadChannel)2 Controller (io.openems.api.controller.Controller)2 Device (io.openems.api.device.Device)2 Persistence (io.openems.api.persistence.Persistence)2 QueryablePersistence (io.openems.api.persistence.QueryablePersistence)2 Scheduler (io.openems.api.scheduler.Scheduler)2 List (java.util.List)2 BiMap (com.google.common.collect.BiMap)1 HashBasedTable (com.google.common.collect.HashBasedTable)1 HashBiMap (com.google.common.collect.HashBiMap)1 HashMultimap (com.google.common.collect.HashMultimap)1 Table (com.google.common.collect.Table)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 Channel (io.openems.api.channel.Channel)1 ConfigChannel (io.openems.api.channel.ConfigChannel)1 ThingStateChannel (io.openems.api.channel.ThingStateChannel)1