Class: Domotics::Core::Switch

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

Constant Summary collapse

MINIMUM_LAG =
1

Instance Attribute Summary

Attributes inherited from Element

#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) ⇒ Object



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

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

#delay_on(timer) ⇒ Object



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

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

#delay_toggle(timer) ⇒ Object



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

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

#off(timer = nil) ⇒ Object



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

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

#off?Boolean

Returns:

  • (Boolean)


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

def off?
  state == :off
end

#on(timer = nil) ⇒ Object



17
18
19
20
# File 'lib/domotics/core/element/switch.rb', line 17

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

#on?Boolean

Returns:

  • (Boolean)


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

def on?
  state == :on
end

#set_state(value) ⇒ Object



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

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

#toggle(timer = nil) ⇒ Object



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

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