From 934aac5b5b330ce01c99b5a04925e8898643eb22 Mon Sep 17 00:00:00 2001 From: jimtng <2554958+jimtng@users.noreply.github.com> Date: Wed, 6 Mar 2024 01:35:04 +1000 Subject: [PATCH] Items Builder: allow setting initial state on a group item (#261) Signed-off-by: Jimmy Tanagra --- lib/openhab/dsl/items/builder.rb | 1 - spec/openhab/dsl/items/builder_spec.rb | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/openhab/dsl/items/builder.rb b/lib/openhab/dsl/items/builder.rb index b50bab607a..9ec7b392e0 100644 --- a/lib/openhab/dsl/items/builder.rb +++ b/lib/openhab/dsl/items/builder.rb @@ -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 diff --git a/spec/openhab/dsl/items/builder_spec.rb b/spec/openhab/dsl/items/builder_spec.rb index 0ec09b377c..07e5d8c016 100644 --- a/spec/openhab/dsl/items/builder_spec.rb +++ b/spec/openhab/dsl/items/builder_spec.rb @@ -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