pkg

package
v0.0.0-...-c36b137 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TimeLocationFromOffset

func TimeLocationFromOffset(offsetMinutes string) (*time.Location, error)

TimeLocationFromOffset uses an offset minutes from JS `new Date().getTimezoneOffset()` and parses it into Go's time.Location. JS offsets are positive if they are behind UTC

func ValidateScaleControl

func ValidateScaleControl(sc *weather.ScaleControl) error

ValidateScaleControl validates input for ScaleControl

func ValidateWeatherControl

func ValidateWeatherControl(wc *weather.Control) error

ValidateWeatherControl validates input for the WeatherControl of a WaterSchedule

Types

type ActivePeriod

type ActivePeriod struct {
	StartMonth string `json:"start_month" yaml:"start_month"`
	EndMonth   string `json:"end_month" yaml:"end_month"`
	// contains filtered or unexported fields
}

ActivePeriod contains the start and end months for when a WaterSchedule should be considered active. Both of these constraints are inclusive

func (*ActivePeriod) Patch

func (ap *ActivePeriod) Patch(new *ActivePeriod)

Patch allows for easily updating/editing an ActivePeriod

func (*ActivePeriod) Validate

func (ap *ActivePeriod) Validate() error

Validate parses the Month strings to make sure they are valid

type Duration

type Duration struct {
	time.Duration
	Cron string
}

Duration is a wrapper around the time.Duration that allows it to be used as interger or string representation. It also supports inputting a cron string as an interval instead if using the prefix "cron:"

func (*Duration) MarshalJSON

func (d *Duration) MarshalJSON() ([]byte, error)

MarshalJSON will convert Duration into the string representation

func (*Duration) MarshalYAML

func (d *Duration) MarshalYAML() (interface{}, error)

MarshalYAML will convert Duration into the string representation

func (*Duration) SchedulerFunc

func (d *Duration) SchedulerFunc(s *gocron.Scheduler) *gocron.Scheduler

SchedulerFunc is a wrapper around gocron's fluent style to easily choose the cron or duration-based scheduling

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(data []byte) error

UnmarshalJSON with allow reading a Duration as a string or integer into time.Duration

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(data []byte) error

UnmarshalText is used for HTML form decoding. It doesn't know if it's an integer or string representation so it will try both. It parses integer input as milliseconds

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML with allow reading a Duration as a string or integer into time.Duration

type EndDateable

type EndDateable interface {
	EndDated() bool
	SetEndDate(time.Time)
}

type Garden

type Garden struct {
	Name                      string         `json:"name" yaml:"name,omitempty"`
	TopicPrefix               string         `json:"topic_prefix,omitempty" yaml:"topic_prefix,omitempty"`
	ID                        babyapi.ID     `json:"id" yaml:"id,omitempty"`
	MaxZones                  *uint          `json:"max_zones" yaml:"max_zones"`
	CreatedAt                 *time.Time     `json:"created_at" yaml:"created_at,omitempty"`
	EndDate                   *time.Time     `json:"end_date,omitempty" yaml:"end_date,omitempty"`
	LightSchedule             *LightSchedule `json:"light_schedule,omitempty" yaml:"light_schedule,omitempty"`
	TemperatureHumiditySensor *bool          `json:"temperature_humidity_sensor,omitempty" yaml:"temperature_humidity_sensor,omitempty"`
	NotificationClientID      *string        `json:"notification_client_id,omitempty" yaml:"notification_client_id,omitempty"`
	Version                   uint           `json:"version,omitempty" yaml:"version"`
}

Garden is the representation of a single garden-controller device

func (*Garden) Bind

func (g *Garden) Bind(r *http.Request) error

func (*Garden) EndDated

func (g *Garden) EndDated() bool

EndDated returns true if the Garden is end-dated

func (*Garden) GetID

func (g *Garden) GetID() string

func (*Garden) GetNotificationClientID

func (g *Garden) GetNotificationClientID() string

func (*Garden) GetVersion

func (g *Garden) GetVersion() uint

func (*Garden) HasTemperatureHumiditySensor

func (g *Garden) HasTemperatureHumiditySensor() bool

HasTemperatureHumiditySensor determines if the Garden has a sensor configured

func (*Garden) Health

func (g *Garden) Health(ctx context.Context, influxdbClient influxdb.Client) *GardenHealth

Health returns a GardenHealth struct after querying InfluxDB for the Garden controller's last contact time

func (*Garden) Patch

func (g *Garden) Patch(newGarden *Garden) *babyapi.ErrResponse

Patch allows for easily updating individual fields of a Garden by passing in a new Garden containing the desired values

func (*Garden) Render

func (g *Garden) Render(_ http.ResponseWriter, _ *http.Request) error

func (*Garden) SetEndDate

func (g *Garden) SetEndDate(now time.Time)

func (*Garden) SetVersion

func (g *Garden) SetVersion(v uint)

func (*Garden) String

func (g *Garden) String() string

String...

type GardenHealth

