solarmanager

package
v0.0.0-...-f7aac99 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

Package solarmanager implements a client for the SolarManager API. See https://external-web.solar-manager.ch.

Index

Examples

Constants

View Source
const (
	Day   = "day"
	Month = "month"
	Year  = "year"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL   *url.URL
	UserAgent string
	Verbose   bool
	Username  string
	Password  string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(httpClient *http.Client, baseURL *url.URL, username, password string) *Client

NewClient returns a new SolarManager API client using the supplied credentials. If a nil httpClient is provided, a new http.Client will be used.

func (*Client) GetGatewayConsumptionStatistics

func (c *Client) GetGatewayConsumptionStatistics(solarManagerID string, period StatisticPeriod) (GetGatewayConsumptionStatisticsResponse, error)

func (*Client) GetGatewayData

func (c *Client) GetGatewayData(solarManagerID string) (GetGatewayDataResponse, error)

func (*Client) GetGatewayForecast

func (c *Client) GetGatewayForecast(solarManagerID string) (GetGatewayForecastResponse, error)

func (*Client) GetGatewayInfo

func (c *Client) GetGatewayInfo(solarManagerID string) (GetGatewayInfoResponse, error)

func (*Client) GetGatewayPieChart

func (c *Client) GetGatewayPieChart(solarManagerID string) (GetGatewayPieChartResponse, error)

func (*Client) GetLowRateTariff

func (c *Client) GetLowRateTariff(solarManagerID string) (GetLowRateTariffResponse, error)

func (*Client) GetSensor

func (c *Client) GetSensor(sensorID string) (GetSensorResponse, error)

func (*Client) GetSensorConsumptionStatistics

func (c *Client) GetSensorConsumptionStatistics(sensorID string, period StatisticPeriod) (GetSensorConsumptionStatisticsResponse, error)

func (*Client) GetSensorData

func (c *Client) GetSensorData(solarManagerID string, sensorID string) (GetSensorDataResponse, error)

func (*Client) GetSensors

func (c *Client) GetSensors(solarManagerID string) (GetSensorsResponse, error)
Example
username := os.Getenv("SOLARMANAGER_USERNAME")
password := os.Getenv("SOLARMANAGER_PASSWORD")
smID := os.Getenv("SOLARMANAGER_ID")

client := NewClient(nil, nil, username, password)
sensors, err := client.GetSensors(smID)
if err != nil {
	panic(err)
}
fmt.Println(sensors)
Output:

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

type ForecastEntry

type ForecastEntry struct {
	Timestamp int64 `json:"timestamp"`
	Expected  int   `json:"expected"`
	Min       int   `json:"min"`
	Max       int   `json:"max"`
}

type GatewayData

type GatewayData struct {
	InterfaceVersion              string       `json:"Interface Version"`
	TimeStamp                     time.Time    `json:"TimeStamp"`
	CurrentBatteryChargeDischarge int          `json:"currentBatteryChargeDischarge"`
	CurrentPowerConsumption       int          `json:"currentPowerConsumption"`
	CurrentPvGeneration           int          `json:"currentPvGeneration"`
	Devices                       []SensorData `json:"devices"`
	Errors                        []int        `json:"errors"`
	Soc                           int          `json:"soc"`
}

type GatewayInfo

type GatewayInfo struct {
	Id                      string    `json:"_id"`    // db id for gateway
	Signal                  string    `json:"signal"` // gateway signal
	Name                    string    `json:"name"`   // gateway name in system
	SmId                    string    `json:"sm_id"`  // gateway unique id
	Owner                   string    `json:"owner"`  // id of user - owner of gateway
	IsInstallationCompleted bool      `json:"isInstallationCompleted"`
	Firmware                string    `json:"firmware"`      // gateway firmware version
	LastErrorDate           time.Time `json:"lastErrorDate"` // date of last error
	Mac                     string    `json:"mac"`           // gateway mac address
	Ip                      string    `json:"ip"`            // gateway ip
}

type GetGatewayConsumptionStatisticsResponse

type GetGatewayConsumptionStatisticsResponse struct {
	GatewayId string `json:"gatewayId"`
	Period    string `json:"period"`
	Data      []struct {
		CreatedAt   string `json:"createdAt"`
		Consumption int    `json:"consumption"`
		Production  int    `json:"production"`
	} `json:"data"`
	TotalConsumption int `json:"totalConsumption"`
}

type GetGatewayDataResponse

type GetGatewayDataResponse GatewayData

type GetGatewayForecastResponse

type GetGatewayForecastResponse []ForecastEntry

type GetGatewayInfoResponse

type GetGatewayInfoResponse struct {
	Gateway GatewayInfo `json:"gateway"`

	Settings struct {
		OffsetWatt     int     `json:"offset_watt"`
		LowMFFrom      string  `json:"low_m_f_from"`
		LowMFTo        string  `json:"low_m_f_to"`
		LowSatFrom     string  `json:"low_sat_from"`
		LowSatTo       string  `json:"low_sat_to"`
		LowSunFrom     string  `json:"low_sun_from"`
		LowSunTo       string  `json:"low_sun_to"`
		KWp            float64 `json:"kWp"`
		HouseFuse      int     `json:"houseFuse"`
		LoadManagement bool    `json:"loadManagement"`
		CommonSeasons  struct {
			MondayFriday []struct {
				From   string `json:"from"`
				Tariff string `json:"tariff"`
			} `json:"mondayFriday"`
			Saturday []struct {
				From   string `json:"from"`
				Tariff string `json:"tariff"`
			} `json:"saturday"`
			Sunday []struct {
				From   string `json:"from"`
				Tariff string `json:"tariff"`
			} `json:"sunday"`
		} `json:"commonSeasons"`
		HighTariff          float64 `json:"highTariff"`
		IsWinterTimeEnabled bool    `json:"isWinterTimeEnabled"`
		LowTariff           float64 `json:"lowTariff"`
		Provider            string  `json:"provider"`
		TariffType          string  `json:"tariffType"`
		WinterSeason        struct {
			MondayFriday []struct {
				From   string `json:"from"`
				Tariff string `json:"tariff"`
			} `json:"mondayFriday"`
			Saturday []struct {
				From   string `json:"from"`
				Tariff string `json:"tariff"`
			} `json:"saturday"`
			Sunday []struct {
				From   string `json:"from"`
				Tariff string `json:"tariff"`
			} `json:"sunday"`
		} `json:"winterSeason"`
	} `json:"settings"`
	User struct {
		FirstName    string `json:"first_name"`
		UserId       string `json:"user_id"`
		LastName     string `json:"last_name"`
		Email        string `json:"email"`
		Status       string `json:"status"`
		Country      string `json:"country"`
		City         string `json:"city"`
		Zip          string `json:"zip"`
		Plant        string `json:"plant"`
		CompanyName  string `json:"company_name"`
		Company      string `json:"company"`
		ConnectedOem string `json:"connectedOem"`
	} `json:"user"`
	Versions struct {
		SupportContract bool `json:"supportContract"`
	} `json:"versions"`
}

type GetGatewayPieChartResponse

type GetGatewayPieChartResponse struct {
	LastUpdate  time.Time `json:"lastUpdate"`
	Production  int       `json:"production"`
	Consumption int       `json:"consumption"`
	Battery     struct {
		Capacity           int `json:"capacity"`
		BatteryCharging    int `json:"batteryCharging"`
		BatteryDischarging int `json:"batteryDischarging"`
	} `json:"battery"`
	Arrows []struct {
		Direction string `json:"direction"`
		Value     int    `json:"value"`
	} `json:"arrows"`
}

type GetLowRateTariffResponse

type GetLowRateTariffResponse struct {
	MondayFridayFrom string `json:"Monday_Friday_from"`
	MondayFridayTo   string `json:"Monday_Friday_to"`
	SatudayFrom      string `json:"Satuday_from"`
	SatudayTo        string `json:"Satuday_to"`
	SundayFrom       string `json:"Sunday_from"`
	SundayTo         string `json:"Sunday_to"`
}

type GetSensorConsumptionStatisticsResponse

type GetSensorConsumptionStatisticsResponse struct {
	SensorId string `json:"sensorId"`
	Period   string `json:"period"`
	Data     []struct {
		CreatedAt   string  `json:"createdAt"`
		Consumption float64 `json:"consumption"`
	} `json:"data"`
	TotalConsumption float64 `json:"totalConsumption"`
}

type GetSensorDataResponse

type GetSensorDataResponse struct {
	Date time.Time  `json:"date"`
	Data SensorData `json:"data"`
}

type GetSensorResponse

type GetSensorResponse SensorInfo

type GetSensorsResponse

type GetSensorsResponse []SensorInfo

type HeatPumpOperationState

type HeatPumpOperationState int
const (
	NoInformation HeatPumpOperationState = iota
	Standby
	Heating
	WarmWater
	PartialError
	Failure
	Cooling
	EVU
	Defrosting
)

type SensorData

type SensorData struct {
	Id                    string `json:"_id"`
	AccumulatedErrorCount int    `json:"accumulatedErrorCount"`
	CurrentPowerInvSm     int    `json:"currentPowerInvSm,omitempty"`
	CurrentEnergy         int    `json:"currentEnergy,omitempty"`
	Errors                []int  `json:"errors"`
	Signal                string `json:"signal"`
	ActiveDevice          int    `json:"activeDevice,omitempty"`
	CurrentPower          int    `json:"currentPower,omitempty"`
	SwitchState           int    `json:"switchState,omitempty"`
	CurrentWaterTemp      int    `json:"currentWaterTemp,omitempty"`
	Status                int    `json:"status,omitempty"`
	SOC                   int    `json:"SOC,omitempty"`
}

type SensorInfo

type SensorInfo struct {
	Id          string `json:"_id"`
	Priority    int    `json:"priority"`
	DeviceType  string `json:"device_type"`
	Signal      string `json:"signal"`
	Type        string `json:"type"`
	DeviceGroup string `json:"device_group"`
	Ip          string `json:"ip"`
	Tag         struct {
		Id   string `json:"_id"`
		Name string `json:"name"`
	} `json:"tag"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

type StatisticPeriod

type StatisticPeriod string

Jump to

Keyboard shortcuts

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