Also checkout JRuby
Your rule above can be rewritten in JRuby like this:
rule "Vanja Call State" do
received_command XinezCallState
only_if { Vanja.on? }
run do |event|
if ["OFFHOOK", "RINGING"].include?(event.command)
Mute.ensure.off
elsif event.command == "IDLE"
Mute.ensure.on
end
end
end
Or:
rule "Vanja Call State" do
received_command XinezCallState
only_if { Vanja.on? }
run do |event|
case event.command
when "OFFHOOK", "RINGING" then Mute.ensure.off
when "IDLE" then Mute.ensure.on
end
end
end
Or if you can change the logic a bit and send Mute ON when the state is anything but OFFHOOK/RINGING, you can simplify it even more because Item.command takes a boolean that translates truthy to ON and falsey to OFF.
rule "Vanja Call State" do
received_command XinezCallState
only_if { Vanja.on? }
run { |event| Mute.ensure.command !["OFFHOOK", "RINGING"].include?(event.command) }
end