automation

package
v0.0.26-beta-rc.4 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: GPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActivateAutomationSystem

func ActivateAutomationSystem() error

Activates all jobs saved in the database, will be used when the server was restarted If a non-critical error occurs, for example the failure to setup a job, it will be returned This function will not cancel directly if an error occurs in order to preserve the automation system's uptime

func CalculateSunRiseSet

func CalculateSunRiseSet(lat float32, lon float32) (SunTime, SunTime)

Returns (sunrise, sunset) based on the provided coordinates which are stored in the server configuration

func CreateNewAutomation

func CreateNewAutomation(
	name string,
	description string,
	hour uint8,
	minute uint8,
	days []uint8,
	homescriptId string,
	owner string,
	enabled bool,
	timingMode database.TimingMode,
) (uint, error)

Creates a new automation which an according database entry Sets up the scheduler based on the provided hour, minute, and days of the week on which the automation should run

func DeactivateAutomationSystem

func DeactivateAutomationSystem() error

Stops all jobs in the automation scheduler

func GenerateCronExpression

func GenerateCronExpression(hour uint8, minute uint8, days []uint8) (string, error)

Generates a cron-expression based on the hour, minute, and days on which the automation should run Is used for sending the owner of an automation a notification or for listing a users automations

func GetDaysFromCronExpression

func GetDaysFromCronExpression(expr string) ([]uint8, error)

Returns a slice which contains the days on which a given cron-expression will run Used for generating a new cron-expression when the timing function is set to either `sunrise` or `sunset`

func Init

func Init() error

Initializes the scheduler

func InitLogger

func InitLogger(logger *logrus.Logger)

func IsValidCronExpression

func IsValidCronExpression(expr string) bool

Validates a given cron-expression, returns false if the given cron-expression is invalid

func ModifyAutomationById

func ModifyAutomationById(automationId uint, newAutomation database.AutomationWithoutIdAndUsername) error

Changes the metadata of a given automation, then restarts it so it uses the updated values such as execution time Is also used after an automation with non-normal timing has been added

func RemoveAutomation

func RemoveAutomation(automationId uint) error

Removes an automation from the database and prevents its further execution

Types

type Automation

type Automation struct {
	Id              uint
	Name            string
	Description     string
	CronExpression  string
	CronDescription string
	HomescriptId    string
	Owner           string
	Enabled         bool
	TimingMode      database.TimingMode
}

func GetUserAutomationById

func GetUserAutomationById(username string, automationId uint) (Automation, bool, error)

Given an username and id, it returns a matching automation, whether it exists and an error

func GetUserAutomations

func GetUserAutomations(username string) ([]Automation, error)

Returns a slice of automations which a given user has set up Does not check the validity of the user

type SunTime

type SunTime struct {
	Hour   uint
	Minute uint
}

Jump to

Keyboard shortcuts

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