mirror of
https://github.com/steinhobelgruen/netatmo-api-go.git
synced 2024-12-23 01:43:55 +00:00
Compare commits
No commits in common. "cc9590cf3d74574f7825c2faad0b822460927109" and "a8620474d1ea4477f0ddccc54d8a5662b1aa1599" have entirely different histories.
cc9590cf3d
...
a8620474d1
5
go.mod
5
go.mod
|
@ -1,5 +0,0 @@
|
||||||
module github.com/steinhobelgruen/netatmo-api-go
|
|
||||||
|
|
||||||
go 1.14
|
|
||||||
|
|
||||||
require golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
toml "github.com/BurntSushi/toml"
|
toml "github.com/BurntSushi/toml"
|
||||||
netatmo "github.com/steinhobelgruen/netatmo-api-go"
|
netatmo "github.com/exzz/netatmo-api-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Command line flag
|
// Command line flag
|
||||||
|
|
25
weather.go
25
weather.go
|
@ -16,8 +16,7 @@ const (
|
||||||
// DefaultAuthURL is netatmo auth url
|
// DefaultAuthURL is netatmo auth url
|
||||||
authURL = baseURL + "oauth2/token"
|
authURL = baseURL + "oauth2/token"
|
||||||
// DefaultDeviceURL is netatmo device url
|
// DefaultDeviceURL is netatmo device url
|
||||||
stationURL = baseURL + "/api/getstationsdata"
|
deviceURL = baseURL + "/api/getstationsdata"
|
||||||
homecoachURL = baseURL + "/api/gethomecoachsdata"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config is used to specify credential to Netatmo API
|
// Config is used to specify credential to Netatmo API
|
||||||
|
@ -57,7 +56,7 @@ type DeviceCollection struct {
|
||||||
// Type : Module type :
|
// Type : Module type :
|
||||||
// "NAMain" : for the base station
|
// "NAMain" : for the base station
|
||||||
// "NAModule1" : for the outdoor module
|
// "NAModule1" : for the outdoor module
|
||||||
// "NAModule4" : for the additional indoor module
|
// "NAModule4" : for the additionnal indoor module
|
||||||
// "NAModule3" : for the rain gauge module
|
// "NAModule3" : for the rain gauge module
|
||||||
// "NAModule2" : for the wind gauge module
|
// "NAModule2" : for the wind gauge module
|
||||||
// DashboardData : Data collection from device sensors
|
// DashboardData : Data collection from device sensors
|
||||||
|
@ -90,10 +89,9 @@ type Device struct {
|
||||||
// WindStrength : Current 5 min average wind speed @ LastMeasure (in km/h)
|
// WindStrength : Current 5 min average wind speed @ LastMeasure (in km/h)
|
||||||
// GustAngle : Direction of the last 5 min highest gust wind @ LastMeasure (in °)
|
// GustAngle : Direction of the last 5 min highest gust wind @ LastMeasure (in °)
|
||||||
// GustStrength : Speed of the last 5 min highest gust wind @ LastMeasure (in km/h)
|
// GustStrength : Speed of the last 5 min highest gust wind @ LastMeasure (in km/h)
|
||||||
// FIXME health_idx
|
|
||||||
// LastMeasure : Contains timestamp of last data received
|
// LastMeasure : Contains timestamp of last data received
|
||||||
type DashboardData struct {
|
type DashboardData struct {
|
||||||
Temperature *float32 `json:"Temperature,omitempty"` // use pointer to detect omitted field by json mapping
|
Temperature *float32 `json:"Temperature,omitempty"` // use pointer to detect ommitted field by json mapping
|
||||||
Humidity *int32 `json:"Humidity,omitempty"`
|
Humidity *int32 `json:"Humidity,omitempty"`
|
||||||
CO2 *int32 `json:"CO2,omitempty"`
|
CO2 *int32 `json:"CO2,omitempty"`
|
||||||
Noise *int32 `json:"Noise,omitempty"`
|
Noise *int32 `json:"Noise,omitempty"`
|
||||||
|
@ -106,7 +104,6 @@ type DashboardData struct {
|
||||||
WindStrength *int32 `json:"WindStrength,omitempty"`
|
WindStrength *int32 `json:"WindStrength,omitempty"`
|
||||||
GustAngle *int32 `json:"GustAngle,omitempty"`
|
GustAngle *int32 `json:"GustAngle,omitempty"`
|
||||||
GustStrength *int32 `json:"GustStrength,omitempty"`
|
GustStrength *int32 `json:"GustStrength,omitempty"`
|
||||||
HealthIndex *int32 `json:"health_idx,omitempty"`
|
|
||||||
LastMeasure *int64 `json:"time_utc"`
|
LastMeasure *int64 `json:"time_utc"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +112,7 @@ func NewClient(config Config) (*Client, error) {
|
||||||
oauth := &oauth2.Config{
|
oauth := &oauth2.Config{
|
||||||
ClientID: config.ClientID,
|
ClientID: config.ClientID,
|
||||||
ClientSecret: config.ClientSecret,
|
ClientSecret: config.ClientSecret,
|
||||||
Scopes: []string{"read_station", "read_homecoach"},
|
Scopes: []string{"read_station"},
|
||||||
Endpoint: oauth2.Endpoint{
|
Endpoint: oauth2.Endpoint{
|
||||||
AuthURL: baseURL,
|
AuthURL: baseURL,
|
||||||
TokenURL: authURL,
|
TokenURL: authURL,
|
||||||
|
@ -201,17 +198,10 @@ 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.doHTTPGet(stationURL, 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, c.Dc); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
resp2, err := c.doHTTPGet(homecoachURL, url.Values{"app_type": {"app_station"}})
|
|
||||||
// dc := &DeviceCollection{}
|
|
||||||
|
|
||||||
if err = processHTTPResponse(resp2, err, c.Dc); err != nil {
|
if err = processHTTPResponse(resp, err, c.Dc); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,9 +274,6 @@ func (d *Device) Data() (int64, map[string]interface{}) {
|
||||||
if d.DashboardData.GustStrength != nil {
|
if d.DashboardData.GustStrength != nil {
|
||||||
m["GustStrength"] = *d.DashboardData.GustStrength
|
m["GustStrength"] = *d.DashboardData.GustStrength
|
||||||
}
|
}
|
||||||
if d.DashboardData.HealthIndex != nil {
|
|
||||||
m["HealthIndex"] = *d.DashboardData.HealthIndex
|
|
||||||
}
|
|
||||||
|
|
||||||
return *d.DashboardData.LastMeasure, m
|
return *d.DashboardData.LastMeasure, m
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue