Skip to content

Commit

Permalink
special case mired unit dimension inference in items builder (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccutrer authored Oct 5, 2024
1 parent cc866ce commit a329561
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/openhab/dsl/items/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,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
Expand Down
3 changes: 3 additions & 0 deletions spec/openhab/dsl/items/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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%"
Expand Down

0 comments on commit a329561

Please sign in to comment.