Skip to content

Commit

Permalink
Items Builder: allow setting initial state on a group item (#261)
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
  • Loading branch information
jimtng authored Mar 5, 2024
1 parent de4712e commit 934aac5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/openhab/dsl/items/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,6 @@ def #{m}(*args, groups: nil, **kwargs) # def dimmer_item(*args, groups: nil, **
# @param (see ItemBuilder#initialize)
def initialize(*args, type: nil, function: nil, thing: nil, **kwargs)
raise ArgumentError, "invalid function #{function}" if function && !function.match?(FUNCTION_REGEX)
raise ArgumentError, "state cannot be set on GroupItems" if kwargs[:state]

super(type, *args, **kwargs)
@function = function
Expand Down
5 changes: 5 additions & 0 deletions spec/openhab/dsl/items/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,11 @@ def build_and_update(org_config, new_config, item_to_keep: :new_item, &block)
expect(DateTimeItem1.state).to eq Time.parse("1970-01-01T00:00:00+00:00")
end

it "sets initial state on a group item" do
items.build { group_item "GroupItem1", type: "Switch", state: ON }
expect(GroupItem1.state).to be ON
end

describe "entity lookup" do
it "can reference a group item directly" do
items.build do
Expand Down

0 comments on commit 934aac5

Please sign in to comment.