client

package
v0.0.0-...-f59ffb5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package client exists to protect the Rainforest Eagle from excessive calls and ensure that concurrency is easy to reason about. This is in contrast to the local package which is a bare transformation of rest calls into go objects and does not concern itself with concurrency and protection.

Concurrency

On creation the client starts a go routine that listens to a request channel. Then all client requests functions are wrappers around a send of a request and a wait for a reply on that channel. This means in effect that all requests are linearized.

Rate Limit

Given the Eagle is a fairly small server, it seems prudent to ensure that it is not aggressively called against. To that end a simple time based rate limit is enforced. Any calls that come in faster than the time limit will be responded to with an error instead of being forwarded to teh Eagle.

Hardware Address

The Eagle will read all of the devices on the zigbee network but in most cases we only care about the smart meter. The client attempts to find the expected smart meter and then caches the hardware address for that meter as it should not change over the lifecycle of the client.

Index

Constants

This section is empty.

Variables

View Source
var ErrRateLimited = fmt.Errorf("not enough time has passed since last action")

ErrRateLimited is returned when the RateLimit is being enforced

Functions

func EnforceLimit

func EnforceLimit(ctx context.Context, limit RateLimit) error

EnforceLimit will return ErrRateLimited if the limit is already in effect. If not it will start the limit and return nil.

func Limited

func Limited(ctx context.Context, limit RateLimit, action func() error) func() error

Limited wraps the provided action with a RateLimit. If the RateLimit is in effect the action is not called and ErrRateLimited is returned otherwise the action is called and its error returned.

func LoadBool

func LoadBool(addr AtomicBool) bool

LoadBool atomically loads addr.

func StoreBool

func StoreBool(addr AtomicBool, b bool)

StoreBool atomically stores val into addr.

Types

type AtomicBool

type AtomicBool uint32

AtomicBool stores boolean values atomically

type BaseMetrics

type BaseMetrics struct {
	Demand    float64 `json:"demand"`
	Delivered float64 `json:"delivered"`
	Price     float64 `json:"price"`
	Currency  string  `json:"currency"`
}

BaseMetrics are the most commonly used metrics on the smart meter

type Local

type Local chan<- Request

Local wraps the local api with the client potections

func Get

func Get(ctx context.Context, api local.API, wait time.Duration) Local

Get returns the Local

func NewDangerous

func NewDangerous(ctx context.Context, api local.API, wait time.Duration) Local

NewDangerous creates a new Local, if multiple Locals are created during a single session you've lost the concurrency protections this client provides so you probably shouldn't use this. Instead use Get.

func (Local) Request

func (l Local) Request(ctx context.Context, request Request) (interface{}, error)

Request sends the Request to the Local

type RateLimit

type RateLimit struct {
	// contains filtered or unexported fields
}

RateLimit is used to implement a simple time based rate limit

func NewRateLimit

func NewRateLimit(wait time.Duration) RateLimit

NewRateLimit returns a RateLimit with the passed in wait

type Request

type Request struct {
	// contains filtered or unexported fields
}

Request is used to send information to the client

func RequestAllVariables

func RequestAllVariables() Request

RequestAllVariables is a Request to do a device query for all available variables on the smart meter

func RequestBaseMetrics

func RequestBaseMetrics() Request

RequestBaseMetrics is a Request to do a device query for a BaseMetrics

func RequestDeviceList

func RequestDeviceList() Request

RequestDeviceList is a Request to do a device list for all devices

func RequestMeterDetails

func RequestMeterDetails() Request

RequestMeterDetails is a Request to do a device details on the smart meter

func RequestSpecificVariable

func RequestSpecificVariable(variable string) Request

RequestSpecificVariable is a Request to do a device query for the provided variable name on the smart meter

func RequestWifiStatus

func RequestWifiStatus() Request

RequestWifiStatus is a Request to do a wifi status call on the Eagle

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL