From 6ae473928380da5547fb11a0b9c659fb54765b33 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Fri, 4 Oct 2024 15:56:39 -0600 Subject: [PATCH] special case mired unit dimension inference in items builder mired is 1/Temperature, but the rest of openHAB treats it as Temperature, so special case it Signed-off-by: Cody Cutrer --- lib/openhab/dsl/items/builder.rb | 1 + spec/openhab/dsl/items/builder_spec.rb | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lib/openhab/dsl/items/builder.rb b/lib/openhab/dsl/items/builder.rb index c50703ff4..b1d256b50 100644 --- a/lib/openhab/dsl/items/builder.rb +++ b/lib/openhab/dsl/items/builder.rb @@ -554,6 +554,7 @@ def expire(*args, command: nil, state: nil, ignore_state_updates: nil, ignore_co def unit=(unit) @unit = unit + self.dimension ||= "Temperature" if unit&.to_s == "mired" self.dimension ||= unit && org.openhab.core.types.util.UnitUtils.parse_unit(unit)&.then do |u| org.openhab.core.types.util.UnitUtils.get_dimension_name(u) end diff --git a/spec/openhab/dsl/items/builder_spec.rb b/spec/openhab/dsl/items/builder_spec.rb index 7e8e653d3..72176152f 100644 --- a/spec/openhab/dsl/items/builder_spec.rb +++ b/spec/openhab/dsl/items/builder_spec.rb @@ -346,9 +346,12 @@ def build_and_update(org_config, new_config, item_to_keep: :new_item, &block) it "can infer the dimension from the explicit unit for a number item" do items.build do number_item "MyNumberItem", unit: "kW" + number_item "ColorTempItem", unit: "mired" end expect(MyNumberItem.dimension.ruby_class).to be javax.measure.quantity.Power expect(MyNumberItem.metadata["unit"].value).to eql "kW" + expect(ColorTempItem.dimension.ruby_class).to be javax.measure.quantity.Temperature + expect(ColorTempItem.metadata["unit"].value).to eql "mired" if OpenHAB::Core.version >= OpenHAB::Core::V4_0 expect(MyNumberItem.unit.to_s).to eql "kW" expect(MyNumberItem.state_description.pattern).to eql "%s %unit%"