core

package
v0.0.0-...-a662f2c Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2023 License: Unlicense Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Sunday = 1 << iota
	Monday
	Tuesday
	Wednesday
	Thursday
	Friday
	Saturday
	Week
	WeekEnd
)
View Source
const (
	// DefaultInterval is used when interval is not set (or set to zero)
	DefaultInterval = time.Minute * 10
)

Variables

This section is empty.

Functions

func InitCoordinates

func InitCoordinates(zoneName string) error

InitCoordinates gets the latitude and longitude of a Home Assistant zone entity

func StringInSliceP

func StringInSliceP(str string, patterns []string) bool

StringInSliceP checks whether a string is present in the given slice (using regexp patterns)

Types

type Action

type Action struct {

	// Entities triggers events only from specific lights. No filter -> all events arrive
	// Use either trigger_entities OR trigger_events
	Entities []model.HassEntity `mapstructure:"trigger_entities"`
	// EventTypes triggers events only from specific event type
	// Use either trigger_entities OR trigger_events
	EventTypes []string `mapstructure:"trigger_events"`
	// contains filtered or unexported fields
}

Action is triggered on state change

func (*Action) Disable

func (a *Action) Disable()

func (*Action) Enable

func (a *Action) Enable()

func (*Action) GetEntitiesForTrigger

func (a *Action) GetEntitiesForTrigger() []model.HassEntity

GetEntitiesForTrigger godoc

func (*Action) GetEventTypesForTrigger

func (a *Action) GetEventTypesForTrigger() []string

GetEventTypesForTrigger godoc

func (*Action) GetName

func (a *Action) GetName() string

GetName godoc

func (*Action) GinHandler

func (a *Action) GinHandler(c *gin.Context)

GinHandler godoc

func (*Action) IsDisabled

func (a *Action) IsDisabled() bool

IsDisabled godoc

func (*Action) IsEnabled

func (a *Action) IsEnabled() bool

func (*Action) NeedsInitialization

func (a *Action) NeedsInitialization() bool

NeedsInitialization specifies if this Actionable needs to be triggered with a dummy event when program starts (or conf is reloaded)

func (*Action) Trigger

func (a *Action) Trigger(e *model.HassEvent)

Trigger godoc

type Actionable

type Actionable interface {
	Automate
	GetEntitiesForTrigger() []model.HassEntity
	GetEventTypesForTrigger() []string
	Trigger(e *model.HassEvent)
	GinHandler(c *gin.Context)
	// NeedsInitialization specifies if this Actionable needs to be triggered with a dummy event
	// when program starts (or conf is reloaded)
	NeedsInitialization() bool
}

Actionable is an interface to react on change event

type Automate

type Automate interface {
	IsEnabled() bool
	Enable()
	Disable()
	GetName() string
}

Automate is the base struct for all kind of automation stuff

type Checkable

type Checkable interface {
	Configurable
	routines.Runnable
	GetModular() Modular
}

Checkable is an interface to check something at a regular interval

type Checker

type Checker struct {
	Module Modular
	// contains filtered or unexported fields
}

Checker checks a Modular at a regular interval

func (*Checker) Configure

func (c *Checker) Configure(data interface{}, module interface{}) error

Configure reads the configuration and returns a new Checkable object

func (*Checker) GetModular

func (c *Checker) GetModular() Modular

GetModular godoc

func (*Checker) GetName

func (c *Checker) GetName() string

GetName returns the name of this runnable object

func (*Checker) IsAutoStart

func (c *Checker) IsAutoStart() bool

func (*Checker) IsStarted

func (c *Checker) IsStarted() bool

IsStarted checks whether or not the routine is already started

func (*Checker) Start

func (c *Checker) Start() error

Start starts to check

func (*Checker) Stop

func (c *Checker) Stop()

Stop stops to check

type Configurable

type Configurable interface {
	Configure(config interface{}, obj interface{}) error
}

Configurable is an interface to make any object configurable using a config file

type Coordinates

type Coordinates interface {
	routines.Runnable
	GetSunriseSunset() (time.Time, time.Time, error)
	IsDarkNow(offsetDawn, offsetDusk time.Duration) bool
	GetLatitude() float64
	GetLongitude() float64
}

Coordinates represents GPS coordinates using latitude and longitude

func Coords

func Coords() Coordinates

Coords returns the Coordinates singleton

type CronEntry

type CronEntry struct {
	Expr     string             `mapstructure:"expr"`
	Action   string             `mapstructure:"action"`
	Entities []model.HassEntity `mapstructure:"entities"`
}

CronEntry is a struct to configure a crontab's entry

func (*CronEntry) Configure

func (c *CronEntry) Configure(data interface{}, i interface{}) error

Configure reads the configuration and returns a new Checkable object

func (*CronEntry) GetActionFunc

func (c *CronEntry) GetActionFunc() func()

GetActionFunc returns a func to execute when cron time is triggered

type Crontab

