local

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: 14 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	//LocationEnv is the name of the environment variable that stores the ip/domain name for the eagle device (e.g. 192.168.100.164)
	LocationEnv string = "REAGLE_LOCAL_LOCATION"
	//UserEnv is the name of the environment variable that stores the username for the local api authentication, usually the cloudid of the eagle device
	UserEnv string = "REAGLE_LOCAL_USER"
	//PasswordEnv is the name of the environment variable that stores the password for the local api authentication, usually the install code of the eagle device
	PasswordEnv string = "REAGLE_LOCAL_PASSWORD"

	//DebugRequestEnv will turn on request debugging if it is any value other than empty
	DebugRequestEnv string = "REAGLE_DEBUG_REQUEST"
	//DebugResponseEnv will turn on response debugging if it is any value other than empty
	DebugResponseEnv string = "REAGLE_DEBUG_RESPONSE"

	//ImprovedFirmwareEnv set to yes if your firmware responds with well formed queries to multiplier and divisor queries, set to no if not
	ImprovedFirmwareEnv string = "REAGLE_IMPROVED_FIRMWARE"

	//MeterModelIDEnv is the name of the 'model_id' returned by the device for the smart meter being watched.  defaults to 'electric_meter' if not set
	MeterModelIDEnv string = "REAGLE_MODEL_ID_NAME"
)

Variables

View Source
var (
	//BadResponseVariables is a list of variables that return bad xml responses in some firmwares of the reagle
	BadResponseVariables = VariableFilter(map[string]bool{"zigbee:Multiplier": true, "zigbee:Divisor": true})

	//NoFilter won't filter anything
	NoFilter = VariableFilter(map[string]bool{})
)

Functions

func ConfigOK

func ConfigOK(config Config) bool

ConfigOK returns true if the Config can be used

func PostCommand

func PostCommand(ctx context.Context, client *http.Client, config Config, command interface{}) (code int, body []byte, err error)

PostCommand posts the provided command to the location using the provided client

func PostManagerEndpoint

func PostManagerEndpoint(config Config) string

PostManagerEndpoint returns the url to the PostManagerEndpoint

func ResultsFromDetailsResponse

func ResultsFromDetailsResponse(response DeviceQueryResponse) map[string]map[string]Variable

ResultsFromDetailsResponse returns a map of component name -> variable name -> Variable

func ValidateConfig

func ValidateConfig(c Config) error

ValidateConfig returns an error if the Config is not ready for use

func VariablesFromDetailsResponse

func VariablesFromDetailsResponse(response DeviceDetailsResponse) []string

VariablesFromDetailsResponse unwraps a DeviceDetailsResponse to get the list of Variable names

Types

type API

type API struct {
	Client *http.Client
	Config Config
}

API wraps up the eagle local api for ease of use

func New

func New(config Config) API

New returns an API with a default http client and the provided config

func (API) DeviceDetails

func (a API) DeviceDetails(ctx context.Context, hardwareAddress string) (DeviceDetailsResponse, error)

DeviceDetails returns the available variables

func (API) DeviceList

func (a API) DeviceList(ctx context.Context) ([]Device, error)

DeviceList returns the configured devices

func (API) DeviceQuery

func (a API) DeviceQuery(ctx context.Context, hardwareAddress string, variables ...string) (DeviceQueryResponse, error)

DeviceQuery returns the queried variable

func (API) GetMeterHardwareAddress

func (a API) GetMeterHardwareAddress(ctx context.Context) (string, error)

GetMeterHardwareAddress returns the hardware address of the smart meter, using the name provided in the config

func (API) WifiStatus

func (a API) WifiStatus(ctx context.Context) (WifiStatus, error)

WifiStatus returns the wifi status of the eagle 200

type Command

type Command struct {
	XMLName xml.Name `xml:"Command"`
	Name    string
}

Command is the request body structure

Example
command := Command{Name: "wifi_status"}

output, err := xml.Marshal(command)
if err != nil {
	fmt.Printf("error: %v\n", err)
}

os.Stdout.Write(output)
Output:

<Command><Name>wifi_status</Name></Command>

func NewCommand

func NewCommand(name string) Command

func NewDeviceListCommand

func NewDeviceListCommand() Command

DeviceListCommand creates the Command request for device lists

func NewWifiStatusCommand

func NewWifiStatusCommand() Command

NewWifiStatusCommand creates the Command request for wifi status

type Component

type Component struct {
	XMLName    xml.Name  `xml:"Component" json:"-"`
	Name       string    `json:"name"`
	HardwareID string    `xml:"HarwareId" json:"hardware_id"`
	FixedID    int       `xml:"FixedId" json:"fixed_id"`
	Variables  Variables `json:"variables"`
}

func NewComponent

func NewComponent(name string, variable ...string) Component

type ComponentName

type ComponentName struct {
	XMLName    xml.Name      `xml:"Component" json:"-"`
	Name       string        `json:"name"`
	HardwareID string        `xml:"HarwareId" json:"hardware_id"`
	FixedID    int           `xml:"FixedId" json:"fixed_id"`
	Variables  VariableNames `json:"variables"`
}

type ComponentNames

type ComponentNames struct {
	XMLName   xml.Name        `xml:"Components" json:"-"`
	Component []ComponentName `json:"components"`
}

type Components

type Components struct {
	XMLName   xml.Name    `xml:"Components" json:"-"`
	Component []Component `json:"components"`
}

func NewComponents

func NewComponents(components ...Component) Components

type Config

