homewizard

package module
v0.0.0-...-81a2e4c Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2019 License: MIT Imports: 9 Imported by: 0

README

homewizard-go

Golang API client for HomeWizard

Documentation

Overview

package homewizard implements basic API calls for reading HomeWizard data

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscoverIP

func DiscoverIP() (*net.IP, error)

Types

type Camera

type Camera struct {
	ID       int      `json:"id"`
	IP       string   `json:"ip"`
	Mode     int      `json:"mode"`
	Model    int      `json:"model"`
	Name     string   `json:"name"`
	Password string   `json:"password"`
	Port     string   `json:"port"`
	Presets  []Preset `json:"presets"`
	URL      struct {
		Auth  string `json:"auth"`
		Path  string `json:"path"`
		Query string `json:"query"`
	} `json:"url"`
	Username string `json:"username"`
}

type ConfigFile

type ConfigFile struct {
	IP       string
	Password string
	Verbose  bool
}

func ReadConfig

func ReadConfig(cfgFile string) (*ConfigFile, error)

type DiscoverResponse

type DiscoverResponse struct {
	IP     string `json:"ip"`
	Status string `json:"status"`
}
type Energylink struct{} //TODO

type Energymeter

type Energymeter struct {
	Code       string  `json:"code"`
	DayTotal   float64 `json:"dayTotal"`
	Favorite   string  `json:"favorite"`
	ID         int     `json:"id"`
	Key        string  `json:"key"`
	LowBattery string  `json:"lowBattery"`
	Name       string  `json:"name"`
	Po         int     `json:"po"`
	PoMax      int     `json:"po+"`
	PoMaxT     string  `json:"po+t"`
	PoMin      int     `json:"po-"`
	PoMinT     string  `json:"po-t"`
}

type GetEnergyMetersInput

type GetEnergyMetersInput struct{}

func (*GetEnergyMetersInput) Route

func (i *GetEnergyMetersInput) Route() *RouteInfo

type GetEnergyMetersOutput

type GetEnergyMetersOutput struct {
	ResponseElems
	Response []Energymeter `json:"response"`
}

type GetSensorsInput

type GetSensorsInput struct{}

func (*GetSensorsInput) Route

func (i *GetSensorsInput) Route() *RouteInfo

type GetSensorsOutput

type GetSensorsOutput struct {
	ResponseElems
	Response struct {
		Cameras         []Camera         `json:"cameras"`
		Energylinks     []Energylink     `json:"energylinks"`
		Energymeters    []Energymeter    `json:"energymeters"`
		Heatlinks       []Heatlink       `json:"heatlinks"`
		Hues            []Hue            `json:"hues"`
		Kakusensors     []Kakusensor     `json:"kakusensors"`
		Preset          int              `json:"preset"`
		Rainmeters      []Rainmeter      `json:"rainmeters"`
		Scenes          []Scene          `json:"scenes"`
		Switches        []Switch         `json:"switches"`
		Thermometers    []Thermometer    `json:"thermometers"`
		Time            Time             `json:"time"`
		Uvmeters        []Uvmeter        `json:"uvmeters"`
		Weatherdisplays []Weatherdisplay `json:"weatherdisplays"`
		Windmeters      []Windmeter      `json:"windmeters"`
	} `json:"response"`
}

type GetSwitchesInput

type GetSwitchesInput struct{}

func (*GetSwitchesInput) Route

func (i *GetSwitchesInput) Route() *RouteInfo

type GetSwitchesOutput

type GetSwitchesOutput struct {
	ResponseElems
	Response Switches `json:"response"`
}

type GetThermometerGraphsDWOutput

type GetThermometerGraphsDWOutput struct {
	ResponseElems
	Response []ThermGraphT `json:"response"`
}

For day and week graphs

func (*GetThermometerGraphsDWOutput) Elem

func (*GetThermometerGraphsDWOutput) Len

type GetThermometerGraphsInput

type GetThermometerGraphsInput struct {
	Id     int
	Period TimePeriod //day-week-month-year
}

func (*GetThermometerGraphsInput) Route

type GetThermometerGraphsMYOutput

type GetThermometerGraphsMYOutput struct {
	ResponseElems
	Response []ThermGraphMinMax `json:"response"`
}

For month and year graphs

func (*GetThermometerGraphsMYOutput) Elem

