shelly

package module
v0.0.0-...-597aa7a Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2023 License: MIT Imports: 9 Imported by: 0

README

go-shelly

Use a subset of the Shelly HTTP API from Golang to control your device.

Currently only features of outlets are supported, but this repository should be fairly easy to extend. It's only HTTP after all!

How to use?

see client_test.go 😄.

How to build

go install github.com/dmarkham/enumer@latest
go generate ./...
go install

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeviceTypeStrings

func DeviceTypeStrings() []string

DeviceTypeStrings returns a slice of all String values of the enum

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a client for communication with a Shelly-powered device.

func NewClient

func NewClient(device Device) *Client

NewClient returns a new Client that is configured to be talking to the given Device.

func (*Client) GetCurrentPower

func (x *Client) GetCurrentPower() (float64, error)

GetCurrentPower returns the current power consumption of the attached devices in Watts.

func (*Client) IsModeColor

func (x *Client) IsModeColor() (bool, error)

func (*Client) IsModeWhite

func (x *Client) IsModeWhite() (bool, error)

func (*Client) IsPowerOn

func (x *Client) IsPowerOn() (bool, error)

IsPowerOn retrieves if the power is on for the configured device.

func (*Client) SetModeColor

func (x *Client) SetModeColor(opts ModeColorOptions) error

func (*Client) SetModeWhite

func (x *Client) SetModeWhite(opts ModeWhiteOptions) error

func (*Client) SetPower

func (x *Client) SetPower(on bool) error

SetPower sets the power state for the configured device. See documentation at https://shelly-api-docs.shelly.cloud/gen1/#shelly-plug-plugs-relay-0

func (*Client) SetPowerOff

func (x *Client) SetPowerOff() error

SetPowerOff turns the power off for the configured device.

func (*Client) SetPowerOn

func (x *Client) SetPowerOn() error

SetPowerOn turns the power on for the configured device.

type Device

type Device struct {
	Hostname string
	Type     DeviceType
}

Device is a Shelly-powered device

func (Device) GetAPIBaseURL

func (x Device) GetAPIBaseURL() string

GetAPIBaseURL returns the base URL to be used to send commands to this Shelly device.

type DeviceType

type DeviceType int
const (
	PlugS DeviceType = iota
	BulbRGBW
)

func DeviceTypeString

func DeviceTypeString(s string) (DeviceType, error)

DeviceTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func DeviceTypeValues

func DeviceTypeValues() []DeviceType

DeviceTypeValues returns all values of the enum

func (DeviceType) IsADeviceType

func (i DeviceType) IsADeviceType() bool

IsADeviceType returns "true" if the value is listed in the enum definition. "false" otherwise

func (DeviceType) String

func (i DeviceType) String() string

type ModeColorOptions

type ModeColorOptions struct {
	Brightness *int
	Transition *int
	Gain       *int
	Color      *colorful.Color
	Error      error
}

func NewModeColorOptions

func NewModeColorOptions() *ModeColorOptions

func (*ModeColorOptions) MustValidate

func (x *ModeColorOptions) MustValidate() *ModeColorOptions

func (*ModeColorOptions) SetBrightness

func (x *ModeColorOptions) SetBrightness(brightness int) *ModeColorOptions

func (*ModeColorOptions) SetColor

func (x *ModeColorOptions) SetColor(color colorful.Color) *ModeColorOptions

func (*ModeColorOptions) SetGain

func (x *ModeColorOptions) SetGain(gain int) *ModeColorOptions

func (*ModeColorOptions) SetTransitionTime

func (x *ModeColorOptions) SetTransitionTime(milliseconds int) *ModeColorOptions

type ModeWhiteOptions

type ModeWhiteOptions struct {
	Brightness *int
	Transition *int
	Temp       *int
	Error      error
}

func NewModeWhiteOptions

func NewModeWhiteOptions() *ModeWhiteOptions

func (*ModeWhiteOptions) MustValidate

func (x *ModeWhiteOptions) MustValidate() *ModeWhiteOptions

func (*ModeWhiteOptions) SetBrightness

func (x *ModeWhiteOptions) SetBrightness(brightness int) *ModeWhiteOptions

func (*ModeWhiteOptions) SetTemp

func (x *ModeWhiteOptions) SetTemp(kelvin int) *ModeWhiteOptions

func (*ModeWhiteOptions) SetTransitionTime

func (x *ModeWhiteOptions) SetTransitionTime(milliseconds int) *ModeWhiteOptions

Jump to

Keyboard shortcuts

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