@@ -9,44 +9,62 @@ import (
99 "time"
1010)
1111
12+ // ElectricUsage contains usage and cost information for a defined period of time.
1213type ElectricUsage struct {
1314 StartTime time.Time
1415 EndTime time.Time
1516 WattHours int64
1617 CostInCents int64
1718}
1819
20+ // Response holds the parsed response from the Novec poll api.
21+ // If Status is "PENDING", this means we need to make the same request again
22+ // as data is still being prepared.
1923type Response struct {
2024 Status string `json:"status"`
2125 Data map [string ][]NovecData `json:"data"`
2226}
2327
28+ // NovecData holds parsed response data from the Novec poll api.
29+ // It holds the Type of data ("USAGE" or "COST"), and the Series
2430type NovecData struct {
2531 Type string `json:"type"`
2632 Series []NovecSeries `json:"series"`
2733}
2834
35+ // NovecSeries holds parsed response data from the Novec poll api.
36+ // It holds a list of NovecPoints.
2937type NovecSeries struct {
3038 Data []NovecPoint `json:"data"`
3139}
3240
41+ // NovecPoint holds parsed response data from the Novec poll api.
42+ // It holds a timestamp, UnixMillis, which is actually in the America/New_York timezone instead of
43+ // UTC as it should be.
44+ // It also holds the Value of the point in dollars or kWh.
3345type NovecPoint struct {
3446 UnixMillis int64 `json:"x"`
3547 Value float64 `json:"y"`
3648}
3749
50+ // RetryableError is an error that indicates to the retryer in Main that another
51+ // poll request to FetchData should be made.
3852type RetryableError struct {
3953 Msg string
4054}
4155
56+ // NewRetryableError creates a RetryableError
4257func NewRetryableError (msg string ) * RetryableError {
4358 return & RetryableError {Msg : msg }
4459}
4560
61+ // Error implements type error for RetryableError.
4662func (t * RetryableError ) Error () string {
4763 return t .Msg
4864}
4965
66+ // ParseReader parses the json response received in FetchData from the Novec poll api.
67+ // It can return a normal error, a RetryableError, or parsed ElectricUsage.
5068func ParseReader (reader io.ReadCloser ) ([]ElectricUsage , error ) {
5169 defer func () {
5270 if err := reader .Close (); err != nil {
0 commit comments