Class: Sensor
- Inherits:
-
HueResource
- Object
- HueResource
- Sensor
- Defined in:
- lib/ha/sensor.rb
Overview
Represent Hue Sensors
Instance Attribute Summary collapse
-
#detail ⇒ Object
readonly
Returns the value of attribute detail.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#on ⇒ Object
readonly
Returns the value of attribute on.
Instance Method Summary collapse
- #analyze_detail(detail) ⇒ Object
- #array(selectors) ⇒ Object
-
#initialize(key, hashvalue) ⇒ Sensor
constructor
A new instance of Sensor.
Methods inherited from HueResource
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
#detail ⇒ Object (readonly)
Returns the value of attribute detail.
5 6 7 |
# File 'lib/ha/sensor.rb', line 5 def detail @detail end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/ha/sensor.rb', line 5 def name @name end |
#on ⇒ Object (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 |