type GardenHealth struct {
	Status      HealthStatus `json:"status,omitempty"`
	Details     string       `json:"details,omitempty"`
	LastContact *time.Time   `json:"last_contact,omitempty"`
}

GardenHealth holds information about the Garden controller's health status

type HealthStatus

type HealthStatus string
const (
	HealthStatusDown    HealthStatus = "DOWN"
	HealthStatusUp      HealthStatus = "UP"
	HealthStatusUnknown HealthStatus = "N/A"
)

type LightSchedule

type LightSchedule struct {
	Duration    *Duration  `json:"duration" yaml:"duration"`
	StartTime   *StartTime `json:"start_time" yaml:"start_time"`
	AdhocOnTime *time.Time `json:"adhoc_on_time,omitempty" yaml:"adhoc_on_time,omitempty"`
}

LightSchedule allows the user to control when the Garden light is turned on and off "Time" should be in the format of LightTimeFormat constant ("15:04:05-07:00")

func (*LightSchedule) Patch

func (ls *LightSchedule) Patch(new *LightSchedule)

Patch allows modifying the struct in-place with values from a different instance

func (*LightSchedule) String

func (ls *LightSchedule) String() string

String...

type LightState

type LightState int

LightState is an enum representing the state of a Light (ON or OFF)

const (
	// LightStateOff is the value used to turn off a light
	LightStateOff LightState = iota
	// LightStateOn is the value used to turn on a light
	LightStateOn
	// LightStateToggle is the empty value that results in toggling
	LightStateToggle
)

func (LightState) MarshalJSON

func (l LightState) MarshalJSON() ([]byte, error)

MarshalJSON will convert LightState into it's JSON string representation

func (LightState) String

func (l LightState) String() string

Return the string representation of this LightState

func (*LightState) UnmarshalJSON

func (l *LightState) UnmarshalJSON(data []byte) error

UnmarshalJSON with convert LightState's JSON string representation, ignoring case, into a LightState

func (*LightState) UnmarshalText

func (l *LightState) UnmarshalText(data []byte) error

type NextWaterDetails

type NextWaterDetails struct {
	Time            *time.Time `json:"time,omitempty"`
	Duration        string     `json:"duration,omitempty"`
	WaterScheduleID *xid.ID    `json:"water_schedule_id,omitempty"`
	Message         string     `json:"message,omitempty"`
}

NextWaterDetails has information about the next time this WaterSchedule will be used

type RainData

type RainData struct {
	MM          float32 `json:"mm"`
	ScaleFactor float32 `json:"scale_factor"`
}

RainData shows the total rain in the last watering interval and the scaling factor it would result in

type StartTime

type StartTime struct {
	Time time.Time `form:"-"`

	Hour   int
	Minute int
	TZ     string
}

StartTime allows for special handling of Time without the date and also allows several formats for decoding so it is more easily compatible with HTML forms

func NewStartTime

func NewStartTime(t time.Time) *StartTime

func StartTimeFromString

func StartTimeFromString(startTime string) (*StartTime, error)

func (*StartTime) MarshalJSON

func (st *StartTime) MarshalJSON() ([]byte, error)

func (*StartTime) String

func (st *StartTime) String() string

func (*StartTime) UnmarshalJSON

func (st *StartTime) UnmarshalJSON(data []byte) error

func (*StartTime) Validate

func (st *StartTime) Validate() error

Validate is used after parsing from HTML form so the time can be parsed

type TemperatureData

type TemperatureData struct {
	Celsius     float32 `json:"celsius"`
	ScaleFactor float32 `json:"scale_factor"`
}

TemperatureData shows the average high temperatures in the last watering interval and the scaling factor it would result in

type WaterHistory

type WaterHistory struct {
	Duration   string    `json:"duration"`
	RecordTime time.Time `json:"record_time"`
}

WaterHistory holds information about a WaterEvent that occurred in the past

type WaterSchedule

type WaterSchedule struct {
	ID                   babyapi.ID       `json:"id" yaml:"id"`
	Duration             *Duration        `json:"duration" yaml:"duration"`
	Interval             *Duration        `json:"interval" yaml:"interval"`
	StartDate            *time.Time       `json:"start_date" yaml:"start_date"`
	StartTime            *StartTime       `json:"start_time" yaml:"start_time"`
	EndDate              *time.Time       `json:"end_date,omitempty" yaml:"end_date,omitempty"`
	WeatherControl       *weather.Control `json:"weather_control,omitempty" yaml:"weather_control,omitempty"`
	Name                 string           `json:"name,omitempty" yaml:"name,omitempty"`
	Description          string           `json:"description,omitempty" yaml:"description,omitempty"`
	ActivePeriod         *ActivePeriod    `json:"active_period,omitempty" yaml:"active_period,omitempty"`
	NotificationClientID *string          `json:"notification_client_id,omitempty" yaml:"notification_client_id,omitempty"`
	Version              uint             `json:"version,omitempty" yaml:"version"`
}

WaterSchedule allows the user to have more control over how the Zone is watered using an Interval. StartTime specifies when the watering interval should originate from. It can be used to increase/decrease delays in watering.

