state

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

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

Bus is a thread-safe broadcast pub/sub hub. Each subscriber gets its own buffered channel (full buffers are skipped, never blocking the publisher), and the latest event per Kind is retained for snapshots to late joiners.

func NewBus

func NewBus() *Bus

func (*Bus) Publish

func (b *Bus) Publish(e Event)

Publish broadcasts e with a monotonic ID, skipping full subscribers.

func (*Bus) Snapshot

func (b *Bus) Snapshot() []Event

Snapshot returns the latest event per Kind in publish order (ascending ID), used to send initial state to new SSE clients.

func (*Bus) Subscribe

func (b *Bus) Subscribe() (<-chan Event, func())

Subscribe returns a channel of future events and an unsubscribe func that must be called to release it; unsubscribe closes the channel so ranges exit.

type Event

type Event struct {
	ID      uint64 // monotonically increasing; used for SSE Last-Event-ID
	Kind    Kind
	Payload Payload
}

Event carries a single state change notification from a producer to subscribers.

type ImagePayload

type ImagePayload struct {
	Names []string `json:"names"`
}

ImagePayload carries the current slide's image names (one solo, two for a split pair). Empty signals no image.

type Kind

type Kind string

Kind identifies the category of an event.

const (
	KindSensor       Kind = "sensor"
	KindScreen       Kind = "screen"
	KindWeather      Kind = "weather"
	KindImage        Kind = "image"
	KindKiosk        Kind = "kiosk"
	KindScreenAspect Kind = "screen_aspect"
)

type KioskLabels

type KioskLabels struct {
	Outside  string `json:"outside"`
	Inside   string `json:"inside"`
	Humidity string `json:"humidity"`
}

KioskLabels mirrors config.KioskLabelsConfig; empty strings hide the caption.

type KioskPayload

type KioskPayload struct {
	Version       string      `json:"version"` // running build; the kiosk reloads when it changes (post-update)
	Locale        string      `json:"locale"`
	HideClockDate bool        `json:"hide_clock_date"`
	Timezone      string      `json:"timezone"`
	Sensors       []string    `json:"sensors"`
	Weather       bool        `json:"weather"`
	Labels        KioskLabels `json:"labels"`
}

KioskPayload carries the kiosk overlay's render inputs.

type Payload

type Payload interface {
	// contains filtered or unexported methods
}

Payload is a sealed interface. Only types defined in this package satisfy it, keeping the set of bus event shapes explicit and compiler-checked at publish sites.

type ScreenAspectPayload added in v1.1.0

type ScreenAspectPayload struct {
	Aspect float64 `json:"aspect"`
}

ScreenAspectPayload carries the kiosk's reported aspect (width/height) so the admin dashboard can size its preview to match the frame.

type ScreenPayload

type ScreenPayload struct {
	On   bool `json:"on"`
	Auto bool `json:"auto"`
}

ScreenPayload carries two distinct facets so consumers don't conflate them: On is the live panel power (moves on idle-blank, motion, drift); Auto is the manual intent (motion auto-wake enabled), which only a manual on/off changes.

type SensorPayload

type SensorPayload struct {
	DeviceID  string    `json:"device_id"`
	Role      string    `json:"role,omitempty"` // display role, e.g. "inside"; set by the kiosk config mapping
	Kind      string    `json:"kind"`
	Value     float64   `json:"value"`
	Timestamp time.Time `json:"timestamp"`
}

type WeatherPayload

type WeatherPayload struct {
	IconCode string  `json:"icon_code"`
	Temp     float64 `json:"temp"`
	Humidity float64 `json:"humidity"`
}

WeatherPayload carries the latest weather; a zero value (empty IconCode) signals a failed poll.

Jump to

Keyboard shortcuts

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