This commit is contained in:
Nicolas Leclercq 2016-11-14 13:45:12 +01:00
parent d037c7c603
commit 9900516e0f
1 changed files with 5 additions and 11 deletions

View File

@ -33,20 +33,14 @@ type Config struct {
} }
// Client use to make request to Netatmo API // Client use to make request to Netatmo API
// ClientID : Client ID from netatmo app registration at http://dev.netatmo.com/dev/listapps
// ClientSecret : Client app secret
// Username : Your netatmo account username
// Password : Your netatmo account password
// Stations : Contains all Station account
type Client struct { type Client struct {
oauth *oauth2.Config oauth *oauth2.Config
httpClient *http.Client httpClient *http.Client
httpResponse *http.Response httpResponse *http.Response
Dc *DeviceCollection
} }
// DeviceCollection hold all devices from netatmo account // DeviceCollection hold all devices from netatmo account
// Error : returned error (nil if OK)
// Stations : List of stations
type DeviceCollection struct { type DeviceCollection struct {
Body struct { Body struct {
Devices []*Device `json:"devices"` Devices []*Device `json:"devices"`
@ -125,6 +119,7 @@ func NewClient(config Config) (*Client, error) {
return &Client{ return &Client{
oauth: oauth, oauth: oauth,
httpClient: oauth.Client(oauth2.NoContext, token), httpClient: oauth.Client(oauth2.NoContext, token),
Dc: &DeviceCollection{},
}, err }, err
} }
@ -198,15 +193,14 @@ func processHTTPResponse(resp *http.Response, err error, holder interface{}) err
// GetStations returns the list of stations owned by the user, and their modules // GetStations returns the list of stations owned by the user, and their modules
func (c *Client) Read() (*DeviceCollection, error) { func (c *Client) Read() (*DeviceCollection, error) {
//resp, err := c.doHTTPPostForm(deviceURL, url.Values{"app_type": {"app_station"}})
resp, err := c.doHTTPGet(deviceURL, url.Values{"app_type": {"app_station"}}) resp, err := c.doHTTPGet(deviceURL, url.Values{"app_type": {"app_station"}})
dc := &DeviceCollection{} //dc := &DeviceCollection{}
if err = processHTTPResponse(resp, err, dc); err != nil { if err = processHTTPResponse(resp, err, c.Dc); err != nil {
return nil, err return nil, err
} }
return dc, nil return c.Dc, nil
} }
// Devices returns the list of devices // Devices returns the list of devices