huedb

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2023 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package huedb contains the persistence layer for the hue web app

Index

Constants

This section is empty.

Variables

View Source
var (
	// Indicates that the id does not exist in the database.
	ErrNoSuchId = errors.New("huedb: No such Id.")
	// Indicates that LightColors map has bad values.
	ErrBadLightColors = errors.New("huedb: Bad values in LightColors.")
)

Functions

func HueTaskById

func HueTaskById(store NamedColorsByIdRunner, hueTaskId int) *ops.HueTask

HueTaskById returns a hue task for named colors by its Id. If not found or if store is nil, returns a Hue task with an action that reports ErrNoSuchId.

func HueTasks

func HueTasks(store NamedColorsRunner) (ops.HueTaskList, error)

HueTasks returns all the named colors as hue tasks.

Types

type ActionDecoder

type ActionDecoder interface {
	Decode(hueTaskId int, encoded string) (ops.HueAction, error)
}

ActionDecoder converts a string back to a hue action. hueTaskId is the id of the enclosing hue task; encoded is the string form of the hue action.

func NewActionDecoder

func NewActionDecoder(
	store DynamicHueTaskStore,
	dbStore NamedColorsByIdRunner) ActionDecoder

NewActionDecoder returns an ActionDecoder. The Decode method of the returned ActionDecoder works the following way. If hueTaskId < ops.PersistentTaskIdOffset, then Decode uses store to look up the HueTask by hueTaskId. Decode delegates to the Factory field of the fetched hue task after converting it to a dynamic.Decoder. Decode reports an error if the Factory field cannot be converted to a dynamic.Decoder. If hueTaskId >= ops.PersistentTaskIdOffset, then Decode uses dbStore to look up the hue action with id: hueTaskId - ops.PersistentTaskIdOffset.

type ActionEncoder

type ActionEncoder interface {
	Encode(hueTaskId int, action ops.HueAction) (string, error)
}

ActionEncoder converts a hue action to a string. hueTaskId is the id of the enclosing hue task; action is what is to be encoded.

func NewActionEncoder

func NewActionEncoder(store DynamicHueTaskStore) ActionEncoder

NewActionEncoder returns an ActionEncoder. The Encode method of the returned ActionEncoder works the following way. If hueTaskId < ops.PersistentTaskIdOffset, then Encode uses store to look up the HueTask by hueTaskId. Encode delegates to the Factory field of the fetched hue task after converting it to a dynamic.Encoder. Encode reports an error if the Factory field cannot be converted to a dynamic.Encoder. If hueTaskId >= ops.PersistentTaskIdOffset, then Encode returns the empty string with no error.

type AddNamedColorsRunner

type AddNamedColorsRunner interface {
	// AddNamedColros adds named colors.
	AddNamedColors(t db.Transaction, colors *ops.NamedColors) error
}

type AtTimeTaskStore

type AtTimeTaskStore struct {
	// contains filtered or unexported fields
}

AtTimeTaskStore is a store for ops.AtTimeTask instances.

func NewAtTimeTaskStore

func NewAtTimeTaskStore(
	encoder ActionEncoder,
	decoder ActionDecoder,
	store EncodedAtTimeTaskStore,
	groupId string,
	logger *log.Logger) *AtTimeTaskStore

NewAtTimeTaskStore creates and returns a new AtTimeTaskStore ready for use

func (*AtTimeTaskStore) Add

func (s *AtTimeTaskStore) Add(task *ops.AtTimeTask)

Add adds a new scheduled task

func (*AtTimeTaskStore) All

func (s *AtTimeTaskStore) All() []*ops.AtTimeTask

All returns all tasks.

func (*AtTimeTaskStore) Remove

func (s *AtTimeTaskStore) Remove(scheduleId string)

Remove removes a scheduled task by id

type DescriptionMap

type DescriptionMap map[int]string

DescriptionMap maps hue task ids to descriptions. These instances must be treated as immutable.

type DynamicHueTaskStore

type DynamicHueTaskStore interface {
	ById(id int) *dynamic.HueTask
}

DynamicHueTaskStore fetches a dynamic.HueTask by Id. If no task can be fetched, returns nil.

type EncodedAtTimeTask

