openhab-scripting 2.12.0 → 2.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openhab.rb +3 -0
  3. data/lib/openhab/core/dsl/actions.rb +1 -1
  4. data/lib/openhab/core/dsl/entities.rb +41 -4
  5. data/lib/openhab/core/dsl/gems.rb +1 -1
  6. data/lib/openhab/core/dsl/group.rb +3 -1
  7. data/lib/openhab/core/dsl/items/items.rb +3 -1
  8. data/lib/openhab/core/dsl/items/number_item.rb +151 -50
  9. data/lib/openhab/core/dsl/items/string_item.rb +21 -3
  10. data/lib/openhab/core/dsl/monkey_patch/items/dimmer_item.rb +42 -0
  11. data/lib/openhab/core/dsl/monkey_patch/items/metadata.rb +66 -42
  12. data/lib/openhab/core/dsl/monkey_patch/items/switch_item.rb +2 -1
  13. data/lib/openhab/core/dsl/monkey_patch/ruby/number.rb +7 -35
  14. data/lib/openhab/core/dsl/monkey_patch/ruby/range.rb +2 -1
  15. data/lib/openhab/core/dsl/monkey_patch/ruby/ruby.rb +1 -0
  16. data/lib/openhab/core/dsl/property.rb +15 -4
  17. data/lib/openhab/core/dsl/rule/automation_rule.rb +348 -0
  18. data/lib/openhab/core/dsl/rule/guard.rb +43 -6
  19. data/lib/openhab/core/dsl/rule/rule.rb +80 -354
  20. data/lib/openhab/core/dsl/rule/rule_config.rb +153 -0
  21. data/lib/openhab/core/dsl/rule/triggers/changed.rb +145 -0
  22. data/lib/openhab/core/dsl/rule/{channel.rb → triggers/channel.rb} +22 -8
  23. data/lib/openhab/core/dsl/rule/triggers/command.rb +106 -0
  24. data/lib/openhab/core/dsl/rule/{cron.rb → triggers/cron.rb} +58 -13
  25. data/lib/openhab/core/dsl/rule/triggers/trigger.rb +126 -0
  26. data/lib/openhab/core/dsl/rule/triggers/updated.rb +100 -0
  27. data/lib/openhab/core/dsl/time_of_day.rb +50 -24
  28. data/lib/openhab/core/dsl/timers.rb +3 -9
  29. data/lib/openhab/core/dsl/types/quantity.rb +106 -69
  30. data/lib/openhab/core/log.rb +3 -8
  31. data/lib/openhab/core/startup_delay.rb +1 -0
  32. data/lib/openhab/osgi.rb +7 -0
  33. data/lib/openhab/version.rb +1 -1
  34. metadata +10 -7
  35. data/lib/openhab/core/dsl/rule/item.rb +0 -208
  36. data/lib/openhab/core/dsl/rule/triggers.rb +0 -77
  37. data/lib/openhab/core/duration.rb +0 -78
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'securerandom'
4
-
5
- module OpenHAB
6
- module Core
7
- module DSL
8
- module Rule
9
- #
10
- # Class for creating and managing triggers
11
- #
12
- class Trigger
13
- java_import org.openhab.core.automation.util.TriggerBuilder
14
- java_import org.openhab.core.config.core.Configuration
15
-
16
- # @return [String] A channel event trigger
17
- CHANNEL_EVENT = 'core.ChannelEventTrigger'
18
-
19
- # @return [String] A thing status Change trigger
20
- THING_CHANGE = 'core.ThingStatusChangeTrigger'
21
-
22
- # @return [String] A thing status update trigger
23
- THING_UPDATE = 'core.ThingStatusUpdateTrigger'
24
-
25
- # @return [String] An item command trigger
26
- ITEM_COMMAND = 'core.ItemCommandTrigger'
27
-
28
- # @return [String] An item state update trigger
29
- ITEM_STATE_UPDATE = 'core.ItemStateUpdateTrigger'
30
-
31
- # @return [String] An item state change trigger
32
- ITEM_STATE_CHANGE = 'core.ItemStateChangeTrigger'
33
-
34
- # @return [String] A group state change trigger for items in the group
35
- GROUP_STATE_CHANGE = 'core.GroupStateChangeTrigger'
36
-
37
- # @return [String] A group state update trigger for items in the group
38
- GROUP_STATE_UPDATE = 'core.GroupStateUpdateTrigger'
39
-
40
- # @return [String] A group command trigger for items in the group
41
- GROUP_COMMAND = 'core.GroupCommandTrigger'
42
-
43
- # @return [String] A time of day trigger
44
- TIME_OF_DAY = 'timer.TimeOfDayTrigger'
45
-
46
- # @return [String] A cron trigger
47
- CRON = 'timer.GenericCronTrigger'
48
-
49
- #
50
- # Create a trigger
51
- #
52
- # @param [String] type of trigger
53
- # @param [Map] config map
54
- #
55
- # @return [OpenHAB Trigger] configured by type and supplied config
56
- #
57
- def self.trigger(type:, config:)
58
- TriggerBuilder.create
59
- .with_id(uuid)
60
- .with_type_uid(type)
61
- .with_configuration(Configuration.new(config))
62
- .build
63
- end
64
-
65
- #
66
- # Generate a UUID for triggers
67
- #
68
- # @return [String] UUID
69
- #
70
- def self.uuid
71
- SecureRandom.uuid
72
- end
73
- end
74
- end
75
- end
76
- end
77
- end
@@ -1,78 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'openhab/core/cron'
4
-
5
- module OpenHAB
6
- module Core
7
- #
8
- # This class represents a duration of time
9
- #
10
- class Duration
11
- include OpenHAB::Core::Cron
12
-
13
- # @return [Array] of supported temperal units (milliseconds, seconds, minutes and hours)
14
- TEMPORAL_UNITS = %i[MILLISECONDS SECONDS MINUTES HOURS].freeze
15
-
16
- #
17
- # Create a new Duration object
18
- #
19
- # @param [Symbol] temporal_unit Unit for duration
20
- # @param [Integer] amount of that unit
21
- #
22
- def initialize(temporal_unit:, amount:)
23
- unless TEMPORAL_UNITS.include? temporal_unit
24
- raise ArgumentError,
25
- "Unexpected Temporal Unit: #{temporal_unit}"
26
- end
27
-
28
- @temporal_unit = temporal_unit
29
- @amount = amount
30
- end
31
-
32
- #
33
- # Return a map
34
- #
35
- # @return [Map] Map with fields representing this duration @see OpenHAB::Core::Cron
36
- #
37
- def cron_map
38
- case @temporal_unit
39
- when :SECONDS
40
- cron_expression_map.merge(second: "*/#{@amount}")
41
- when :MINUTES
42
- cron_expression_map.merge(minute: "*/#{@amount}")
43
- when :HOURS
44
- cron_expression_map.merge(hour: "*/#{@amount}")
45
- else
46
- raise ArgumentError, "Cron Expression not supported for temporal unit: #{temporal_unit}"
47
- end
48
- end
49
-
50
- #
51
- # Convert the duration to milliseconds
52
- #
53
- # @return [Integer] Duration in milliseconds
54
- #
55
- def to_ms
56
- case @temporal_unit
57
- when :MILLISECONDS
58
- @amount
59
- when :SECONDS
60
- @amount * 1000
61
- when :MINUTES
62
- @amount * 1000 * 60
63
- when :HOURS
64
- @amount * 1000 * 60 * 60
65
- end
66
- end
67
-
68
- #
69
- # Return a string representation of the duration
70
- #
71
- # @return [String] Duration in string
72
- #
73
- def to_s
74
- "#{@amount} #{(@amount == 1) ? @temporal_unit.to_s.downcase.delete_suffix('s') : @temporal_unit.to_s.downcase}"
75
- end
76
- end
77
- end
78
- end