openhab / openhab-jruby

A Helper Library for Writing openHAB Automations in Ruby
https://www.openhab.org/addons/automation/jrubyscripting/
Eclipse Public License 2.0
5 stars 5 forks source link

Sitemap updates not propagated to listeners #327

Closed jimtng closed 1 month ago

jimtng commented 2 months ago

See: https://github.com/openhab/openhab-core/blob/8d54ccefef1ec06b16542bf28af5452742cfaba7/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/SitemapSubscriptionService.java#L340

Without this fix, you'd have to refresh the ui (e.g. BasicUI) to "see" the change in the given example below. With the fix, BasicUI will automatically refresh.

sitemaps.build do
  sitemap "test" do
    text label: "Old1"
    text label: "Old2"
  end
end

items.build { switch_item TestSwitch1 }

received_command(TestSwitch1) do
  # Recreate the sitemap completely
  sitemaps.build do
    sitemap "test" do
      text label: "New"
    end
  end
end

Steps:

jimtng commented 2 months ago

it will involve manually adding an instance_double as a listener to the provider, and then setting an expectation on that listener that it gets the proper notification

I couldn't seem to get to org.openhab.core.io.rest.sitemap.SitemapSubscriptionService in the spec, even after adding org.openhab.core.io.rest.sitemap to ALLOWED_BUNDLES` in karaf.rb. I haven't dug deep enough to figure out why. So I'm creating an impl of the interface instead.

jimtng commented 2 months ago

I've just noticed another issue. When I updated the sitemap by reloading the script, it doesn't send an update notification it seems.

jimtng commented 2 months ago

I've just noticed another issue. When I updated the sitemap by reloading the script, it doesn't send an update notification it seems.

This is now fixed and explained in the comments.