ig

package
v0.0.0-...-7402497 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2018 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package ig provides a client to the IntelliGrow API which allows users to interface programmatically with their IntelliClimate and IntelliDose devices.

To connect to IntelliGrow a username and password must be provided on instantiation of the client:

client, err := ig.NewClient("me", "secret")
if err != nil {
  panic(err)
}

From there the client can be used to query the devices and growrooms attached to their account. Readings can be requested and various actions can be taken to change settings of the device and even force dosing.

Index

Constants

View Source
const (
	// MetricsEP - use metric endpoint
	MetricsEP = "metrics"
	// ConfigEP - use config endpoint
	ConfigEP = "config"
	// StateEP - use state endpoint
	StateEP = "state"
)
View Source
const (
	// IDose - type reported by a device if it is an IntelliDose
	IDose = "idose"
	// NutrientDosingFunction - string used to identify the status field for nutrient dosing
	NutrientDosingFunction = "Nutrient Dosing"
	// PHDosingFunction - string used to identify the status field for ph dosing
	PHDosingFunction = "ph"
	// IrrigationFunction - string used to identify the status field for irrigation
	IrrigationFunction = "irrigation"
	// StationFunction - string used to identify the status field for irrigation station 1
	StationFunction = "Irrigation Station "
)
View Source
const (
	// IClimate - type reported by a device if it is an IntelliClimate
	IClimate = "iclimate"
)

Variables

This section is empty.

Functions

func AverageClimateReadings

func AverageClimateReadings(climates []*IntelliClimate, field string) float64

AverageClimateReadings - returns an average for the field specified from a list of IntelliDose

func AverageDoseReadings

func AverageDoseReadings(dosers []*IntelliDose, field string) float64

AverageDoseReadings - returns an average for the field specified from a list of IntelliDose

Types

type Client

type Client struct {
	*http.Client

	CheckedDevices float64
	// contains filtered or unexported fields
}

Client - object that can be used to communicate directly with intelligrow

func NewClient

func NewClient(user, pass string) (*Client, error)

NewClient creates a new client with the given username and password. It will return an error if the authentication fails

func (*Client) AutoUpdater

func (c *Client) AutoUpdater(pollInterval int, quit chan bool, updateInterval chan int)

AutoUpdater - automatically updates the device connected to the client

func (*Client) Close

func (c *Client) Close() error

Close the client (read: stop trying to refresh the auth token every hour)

func (*Client) Devices

func (c *Client) Devices() []*Device

Devices returns the devices found in IntelliGrow for the user

func (*Client) GetDevices

func (c *Client) GetDevices() error

GetDevices is deprecated in favour of RefreshDevices

func (*Client) GetGrowroom

func (c *Client) GetGrowroom(name string) (*Growroom, bool)

GetGrowroom is deprecated in favour of Growroom

func (*Client) GetGrowroomReading

func (c *Client) GetGrowroomReading(gr, reading string) (string, error)

GetGrowroomReading - returns the reading for the growroom specified as a string, also return an error

func (*Client) Growroom

func (c *Client) Growroom(name string) (*Growroom, bool)

Growroom returns the growroom with the given name, and a false if it wasn't found

func (*Client) Growrooms

func (c *Client) Growrooms() []*Growroom

Growrooms returns a slice of all the known growrooms

func (*Client) IntelliClimate

func (c *Client) IntelliClimate(nameOrID string) (*IntelliClimate, error)

IntelliClimate will return the IntelliClimate with the given name or serial

func (*Client) IntelliClimates

func (c *Client) IntelliClimates() ([]*IntelliClimate, error)

IntelliClimates will return all known IntelliClimates

func (*Client) IntelliDose

func (c *Client) IntelliDose(nameOrID string) (*IntelliDose, error)

IntelliDose will return the IntelliDose with the given name or serial

func (*Client) IntelliDoses

func (c *Client) IntelliDoses() ([]*IntelliDose, error)

IntelliDoses will return all known IntelliDoses

func (*Client) ListDevicesBySerial

func (c *Client) ListDevicesBySerial() []string

ListDevicesBySerial will return the serial numbers of all known devices

func (*Client) ListGrowrooms

func (c *Client) ListGrowrooms() []string

ListGrowrooms returns a list of the names known growrooms

func (*Client) RefreshDevices

func (c *Client) RefreshDevices() error

RefreshDevices will get the latest data from the API and update all known structs

func (*Client) SaveDevice

func (c *Client) SaveDevice(i Intelli) error

SaveDevice will save the config and state of the given device

func (*Client) UpdateAllGrowrooms

func (c *Client) UpdateAllGrowrooms()

UpdateAllGrowrooms - Updated all growrooms

func (*Client) UpdateGrowroom

func (c *Client) UpdateGrowroom(gr string) error

UpdateGrowroom - returns the growroom specified and an error

type Device

type Device struct {
	ID             string  `json:"device_id"`
	Type           string  `json:"device_type"`
	Growroom       string  `json:"growroom"`
	Checked        float64 `json:"schecked"`
	SchedulingMode string  `json:"scheduling_mode"`
	LastUpdated    float64 `json:"last_updated"`
	TimeZoneOffset float64 `json:"time_zone_offset"`
	DeviceName     string  `json:"device_name"`

	Readings map[string]interface{}
	// contains filtered or unexported fields
}

Device - general structure that holds devices

func (*Device) AttachClient

func (d *Device) AttachClient(c *Client)

AttachClient - since all information relating to a device has to be got specifically from a device endpoint it makes sense to attach a valid API client to the device.

func (*Device) GetGrowroom

func (d *Device) GetGrowroom() string

GetGrowroom - returns the growroom name this device is assigned to

func (*Device) GetID

func (d *Device) GetID() string

GetID - returns the ID for a device

func (*Device) GetType

func (d *Device) GetType() string

GetType - return type for a device

func (*Device) IntelliClimate

func (d *Device) IntelliClimate() (*IntelliClimate, error)

IntelliClimate returns this device as an IntelliClimate, or an error if this device is not an IntelliClimate

func (*Device) IntelliDose

func (d *Device) IntelliDose() (*IntelliDose, error)

IntelliDose returns this device as an IntelliDose, or an error if this device is not an IntelliDose

func (*Device) IsIClimate

func (d *Device) IsIClimate() bool

IsIClimate - returns a true if the device is a IntelliClimate

func (*Device) IsIDose

func (d *Device) IsIDose() bool

IsIDose - returns a true if the device is a IntelliDose

func (*Device) IsValid

func (d *Device) IsValid() bool

IsValid - returns a true if the last updated time is with 1 minute of now

type Devices

type Devices struct {
	IntelliClimates []*IntelliClimate
	IntelliDoses    []*IntelliDose
}

Devices - object that contains a slice of intellidosers and intelliclimates

func NewDevices

func NewDevices() *Devices

NewDevices - creates a new devices object

func (*Devices) Add

func (ds *Devices) Add(newDev *Device)

Add - adds a new device to the devices structure it will assign the devcies to the climate or doser slice depending on its type

func (*Devices) Climates

func (ds *Devices) Climates() []*IntelliClimate

Climates - returns the intelliclimate slice

func (*Devices) Dosers

func (ds *Devices) Dosers() []*IntelliDose

Dosers - returns the intellidosers slice

func (*Devices) GetClimateByID

func (ds *Devices) GetClimateByID(id string) (*IntelliClimate, error)

GetClimateByID - returns a climate with the id that matches the serial number provided

func (*Devices) GetClimateByName

func (ds *Devices) GetClimateByName(name string) (*IntelliClimate, error)

GetClimateByName - returns a climate with the name that matches the one provided

func (*Devices) GetDoserByID

func (ds *Devices) GetDoserByID(id string) (*IntelliDose, error)

GetDoserByID - returns a doser with the id that matches the serial number provided

func (*Devices) GetDoserByName

func (ds *Devices) GetDoserByName(name string) (*IntelliDose, error)

GetDoserByName - returns a doser with the name that matches the one provided

func (*Devices) IsEmpty

func (ds *Devices) IsEmpty() bool

IsEmpty returns true if there are no intellis in this devices collection

func (*Devices) UpdateClimateMetrics

func (ds *Devices) UpdateClimateMetrics() error

UpdateClimateMetrics - updates all intellicliamte metrics

func (*Devices) UpdateDoserMetrics

func (ds *Devices) UpdateDoserMetrics() error

UpdateDoserMetrics - updates all intellidosers metrics

type Growroom

