class Wemote::Insight
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 {#poll} method, which accepts a block to be executed any time the insight changes state.
Constants
- GET_HEADERS_POWER
Public Class Methods
all(refresh=false)
click to toggle source
device_type()
click to toggle source
# File lib/wemote/insight.rb, line 21 def device_type 'urn:Belkin:device:insight:1' end
Public Instance Methods
energy()
click to toggle source
# File lib/wemote/insight.rb, line 52 def energy get_insight_params()[:energy] end
on_today()
click to toggle source
# File lib/wemote/insight.rb, line 56 def on_today get_insight_params()[:on_today] end
power()
click to toggle source
# File lib/wemote/insight.rb, line 48 def power get_insight_params()[:power] end
standby?()
click to toggle source
Return whether the Insight
is standby
@return [Boolean]
# File lib/wemote/insight.rb, line 44 def standby? get_state == :standby; end
toggle!()
click to toggle source
Turn the Insight
on or off, based on its current state
# File lib/wemote/insight.rb, line 37 def toggle! on? or standby? ? off! : on!; end
Private Instance Methods
get_insight_params()
click to toggle source
# File lib/wemote/insight.rb, line 73 def get_insight_params response = begin client.post("http://#{@host}:#{@port}/upnp/control/insight1",Wemote::XML.get_insight_params,GET_HEADERS_POWER) rescue Exception client.post("http://#{@host}:#{@port}/upnp/control/insight1",Wemote::XML.get_insight_params,GET_HEADERS_POWER) end params = response.body.match(/<InsightParams>(.*)<\/InsightParams>/)[1].split('|') { value: (params[0].to_i == 0 ? :off : :on), energy: (params[8].to_i / 60000000.0).ceil, power: (params[7].to_i / 1000.0).round, on_today: (params[3].to_i / 60.0).floor } end
get_state()
click to toggle source
# File lib/wemote/insight.rb, line 62 def get_state case get_binary_state() when '0' :off when '1' :on when '8' :standby end end