Documentation ¶
Index ¶
- Constants
- Variables
- func ConfigOK(config Config) bool
- func PostCommand(ctx context.Context, client *http.Client, config Config, command interface{}) (code int, body []byte, err error)
- func PostManagerEndpoint(config Config) string
- func ResultsFromDetailsResponse(response DeviceQueryResponse) map[string]map[string]Variable
- func ValidateConfig(c Config) error
- func VariablesFromDetailsResponse(response DeviceDetailsResponse) []string
- type API
- func (a API) DeviceDetails(ctx context.Context, hardwareAddress string) (DeviceDetailsResponse, error)
- func (a API) DeviceList(ctx context.Context) ([]Device, error)
- func (a API) DeviceQuery(ctx context.Context, hardwareAddress string, variables ...string) (DeviceQueryResponse, error)
- func (a API) GetMeterHardwareAddress(ctx context.Context) (string, error)
- func (a API) WifiStatus(ctx context.Context) (WifiStatus, error)
- type Command
- type Component
- type ComponentName
- type ComponentNames
- type Components
- type Config
- type Device
- type DeviceData
- type DeviceDetails
- type DeviceDetailsCommand
- type DeviceDetailsResponse
- type DeviceList
- type DeviceQueryCommand
- type DeviceQueryResponse
- type TestServerPayload
- type Variable
- type VariableFilter
- type VariableNames
- type Variables
- type WifiStatus
Examples ¶
Constants ¶
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 ¶
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 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 ¶
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 ¶
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 ¶
API wraps up the eagle local api for ease of use
func (API) DeviceDetails ¶
func (a API) DeviceDetails(ctx context.Context, hardwareAddress string) (DeviceDetailsResponse, error)
DeviceDetails returns the available variables
func (API) DeviceList ¶
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 ¶
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 ¶
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 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 ¶
type ComponentName ¶
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 ¶
ConfigFromEnv returns a Config and true using the environment variables or a Config and false if any aren't set
func SetPassword ¶
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 ¶
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 ¶
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 ¶
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 ¶
type VariableFilter ¶
func (VariableFilter) Exclude ¶
func (f VariableFilter) Exclude(variable string) bool
type VariableNames ¶
type Variables ¶
type Variables struct { XMLName xml.Name `xml:"Variables" json:"-"` Variable []Variable `json:"variables"` }
func NewVariables ¶
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