Class: Sensor

Inherits:
HueResource show all
Defined in:
lib/ha/sensor.rb

Overview

Represent Hue Sensors

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from HueResource

#gen_reskey

Constructor Details

#initialize(key, hashvalue) ⇒ Sensor

Returns a new instance of Sensor.



7
8
9
10
11
12
13
# File 'lib/ha/sensor.rb', line 7

def initialize(key, hashvalue)
  super
  key = analyze_detail @detail
  @on = hashvalue.dig("state", key)
  gen_reskey("s")
  @state.merge! ({"on" => @on})
end

Instance Attribute Details

#detailObject (readonly)

Returns the value of attribute detail.



5
6
7
# File 'lib/ha/sensor.rb', line 5

def detail
  @detail
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/ha/sensor.rb', line 5

def name
  @name
end

#onObject (readonly)

Returns the value of attribute on.



5
6
7
# File 'lib/ha/sensor.rb', line 5

def on
  @on
end

Instance Method Details

#analyze_detail(detail) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ha/sensor.rb', line 19

def analyze_detail detail
  key = "status"
  if detail == "CLIPPresence"
    key = "presence"
  elsif detail == "Geofence"
    key = "presence"
  elsif detail == "CLIPGenericFlag"
    key = "flag"
  elsif detail == "Daylight"
    key = "daylight"
  end
  key
end

#array(selectors) ⇒ Object



15
16
17
# File 'lib/ha/sensor.rb', line 15

def array(selectors)
  selectors.map { |key| @state[key] }
end