Documentation
¶
Overview ¶
Package mqtt bridges the state bus to MQTT with Home Assistant auto-discovery: it publishes BLE sensors, a screen intent switch plus a live-power binary_sensor, and routes screen commands back.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
OnConnect(func())
OnConnectionLost(func(err error))
Connect() error
Disconnect()
Publish(topic string, qos byte, retain bool, payload []byte) error
Subscribe(topic string, qos byte, handler func(payload []byte, retained bool)) error
}
Client is the minimal MQTT transport the Hub needs (paho in the adapter subpackage). OnConnect must fire on every (re)connect.
type Deps ¶ added in v1.2.3
type Deps struct {
Bus *state.Bus
Screen Screen
Metrics MetricsReader
Host HostReader
Power PowerController
}
Deps groups the Publisher's collaborators to keep New's signature short.
type DeviceMeta ¶ added in v1.2.1
type DeviceMeta struct {
Manufacturer string
Model string
HwVersion string
SwVersion string
ConfigurationURL string
}
DeviceMeta is the optional hardware/software metadata shown on the HA device card.
type HostReader ¶ added in v1.2.3
IP is read per tick because DHCP can move it under a running frame.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub multiplexes one MQTT connection; subscriptions and OnConnect handlers persist across reconnects.
func (*Hub) AddOnConnect ¶
func (h *Hub) AddOnConnect(f func())
AddOnConnect registers f for every (re)connect. f runs on paho's onConnect goroutine, hop off it if you own mutable state.
func (*Hub) Connect ¶
Connect retries until success or ctx is cancelled; paho keeps the connection alive after.
func (*Hub) Disconnect ¶
func (h *Hub) Disconnect()
Disconnect closes the underlying connection. Safe to call without Connect.
type MetricsReader ¶ added in v1.2.1
type MetricsReader interface {
Read(ctx context.Context) hostmetrics.Metrics
}
MetricsReader supplies Pi telemetry snapshots; implemented by *hostmetrics.Reader.
type PowerController ¶ added in v1.2.3
type Publisher ¶
type Publisher struct {
// contains filtered or unexported fields
}
Publisher mirrors bus state to MQTT and applies inbound screen commands.
type Screen ¶
type Screen interface {
On(ctx context.Context) error
Off(ctx context.Context) error
Auto() bool // intent: motion auto-wake enabled (the switch)
State() bool // live panel power (the binary_sensor)
}
Screen is the manual screen-control surface; implemented by *display.Screen.
type SensorSpec ¶
type SensorSpec struct {
ID string // matches Reading.DeviceID and the config sensor id
Role string // friendly label; falls back to ID
Kinds []string // "temperature" | "humidity" | "motion"
}
SensorSpec is one sensor and the kinds it emits, used to build HA entities before any reading arrives.
type Settings ¶
type Settings struct {
NodeID string
BaseTopic string
DiscoveryPrefix string
DeviceName string // HA device friendly name; defaults to a title-cased NodeID
StaleAfter time.Duration
Device DeviceMeta // hardware/software metadata for the HA device card
Undervoltage bool // advertise the undervoltage entity (vcgencmd available)
Hostname string // OS hostname for the diagnostic sensor
CanReboot bool // logind permits reboot (polkit rule present)
CanPowerOff bool // logind permits power-off (polkit rule present)
}
Settings configures the MQTT bridge. NodeID identifies this frame, it forms the HA device id, prefixes every unique_id, and groups discovery topics, so multiple frames need only distinct NodeIDs (no hardcoded MACs).
func (Settings) BridgeAvailabilityTopic ¶
BridgeAvailabilityTopic is the bridge availability topic; callers set it as the MQTT Last Will so an unclean disconnect marks the frame offline.