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 ¶
- Variables
- func EnforceLimit(ctx context.Context, limit RateLimit) error
- func Limited(ctx context.Context, limit RateLimit, action func() error) func() error
- func LoadBool(addr AtomicBool) bool
- func StoreBool(addr AtomicBool, b bool)
- type AtomicBool
- type BaseMetrics
- type Local
- type RateLimit
- type Request
Constants ¶
This section is empty.
Variables ¶
var ErrRateLimited = fmt.Errorf("not enough time has passed since last action")
ErrRateLimited is returned when the RateLimit is being enforced
Functions ¶
func EnforceLimit ¶
EnforceLimit will return ErrRateLimited if the limit is already in effect. If not it will start the limit and return nil.
Types ¶
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 NewDangerous ¶
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.
type RateLimit ¶
type RateLimit struct {
// contains filtered or unexported fields
}
RateLimit is used to implement a simple time based rate limit
func NewRateLimit ¶
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 ¶
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