From a1ad4cfc61a16760428ae5c64072e45662db5cbb Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Sun, 17 Nov 2024 05:33:54 -0700 Subject: [PATCH] support sitemap colortemperaturepicker Signed-off-by: Cody Cutrer --- lib/openhab/dsl/sitemaps/builder.rb | 45 +++++++++++++++++++++++ spec/openhab/dsl/sitemaps/builder_spec.rb | 8 ++++ 2 files changed, 53 insertions(+) diff --git a/lib/openhab/dsl/sitemaps/builder.rb b/lib/openhab/dsl/sitemaps/builder.rb index df37a0cbc..167d47845 100644 --- a/lib/openhab/dsl/sitemaps/builder.rb +++ b/lib/openhab/dsl/sitemaps/builder.rb @@ -689,6 +689,33 @@ def build end end + # Builds a `Colortemperaturepicker` element + # @since openHAB 4.3 + # @see https://www.openhab.org/docs/ui/sitemaps.html#element-type-colortemperaturepicker + # @see org.openhab.core.model.sitemap.sitemap.Colortemperaturepicker + class ColortemperaturepickerBuilder < WidgetBuilder + # Allowed range of the value + # @return [Range, nil] + attr_accessor :range + + # (see WidgetBuilder#initialize) + # @!method initialize(item: nil, label: nil, icon: nil, static_icon: nil, range: nil, label_color: nil, value_color: nil, icon_color: nil, visibility: nil) + # @param range [Range, nil] Allowed range of the value (see {ColortemperaturepickerBuilder#range}) + # @!visibility private + def initialize(type, builder_proxy, frequency: nil, **kwargs, &block) + super(type, builder_proxy, **kwargs, &block) + + @frequency = frequency + end + + # @!visibility private + def build + widget = super + widget.frequency = (frequency * 1000).to_i if frequency + widget + end + end + # Builds a `Mapview` element # @see https://www.openhab.org/docs/ui/sitemaps.html#element-type-mapview # @see org.openhab.core.model.sitemap.sitemap.Mapview @@ -1084,6 +1111,23 @@ class LinkableWidgetBuilder < WidgetBuilder # visibility: nil) # end # + # # (see ColortemperaturepickerBuilder#initialize) + # # Create a new `Colortemperaturepicker` element. + # # @since openHAB 4.3 + # # @yield Block executed in the context of a {ColortemperaturepickerBuilder} + # # @return [ColortemperaturepickerBuilder] + # # @!visibility public + # def colortemperaturepicker(item: nil, + # label: nil, + # icon: nil, + # static_icon: nil, + # range: nil, + # label_color: nil, + # value_color: nil, + # icon_color: nil, + # visibility: nil) + # end + # # # (see DefaultBuilder#initialize) # # Create a new `Default` element. # # @yield Block executed in the context of a {DefaultBuilder} @@ -1116,6 +1160,7 @@ class LinkableWidgetBuilder < WidgetBuilder buttongrid setpoint colorpicker + colortemperaturepicker default].each do |method| class_eval <<~RUBY, __FILE__, __LINE__ + 1 def #{method}(*args, **kwargs, &block) # def frame(*args, **kwargs, &block) diff --git a/spec/openhab/dsl/sitemaps/builder_spec.rb b/spec/openhab/dsl/sitemaps/builder_spec.rb index e35e4129d..b285031a2 100644 --- a/spec/openhab/dsl/sitemaps/builder_spec.rb +++ b/spec/openhab/dsl/sitemaps/builder_spec.rb @@ -599,6 +599,14 @@ end end + it "can add a colortemperaturepicker", if: OpenHAB::Core.version >= OpenHAB::Core::V4_3 do + sitemaps.build do + sitemap "default" do + colortemperaturepicker label: "My Colorpicker" + end + end + end + # @deprecated OH 4.0 guard is only needed for < OH 4.1 describe "#buttongrid", if: OpenHAB::Core.version >= OpenHAB::Core::V4_1 do it "works" do