type EncodedAtTimeTask struct {
	// The unique database dependent numeric ID of this scheduled task.
	Id int64

	// The group id.
	GroupId string

	// The string ID of this scheduled task. Database independent.
	ScheduleId string

	// The ID of the scheduled hue task.
	HueTaskId int

	// The encoded form of the hue action in the scheduled hue task.
	Action string

	// The description of the scheduled hue task.
	Description string

	// The encoded set of lights on which the scheduled hue task will run.
	LightSet string

	// The time the hue task is to run in seconds after Jan 1 1970 GMT
	Time int64
}

EncodedAtTimeTask is the form of ops.AtTimeTask that can be persisted to a database.

type EncodedAtTimeTaskStore

type EncodedAtTimeTaskStore interface {

	// AddEncodedAtTimeTask adds a task.
	AddEncodedAtTimeTask(t db.Transaction, task *EncodedAtTimeTask) error

	// RemoveEncodedAtTimeTaskByScheduleId removes a task by
	// group Id and schedule id.
	RemoveEncodedAtTimeTaskByScheduleId(
		t db.Transaction, groupId, scheduleId string) error

	// EncodedAtTimeTasks fetches all tasks in a particular group.
	EncodedAtTimeTasks(
		t db.Transaction,
		groupId string,
		consumer consume2.Consumer[EncodedAtTimeTask]) error
}

EncodedAtTimeTaskStore persists EncodedAtTimeTask instances.

type FutureHueTask

type FutureHueTask struct {
	// Id is the HueTaskId
	Id int
	// Description is the description
	Description string
	// Store retrieves from persistent storage.
	Store NamedColorsByIdRunner
}

FutureHueTask creates a HueTask from persistent storage by Id.

func (*FutureHueTask) GetDescription

func (f *FutureHueTask) GetDescription() string

GetDescription returns the description of this instance.

func (*FutureHueTask) Refresh

func (f *FutureHueTask) Refresh() *ops.HueTask

Refresh returns the HueTask freshly read from persistent storage.

type NamedColorsByIdRunner

type NamedColorsByIdRunner interface {
	// NamedColorsById gets named colors by id.
	NamedColorsById(t db.Transaction, id int64, colors *ops.NamedColors) error
}

func FixDescriptionByIdRunner

func FixDescriptionByIdRunner(
	delegate NamedColorsByIdRunner,
	descriptionMap DescriptionMap) NamedColorsByIdRunner

FixDescriptionByIdRunner returns a new NamedColorsByIdRunner that works just like delegate except that for a fetched NamedColors, x, if x.Id + utils.PersistentTaskIdOffset is in descriptionMap, then x.Description is replaced with the corresponding value in descriptionMap.

type NamedColorsRunner

type NamedColorsRunner interface {
	// NamedColors gets all named colors.
	NamedColors(
		t db.Transaction, consumer consume2.Consumer[ops.NamedColors]) error
}

func FixDescriptionsRunner

func FixDescriptionsRunner(
	delegate NamedColorsRunner,
	descriptionMap DescriptionMap) NamedColorsRunner

FixDescriptionsRunner returns a new NamedColorsRunner that works just like delegate except that ifor a fetched NamedColors, x, if x.Id + utils.PersistentTaskIdOffset is in descriptionMap, then x.Description is replaced with the corresponding value in descriptionMap.

type RemoveNamedColorsRunner

type RemoveNamedColorsRunner interface {
	// RemoveNamedColors removes named colors by id.
	RemoveNamedColors(t db.Transaction, id int64) error
}

type UpdateNamedColorsRunner

type UpdateNamedColorsRunner interface {
	// UpdateNamedColors updates named colors by id.
	UpdateNamedColors(t db.Transaction, colors *ops.NamedColors) error
}

Directories

Path Synopsis
Package fixture provides test suites to test implementations of the interfaces in the huedb package.
Package fixture provides test suites to test implementations of the interfaces in the huedb package.
Package for_sqlite provides a sqlite implementation of interfaces in huedb package.
Package for_sqlite provides a sqlite implementation of interfaces in huedb package.
Package sqlite_setup sets up a sqlite database for Hue Web App
Package sqlite_setup sets up a sqlite database for Hue Web App

Jump to

Keyboard shortcuts

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