Class: Wemote::Insight

Inherits:
Switch
  • Object
show all
Defined in:
lib/wemote/insight.rb

Overview

This class encapsulates an individual Wemo Insight. It provides methods for getting and setting the insight’s state, as well as a #toggle! method for convenience. Finally, it provides the Switch#poll method, which accepts a block to be executed any time the insight changes state.

Constant Summary collapse

GET_HEADERS_POWER =
{
  "SOAPACTION"   => '"urn:Belkin:service:insight:1#GetInsightParams"',
  "Content-type" => 'text/xml; charset="utf-8"'
}

Constants inherited from Switch

Switch::GET_HEADERS, Switch::SET_HEADERS

Instance Attribute Summary

Attributes inherited from Switch

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Switch

#device_type, find, #initialize, #off!, #off?, #on!, #on?, #poll

Constructor Details

This class inherits a constructor from Wemote::Switch

Class Method Details

.all(refresh = false) ⇒ Array

Returns all Insight detected on the local network

Parameters:

  • refresh (Boolean) (defaults to: false)

    Refresh and redetect Insight

Returns:

  • (Array)

    all Insight on the network



29
30
31
32
# File 'lib/wemote/insight.rb', line 29

def all(refresh=false)
  @insights = nil if refresh
  @insights ||= Wemote::Collection::Insight.new(discover)
end

.device_typeObject



21
22
23
# File 'lib/wemote/insight.rb', line 21

def device_type
  'urn:Belkin:device:insight:1'
end

Instance Method Details

#energyObject



52
53
54
# File 'lib/wemote/insight.rb', line 52

def energy
  get_insight_params()[:energy]
end

#on_todayObject



56
57
58
# File 'lib/wemote/insight.rb', line 56

def on_today
  get_insight_params()[:on_today]
end

#powerObject



48
49
50
# File 'lib/wemote/insight.rb', line 48

def power
  get_insight_params()[:power]
end

#standby?Boolean

Return whether the Insight is standby

Returns:

  • (Boolean)


44
45
46
# File 'lib/wemote/insight.rb', line 44

def standby?
  get_state == :standby;   
end

#toggle!Object

Turn the Insight on or off, based on its current state



37
38
39
# File 'lib/wemote/insight.rb', line 37

def toggle!  
  on? or standby? ? off! : on!;   
end