Interface OpenemsComponent

    • Method Detail

      • id

        java.lang.String id()
        Returns a unique ID for this OpenEMS component.
        Returns:
        the unique ID
      • alias

        java.lang.String alias()
        Returns a human-readable name of this Component..
        Returns:
        the human-readable name
      • isEnabled

        boolean isEnabled()
        Returns whether this component is enabled.
        Returns:
        true if the component is enabled
      • servicePid

        default java.lang.String servicePid()
        Returns the Service PID.
        Returns:
        the OSGi Service PID
      • serviceFactoryPid

        default java.lang.String serviceFactoryPid()
        Returns the Service Factory-PID.
        Returns:
        the OSGi Service Factory-PID
      • getComponentContext

        org.osgi.service.component.ComponentContext getComponentContext()
        Returns the ComponentContext.
        Returns:
        the OSGi ComponentContext
      • _channel

        @Deprecated
        Channel<?> _channel​(java.lang.String channelName)
        Deprecated.
        Returns an undefined Channel defined by its ChannelId string representation.

        Note: It is preferred to use the typed channel()-method, that's why it is marked as @Deprecated.

        Parameters:
        channelName - the Channel-ID as a string
        Returns:
        the Channel or null
      • channel

        default <T extends Channel<?>> T channel​(java.lang.String channelName)
                                          throws java.lang.IllegalArgumentException
        Returns a Channel defined by its ChannelId string representation.
        Type Parameters:
        T - the expected typed Channel
        Parameters:
        channelName - the Channel-ID as a string
        Returns:
        the Channel or throw Exception
        Throws:
        java.lang.IllegalArgumentException - on error
      • channel

        default <T extends Channel<?>> T channel​(ChannelId channelId)
                                          throws java.lang.IllegalArgumentException
        Returns a Channel defined by its ChannelId.
        Type Parameters:
        T - the Type of the Channel. See Doc.getType()
        Parameters:
        channelId - the Channel-ID
        Returns:
        the Channel
        Throws:
        java.lang.IllegalArgumentException - on error
      • channels

        java.util.Collection<Channel<?>> channels()
        Returns all Channels.
        Returns:
        a Collection of Channels
      • getStateChannel

        default StateCollectorChannel getStateChannel()
        Gets the Component State-Channel.
        Returns:
        the StateCollectorChannel
      • getState

        default Level getState()
        Gets the Component State Level.
        Returns:
        the StateCollectorChannel
      • _getChannelAs

        default <T extends Channel<?>> T _getChannelAs​(OpenemsComponent.ChannelId channelId,
                                                       java.lang.Class<T> type)
        Gets the Channel as the given Type.
        Type Parameters:
        T - the expected Channel type
        Parameters:
        channelId - the Channel-ID
        type - the expected Type
        Returns:
        the Channel
      • debugLog

        default java.lang.String debugLog()
        Gets some output that is suitable for a continuous Debug log. Returns 'null' by default which causes no output.
        Returns:
        the debug log output
      • hasFaults

        default boolean hasFaults()
        Does this OpenEMS Component report any Faults?

        Evaluates all StateChannels and returns true if any Channel with Level.FAULT is set.

        Returns:
        true if there is a Fault.
      • updateReferenceFilter

        static boolean updateReferenceFilter​(org.osgi.service.cm.ConfigurationAdmin cm,
                                             java.lang.String pid,
                                             java.lang.String member,
                                             java.lang.String... ids)
        Sets a target filter for a Declarative Service @Reference member.

        Usage:

         updateReferenceFilter(config.service_pid(), "Controllers", controllersIds);
         

        Generates a 'target' filter on the 'Controllers' member so, that the the expected service to be injected needs to fulfill:

        • the service must be enabled
        • the service must not have the same PID as the calling component
        • the service "id" must be one of the provided "controllersIds"
        Parameters:
        cm - a ConfigurationAdmin instance. Get one using
                       @Reference
                       ConfigurationAdmin cm;
                       
        pid - PID of the calling component (use 'config.service_pid()' or '(String)prop.get(Constants.SERVICE_PID)'; if null, PID filter is not added to the resulting target filter
        member - Name of the Method or Field with the Reference annotation, e.g.
        ids - Component IDs to be filtered for; for empty list, no ids are added to the target filter
        Returns:
        true if the filter was updated. You may use it to abort the activate() method.
      • updateConfigurationProperty

        static void updateConfigurationProperty​(org.osgi.service.cm.ConfigurationAdmin cm,
                                                java.lang.String pid,
                                                java.lang.String property,
                                                java.lang.Object value)
        Update a configuration property.

        Usage:

         updateConfigurationProperty(cm, servicePid, "propertyName", "propertyValue");
         

        Parameters:
        cm - a ConfigurationAdmin instance. Get one using
                         @Reference
                         ConfigurationAdmin cm;
                         
        pid - PID of the calling component (use 'config.service_pid()' or '(String)prop.get(Constants.SERVICE_PID)'
        property - Name of the configuration property
        value - New configuration value
      • logDebug

        static void logDebug​(OpenemsComponent component,
                             org.slf4j.Logger log,
                             java.lang.String message)
        Log a debug message including the Component ID.
        Parameters:
        component - the OpenemsComponent
        log - the Logger instance
        message - the message
      • logInfo

        static void logInfo​(OpenemsComponent component,
                            org.slf4j.Logger log,
                            java.lang.String message)
        Log a info message including the Component ID.
        Parameters:
        component - the OpenemsComponent
        log - the Logger instance
        message - the message
      • logWarn

        static void logWarn​(OpenemsComponent component,
                            org.slf4j.Logger log,
                            java.lang.String message)
        Log a warn message including the Component ID.
        Parameters:
        component - the OpenemsComponent
        log - the Logger instance
        message - the message
      • logError

        static void logError​(OpenemsComponent component,
                             org.slf4j.Logger log,
                             java.lang.String message)
        Log a error message including the Component ID.
        Parameters:
        component - the OpenemsComponent
        log - the Logger instance
        message - the message