alarm

package
v0.0.0-...-db03bfd Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package alarm defines the alarms based on the time of the day.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(b msgbus.Bus, config *Config) error

Init initializes the timers.

Types

type Alarm

type Alarm struct {
	Enabled bool
	Hour    int
	Minute  int
	Days    WeekdayBit
	Cmd     rules.Command
	// contains filtered or unexported fields
}

Alarm represents a single alarm.

func (*Alarm) Next

func (a *Alarm) Next(now time.Time) time.Time

Next returns when the next trigger should be according to the alarm schedule.

Return 0 if not enabled.

func (*Alarm) Reset

func (a *Alarm) Reset(b msgbus.Bus) error

Reset reinitializes with a message bus.

func (*Alarm) String

func (a *Alarm) String() string

func (*Alarm) Validate

func (a *Alarm) Validate() error

Validate confirms the settings are valid.

type Config

type Config struct {
	Alarms map[string]*Alarm
}

Config is what should be serialized.

func (*Config) ResetDefault

func (c *Config) ResetDefault()

ResetDefault initializes the default alarms.

func (*Config) Validate

func (c *Config) Validate() error

Validate confirms the settings are valid.

type WeekdayBit

type WeekdayBit int

WeekdayBit is a bitmask of each day.

const (
	Sunday WeekdayBit = 1 << iota
	Monday
	Tuesday
	Wednesday
	Thursday
	Friday
	Saturday
)

Week days.

func (WeekdayBit) IsEnabledFor

func (w WeekdayBit) IsEnabledFor(d time.Weekday) bool

IsEnabledFor returns true if the bitmask is set for this week day.

func (WeekdayBit) String

func (w WeekdayBit) String() string

Jump to

Keyboard shortcuts

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