Sha256: 53bb2aaba51868d3df907694328da19116f027d4b6342a13bcaa926b2fc0e108

Contents?: true

Size: 1006 Bytes

Versions: 1

Compression:

Stored size: 1006 Bytes

Contents

module Helium
  class Sensor < Resource
    attr_reader :name, :mac, :ports

    def initialize(client:, params:)
      super(client: client, params: params)

      @name  = params.dig('attributes', 'name')
      @mac   = params.dig('meta', 'mac')
      @ports = params.dig('meta', 'ports')
    end

    def timeseries(size: 1000, port: nil, start_time: nil, end_time: nil, aggtype: nil, aggsize: nil)
      @client.sensor_timeseries(self,
        size:       size,
        port:       port,
        start_time: start_time,
        end_time:   end_time,
        aggtype:    aggtype,
        aggsize:    aggsize
      )
    end

    # TODO CRUD methods will be generalized into the Resource object
    def update(name:)
      @client.update_sensor(self, name: name)
    end

    def destroy
      @client.delete_sensor(self)
    end

    # TODO can probably generalize this a bit more
    def as_json
      super.merge({
        name: name,
        mac: mac,
        ports: ports
      })
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
helium-ruby-0.4.0 lib/helium/sensor.rb