Skip to content

Commit

Permalink
add/document ChannelTriggeredEvent (#198)
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Cutrer <cody@cutrer.us>
  • Loading branch information
ccutrer authored Dec 15, 2023
1 parent 3e90412 commit b0093b5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/openhab/core/events/channel_triggered_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module OpenHAB
module Core
module Events
java_import org.openhab.core.thing.events.ChannelTriggeredEvent

#
# {AbstractEvent} sent when a channel triggers.
#
class ChannelTriggeredEvent < AbstractEvent
extend Forwardable

# @!attribute [r] channel_uid
# @return [Things::ChannelUID] The UID of the {Things::Channel Channel} that triggered this event.
alias_method :channel_uid, :get_channel

# @!attribute [r] channel
# @return [Things::Channel, nil] The channel that triggered this event.

# @!attribute [r] thing
# @return [Things::Thing, nil] The thing that triggered this event.
def_delegators :channel_uid, :thing, :channel

# @!attribute [r] event
# @return [String] The event data
end
end
end
end
10 changes: 10 additions & 0 deletions lib/openhab/core/things/channel_uid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ def thing
EntityLookup.lookup_thing(thing_uid)
end

# @attribute [r] channel
#
# Return the channel object for this channel
#
# @return [Channel, nil]
#
def channel
things.channels[self]
end

#
# @attribute [r] item
#
Expand Down
1 change: 1 addition & 0 deletions lib/openhab/core/things/thing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def initialize(thing, array)
# Allows indexing by both integer as an array or channel id acting like a hash.
# @param [Integer, String, ChannelUID] index
# Numeric index, string channel id, or a {ChannelUID} to search for.
# @return [Channel, nil]
def [](index)
return @thing.get_channel(index) if index.is_a?(ChannelUID)
return @thing.get_channel(index.to_str) if index.respond_to?(:to_str)
Expand Down

0 comments on commit b0093b5

Please sign in to comment.