Skip to content

Cloud Notification: support enhanced notification #285

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

Merged
merged 1 commit into from
Jun 28, 2024

Conversation

jimtng
Copy link
Contributor

@jimtng jimtng commented Jun 28, 2024

add title, on_click, attachment, and buttons

See openhab/openhab-addons#16938

@jimtng jimtng added the enhancement New feature or request label Jun 28, 2024
@jimtng jimtng force-pushed the enhanced-notify branch 4 times, most recently from 51d2b1f to 5662d8e Compare June 28, 2024 04:08
@jimtng jimtng requested a review from ccutrer June 28, 2024 04:12
unless Actions.const_defined?(:NotificationAction)
raise NotImplementedError, "NotificationAction is not available. Please install the openHAB Cloud addon."
end

if email
# @!deprecated OH 4.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given the 4 branches here, I'd suggest building up the args list dynamically:

args = []
if email
  args.push(:send_notification, email)
else
  args.push(:send_broadcast_notification)
end
args.push(msg.to_s, icon&.to_s, severity&.to_s)

if Core.version >= Core::V4_2
  buttons ||= []
  buttons = buttons.map { |title, action| "#{title}=#{action}" } if buttons.is_a?(Hash)
  raise ArgumentError, "buttons must contain (0..3) elements." unless (0..3).cover?(buttons.size)

  args.push(on_click&.to_s, attachment&.to_s, buttons[0]&.to_s, buttons[1]&.to_s, buttons[2]&.to_s)
end

NotificationAction.__send__(*args)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So elegant! Thanks, master!

add title, on_click, attachment, and buttons

Signed-off-by: Jimmy Tanagra <[email protected]>
@jimtng jimtng force-pushed the enhanced-notify branch from 5662d8e to f7d5b42 Compare June 28, 2024 14:40
@ccutrer ccutrer merged commit a4d4d5e into openhab:main Jun 28, 2024
18 checks passed
@jimtng jimtng deleted the enhanced-notify branch June 28, 2024 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants