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
- func AverageClimateReadings(climates []*IntelliClimate, field string) float64
- func AverageDoseReadings(dosers []*IntelliDose, field string) float64
- type Client
- func (c *Client) AutoUpdater(pollInterval int, quit chan bool, updateInterval chan int)
- func (c *Client) Close() error
- func (c *Client) Devices() []*Device
- func (c *Client) GetDevices() error
- func (c *Client) GetGrowroom(name string) (*Growroom, bool)
- func (c *Client) GetGrowroomReading(gr, reading string) (string, error)
- func (c *Client) Growroom(name string) (*Growroom, bool)
- func (c *Client) Growrooms() []*Growroom
- func (c *Client) IntelliClimate(nameOrID string) (*IntelliClimate, error)
- func (c *Client) IntelliClimates() ([]*IntelliClimate, error)
- func (c *Client) IntelliDose(nameOrID string) (*IntelliDose, error)
- func (c *Client) IntelliDoses() ([]*IntelliDose, error)
- func (c *Client) ListDevicesBySerial() []string
- func (c *Client) ListGrowrooms() []string
- func (c *Client) RefreshDevices() error
- func (c *Client) SaveDevice(i Intelli) error
- func (c *Client) UpdateAllGrowrooms()
- func (c *Client) UpdateGrowroom(gr string) error
- type Device
- func (d *Device) AttachClient(c *Client)
- func (d *Device) GetGrowroom() string
- func (d *Device) GetID() string
- func (d *Device) GetType() string
- func (d *Device) IntelliClimate() (*IntelliClimate, error)
- func (d *Device) IntelliDose() (*IntelliDose, error)
- func (d *Device) IsIClimate() bool
- func (d *Device) IsIDose() bool
- func (d *Device) IsValid() bool
- type Devices
- func (ds *Devices) Add(newDev *Device)
- func (ds *Devices) Climates() []*IntelliClimate
- func (ds *Devices) Dosers() []*IntelliDose
- func (ds *Devices) GetClimateByID(id string) (*IntelliClimate, error)
- func (ds *Devices) GetClimateByName(name string) (*IntelliClimate, error)
- func (ds *Devices) GetDoserByID(id string) (*IntelliDose, error)
- func (ds *Devices) GetDoserByName(name string) (*IntelliDose, error)
- func (ds *Devices) IsEmpty() bool
- func (ds *Devices) UpdateClimateMetrics() error
- func (ds *Devices) UpdateDoserMetrics() error
- type Growroom
- func (g *Growroom) AddDevice(dev *Device)
- func (g *Growroom) AirTemp() (bool, string)
- func (g *Growroom) CO2() (bool, string)
- func (g *Growroom) Devices() []*Device
- func (g *Growroom) EC() (bool, string)
- func (g *Growroom) GetClimateHistory(from, to time.Time, points int) error
- func (g *Growroom) GetClimateReading(reading string) (bool, string)
- func (g *Growroom) GetDevices() ([]string, []string)
- func (g *Growroom) GetDoserHistory(from, to time.Time, points int) error
- func (g *Growroom) GetName() string
- func (g *Growroom) GetReading(reading string) (bool, string)
- func (g *Growroom) GetRootzoneReading(reading string) (bool, string)
- func (g *Growroom) HasIntelliClimate() bool
- func (g *Growroom) HasIntelliDose() bool
- func (g *Growroom) IntelliClimate(nameOrID string) (*IntelliClimate, error)
- func (g *Growroom) IntelliClimates() ([]*IntelliClimate, error)
- func (g *Growroom) IntelliDose(nameOrID string) (*IntelliDose, error)
- func (g *Growroom) IntelliDoses() ([]*IntelliDose, error)
- func (g *Growroom) Light() (bool, string)
- func (g *Growroom) ListDevicesBySerial() []string
- func (g *Growroom) PH() (bool, string)
- func (g *Growroom) RH() (bool, string)
- func (g *Growroom) Update() error
- func (g *Growroom) UpdateClimate() error
- func (g *Growroom) UpdateRootzone() error
- func (g *Growroom) WaterTemp() (bool, string)
- type GrowroomClimate
- type GrowroomRootzone
- type Intelli
- type IntelliClimate
- func (ic *IntelliClimate) DisableCO2Dosing() error
- func (ic *IntelliClimate) EnableCO2Dosing() error
- func (ic *IntelliClimate) GetAll() error
- func (ic *IntelliClimate) GetConfig() error
- func (ic *IntelliClimate) GetConfigState() error
- func (ic *IntelliClimate) GetHistory(to, from time.Time, points int) error
- func (ic *IntelliClimate) GetMetrics() error
- func (ic *IntelliClimate) GetState() error
- func (ic *IntelliClimate) SaveConfigState() error
- func (ic *IntelliClimate) SetCO2Target(target float64) error
- func (ic *IntelliClimate) SetRHTarget(target float64) error
- func (ic *IntelliClimate) SetTempTarget(target float64) error
- func (ic *IntelliClimate) StatePayload() (interface{}, error)
- func (ic *IntelliClimate) Transaction(runner func() error) error
- type IntelliDose
- func (id *IntelliDose) DisableNutrientDosing(target float64) error
- func (id *IntelliDose) DisablePHDosing(target float64) error
- func (id *IntelliDose) EnableNutrientDosing(target float64) error
- func (id *IntelliDose) EnablePHDosing(target float64) error
- func (id *IntelliDose) ForceIrrigation() error
- func (id *IntelliDose) ForceNutrientDose() error
- func (id *IntelliDose) ForcePHDose() error
- func (id *IntelliDose) ForceStation(stn string) error
- func (id *IntelliDose) GetAll() error
- func (id *IntelliDose) GetConfig() error
- func (id *IntelliDose) GetConfigState() error
- func (id *IntelliDose) GetHistory(to, from time.Time, points int) error
- func (id *IntelliDose) GetMetrics() error
- func (id *IntelliDose) GetState() error
- func (id *IntelliDose) SaveConfigState() error
- func (id *IntelliDose) SetNutrientTarget(target float64) error
- func (id *IntelliDose) SetPHTarget(target float64) error
- func (id *IntelliDose) StatePayload() (interface{}, error)
- func (id *IntelliDose) Transaction(runner func() error) error
Constants ¶
const ( // MetricsEP - use metric endpoint MetricsEP = "metrics" // ConfigEP - use config endpoint ConfigEP = "config" // StateEP - use state endpoint StateEP = "state" )
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 " )
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 ¶
NewClient creates a new client with the given username and password. It will return an error if the authentication fails
func (*Client) AutoUpdater ¶
AutoUpdater - automatically updates the device connected to the client
func (*Client) GetDevices ¶
GetDevices is deprecated in favour of RefreshDevices
func (*Client) GetGrowroom ¶
GetGrowroom is deprecated in favour of Growroom
func (*Client) GetGrowroomReading ¶
GetGrowroomReading - returns the reading for the growroom specified as a string, also return an error
func (*Client) Growroom ¶
Growroom returns the growroom with the given name, and a false if it wasn't found
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 ¶
ListDevicesBySerial will return the serial numbers of all known devices
func (*Client) ListGrowrooms ¶
ListGrowrooms returns a list of the names known growrooms
func (*Client) RefreshDevices ¶
RefreshDevices will get the latest data from the API and update all known structs
func (*Client) SaveDevice ¶
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 ¶
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 ¶
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 ¶
GetGrowroom - returns the growroom name this device is assigned to
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 ¶
IsIClimate - returns a true if the device is a IntelliClimate
type Devices ¶
type Devices struct { IntelliClimates []*IntelliClimate IntelliDoses []*IntelliDose }
Devices - object that contains a slice of intellidosers and intelliclimates
func (*Devices) Add ¶
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) UpdateClimateMetrics ¶
UpdateClimateMetrics - updates all intellicliamte metrics
func (*Devices) UpdateDoserMetrics ¶
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 ¶
NewGrowroom - return a new growroom with the name specified
func (*Growroom) GetClimateHistory ¶
GetClimateHistory - returns the history for the growroom
func (*Growroom) GetClimateReading ¶
GetClimateReading - returns an avaliable flag and the reading as a string
func (*Growroom) GetDevices ¶
GetDevices - updated the device inside the growroom
func (*Growroom) GetDoserHistory ¶
GetDoserHistory - returns the history for the growroom
func (*Growroom) GetReading ¶
GetReading - returns an avaliable flag and the reading as a string
func (*Growroom) GetRootzoneReading ¶
GetRootzoneReading - returns an avaliable flag and the reading as a string
func (*Growroom) HasIntelliClimate ¶
HasIntelliClimate will return true if the growroom has one of more IntelliClimate devices
func (*Growroom) HasIntelliDose ¶
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) ListDevicesBySerial ¶
ListDevicesBySerial will return the serial numbers of all known devices
func (*Growroom) UpdateClimate ¶
UpdateClimate - takes the readings dict from an intelliclimate and update them into the room climate
func (*Growroom) UpdateRootzone ¶
UpdateRootzone - takes the readings dict from an intellidose and update them into the room rootzone
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 ¶
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.