Class: AMON::Reading

Inherits:
DocumentPart show all
Defined in:
lib/amon/reading.rb

Overview

AMON readings are ‘categories’ of measurements which are taken by devices. For example, one reading may be ‘electricalInput’ with the unit ‘kWh’.

Instance Attribute Summary

Attributes inherited from DocumentPart

#parent

Attributes included from JSONHelper

#json

Instance Method Summary collapse

Methods inherited from DocumentPart

#initialize

Constructor Details

This class inherits a constructor from AMON::DocumentPart

Instance Method Details

#==(other) ⇒ Boolean

One reading is equal to another if the devices are equal and they are the same type

Parameters:

  • other (Reading)

    The other reading to compare with.

Returns:

  • (Boolean)


63
64
65
# File 'lib/amon/reading.rb', line 63

def ==(other)
  device == other.device && type == other.type
end

#accuracyNumeric

Returns The accuracy of the reading.

Returns:

  • (Numeric)

    The accuracy of the reading



23
# File 'lib/amon/reading.rb', line 23

field :accuracy

#durational?Boolean

Returns The opposite of #instantaneous?.

Returns:



55
56
57
# File 'lib/amon/reading.rb', line 55

def durational?
  !instantaneous?
end

#frequencyNumeric

Returns The frequency of the reading.

Returns:

  • (Numeric)

    The frequency of the reading



26
# File 'lib/amon/reading.rb', line 26

field :frequency

#idString

A unique id for the reading, composed of the device id, and the #type. So an ‘electricalInput’ reading for a device with id ‘b7ddac00-9415-012d-b57e-001c23973687’ would have the id ‘b7ddac00-9415-012d-b57e-001c23973687-electricalInput’.

Returns:

  • (String)

    the id



72
73
74
# File 'lib/amon/reading.rb', line 72

def id
  "#{device.id}-#{type}"
end

#instantaneous?true, false

Returns:

  • (true)

    if the #period is ‘instant’

  • (false)

    if the #period is ‘duration’



50
51
52
# File 'lib/amon/reading.rb', line 50

def instantaneous?
  period == "instant"
end

#maxNumeric

Returns The expected maximum of the readings.

Returns:

  • (Numeric)

    The expected maximum of the readings



32
# File 'lib/amon/reading.rb', line 32

field :max

#measurements(entity_id, start_date, end_date, raw = false) ⇒ Array<Measurement>

Returns Measurements for this reading.

Returns:

  • (Array<Measurement>)

    Measurements for this reading

See Also:



44
45
46
# File 'lib/amon/reading.rb', line 44

def measurements(entity_id, start_date, end_date, raw = false)
  device.measurements_by_name(entity_id, start_date, end_date, raw)[type] || []
end

#minNumeric

Returns The expected minimum of the readings.

Returns:

  • (Numeric)

    The expected minimum of the readings



29
# File 'lib/amon/reading.rb', line 29

field :min

#nameString

Returns An arbitrary name for the reading.

Returns:

  • (String)

    An arbitrary name for the reading



13
# File 'lib/amon/reading.rb', line 13

field :name

#period"instant", "duration"

values taken at a specific point in time (‘instant’), or taken as an average over a period of time (‘duration’)

Returns:

  • ("instant", "duration")

    Whether this reading records measurement



37
# File 'lib/amon/reading.rb', line 37

field :period, :default => "instant"

#resolutionNumeric

Returns The resolution of the reading.

Returns:

  • (Numeric)

    The resolution of the reading



20
# File 'lib/amon/reading.rb', line 20

field :resolution

#typeString

Returns:

  • (String)

    The type of reading, which is unique within the parent



10
# File 'lib/amon/reading.rb', line 10

field :type

#unitString

Returns:

  • (String)

    The units this reading records



17
# File 'lib/amon/reading.rb', line 17

field :unit