shelly

package
v0.0.0-...-15fac35 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package shelly implements calls to a shelly unit using HTTP RPC

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSchedule

func CreateSchedule(ctx context.Context, dest fmt.Stringer, s Schedule) error

func CreateScheduleRefresherSchedule

func CreateScheduleRefresherSchedule(ctx context.Context, dest fmt.Stringer, myPort int) error

CreateScheduleRefresherSchedule will make sure that the schedules are refreshed every day @ 23.55

func DeleteAllSchedules

func DeleteAllSchedules(ctx context.Context, dest fmt.Stringer) error

func DisableSchedules

func DisableSchedules(ctx context.Context, dest fmt.Stringer, ids ...int) error

func DoGet

func DoGet(ctx context.Context, dest fmt.Stringer, method string, options map[string]string) ([]byte, int, error)

func DoRPCCall

func DoRPCCall(ctx context.Context, dest fmt.Stringer, httpMethod, method string, options map[string]string, reqBody []byte) ([]byte, int, error)

DoRPCCall calls RPC endpoints towards the Shelly. Returns body (or nil if empty), http response code and an error

func EnableSchedules

func EnableSchedules(ctx context.Context, dest fmt.Stringer, ids ...int) error

func GetInputState

func GetInputState(ctx context.Context, dest fmt.Stringer) (bool, error)

GetInputState returns true if the controller input is on, false otherwise

func SetSwitch

func SetSwitch(ctx context.Context, dest fmt.Stringer, state State) error

SetSwitch sets the Shelly's switch to the given state

func TurnOff

func TurnOff(ctx context.Context, dest fmt.Stringer) error

TurnOff sets the Shelly's switch to the "Off" state

func TurnOn

func TurnOn(ctx context.Context, dest fmt.Stringer) error

TurnOn sets the Shelly's switch to the "On" state

Types

type Call

type Call struct {
	Method string                 `json:"method"`
	Params map[string]interface{} `json:"params,omitempty"`
}

Call is what the job should do

type JobSpec

type JobSpec struct {
	Id       int    `json:"id,omitempty"`
	Enable   bool   `json:"enable"`
	Timespec string `json:"timespec"`
	Calls    []Call `json:"calls"`
}

JobSpec is a Shelly schedule trigger

func (JobSpec) HasMethod

func (j JobSpec) HasMethod(m string) bool

HasMethod returns true if m is a method in j

func (JobSpec) Methods

func (j JobSpec) Methods() []string

Methods returns the Methods the job calls

func (JobSpec) Time

func (j JobSpec) Time() (time.Time, error)

Time returns the timestamp for the job (with today's date)

type Schedule

type Schedule struct {
	Jobs Schedules `json:"jobs"`
}

Schedule is a top-level shelly schedule collection

func ShellySchedule

func ShellySchedule(in schedule.Schedule, enable bool) Schedule

ShellySchedule converts a schedule.Schedule to something a Shelly can understand.

func (Schedule) Hours

func (s Schedule) Hours() int

type Schedules

type Schedules []JobSpec

func GetSchedules

func GetSchedules(ctx context.Context, ip fmt.Stringer) (Schedules, error)

type State

type State bool
const (
	StateOn  State = true
	StateOff State = false
)

Jump to

Keyboard shortcuts

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