type Config struct {
	Location string `json:"location"`
	User     string `json:"user"`

	//Older versions of the firmware respond with invalid xml for multiplier/divisor
	ImprovedFirmware bool `json:"improved_firmware"`

	DebugRequest  bool `json:"debug_request"`
	DebugResponse bool `json:"debug_response"`

	Filter VariableFilter `json:"variable_filter"`

	//what the eagle returns for the model id of the smart meter to watch.  defaults to electric_meter
	ModelIDForMeter string `json:"model_id"`
	// contains filtered or unexported fields
}

Config is used to locate/auth the eagle local api

func ConfigFromEnv

func ConfigFromEnv() (Config, bool)

ConfigFromEnv returns a Config and true using the environment variables or a Config and false if any aren't set

func SetPassword

func SetPassword(c Config, password string) Config

SetPassword sets the password on the config

func StartTestServer

func StartTestServer(payload TestServerPayload) (*httptest.Server, Config)

StartTestServer returns an httptest.Server that responds similar to the Eagle

func TestConfigOrSkip

func TestConfigOrSkip(t testing.TB) Config

TestConfigOrSkip returns teh Config from the environment variables or skips if any aren't set

func (Config) GetFilter

func (c Config) GetFilter() VariableFilter

func (Config) GetModelIDForMeter

func (c Config) GetModelIDForMeter() string

type Device

type Device struct {
	DeviceData
	XMLName xml.Name `xml:"Device" json:"-"`
}

Device is sometimes used

type DeviceData

type DeviceData struct {
	HardwareAddress  string `json:"hardware_address"`
	Manufacturer     string `json:"manufacturer"`
	ModelID          string `xml:"ModelId" json:"model_id"`
	Protocol         string `json:"protocol"`
	LastContact      string `json:"last_contact"`
	ConnectionStatus string `json:"connection_status"`
	NetworkAddress   string `json:"network_address"`
}

DeviceData is the data about a device, it is named Device in some responses and DeviceDetails in others

func (DeviceData) LastContactTime

func (item DeviceData) LastContactTime() (t time.Time, err error)

LastContactTime parses the contact time string into a golang time TODO: change this so the unmarshaller does it

type DeviceDetails

type DeviceDetails struct {
	DeviceData
	XMLName xml.Name `xml:"DeviceDetails" json:"-"`
}

DeviceDestails is also used

type DeviceDetailsCommand

type DeviceDetailsCommand struct {
	Command
	DeviceDetails DeviceDetails
}

DeviceDetailsCommand gets all variables available

func NewDeviceDetailsCommand

func NewDeviceDetailsCommand(hardwareAddress string) DeviceDetailsCommand

type DeviceDetailsResponse

type DeviceDetailsResponse struct {
	XMLName       xml.Name       `xml:"Device" json:"-"`
	DeviceDetails DeviceDetails  `json:"details"`
	Components    ComponentNames `json:"components"`
}

type DeviceList

type DeviceList struct {
	XMLName xml.Name `xml:"DeviceList"`
	Device  []Device
}

DeviceList is a list of configured devices on the eagle

type DeviceQueryCommand

type DeviceQueryCommand struct {
	Command
	DeviceDetails DeviceDetails
	Components    Components
}

DeviceQueryCommand allows you to query variables

func NewDeviceQueryCommand

func NewDeviceQueryCommand(hardwareAddress string, variables ...string) DeviceQueryCommand

type DeviceQueryResponse

type DeviceQueryResponse struct {
	XMLName       xml.Name      `xml:"Device" json:"-"`
	DeviceDetails DeviceDetails `json:"details"`
	Components    Components    `json:"components"`
}

type TestServerPayload

type TestServerPayload struct {
	DeviceList    []Device
	DeviceDetails *DeviceDetailsResponse
	DeviceQuery   *DeviceQueryResponse
	WifiStatus    *WifiStatus
}

TestServerPayload is the responses the httptest.Server should respond with

func ServeDeviceDetails

func ServeDeviceDetails(details DeviceDetailsResponse) TestServerPayload

ServeDeviceDetails returns a payload for testing DeviceDetails commands

func ServeDeviceList

func ServeDeviceList(list []Device) TestServerPayload

ServeDeviceList returns a payload for testing DeviceList commands

func ServeDeviceQuery

func ServeDeviceQuery(query DeviceQueryResponse) TestServerPayload

ServeDeviceQuery returns a payload for testing DeviceQuery commands

func ServeWifiStatus

func ServeWifiStatus(status WifiStatus) TestServerPayload

ServeWifiStatus returns a payload for testing WifiStatus commands

type Variable

type Variable struct {
	XMLName     xml.Name `xml:"Variable" json:"-"`
	Name        string   `json:"name"`
	Value       string   `json:"value"`
	Units       string   `json:"units"`
	Description string   `json:"description"`
}

func NewVariable

func NewVariable(variable string) Variable

type VariableFilter

type VariableFilter map[string]bool

func (VariableFilter) Exclude

func (f VariableFilter) Exclude(variable string) bool

type VariableNames

type VariableNames struct {
	XMLName  xml.Name `xml:"Variables" json:"-"`
	Variable []string `json:"variables"`
}

type Variables

type Variables struct {
	XMLName  xml.Name   `xml:"Variables" json:"-"`
	Variable []Variable `json:"variables"`
}

func NewVariables

func NewVariables(variables ...Variable) Variables

type WifiStatus

type WifiStatus struct {
	XMLName    xml.Name `xml:"WiFiStatus" json:"-"`
	Enabled    string   `json:"enabled"`
	Type       string   `json:"type"`
	SSID       string   `json:"ssid"`
	Encryption string   `json:"encryption"`
	Channel    string   `json:"channel"`
	IPAddress  string   `xml:"IpAddress" json:"ip_address"`
}

WifiStatus is the response from the wifi_status command

Jump to

Keyboard shortcuts

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