Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Every #32

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
if: "!contains(github.event.head_commit.message, 'ci skip')"
outputs:
openhab_matrix: |
["3.4.5", "4.0.4", "4.1.1", "4.2.0.RC1", "4.2.0-SNAPSHOT"]
["3.4.5", "4.0.4", "4.1.1", "4.2.0", "4.3.0-SNAPSHOT"]
snapshot_date: |
${{ steps.snapshot-date.outputs.SNAPSHOT_DATE }}
steps:
Expand Down Expand Up @@ -133,9 +133,9 @@ jobs:
jruby_version: jruby-9.3.10.0
- openhab_version: 4.1.1
jruby_version: jruby-9.3.10.0
- openhab_version: 4.2.0-SNAPSHOT
- openhab_version: 4.2.0
jruby_version: jruby-9.3.10.0
- openhab_version: 4.2.0.RC1
- openhab_version: 4.3.0-SNAPSHOT
jruby_version: jruby-9.3.10.0
steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions lib/openhab/dsl/rules/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1369,9 +1369,9 @@ def every(value, at: nil, attach: nil)
@ruby_triggers << [:every, value, { at: at }]

if value == :day && at.is_a?(Item)
raise ArgumentError, "Attachments are not supported with dynamic datetime triggers" unless attach.nil?
# raise ArgumentError, "Attachments are not supported with dynamic datetime triggers" unless attach.nil?

return trigger("timer.DateTimeTrigger", itemName: at.name, timeOnly: true)
return trigger("timer.DateTimeTrigger", itemName: at.name, timeOnly: true, attach: attach)
end

cron_expression = case value
Expand Down
2 changes: 1 addition & 1 deletion rakelib/openhab.rake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require "net/http"
# Disabled due to part of buid / potentially refactor into classes
# rubocop: disable Rake/MethodDefinitionInTask Legacy code
namespace :openhab do
@openhab_version = ENV["OPENHAB_VERSION"] || "4.2.0-SNAPSHOT"
@openhab_version = ENV["OPENHAB_VERSION"] || "4.3.0-SNAPSHOT"
@port_numbers = {
ssh: { port: ENV["OPENHAB_SSH_PORT"] || 8101, config: "org.apache.karaf.shell:sshPort" },
lsp: { port: ENV["OPENHAB_LSP_PORT"] || 5007, config: "org.openhab.lsp:port" }
Expand Down
5 changes: 3 additions & 2 deletions spec/openhab/core/items/persistence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ def call_method(method, item)
end

it "accepts a TimeSeries" do
item.persist(TimeSeries.new)
item.persist(TimeSeries.new, :influxdb)
time_series = TimeSeries.new.add(Time.now, 0)
item.persist(time_series)
item.persist(time_series, :influxdb)
end
end
end
Expand Down
36 changes: 24 additions & 12 deletions spec/openhab/dsl/rules/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1323,23 +1323,35 @@ def self.generate(name, cron_expression, *every_args, attach: nil, **kwargs)
generate("can use MonthDay as a string", "0 0 12 17 11 ? *", "11-17", at: LocalTime.parse("12:00"))
generate("can use LocalTime a string", "0 0 12 17 11 ? *", MonthDay.parse("11-17"), at: "12:00")

it "supports dynamic `at`" do
items.build { date_time_item MyDateTimeItem }
context "with dynamic `at`" do
let(:item) { items.build { date_time_item MyDateTimeItem } }

triggered = false
every(:day, id: "dynamic_at_rule", at: MyDateTimeItem) { triggered = true }
it "works" do
triggered = false
every(:day, id: "dynamic_at_rule", at: item) { triggered = true }

rule = rules["dynamic_at_rule"]
trigger = rule.triggers.first
rule = rules["dynamic_at_rule"]
trigger = rule.triggers.first

handler = OpenHAB::Core::Rules.manager.get_module_handler_factory(trigger.type_uid)
.get_handler(trigger, rule.uid)
handler = OpenHAB::Core::Rules.manager.get_module_handler_factory(trigger.type_uid)
.get_handler(trigger, rule.uid)

expect(handler.getTemporalAdjuster).not_to be_nil
expect(handler.getTemporalAdjuster).not_to be_nil

MyDateTimeItem.update(Time.now + 2 - 2.days)
wait(4.seconds) do
expect(triggered).to be true
item.update(Time.now + 2 - 2.days)
wait(4.seconds) do
expect(triggered).to be true
end
end

it "supports attachments" do
triggered = nil
every(:day, id: "dynamic_at_rule", at: item, attach: 1) { |event| triggered = event.attachment }

item.update(Time.now + 2 - 2.days)
wait(4.seconds) do
expect(triggered).to be 1
end
end
end

Expand Down
Loading