advantageair

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

go-advantage-air

Go client for the Advantage Air system

Usage
go get -u github.com/axatol/go-advantage-air
Example
package main

import advantageair "github.com/axatol/go-advantage-air"

func main() {
  ctx := context.Background()
  client := advantageair.NewClient("http://192.168.1.2:2025")

  data, err := client.GetSystemData(ctx)
  if err != nil {
    panic(err)
  }

  zone := data.GetAirconByID("ac1").GetZoneByName("z01")
  if zone.State == advantageair.AirconZoneStateOpen {
    change := advantageair.
      NewChange().
      SetAirconZoneState(advantageair.AirconZoneStateClose)

    if err := client.SetAircon(ctx, change); err != nil {
      panic(err)
    }
  }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aircon

type Aircon struct {
	Info  AirconInfo            `json:"info"`
	Zones map[string]AirconZone `json:"zones"`
}

func (*Aircon) GetZoneByID

func (a *Aircon) GetZoneByID(id string) *AirconZone

func (*Aircon) GetZoneByName

func (a *Aircon) GetZoneByName(name string) *AirconZone

func (*Aircon) GetZoneByNumber

func (a *Aircon) GetZoneByNumber(number int64) *AirconZone

type AirconFanSpeed

type AirconFanSpeed string
const (
	AirconFanSpeedLow    AirconFanSpeed = "low"
	AirconFanSpeedMedium AirconFanSpeed = "medium"
	AirconFanSpeedHigh   AirconFanSpeed = "high"
	AirconFanSpeedAuto   AirconFanSpeed = "auto"
)

type AirconInfo

type AirconInfo struct {
	Error   string `json:"airconErrorCode"`
	Fan     string `json:"fan"`
	Mode    string `json:"mode"`
	MyZone  int64  `json:"myZone"`
	Name    string `json:"name"`
	SetTemp int64  `json:"setTemp"`
	State   string `json:"state"`
}

type AirconMode

type AirconMode string
const (
	AirconModeCool AirconMode = "cool"
	AirconModeHeat AirconMode = "heat"
	AirconModeFan  AirconMode = "fan"
	AirconModeDry  AirconMode = "dry"
)

type AirconState

type AirconState string
const (
	AirconStateOpen  AirconState = "on"
	AirconStateClose AirconState = "off"
)

type AirconZone

type AirconZone struct {
	Error               int64   `json:"error"`
	MeasuredTemperature float64 `json:"measuredTemp"`
	Name                string  `json:"name"`
	Number              int64   `json:"number"`
	SensorUID           string  `json:"SensorUid"`
	SetTemperature      int64   `json:"setTemp"`
	State               string  `json:"state"`
}

type AirconZoneState

type AirconZoneState string
const (
	AirconZoneStateOpen  AirconZoneState = "open"
	AirconZoneStateClose AirconZoneState = "close"
)

type Change

type Change interface {
	SetAirconState(aircon string, state AirconState) Change                        // SetAirconState turns an aircon on or off.
	SetAirconMode(aircon string, mode AirconMode) Change                           // SetAirconMode sets the mode of an aircon, e.g. heating/cooling.
	SetAirconFan(aircon string, speed AirconFanSpeed) Change                       // SetAirconFan sets the fan speed of an aircon.
	SetAirconZoneTemperature(aircon string, zone string, temperature int64) Change // SetAirconZoneTemperature sets the temperature of a zone.
	SetAirconZoneState(aircon string, zone string, state AirconZoneState) Change   // SetAirconZoneState opens or closes airflow to a zone.
}

Change is the interface for building a change to the system.

func NewChange

func NewChange() Change

type Client

type Client interface {
	// GetSystemInfo returns the system info the hub responds with by default.
	GetSystemInfo(ctx context.Context) (string, error)
	// GetSystemData returns the current state of the system.
	GetSystemData(ctx context.Context) (*SystemData, error)
	// SetAircon sets the state of the aircon.
	SetAircon(ctx context.Context, change Change) error
}

Client is the interface for interacting with the Advantage Air hub.

func NewClient

func NewClient(address string, retries int) Client

NewClient returns a new Client.

The address should be the address of the Advantage Air hub, including protocol and port, e.g. http://192.168.1.2:2025.

type SetResponse

type SetResponse struct {
	Acknowledged bool   `json:"ack"`
	Request      string `json:"request"`
}

type System

type System struct {
	ServiceVersion string            `json:"aaServiceRev"`
	DeviceNames    map[string]string `json:"deviceNames"`
	AppRevision    string            `json:"myAppRev"`
	Name           string            `json:"name"`
	NeedsUpdate    bool              `json:"needsUpdate"`
	TSPErrorCode   string            `json:"tspErrorCode"`
	TSPIP          string            `json:"tspIp"`
	TSPModel       string            `json:"tspModel"`
}

type SystemData

type SystemData struct {
	Aircons map[string]Aircon `json:"aircons"`
	System  System            `json:"system"`
}

func (*SystemData) GetAirconByID

func (s *SystemData) GetAirconByID(id string) *Aircon

func (*SystemData) GetAirconByName

func (s *SystemData) GetAirconByName(name string) *Aircon

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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