Skip to content

Commit

Permalink
support ItemStateUpdatedEvent
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <[email protected]>
  • Loading branch information
jimtng committed Apr 1, 2023
1 parent 0db2fef commit 6bb1fb0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/openhab/core/events/item_state_updated_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require_relative "item_state_event"

module OpenHAB
module Core
module Events
begin
java_import org.openhab.core.items.events.ItemStateUpdatedEvent

#
# {AbstractEvent} sent when an item's state has updated.
#
class ItemStateUpdatedEvent < ItemEvent
include ItemState
end
rescue
# @deprecated OH3.4 OH3 will raise an error ItemStateUpdatedEvent is only in OH4
end
end
end
end
32 changes: 32 additions & 0 deletions spec/openhab/core/events/item_state_updated_event_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

if OpenHAB::Core::Events.const_defined?(:ItemStateUpdatedEvent) # @deprecated OH3.4 - introduced in OH4
RSpec.describe OpenHAB::Core::Events::ItemStateUpdatedEvent do
it "has proper predicates for a NULL event" do
event = org.openhab.core.items.events.ItemEventFactory.create_state_updated_event("item", NULL)

expect(event).to be_null
expect(event).not_to be_undef
expect(event.state?).to be false
expect(event.state).to be_nil
end

it "has proper predicates for an UNDEF event" do
event = org.openhab.core.items.events.ItemEventFactory.create_state_updated_event("item", UNDEF)

expect(event).not_to be_null
expect(event).to be_undef
expect(event.state?).to be false
expect(event.state).to be_nil
end

it "has proper predicates for an ON event" do
event = org.openhab.core.items.events.ItemEventFactory.create_state_updated_event("item", ON)

expect(event).not_to be_null
expect(event).not_to be_undef
expect(event.state?).to be true
expect(event.state).to be ON
end
end
end

0 comments on commit 6bb1fb0

Please sign in to comment.