Class: RemoteDroid::Controller
- Inherits:
-
Object
- Object
- RemoteDroid::Controller
- Defined in:
- lib/remotedroid.rb
Instance Attribute Summary collapse
-
#control ⇒ Object
readonly
Returns the value of attribute control.
-
#macros ⇒ Object
Returns the value of attribute macros.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #export(s) ⇒ Object
-
#initialize(mcs, model = MODEL, deviceid: nil, debug: false) ⇒ Controller
constructor
A new instance of Controller.
- #invoke(name, options = {}) ⇒ Object
-
#op ⇒ Object
Object Property (op) Helpful for accessing properites in dot notation e.g.
- #query(trigger) ⇒ Object
- #request(s) ⇒ Object
- #store ⇒ Object
- #trigger(name, detail = {time: Time.now}) ⇒ Object (also: #trigger_fired)
Constructor Details
#initialize(mcs, model = MODEL, deviceid: nil, debug: false) ⇒ Controller
Returns a new instance of Controller.
327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/remotedroid.rb', line 327 def initialize(mcs, model=MODEL, deviceid: nil, debug: false) @debug = debug @syslog = [] @control = Control.new(deviceid) @macros = mcs.macros if model then @model = Model.new(model) end end |
Instance Attribute Details
#control ⇒ Object (readonly)
Returns the value of attribute control.
324 325 326 |
# File 'lib/remotedroid.rb', line 324 def control @control end |
#macros ⇒ Object
Returns the value of attribute macros.
325 326 327 |
# File 'lib/remotedroid.rb', line 325 def macros @macros end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
324 325 326 |
# File 'lib/remotedroid.rb', line 324 def model @model end |
#title ⇒ Object
Returns the value of attribute title.
325 326 327 |
# File 'lib/remotedroid.rb', line 325 def title @title end |
Instance Method Details
#export(s) ⇒ Object
341 342 343 |
# File 'lib/remotedroid.rb', line 341 def export(s) @macros = MacroDroid.new(s).macros end |
#invoke(name, options = {}) ⇒ Object
345 346 347 |
# File 'lib/remotedroid.rb', line 345 def invoke(name, ={}) @control.method(name.to_sym).call() end |
#op ⇒ Object
Object Property (op) Helpful for accessing properites in dot notation e.g. op.livingroom.light.switch = ‘off’
353 354 355 |
# File 'lib/remotedroid.rb', line 353 def op() @model.op end |
#query(trigger) ⇒ Object
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/remotedroid.rb', line 357 def query(trigger) @h[trigger] = nil # send http request via macrodroid.com API @control.http_exec trigger # wait for the local variable to be updated # timeout after 5 seoncds t = Time.now begin sleep 1 end until @h[trigger] or Time.now > t + 5 if @h[trigger] then yield(@h[trigger]) end end |
#request(s) ⇒ Object
378 379 380 |
# File 'lib/remotedroid.rb', line 378 def request(s) @model.request s end |
#store ⇒ Object
412 413 414 |
# File 'lib/remotedroid.rb', line 412 def store() @h end |
#trigger(name, detail = {time: Time.now}) ⇒ Object Also known as: trigger_fired
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/remotedroid.rb', line 383 def trigger(name, detail={time: Time.now}) macros = @macros.select do |macro| puts 'macro: ' + macro.inspect if @debug # fetch the associated properties from the model if possible and # merge them into the detail. # valid_trigger = macro.match?(name, detail, @model.op) puts 'valid_trigger: ' + valid_trigger.inspect if @debug if valid_trigger then @syslog << [Time.now, :trigger, name] @syslog << [Time.now, :macro, macro.title] end valid_trigger end puts 'macros: ' + macros.inspect if @debug macros.flat_map(&:run) end |