func (*WaterSchedule) Bind

func (ws *WaterSchedule) Bind(r *http.Request) error

func (*WaterSchedule) EndDated

func (ws *WaterSchedule) EndDated() bool

EndDated returns true if the WaterSchedule is end-dated

func (*WaterSchedule) GetID

func (ws *WaterSchedule) GetID() string

func (*WaterSchedule) GetNotificationClientID

func (ws *WaterSchedule) GetNotificationClientID() string

func (*WaterSchedule) GetVersion

func (ws *WaterSchedule) GetVersion() uint

func (*WaterSchedule) HasRainControl

func (ws *WaterSchedule) HasRainControl() bool

HasRainControl is used to determine if rain conditions should be checked before watering the Zone

func (*WaterSchedule) HasTemperatureControl

func (ws *WaterSchedule) HasTemperatureControl() bool

HasTemperatureControl is used to determine if configuration is available for environmental scaling

func (*WaterSchedule) HasWeatherControl

func (ws *WaterSchedule) HasWeatherControl() bool

HasWeatherControl is used to determine if weather conditions should be checked before watering the Zone This checks that WeatherControl is defined and has at least one type of control configured

func (*WaterSchedule) IsActive

func (ws *WaterSchedule) IsActive(now time.Time) bool

IsActive determines if the WaterSchedule is currently in it's ActivePeriod. Always true if no ActivePeriod is configured

func (*WaterSchedule) Patch

Patch allows modifying the struct in-place with values from a different instance

func (*WaterSchedule) Render

func (ws *WaterSchedule) Render(_ http.ResponseWriter, _ *http.Request) error

func (*WaterSchedule) SetEndDate

func (ws *WaterSchedule) SetEndDate(now time.Time)

func (*WaterSchedule) SetVersion

func (ws *WaterSchedule) SetVersion(v uint)

func (*WaterSchedule) String

func (ws *WaterSchedule) String() string

String...

type WeatherData

type WeatherData struct {
	Rain        *RainData        `json:"rain,omitempty"`
	Temperature *TemperatureData `json:"average_temperature,omitempty"`
}

WeatherData is used to represent the data used for WeatherControl to a user

type Zone

type Zone struct {
	Name             string       `json:"name" yaml:"name,omitempty"`
	Details          *ZoneDetails `json:"details,omitempty" yaml:"details,omitempty"`
	ID               babyapi.ID   `json:"id" yaml:"id,omitempty"`
	GardenID         xid.ID       `json:"garden_id" yaml:"garden_id,omitempty"`
	Position         *uint        `json:"position" yaml:"position"`
	CreatedAt        *time.Time   `json:"created_at" yaml:"created_at,omitempty"`
	EndDate          *time.Time   `json:"end_date,omitempty" yaml:"end_date,omitempty"`
	WaterScheduleIDs []xid.ID     `json:"water_schedule_ids" yaml:"water_schedule_ids"`
	SkipCount        *uint        `json:"skip_count" yaml:"skip_count"`
	Version          uint         `json:"version,omitempty" yaml:"version"`
}

Zone represents a "waterable resource" that is owned by a Garden.. This allows for more complex Garden setups where a large irrigation system will be watering entire groups of Zones rather than watering individually. This contains the important information for managing WaterSchedules and some additional details describing the Zone. The Position is an integer that tells the controller which part of hardware needs to be switched on to start watering

func (*Zone) Bind

func (z *Zone) Bind(r *http.Request) error

func (*Zone) EndDated

func (z *Zone) EndDated() bool

EndDated returns true if the Zone is end-dated

func (*Zone) GetID

func (z *Zone) GetID() string

func (*Zone) GetVersion

func (z *Zone) GetVersion() uint

func (*Zone) Patch

func (z *Zone) Patch(newZone *Zone) *babyapi.ErrResponse

Patch allows for easily updating individual fields of a Zone by passing in a new Zone containing the desired values

func (*Zone) Render

func (z *Zone) Render(_ http.ResponseWriter, _ *http.Request) error

func (*Zone) SetEndDate

func (z *Zone) SetEndDate(now time.Time)

func (*Zone) SetVersion

func (z *Zone) SetVersion(v uint)

func (*Zone) String

func (z *Zone) String() string

String...

type ZoneAndGarden

type ZoneAndGarden struct {
	*Zone
	*Garden
}

ZoneAndGarden allows grouping the Zone and Garden it belongs too and is useful in some cases where both are needed in a return value

type ZoneDetails

type ZoneDetails struct {
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
	Notes       string `json:"notes,omitempty" yaml:"notes,omitempty"`
}

ZoneDetails is a struct holding some additional details about a Zone that are primarily for user convenience and are generally not used by the application

func (*ZoneDetails) Patch

func (zd *ZoneDetails) Patch(new *ZoneDetails)

Patch allows modifying the struct in-place with values from a different instance

func (*ZoneDetails) String

func (zd *ZoneDetails) String() string

String...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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