func (*GetThermometerGraphsMYOutput) Len

type GetThermometersInput

type GetThermometersInput struct{}

func (*GetThermometersInput) Route

func (i *GetThermometersInput) Route() *RouteInfo

type GetThermometersOutput

type GetThermometersOutput struct {
	ResponseElems
	Response []Thermometer `json:"response"`
}

type HWInput

type HWInput interface {
	Route() *RouteInfo
}

type HWOutput

type HWOutput interface {
	GetStatus() string
	GetVersion() string
}

type Handshake

type Handshake struct {
	Homewizard              string `json:"homewizard"`
	Version                 string `json:"version"`
	Firmwareupdateavailable string `json:"firmwareupdateavailable"`
	Appupdaterequired       string `json:"appupdaterequired"`
	Serial                  string `json:"serial"`
}

type HandshakeInput

type HandshakeInput struct{}

func (*HandshakeInput) Route

func (i *HandshakeInput) Route() *RouteInfo

type HandshakeOutput

type HandshakeOutput struct {
	ResponseElems
	Response Handshake `json:"response"`
}
type Heatlink struct{} //TODO

type HomeWizard

type HomeWizard struct {
	Name       string
	IP         net.IP
	Password   string
	Verbose    bool
	HTTPClient *http.Client
}

HomeWizard is the main struct for calling all methods

func NewHomeWizard

func NewHomeWizard(ip string, password string) *HomeWizard

func NewHomeWizardFromConfig

func NewHomeWizardFromConfig(cfgFile string) (*HomeWizard, error)

func NewHomeWizardFromDiscovery

func NewHomeWizardFromDiscovery(password string, verbose bool) (*HomeWizard, error)

func (*HomeWizard) Do

func (hw *HomeWizard) Do(in HWInput, out HWOutput) error

func (*HomeWizard) GetEnergyMeters

func (hw *HomeWizard) GetEnergyMeters() (*GetEnergyMetersOutput, error)

func (*HomeWizard) GetSensors

func (hw *HomeWizard) GetSensors() (*GetSensorsOutput, error)

func (*HomeWizard) GetSwitches

func (hw *HomeWizard) GetSwitches() (*GetSwitchesOutput, error)

func (*HomeWizard) GetThermometerGraph

func (hw *HomeWizard) GetThermometerGraph(id int, period TimePeriod) (ThermGraph, error)

func (*HomeWizard) GetThermometers

func (hw *HomeWizard) GetThermometers() (*GetThermometersOutput, error)

func (*HomeWizard) OperateSwitch

func (hw *HomeWizard) OperateSwitch(in *OperateSwitchInput) (*OperateSwitchOutput, error)

type Hue

type Hue struct{} //TODO

type Kakusensor

type Kakusensor struct {
	Cameraid  int    `json:"cameraid"`
	Favorite  string `json:"favorite"`
	ID        int    `json:"id"`
	Name      string `json:"name"`
	Status    string `json:"status"`
	Timestamp string `json:"timestamp"`
	Type      string `json:"type"`
}

type OperateSwitchInput

type OperateSwitchInput struct {
	ID            int
	Type          SwitchType
	DesiredStatus SwitchStatus
	DesiredTte    float64
}

func (*OperateSwitchInput) Route

func (i *OperateSwitchInput) Route() *RouteInfo

type OperateSwitchOutput

type OperateSwitchOutput struct {
	ResponseElems
}

type Preset

type Preset struct{} //TODO

type Rainmeter

type Rainmeter struct {
	Mm float64 `json:"mm"`
	H3 float64 `json:"3h"`
}

type ResponseElems

type ResponseElems struct {
	Request struct {
		Route string `json:"route"`
	} `json:"request"`
	Status  string `json:"status"`
	Version string `json:"version"`
}

func (*ResponseElems) GetStatus

func (r *ResponseElems) GetStatus() string

func (*ResponseElems) GetVersion

func (r *ResponseElems) GetVersion() string

type RouteInfo

type RouteInfo struct {
	Method string
	Route  string
}

type Scene

type Scene struct{} //TODO

type Switch

type Switch struct {
	ID       int          `json:"id"`
	Name     string       `json:"name"`
	Type     SwitchType   `json:"type"`
	Status   SwitchStatus `json:"status"`
	Favorite string       `json:"favorite"`
	Tte      float64      `json:"tte"`
}

