Documentation
¶
Index ¶
- func CORSMiddleware(next http.Handler) http.Handler
- func ContentTypeMiddleware(contentType string) func(http.Handler) http.Handler
- func GetDevice(handlers *Handlers) http.HandlerFunc
- func LoggingMiddleware(logger *slog.Logger) func(http.Handler) http.Handler
- func RecoverMiddleware(logger *slog.Logger) func(http.Handler) http.Handler
- func SetupRoutes(mux *http.ServeMux, manager *state.Manager, adapter *adapter.Adapter, ...)
- func WriteJSON(w http.ResponseWriter, code int, data interface{})
- type ControlResponse
- type DeviceDetailsResponse
- type DeviceListResponse
- type DeviceNameResponse
- type DeviceStateResponse
- type DeviceSummary
- type ErrorResponse
- type Handlers
- func (h *Handlers) GetDevice(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) GetDeviceState(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) GetSensorData(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) HealthCheck(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) Identify(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) ListDevices(w http.ResponseWriter, _ *http.Request)
- func (h *Handlers) SetBrightness(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) SetColorTemperature(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) SetDeviceName(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) Toggle(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) TurnOff(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) TurnOn(w http.ResponseWriter, r *http.Request)
- type HealthResponse
- type SensorDataResponse
- type SensorReading
- type TimestampedValue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CORSMiddleware ¶
CORSMiddleware adds CORS headers for cross-origin requests.
func ContentTypeMiddleware ¶
ContentTypeMiddleware ensures responses have Content-Type header.
func GetDevice ¶
func GetDevice(handlers *Handlers) http.HandlerFunc
GetDevice is a wrapper handler that serves as a redirect from the base path. This handles requests like GET /api/v1/devices/ without an identifier.
func LoggingMiddleware ¶
LoggingMiddleware logs HTTP requests.
func RecoverMiddleware ¶
RecoverMiddleware recovers from panics in handlers.
func SetupRoutes ¶
func SetupRoutes(mux *http.ServeMux, manager *state.Manager, adapter *adapter.Adapter, logger *slog.Logger)
SetupRoutes configures and returns the HTTP router with all handlers registered.
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, code int, data interface{})
WriteJSON writes a JSON response with the given status code.
Types ¶
type ControlResponse ¶
type ControlResponse struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
}
ControlResponse represents a device control response.
type DeviceDetailsResponse ¶
type DeviceDetailsResponse struct {
IEEEAddr string `json:"ieee_addr"`
NwkAddr string `json:"nwk_addr"`
Slug string `json:"slug"`
Name string `json:"name,omitempty"`
Manufacturer string `json:"manufacturer,omitempty"`
Model string `json:"model,omitempty"`
Capabilities string `json:"capabilities,omitempty"`
Endpoints []uint8 `json:"endpoints"`
LastSeen time.Time `json:"last_seen"`
JoinedAt time.Time `json:"joined_at"`
State DeviceStateResponse `json:"state"`
}
DeviceDetailsResponse represents the device details response.
type DeviceListResponse ¶
type DeviceListResponse struct {
Devices []DeviceSummary `json:"devices"`
Count int `json:"count"`
}
DeviceListResponse represents the list devices response.
type DeviceNameResponse ¶
type DeviceNameResponse struct {
Success bool `json:"success"`
Slug string `json:"slug,omitempty"`
Error string `json:"error,omitempty"`
}
DeviceNameResponse represents the device name response.
type DeviceStateResponse ¶
type DeviceStateResponse struct {
OnOff *bool `json:"on_off,omitempty"`
Brightness *uint8 `json:"brightness,omitempty"`
ColorTemp *uint16 `json:"color_temp,omitempty"`
ColorHue *uint8 `json:"color_hue,omitempty"`
ColorSat *uint8 `json:"color_saturation,omitempty"`
Temperature *float32 `json:"temperature,omitempty"`
Humidity *float32 `json:"humidity,omitempty"`
LastUpdated time.Time `json:"last_updated"`
}
DeviceStateResponse represents the cached device state.
type DeviceSummary ¶
type DeviceSummary struct {
IEEEAddr string `json:"ieee_addr"`
NwkAddr string `json:"nwk_addr"`
Slug string `json:"slug"`
Name string `json:"name,omitempty"`
Model string `json:"model,omitempty"`
Manufacturer string `json:"manufacturer,omitempty"`
LastSeen time.Time `json:"last_seen"`
JoinedAt time.Time `json:"joined_at"`
IsRouter bool `json:"is_router"`
IsBattery bool `json:"is_battery_powered"`
}
DeviceSummary represents a summary of a device for list views.
type ErrorResponse ¶
ErrorResponse represents an API error response.
type Handlers ¶
type Handlers struct {
// contains filtered or unexported fields
}
Handlers contains all HTTP handlers for the daemon API.
func NewHandlers ¶
NewHandlers creates a new handlers instance.
func (*Handlers) GetDevice ¶
func (h *Handlers) GetDevice(w http.ResponseWriter, r *http.Request)
GetDevice returns details for a specific device. GET /api/v1/devices/:identifier (can be slug or IEEE address)
func (*Handlers) GetDeviceState ¶
func (h *Handlers) GetDeviceState(w http.ResponseWriter, r *http.Request)
GetDeviceState returns the cached state for a specific device. GET /api/v1/devices/:identifier/state
func (*Handlers) GetSensorData ¶
func (h *Handlers) GetSensorData(w http.ResponseWriter, r *http.Request)
GetSensorData returns the latest sensor readings for a device. GET /api/v1/devices/:identifier/sensor
func (*Handlers) HealthCheck ¶
func (h *Handlers) HealthCheck(w http.ResponseWriter, r *http.Request)
HealthCheck returns the health status of the daemon. GET /health
func (*Handlers) Identify ¶
func (h *Handlers) Identify(w http.ResponseWriter, r *http.Request)
Identify makes a device identify itself for a specific duration. POST /api/v1/devices/:identifier/identify Request body: {"time": 5} (duration in seconds, default: 5)
func (*Handlers) ListDevices ¶
func (h *Handlers) ListDevices(w http.ResponseWriter, _ *http.Request)
ListDevices returns all devices. GET /api/v1/devices
func (*Handlers) SetBrightness ¶
func (h *Handlers) SetBrightness(w http.ResponseWriter, r *http.Request)
SetBrightness sets the brightness level of a device. POST /api/v1/devices/:identifier/brightness Request body: {"level": 128} (0-254)
func (*Handlers) SetColorTemperature ¶
func (h *Handlers) SetColorTemperature(w http.ResponseWriter, r *http.Request)
SetColorTemperature sets the color temperature. POST /api/v1/devices/:identifier/color-temp Request body: {"kelvin": 2700} (2700-6500)
func (*Handlers) SetDeviceName ¶
func (h *Handlers) SetDeviceName(w http.ResponseWriter, r *http.Request)
SetDeviceName sets a friendly name for a device. POST /api/v1/devices/:identifier/name Request body: {"name": "Device Name"}
func (*Handlers) Toggle ¶
func (h *Handlers) Toggle(w http.ResponseWriter, r *http.Request)
Toggle toggles a device. POST /api/v1/devices/:identifier/toggle
type HealthResponse ¶
HealthResponse represents the health check response.
type SensorDataResponse ¶
type SensorDataResponse struct {
IEEEAddr string `json:"ieee_addr"`
Slug string `json:"slug,omitempty"`
LastUpdated time.Time `json:"last_updated"`
Reading SensorReading `json:"reading"`
}
SensorDataResponse represents the sensor data response.
type SensorReading ¶
type SensorReading struct {
Temperature *state.TimestampedValue[float32] `json:"temperature,omitempty"`
Humidity *state.TimestampedValue[float32] `json:"humidity,omitempty"`
Pressure *state.TimestampedValue[float64] `json:"pressure,omitempty"`
Voltage *state.TimestampedValue[float64] `json:"voltage,omitempty"`
Current *state.TimestampedValue[float64] `json:"current,omitempty"`
Power *state.TimestampedValue[float64] `json:"power,omitempty"`
Energy *state.TimestampedValue[float64] `json:"energy,omitempty"`
Battery *state.TimestampedValue[uint8] `json:"battery,omitempty"`
Illuminance *state.TimestampedValue[float32] `json:"illuminance,omitempty"`
Occupied *state.TimestampedValue[bool] `json:"occupied,omitempty"`
}
SensorReading represents sensor readings.