Skip to content

Commit

Permalink
Add Thing#bridge? (#324)
Browse files Browse the repository at this point in the history
Resolve #323

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
  • Loading branch information
jimtng authored Aug 20, 2024
1 parent 2111a8e commit 62e7ccd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/openhab/core/things/thing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ def bridge
bridge_uid && EntityLookup.lookup_thing(bridge_uid)
end

# @return [true,false] true if this Thing is a bridge
def bridge?
is_a?(org.openhab.core.thing.Bridge)
end

# @return [String]
def inspect
r = "#<OpenHAB::Core::Things::Thing #{uid}"
Expand Down
13 changes: 13 additions & 0 deletions spec/openhab/core/things/thing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,17 @@

expect(thing.elevation).to be 300
end

describe "#bridge?" do
it "returns false for non-bridges" do
expect(thing).not_to be_bridge
end

it "returns true for bridges" do
install_addon "binding-mqtt", ready_markers: "openhab.xmlThingTypes"
things.build { bridge "mqtt:broker:mosquitto", "MQTT Broker" }

expect(things["mqtt:broker:mosquitto"]).to be_bridge
end
end
end

0 comments on commit 62e7ccd

Please sign in to comment.