Skip to content

Commit

Permalink
special case mired unit dimension inference in items builder
Browse files Browse the repository at this point in the history
mired is 1/Temperature, but the rest of openHAB treats it as Temperature,
so special case it

Signed-off-by: Cody Cutrer <cody@cutrer.us>
  • Loading branch information
ccutrer committed Oct 4, 2024
1 parent 0352498 commit 7935a97
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 @@ -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 == "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 7935a97

Please sign in to comment.