Class: Domotics::Core::Switch

Inherits:
Element show all
Defined in:
lib/domotics/core/element/switch.rb

Constant Summary collapse

MINIMUM_LAG =
0

Instance Attribute Summary

Attributes inherited from Element

#device, #name, #room, #type

Instance Method Summary collapse

Methods inherited from Element

data=, #image, #info, #load_driver, #state, #state_changed, #to_s, #verbose_state

Constructor Details

#initialize(args = {}) ⇒ Switch

Returns a new instance of Switch.



4
5
6
7
8
9
10
11
12
13
# File 'lib/domotics/core/element/switch.rb', line 4

def initialize(args = {})
  @type = args[:type] || :switch
  @lag = nil
  @lag_lock = Mutex.new
  args[:driver] = "DigitalPin"
  load_driver args
  @initialized = false
  super
  @initialized = true
end

Instance Method Details

#delay_off(timer, &block) ⇒ Object



41
42
43
# File 'lib/domotics/core/element/switch.rb', line 41

def delay_off(timer, &block)
  lag(:off, timer, &block)
end

#delay_on(timer) ⇒ Object



28
29
30
# File 'lib/domotics/core/element/switch.rb', line 28

def delay_on(timer)
  lag(:on, timer)
end

#delay_toggle(timer) ⇒ Object



50
51
52
# File 'lib/domotics/core/element/switch.rb', line 50

def delay_toggle(timer)
  lag(:toggle, timer)
end

#off(timer = nil) ⇒ Object



32
33
34
35
# File 'lib/domotics/core/element/switch.rb', line 32

def off(timer = nil)
  set_state :off
  lag(:on, timer)
end

#off?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/domotics/core/element/switch.rb', line 37

def off?
  state == :off
end

#on(timer = nil) ⇒ Object



19
20
21
22
# File 'lib/domotics/core/element/switch.rb', line 19

def on(timer = nil)
  set_state :on
  lag(:off, timer)
end

#on?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/domotics/core/element/switch.rb', line 24

def on?
  state == :on
end

#set_state(value) ⇒ Object



15
16
17
# File 'lib/domotics/core/element/switch.rb', line 15

def set_state(value)
  @initialized ? (super unless state == value) : super
end

#toggle(timer = nil) ⇒ Object



45
46
47
48
# File 'lib/domotics/core/element/switch.rb', line 45

def toggle(timer = nil)
  set_state state == :off ? :on : :off
  lag(:toggle, timer)
end