Class ItemEventFactory

java.lang.Object
org.openhab.core.events.AbstractEventFactory
org.openhab.core.items.events.ItemEventFactory
All Implemented Interfaces:
EventFactory

@NonNullByDefault public class ItemEventFactory extends AbstractEventFactory
An ItemEventFactory is responsible for creating item event instances, e.g. ItemCommandEvents and ItemStateEvents.
Author:
Stefan Bußweiler - Initial contribution
  • Constructor Details

    • ItemEventFactory

      public ItemEventFactory()
      Constructs a new ItemEventFactory.
  • Method Details

    • createEventByType

      protected Event createEventByType(String eventType, String topic, String payload, @Nullable String source) throws Exception
      Description copied from class: AbstractEventFactory
      Create a new event instance based on the event type.
      Specified by:
      createEventByType in class AbstractEventFactory
      Parameters:
      eventType - the event type
      topic - the topic
      payload - the payload
      source - the source, can be null
      Returns:
      the created event instance
      Throws:
      Exception - if the creation of the event fails
    • createCommandEvent

      public static ItemCommandEvent createCommandEvent(String itemName, Command command, @Nullable String source)
      Creates an item command event.
      Parameters:
      itemName - the name of the item to send the command for
      command - the command to send
      source - the name of the source identifying the sender (can be null)
      Returns:
      the created item command event
      Throws:
      IllegalArgumentException - if itemName or command is null
    • createCommandEvent

      public static ItemCommandEvent createCommandEvent(String itemName, Command command)
      Creates an item command event.
      Parameters:
      itemName - the name of the item to send the command for
      command - the command to send
      Returns:
      the created item command event
      Throws:
      IllegalArgumentException - if itemName or command is null
    • createStateEvent

      public static ItemStateEvent createStateEvent(String itemName, State state, @Nullable String source)
      Creates an item state event.
      Parameters:
      itemName - the name of the item to send the state update for
      state - the new state to send
      source - the name of the source identifying the sender (can be null)
      Returns:
      the created item state event
      Throws:
      IllegalArgumentException - if itemName or state is null
    • createStateEvent

      public static ItemEvent createStateEvent(String itemName, State state)
      Creates an item state event.
      Parameters:
      itemName - the name of the item to send the state update for
      state - the new state to send
      Returns:
      the created item state event
      Throws:
      IllegalArgumentException - if itemName or state is null
    • createStateUpdatedEvent

      public static ItemStateUpdatedEvent createStateUpdatedEvent(String itemName, State state)
      Creates an item state updated event.
      Parameters:
      itemName - the name of the item to report the state update for
      state - the new state
      Returns:
      the created item state update event
      Throws:
      IllegalArgumentException - if itemName or state is null
    • createStateUpdatedEvent

      public static ItemStateUpdatedEvent createStateUpdatedEvent(String itemName, State state, @Nullable String source)
      Creates an item state updated event.
      Parameters:
      itemName - the name of the item to report the state update for
      state - the new state
      source - the name of the source identifying the sender (can be null)
      Returns:
      the created item state update event
      Throws:
      IllegalArgumentException - if itemName or state is null
    • createTimeSeriesEvent

      public static ItemTimeSeriesEvent createTimeSeriesEvent(String itemName, TimeSeries timeSeries, @Nullable String source)
    • createTimeSeriesUpdatedEvent

      public static ItemTimeSeriesUpdatedEvent createTimeSeriesUpdatedEvent(String itemName, TimeSeries timeSeries, @Nullable String source)
    • createGroupStateUpdatedEvent

      public static GroupStateUpdatedEvent createGroupStateUpdatedEvent(String groupName, String member, State state, @Nullable String source)
      Creates a group item state updated event.
      Parameters:
      groupName - the name of the group to report the state update for
      member - the name of the item that updated the group state
      state - the new state
      source - the name of the source identifying the sender (can be null)
      Returns:
      the created group item state update event
      Throws:
      IllegalArgumentException - if groupName or state is null
    • createStatePredictedEvent

      public static ItemStatePredictedEvent createStatePredictedEvent(String itemName, State state, boolean isConfirmation)
      Creates an item state predicted event.
      Parameters:
      itemName - the name of the item to send the state update for
      state - the predicted state to send
      isConfirmation - whether this is a confirmation of a previous state
      Returns:
      the created item state predicted event
      Throws:
      IllegalArgumentException - if itemName or state is null
    • createStateChangedEvent

      public static ItemStateChangedEvent createStateChangedEvent(String itemName, State newState, State oldState)
      Creates an item state changed event.
      Parameters:
      itemName - the name of the item to send the state changed event for
      newState - the new state to send
      oldState - the old state of the item
      Returns:
      the created item state changed event
      Throws:
      IllegalArgumentException - if itemName or state is null
    • createGroupStateChangedEvent

      public static GroupItemStateChangedEvent createGroupStateChangedEvent(String itemName, String memberName, State newState, State oldState)
      Creates a group item state changed event.
      Parameters:
      itemName - the name of the group item to send the state changed event for
      memberName - the name of the member causing the group item state change
      newState - the new state to send
      oldState - the old state of the group item
      Returns:
      the created group item state changed event
      Throws:
      IllegalArgumentException - if itemName or state is null
    • createAddedEvent

      public static ItemAddedEvent createAddedEvent(Item item)
      Creates an item added event.
      Parameters:
      item - the item
      Returns:
      the created item added event
      Throws:
      IllegalArgumentException - if item is null
    • createRemovedEvent

      public static ItemRemovedEvent createRemovedEvent(Item item)
      Creates an item removed event.
      Parameters:
      item - the item
      Returns:
      the created item removed event
      Throws:
      IllegalArgumentException - if item is null
    • createUpdateEvent

      public static ItemUpdatedEvent createUpdateEvent(Item item, Item oldItem)
      Creates an item updated event.
      Parameters:
      item - the item
      oldItem - the old item
      Returns:
      the created item updated event
      Throws:
      IllegalArgumentException - if item or oldItem is null