boc-tothefuture / openhab-jruby

JRuby Libraries for Openhab
Eclipse Public License 2.0
6 stars 9 forks source link

Error when using semantic model #636

Open boc-tothefuture opened 1 year ago

boc-tothefuture commented 1 year ago
      Office.equipments(Semantics::Receiver)
      .members
      .points(Semantics::Switch, Semantics::Power).first

results in:

2022-09-05 14:08:21.380 [ERROR] [obj.OpenHAB.DSL.Rules.AutomationRule] - undefined method `<=' for nil:NilClass (NoMethodError)
In rule: Render Sitemap
/etc/openhab/automation/lib/ruby/gem_home/gems/openhab-scripting-4.44.1/lib/openhab/dsl/items/semantics.rb:222:in `block in points'
org/jruby/RubyArray.java:4686:in `all?'
/etc/openhab/automation/lib/ruby/gem_home/gems/openhab-scripting-4.44.1/lib/openhab/dsl/items/semantics.rb:221:in `block in points'
org/jruby/RubyArray.java:2746:in `select'
/etc/openhab/automation/lib/ruby/gem_home/gems/openhab-scripting-4.44.1/lib/openhab/dsl/items/semantics.rb:220:in `points'
/etc/openhab/automation/jsr223/ruby/personal/sitemap.rb:40:in `sitemap'
boc-tothefuture commented 1 year ago

Added a bit of debug to where it has an error:

 select do |point|
      logger.debug("Looking at point class(#{point.class}) value(#{point})")
      point.point? && point_or_property_types.all? do |tag|
        (tag < OpenHAB::DSL::Items::Semantics::Point && point.point_type <= tag) ||
          (tag < OpenHAB::DSL::Items::Semantics::Property && point.property_type&.<=(tag))
      end
    end

This is the point that makes it error out.

2022-09-05 14:21:15.982 [DEBUG] [n.jruby.sitemap.render_sitemap.Array] - Looking at point class(Java::OrgOpenhabCoreLibraryItems::DimmerItem) value(35%)
boc-tothefuture commented 1 year ago

Root cause was that I had "SetPoint" instead of "Setpoint".. Should we potentially have a more friendly error?

ccutrer commented 1 year ago

Can you elaborate more an how exactly you caused this error? The exception looks like point.point_type returned nil, but we just checked if it was a point, so point_type should never return nil. AFAICT it's possible to have a property_type of nil if it's a point, but not possible to have a point_type of nil if it's a point. In fact, if it's not a point, property_type is guaranteed to be nil, even if it has a property tag on it.