agent

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: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PollingPeriod - Polling period seconds for fetch to agent
	PollingPeriod = 5000
)

Variables

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

ErrAlreadyExists - When already exists

View Source
var ErrAmbientNotFetched = &status.Error{
	Error: errors.New("ambient not fetched"),
	Code:  "ERR_AMBIENT_NOT_FETCHED",
}

ErrAmbientNotFetched - When ambient not fetched

View Source
var ErrDefaultAgentRequired = &status.Error{
	Error: errors.New("default agent required"),
	Code:  "ERR_DEFAULT_AGENT_REQUIRED",
}

ErrDefaultAgentRequired - When try turn off last default agent

View Source
var ErrNoAgent = &status.Error{
	Error: errors.New("no agents"),
	Code:  "ERR_NO_AGENT",
}

ErrNoAgent - When there is no agent

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

ErrNotFound - When agent does not exists

View Source
var ErrRemoveDefaultAgent = &status.Error{
	Error: errors.New("can't delete default agent"),
	Code:  "ERR_REMOVE_DEFAULT_AGENT",
}

ErrRemoveDefaultAgent - When try remove default agent

Functions

This section is empty.

Types

type Agent

type Agent struct {
	// ID - Agent ID
	ID string `json:"id" default:"<UNIQUE_ID>"`

	// Address - Agent Address (ex. `localhost:8081`)
	Address string `json:"address" validate:"required" example:"localhost:8081"`

	// Default - Agent to use by mainly
	Default bool `json:"default,omitempty"`

	// Label - Name of Agent (ex. `Bedroom`)
	Label string `json:"label,omitempty" example:"Bedroom"`

	// Online - Check online
	Online bool `json:"online,omitempty"`
}

Agent - Store of Agent

type AgentService added in v0.0.27

type AgentService struct {
	Storage *Storage
	Ambient *Ambient
}

AgentService - Provide Agent calls

func New

func New(basePath string) (*AgentService, error)

New - Initialize agent service

func (*AgentService) Add added in v0.0.31

func (as *AgentService) Add(address string, label string) (*Agent, error)

Add - Add agent

func (*AgentService) GetAll added in v0.0.31

func (as *AgentService) GetAll() ([]Agent, error)

GetAll - Get all agents

func (*AgentService) GetAmbient added in v0.0.27

func (as *AgentService) GetAmbient() (*Ambient, error)

func (*AgentService) InitPoll added in v0.0.27

func (as *AgentService) InitPoll()

InitPoll - Start Poll task

func (*AgentService) Poll added in v0.0.27

func (as *AgentService) Poll(c context.Context, agent *Agent) error

Poll - Execute Poll

func (*AgentService) PostSwitch added in v0.0.27

func (as *AgentService) PostSwitch(ctx context.Context, id, mac, command string) error

func (*AgentService) SendIR added in v0.0.27

func (as *AgentService) SendIR(ctx context.Context, id string, h []*hex.HexCode) error

type Ambient

type Ambient struct {
	// Temp - Temperature (celsius)
	Temp float32 `json:"temp" example:"27.5"`

	// Humid - Humidity (percent)
	Humid float32 `json:"humid" example:"50.3"`

	// Pressure - Pressure (hpa)
	Pressure float32 `json:"pressure" example:"1009.4"`

	// LastFetch - Fetched date
	LastFetch time.Time `json:"last_fetch" example:"2020-01-01 01:02:03 UTC"`
}

Ambient - Ambient sensor from BME280

type IRCode

type IRCode struct {
	Code []int `json:"code"`
}

type Payload added in v0.0.9

type Payload struct {
	Signal   []int `json:"signal"`
	Interval int   `json:"interval,omitempty"`
}

type Storage added in v0.0.27

type Storage struct {
	Path         string
	Agents       []*Agent
	DefaultAgent *Agent
}

func NewStorage added in v0.0.27

func NewStorage(basePath string) (*Storage, error)

func (*Storage) Add added in v0.0.31

func (s *Storage) Add(address string, isDefault bool, label string) (*Agent, error)

func (*Storage) GetAll added in v0.0.31

func (s *Storage) GetAll() ([]Agent, error)

GetAll - Get all agents

func (*Storage) GetByAddress added in v0.0.31

func (s *Storage) GetByAddress(address string) *Agent

GetByAddress - Return agent by Address

func (*Storage) GetByID added in v0.0.31

func (s *Storage) GetByID(id string) *Agent

GetByID - Return agent by ID

func (*Storage) GetDefaultAgent added in v0.0.31

func (s *Storage) GetDefaultAgent() (Agent, error)

GetDefaultAgent - Return default agent

func (*Storage) Remove added in v0.0.32

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

Remove - Remove agent

func (*Storage) Update added in v0.0.32

func (s *Storage) Update(id string, entry *Agent) (*Agent, error)

Update - Update agent settings

type SwitchBot

type SwitchBot struct {
	Mac   string `json:"mac" example:"xx:xx:xx:xx:xx:xx"`
	Type  string `json:"type" example:"TOGGLE"`
	State string `json:"state" example:"ON"`
}

func (*SwitchBot) ValidateMacAddress

func (sb *SwitchBot) ValidateMacAddress() bool

ValidateMacAddress - Check mac address range & format

Jump to

Keyboard shortcuts

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