type Growroom struct {
	Name              string            `json:"name"`
	Climate           *GrowroomClimate  `json:"climate"`
	Rootzone          *GrowroomRootzone `json:"rootzone"`
	IntruderAlarm     float64           `json:"intruder_alarm"`
	OutsideTempSensor float64           `json:"outside_temp_sensor"`
	// contains filtered or unexported fields
}

Growroom - object containing all relative information about a single growroom

func NewGrowroom

func NewGrowroom(name string) *Growroom

NewGrowroom - return a new growroom with the name specified

func (*Growroom) AddDevice

func (g *Growroom) AddDevice(dev *Device)

AddDevice - add device to grow room

func (*Growroom) AirTemp

func (g *Growroom) AirTemp() (bool, string)

AirTemp - returns the air temperature for the climate as a string

func (*Growroom) CO2

func (g *Growroom) CO2() (bool, string)

CO2 - returns the CO2 for the climate as a string

func (*Growroom) Devices

func (g *Growroom) Devices() []*Device

Devices returns the devices found in IntelliGrow for the user

func (*Growroom) EC

func (g *Growroom) EC() (bool, string)

EC - returns the ec for the rootzone as a string

func (*Growroom) GetClimateHistory

func (g *Growroom) GetClimateHistory(from, to time.Time, points int) error

GetClimateHistory - returns the history for the growroom

func (*Growroom) GetClimateReading

func (g *Growroom) GetClimateReading(reading string) (bool, string)

GetClimateReading - returns an avaliable flag and the reading as a string

func (*Growroom) GetDevices

func (g *Growroom) GetDevices() ([]string, []string)

GetDevices - updated the device inside the growroom

func (*Growroom) GetDoserHistory

func (g *Growroom) GetDoserHistory(from, to time.Time, points int) error

GetDoserHistory - returns the history for the growroom

func (*Growroom) GetName

func (g *Growroom) GetName() string

GetName - returns the name for the growroom

func (*Growroom) GetReading

func (g *Growroom) GetReading(reading string) (bool, string)

GetReading - returns an avaliable flag and the reading as a string

func (*Growroom) GetRootzoneReading

func (g *Growroom) GetRootzoneReading(reading string) (bool, string)

GetRootzoneReading - returns an avaliable flag and the reading as a string

func (*Growroom) HasIntelliClimate

func (g *Growroom) HasIntelliClimate() bool

HasIntelliClimate will return true if the growroom has one of more IntelliClimate devices

func (*Growroom) HasIntelliDose

func (g *Growroom) HasIntelliDose() bool

HasIntelliDose will return true if the growroom has one of more IntelliDose devices

func (*Growroom) IntelliClimate

func (g *Growroom) IntelliClimate(nameOrID string) (*IntelliClimate, error)

IntelliClimate will return the IntelliClimate with the given name or serial

func (*Growroom) IntelliClimates

func (g *Growroom) IntelliClimates() ([]*IntelliClimate, error)

IntelliClimates will return all known IntelliClimates

func (*Growroom) IntelliDose

func (g *Growroom) IntelliDose(nameOrID string) (*IntelliDose, error)

IntelliDose will return the IntelliDose with the given name or serial

func (*Growroom) IntelliDoses

func (g *Growroom) IntelliDoses() ([]*IntelliDose, error)

IntelliDoses will return all known IntelliDoses

func (*Growroom) Light

func (g *Growroom) Light() (bool, string)

Light - returns the Light level for the climate as a string

func (*Growroom) ListDevicesBySerial

func (g *Growroom) ListDevicesBySerial() []string

ListDevicesBySerial will return the serial numbers of all known devices

func (*Growroom) PH

func (g *Growroom) PH() (bool, string)

PH - returns the ph for the rootzone as a string

func (*Growroom) RH

func (g *Growroom) RH() (bool, string)

RH - returns the relative humidity the climate as a string

func (*Growroom) Update

func (g *Growroom) Update() error

Update - updated the devices and readings inside the growroom

func (*Growroom) UpdateClimate

func (g *Growroom) UpdateClimate() error

UpdateClimate - takes the readings dict from an intelliclimate and update them into the room climate

func (*Growroom) UpdateRootzone

func (g *Growroom) UpdateRootzone() error

UpdateRootzone - takes the readings dict from an intellidose and update them into the room rootzone

func (*Growroom) WaterTemp

func (g *Growroom) WaterTemp() (bool, string)