type SwitchStatus

type SwitchStatus string
const (
	SwitchStatusOn  SwitchStatus = "on"
	SwitchStatusOff SwitchStatus = "off"
)

func (SwitchStatus) Revert

func (st SwitchStatus) Revert() SwitchStatus

type SwitchType

type SwitchType string
const (
	SwitchTypeSwitch   SwitchType = "switch"
	SwitchTypeRadiator SwitchType = "radiator"
	SwitchTypeDimmer   SwitchType = "dimmer"
)

type Switches

type Switches []Switch

func (Switches) ByID

func (sws Switches) ByID(id int) *Switch

func (Switches) ByName

func (sws Switches) ByName(name string) *Switch

func (Switches) ByType

func (sws Switches) ByType(switchType SwitchType) []Switch

type ThermGraph

type ThermGraph interface {
	Len() uint
	Elem(uint) ThermGraphPoint
}

A ThermGraph is a slice of datapoints (graph data) Because HomeWizard returns a different JSON format for specific graphs we can use this interface to read all data

type ThermGraphMinMax

type ThermGraphMinMax struct {
	T     Time    `json:"t"`
	TeMax float64 `json:"te+"`
	TeMin float64 `json:"te-"`
	HuMax int     `json:"hu+"`
	HuMin int     `json:"hu-"`
}

func (*ThermGraphMinMax) Hum

func (g *ThermGraphMinMax) Hum(p int8) int

func (*ThermGraphMinMax) Temp

func (g *ThermGraphMinMax) Temp(p int8) float64

func (*ThermGraphMinMax) Time

func (g *ThermGraphMinMax) Time() *Time

type ThermGraphPoint

type ThermGraphPoint interface {
	Time() *Time
	Temp(int8) float64
	Hum(int8) int
}

A ThermGraphPoint is a single datapoint in a slice of datapoints in graph data Because HomeWizard returns a different JSON format for specific graphs we can use this interface to read all data For Temp() and Time() you pass: - 0 : to get the current temp (or temp of that datapoint) - >0 : to get the maximum temp - <0 : to get the minimum temp

type ThermGraphT

type ThermGraphT struct {
	T  Time    `json:"t"`
	Te float64 `json:"te"`
	Hu int     `json:"hu"`
}

func (*ThermGraphT) Hum

func (g *ThermGraphT) Hum(p int8) int

func (*ThermGraphT) Temp

func (g *ThermGraphT) Temp(p int8) float64

func (*ThermGraphT) Time

func (g *ThermGraphT) Time() *Time

type Thermometer

type Thermometer struct {
	Code       string  `json:"code"`
	Favorite   string  `json:"favorite"`
	Hu         int     `json:"hu"`
	HuMax      int     `json:"hu+"`
	HuMaxT     string  `json:"hu+t"`
	HuMin      int     `json:"hu-"`
	HuMinT     string  `json:"hu-t"`
	ID         int     `json:"id"`
	LowBattery string  `json:"lowBattery"`
	Model      int     `json:"model"`
	Name       string  `json:"name"`
	Outside    string  `json:"outside"`
	Te         float64 `json:"te"`
	TeMax      float64 `json:"te+"`
	TeMaxT     string  `json:"te+t"`
	TeMin      float64 `json:"te-"`
	TeMinT     string  `json:"te-t"`
	Version    float64 `json:"version"`
}

type Time

type Time struct {
	time.Time
}

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(b []byte) error

Format: time: "2015-07-05 22:18"

type TimePeriod

type TimePeriod string
const (
	TimePeriodDay   TimePeriod = "day"
	TimePeriodWeek  TimePeriod = "week"
	TimePeriodMonth TimePeriod = "month"
	TimePeriodYear  TimePeriod = "year"
)

type Uvmeter

type Uvmeter struct{} //TODO

type Weatherdisplay

type Weatherdisplay struct{} //TODO

type Windmeter

type Windmeter struct {
	Ws     float64 `json:"ws"`
	Dir    string  `json:"dir"`
	Gu     float64 `json:"gu"`
	Wc     float64 `json:"wc"`
	WsMax  float64 `json:"ws+"`
	WsMaxT string  `json:"ws+t"`
	WsMin  float64 `json:"ws-"`
	WsMinT string  `json:"ws-t"`
}

Jump to

Keyboard shortcuts

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