Skip to content

Commit

Permalink
Fix #toggle on dimmer items (#378)
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Cutrer <cody@cutrer.us>
  • Loading branch information
ccutrer authored Jan 3, 2025
1 parent 5dc56fb commit 3d47e9c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/openhab/core/items/switch_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def format_type(command)
# @return [self]
#
def toggle(source: nil)
return on!(source: source) unless state?

command!(!state, source: source)
command!(!on?, source: source)
end

# @!method on?
Expand Down
22 changes: 22 additions & 0 deletions spec/openhab/core/items/dimmer_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@
end
end

describe "#toggle" do
specify do
item.on.toggle
expect(item.state).to eq 0
end

specify do
item.off.toggle
expect(item.state).to eq 100
end

specify do
item.update(UNDEF).toggle
expect(item.state).to eq 100
end

specify do
item.update(NULL).toggle
expect(item.state).to eq 100
end
end

it "works with grep" do
items.build { switch_item "Switch1" }
expect(items.grep(DimmerItem)).to match_array [DimmerOne, DimmerTwo]
Expand Down

0 comments on commit 3d47e9c

Please sign in to comment.