WaterTemp - returns the water temp for the rootzone as a string

type GrowroomClimate

type GrowroomClimate struct {
	AirTemp        float64 `json:"air_temp"`
	RH             float64 `json:"rh"`
	VPD            float64 `json:"vpd"`
	Light          float64 `json:"light"`
	PowerFail      bool    `json:"power_fail"`
	FailSafeAlarms bool    `json:"fail_safe_alarms"`
	DayNight       string  `json:"day_night"`
	CO2            float64 `json:"co2"`
	LastUpdate     float64 `json:"last_update"`
}

GrowroomClimate - climate data for a single room

type GrowroomRootzone

type GrowroomRootzone struct {
	EC         float64 `json:"ec"`
	PH         float64 `json:"pH"`
	Temp       float64 `json:"nut_temp"`
	LastUpdate float64 `json:"last_update"`
}

GrowroomRootzone - rootzone data for a single room

type Intelli

type Intelli interface {
	StatePayload() (interface{}, error)
	GetID() string
	GetAll() error
}

Intelli is a generic interface that both IntelliDose and IntelliClimate can adhere to

type IntelliClimate

type IntelliClimate struct {
	*Device     `json:"device"`
	ValidConfig bool                         `json:"valid_config"`
	Config      *datastructs.ConfigIClimate  `json:"config"`
	Metrics     *datastructs.MetricsIClimate `json:"metrics"`
	ValidStatus bool                         `json:"valid_status"`
	Status      *datastructs.StatusIClimate  `json:"status"`
	History     *datastructs.ClimateHistory  `json:"history"`
	// contains filtered or unexported fields
}

IntelliClimate - Intelliclimate object

func NewIntelliClimate

func NewIntelliClimate(dev *Device) *IntelliClimate

NewIntelliClimate - returns a new intelliclimate for the device passed in

func (*IntelliClimate) DisableCO2Dosing

func (ic *IntelliClimate) DisableCO2Dosing() error

DisableCO2Dosing will disable the CO2 dosing

func (*IntelliClimate) EnableCO2Dosing

func (ic *IntelliClimate) EnableCO2Dosing() error

EnableCO2Dosing will enable the CO2 dosing

func (*IntelliClimate) GetAll

func (ic *IntelliClimate) GetAll() error

GetAll will get the config, state and metrics from the API

func (*IntelliClimate) GetConfig

func (ic *IntelliClimate) GetConfig() error

GetConfig - this pulls both the config and state from the device endpoint

func (*IntelliClimate) GetConfigState

func (ic *IntelliClimate) GetConfigState() error

GetConfigState - this pulls both the config and state from the device endpoint

func (*IntelliClimate) GetHistory

func (ic *IntelliClimate) GetHistory(to, from time.Time, points int) error

GetHistory the device by quering the history endpont for the time period specified

func (*IntelliClimate) GetMetrics

func (ic *IntelliClimate) GetMetrics() error

GetMetrics the device by quering the endpoint passed in

func (*IntelliClimate) GetState

func (ic *IntelliClimate) GetState() error

GetState - this pulls both the state from the device endpoint

func (*IntelliClimate) SaveConfigState

func (ic *IntelliClimate) SaveConfigState() error

SaveConfigState will save the config and state

func (*IntelliClimate) SetCO2Target

func (ic *IntelliClimate) SetCO2Target(target float64) error

SetCO2Target will set the CO2 levels in PPM that the room should be kept to

func (*IntelliClimate) SetRHTarget

func (ic *IntelliClimate) SetRHTarget(target float64) error

SetRHTarget will set the RH target that the room should be kept to

func (*IntelliClimate) SetTempTarget

func (ic *IntelliClimate) SetTempTarget(target float64) error

SetTempTarget will set the temperature that the room should be kept to

func (*IntelliClimate) StatePayload

func (ic *IntelliClimate) StatePayload() (interface{}, error)

StatePayload builds and returns the state payload for updating a devices state or config

func (*IntelliClimate) Transaction

func (ic *IntelliClimate) Transaction(runner func() error) error

Transaction allows multiple changes to be modified and pushed in one API request instead of doing multiple API requests as happens when those methods are called outside of a transation.

err := ic.Transaction(func() error) {
  ic.SetCO2Target(2500)
  ic.EnableCO2Dosing()
  return nil
})

