Class: ExternalPowerTrigger

Inherits:
Trigger show all
Defined in:
lib/ruby-macrodroid.rb

Overview

Category: Battery/Power

Instance Attribute Summary

Attributes inherited from Trigger

#constraints

Attributes inherited from MacroObject

#options, #siguid, #type

Instance Method Summary collapse

Methods inherited from Trigger

#match?

Methods inherited from MacroObject

#to_h

Constructor Details

#initialize(h = {}) ⇒ ExternalPowerTrigger

Returns a new instance of ExternalPowerTrigger.



1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
# File 'lib/ruby-macrodroid.rb', line 1436

def initialize(h={})

  options = {
    power_connected_options: [true, true, true],
    has_set_usb_option: true,
    power_connected: true,
    has_set_new_power_connected_options: true
  }

  super(options.merge h)

end

Instance Method Details

#to_s(colour: false) ⇒ Object Also known as: to_summary



1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
# File 'lib/ruby-macrodroid.rb', line 1449

def to_s(colour: false)
  
  return 'Power Disconnected' unless @h[:power_connected]
  
  status = 'Power Connectd'
  options = if @h[:power_connected_options].all? then
    'Any'
  else
    
    a = ['Wired (Fast Charge)', 'Wireless', 'Wired (Slow Charge)']
    @h[:power_connected_options].map.with_index {|x,i| x ? i : nil}\
        .compact.map {|i| a[i] }.join(' + ')
    
  end
  
  "%s: %s" % [status, options]

end