type Crontab interface {
	routines.Runnable
	AddFunc(spec string, cmd func()) error
}

Crontab is a Cron object

func NewCrontab

func NewCrontab() Crontab

NewCrontab returns a new pointer to a Crontab object

type HeaterSchedule

type HeaterSchedule struct {
	Beg     time.Time `mapstructure:"beg"`
	End     time.Time `mapstructure:"end"`
	Comfort float64   `mapstructure:"comfort"`
	Eco     float64   `mapstructure:"eco"`
}

HeaterSchedule represents a heater's schedule

func (HeaterSchedule) IsActive

func (c HeaterSchedule) IsActive(t time.Time) bool

IsActive returns true if given 't' is between c.Beg and c.End

func (HeaterSchedule) MarshalZerologObject

func (c HeaterSchedule) MarshalZerologObject(event *zerolog.Event)

MarshalZerologObject godoc

func (HeaterSchedule) TodayBeg

func (c HeaterSchedule) TodayBeg(now time.Time, loc *time.Location) time.Time

TodayBeg returns c.Beg time with today's date

func (HeaterSchedule) TodayEnd

func (c HeaterSchedule) TodayEnd(now time.Time, loc *time.Location) time.Time

TodayEnd returns c.End time with today's date

type HeaterSchedules

type HeaterSchedules struct {
	Scheds         map[SchedulesDays][]HeaterSchedule `mapstructure:"schedules"`
	DefaultEco     float64                            `mapstructure:"default_eco"`
	ManualOverride model.HassEntity                   `mapstructure:"manual_override"`
	Thermostat     model.HassEntity                   `mapstructure:"thermostat"`
	DateBegin      model.DayMonthDate                 `mapstructure:"date_begin"`
	DateEnd        model.DayMonthDate                 `mapstructure:"date_end"`
}

HeaterSchedules stores all schedules for a heater

func (*HeaterSchedules) Configure

func (c *HeaterSchedules) Configure(data interface{}, i interface{}) error

Configure reads the configuration and returns a new Checkable object

func (*HeaterSchedules) GetTemperatureToSet

func (c *HeaterSchedules) GetTemperatureToSet(t time.Time) float64

GetTemperatureToSet returns the temperature to set corresponding to the time given in parameter

func (*HeaterSchedules) MarshalZerologObject

func (c *HeaterSchedules) MarshalZerologObject(event *zerolog.Event)

MarshalZerologObject godoc

func (*HeaterSchedules) Sort

func (c *HeaterSchedules) Sort()

Sort sorts schedules

type Modular

type Modular interface {
	Automate
	Check()
	GetInterval() time.Duration
	GinHandler(c *gin.Context)
}

Modular is an interface that will implement a check function

type Module

type Module struct {
	Interval time.Duration `mapstructure:"interval"`
	// contains filtered or unexported fields
}

Module is the base struct to build a module

func (*Module) Check

func (m *Module) Check()

Check godoc

func (*Module) Disable

func (a *Module) Disable()

func (*Module) Enable

func (a *Module) Enable()

func (*Module) GetInterval

func (m *Module) GetInterval() time.Duration

GetInterval godoc

func (*Module) GetName

func (a *Module) GetName() string

func (*Module) GinHandler

func (m *Module) GinHandler(c *gin.Context)

GinHandler godoc

func (*Module) IsDisabled

func (a *Module) IsDisabled() bool

IsDisabled godoc

func (*Module) IsEnabled

func (a *Module) IsEnabled() bool

type RandomLightsRoutine

type RandomLightsRoutine interface {
	routines.Runnable
	GetName() string
	GetSlots() uint32
}

func NewRandomLightsRoutine

func NewRandomLightsRoutine(name string, slots uint32, lights []model.RandomLight, startTime, endTime time.Time, odds uint32, refreshEvery time.Duration) (RandomLightsRoutine, error)

type SchedulesDays

type SchedulesDays string

SchedulesDays are the days when the schedules applies Examples:

  • week
  • monday,tuesday,friday
  • monday,wednesday,weekend

func (SchedulesDays) AsFlag

func (s SchedulesDays) AsFlag() int

AsFlag returns an int from a SchedulesDays

func (SchedulesDays) IsScheduled

func (s SchedulesDays) IsScheduled(t time.Time) bool

IsScheduled returns true if the day of 't' is contained into 's' SchedulesDays

type Trigger

type Trigger struct {
	Action Actionable
}

Trigger triggers an action when a change occurs

func (*Trigger) Configure

func (t *Trigger) Configure(data interface{}, action interface{}) error

Configure godoc

func (*Trigger) GetActionable

func (t *Trigger) GetActionable() Actionable

GetActionable godoc

func (*Trigger) GetName

func (t *Trigger) GetName() string

GetName godoc

type Triggerable

type Triggerable interface {
	Configurable
	GetActionable() Actionable
	GetName() string
}

Triggerable is an interface to trigger an action when a change is detected

Jump to

Keyboard shortcuts

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