When the methods are called inside the transaction, the changes will only by sent at the end of the callback and if the callback doesn't return an error.

Using the transaction will also pull down the config and state immediately prior to and push it up immediately after, making the changes. This small window helps to ensure that changes from other parties accessing the API are not overwritten.

type IntelliDose

type IntelliDose struct {
	*Device     `json:"device"`
	ValidConfig bool                      `json:"valid_config"`
	Config      *datastructs.ConfigIDose  `json:"config"`
	Metrics     *datastructs.MetricsIDose `json:"metrics"`
	ValidStatus bool                      `json:"valid_status"`
	Status      *datastructs.StatusIDose  `json:"status"`
	History     *datastructs.DoserHistory `json:"history"`
	// contains filtered or unexported fields
}

IntelliDose - IntelliDose object

func NewIntelliDose

func NewIntelliDose(dev *Device) *IntelliDose

NewIntelliDose - returns a new intellidose for the device passed in

func (*IntelliDose) DisableNutrientDosing

func (id *IntelliDose) DisableNutrientDosing(target float64) error

DisableNutrientDosing will disable the nutrient dosing

func (*IntelliDose) DisablePHDosing

func (id *IntelliDose) DisablePHDosing(target float64) error

DisablePHDosing will disable the pH dosing

func (*IntelliDose) EnableNutrientDosing

func (id *IntelliDose) EnableNutrientDosing(target float64) error

EnableNutrientDosing will enable the nutrient dosing

func (*IntelliDose) EnablePHDosing

func (id *IntelliDose) EnablePHDosing(target float64) error

EnablePHDosing will enable the pH dosing

func (*IntelliDose) ForceIrrigation

func (id *IntelliDose) ForceIrrigation() error

ForceIrrigation will force an irrigation on the controller

func (*IntelliDose) ForceNutrientDose

func (id *IntelliDose) ForceNutrientDose() error

ForceNutrientDose will force a nutrient dose on the controller

func (*IntelliDose) ForcePHDose

func (id *IntelliDose) ForcePHDose() error

ForcePHDose will force a pH dose on the controller

func (*IntelliDose) ForceStation

func (id *IntelliDose) ForceStation(stn string) error

ForceStation will force an irrigation on the station specified (1-4)

func (*IntelliDose) GetAll

func (id *IntelliDose) GetAll() error

GetAll will get the config, state and metrics from the API

func (*IntelliDose) GetConfig

func (id *IntelliDose) GetConfig() error

GetConfig - this pulls both the config and state from the device endpoint

func (*IntelliDose) GetConfigState

func (id *IntelliDose) GetConfigState() error

GetConfigState - this pulls both the config and state from the device endpoint

func (*IntelliDose) GetHistory

func (id *IntelliDose) GetHistory(to, from time.Time, points int) error

GetHistory the device by quering the history endpont for the time period specified

func (*IntelliDose) GetMetrics

func (id *IntelliDose) GetMetrics() error

GetMetrics the device by quering the endpoint passed in

func (*IntelliDose) GetState

func (id *IntelliDose) GetState() error

GetState - this pulls both the state from the device endpoint

func (*IntelliDose) SaveConfigState

func (id *IntelliDose) SaveConfigState() error

SaveConfigState will save the config and state

func (*IntelliDose) SetNutrientTarget

func (id *IntelliDose) SetNutrientTarget(target float64) error

SetNutrientTarget will set the target EC the system should dose to

func (*IntelliDose) SetPHTarget

func (id *IntelliDose) SetPHTarget(target float64) error

SetPHTarget will set the target pH the system should dose to

func (*IntelliDose) StatePayload

func (id *IntelliDose) StatePayload() (interface{}, error)

StatePayload builds and returns the state payload for updating a devices state or config

func (*IntelliDose) Transaction

func (id *IntelliDose) Transaction(runner func() error) error

Transaction allows multiple changes to be modified and pushed in one API request instead of doing multiple API requests as happens when those methods are called outside of a transation.

err := id.Transaction(func() error) {
  id.ForceIrrigation()
  id.ForcePHDose()
  id.ForceECDose()
  return nil
})

When the methods are called inside the transaction, the changes will only by sent at the end of the callback and if the callback doesn't return an error.

Using the transaction will also pull down the config and state immediately prior to and push it up immediately after, making the changes. This small window helps to ensure that changes from other parties accessing the API are not overwritten.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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