controller

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyExists = &status.Error{
	Error: errors.New("already exists"),
	Code:  "ERR_CONTROLLER_ALREADY_EXISTS",
}

ErrAlreadyExists - When already exists

View Source
var ErrInvalidType = &status.Error{
	Error: errors.New("invalid type provided"),
	Code:  "ERR_INVALID_TYPE",
}

ErrInvalidType - When provided invalid type

View Source
var ErrNameTooLong = &status.Error{
	Error: errors.New("name too long"),
	Code:  "ERR_NAME_TOO_LONG",
}

ErrNameTooLong - When name than 20 characters

View Source
var ErrNotFound = &status.Error{
	Error: errors.New("controller not found"),
	Code:  "ERR_CONTROLLER_NOT_FOUND",
}

ErrNotFound - When controller does not exists

View Source
var ErrUnsupportedKind = &status.Error{
	Error: errors.New("unsupported kind"),
	Code:  "ERR_UNSUPPORTED_KIND",
}

ErrUnsupportedKind - When provided unsupported Kind

View Source
var ErrUnsupportedType = &status.Error{
	Error: errors.New("unsupported type"),
	Code:  "ERR_UNSUPPORTED_TYPE",
}

ErrUnsupportedType - When provided unsupported Type

View Source
var ErrValidateMacAddress = &status.Error{
	Error: errors.New("invalid mac address"),
	Code:  "ERR_INVALID_MAC_ADDRESS",
}

ErrValidateMacAddress - When error occurred while in validate mac address...

Functions

This section is empty.

Types

type Controller

type Controller struct {
	Storage *Storage
	Agent   *agent.AgentService
	Remotes *remotego.Remote
}

func New

func New(basePath string, agent *agent.AgentService) (*Controller, error)

func (*Controller) Push added in v0.0.41

func (c *Controller) Push(id string, es *EntrySet) (*PushResult, error)

func (*Controller) RaiseSwitchBot

func (c *Controller) RaiseSwitchBot(id string, command string) error

type Entry

type Entry struct {
	// ID - Generated ID
	ID string `json:"id,omitempty" example:"<UNIQUE_ID>"`

	// AgentID - Use for another agent
	AgentID string `json:"agent_id,omitempty" example:"<AGENT_ID>"`

	// Name - ex. Bedroom Airconditioner
	Name string `json:"name" validate:"required" example:"Bedroom Airconditioner"`

	// Kind - AIRCON, LIGHT, SWITCHBOT...
	Kind appliances.Kind `json:"kind" validate:"required" example:"AIRCON"`

	// Type - type of controller (how to use?) / ex. REMOTE, SWITCHBOT...
	Type string `json:"type" validate:"required" example:"REMOTE"`

	// Remote - Remote Controller settings (required when type is REMOTE)
	Remote *remote.Remote `json:"remote,omitempty"`

	// SwitchBot - SwitchBot settings (required when type is SWITCHBOT)
	SwitchBot *agent.SwitchBot `json:"switchbot,omitempty"`

	// Appliances - State of appliances
	Appliances *appliances.State `json:"appliances,omitempty"`
}

type EntrySet added in v0.0.41

type EntrySet struct {
	Remote    appliances.Request `json:"remote,omitempty"`
	SwitchBot *SwitchBotEntry    `json:"switchbot,omitempty"`
}

EntrySet - Combined remote-go entry (aircon, light etc.)

type Options

type Options struct {
	// Remote
	Remote *remote.Remote `json:"remote,omitempty"`

	// Switch....
	SwitchBot *agent.SwitchBot `json:"switchbot,omitempty"`

	// AgentID
	AgentID string `json:"agent_id,omitempty"`
}

type PushResult added in v0.0.41

type PushResult struct {
	// Aircon - use entry (return current mode)
	Aircon *appliances.Aircon `json:"aircon,omitempty"`

	// Light - use state (return all values)
	Light *appliances.LightState `json:"light,omitempty"`

	// SwitchBot - use entry (return requested command)
	SwitchBot *SwitchBotEntry `json:"switchbot,omitempty"`
}

PushResult - result of push

type Storage

type Storage struct {
	Path       string
	Entries    map[string]*Entry
	Remotes    *remotego.Remote
	AgentStore *agent.Storage
}

func NewStorage

func NewStorage(basePath string, remotes *remotego.Remote, agents *agent.Storage) (*Storage, error)

func (*Storage) Create

func (s *Storage) Create(name string, kind appliances.Kind, t string, opts *Options) (*Entry, error)

Create - Create new Controller

func (*Storage) GetAll

func (s *Storage) GetAll() map[string]*Entry

GetAll - Get all controllers

func (*Storage) GetByID

func (s *Storage) GetByID(id string) (*Entry, error)

func (*Storage) GetByName

func (s *Storage) GetByName(name string) (*Entry, error)

GetByName - Get Controller by Name

func (*Storage) Load

func (s *Storage) Load() error

func (*Storage) Remove

func (s *Storage) Remove(id string) error

Remove - Remove controller

func (*Storage) Save

func (s *Storage) Save() error

func (*Storage) Update

func (s *Storage) Update(id, name string, kind appliances.Kind, t string, opts *Options) (*Entry, error)

Update - Update Controller

type SwitchBotEntry added in v0.0.41

type SwitchBotEntry struct {
	Command string `json:"command,omitempty"`
}

SwitchBotEntry - request entry of switchbot

Jump to

Keyboard shortcuts

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