util

package
v0.0.0-...-6f3d701 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: EPL-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PIC       = iota
	MOTION    = iota
	OCCUPANCY = iota
	DOOR      = iota
)
View Source
const (
	OCCUPIED     = iota
	UNOCCUPIED   = iota
	MOTION_START = iota
	MOTION_STOP  = iota
	DOOR_OPEN    = iota
	DOOR_CLOSED  = iota
)
View Source
const ENV_PREFIX = ""

Variables

View Source
var Client MQTT.Client
View Source
var Config = viper.New()
View Source
var (
	Logger zerolog.Logger
)

Functions

func AdvertiseHA

func AdvertiseHA(r []Room, client MQTT.Client)

func EncodeJPEG

func EncodeJPEG(img image.Image) ([]byte, error)

EncodeJPEG encodes an image.Image to JPEG bytes (quality 85). Exposed so the occupancy layer can re-encode the letterboxed preview if needed.

func GetRandString

func GetRandString(n int) string

func InitTritonClient

func InitTritonClient() error

InitTritonClient creates the gRPC connection to the Triton server. Call this once at startup, and again whenever config changes.

func LogInit

func LogInit(inlevel string)

func MqttInit

func MqttInit()

func OnNewConfig

func OnNewConfig()

func RegisterMQTTConnectHook

func RegisterMQTTConnectHook(name string, handler func(MQTT.Client))

func RegisterMQTTSubscription

func RegisterMQTTSubscription(topic string, handler MQTT.MessageHandler)

func RegisterNewConfigListener

func RegisterNewConfigListener(new_listener func())

func SetupConfig

func SetupConfig()

Types

type CamForwarder

type CamForwarder struct {
	Cameras   []CamForwarderCamera `mapstructure:"cameras"`
	Frequency int64                `mapstructure:"frequency"`
	Workers   int64                `mapstructure:"workers"`
	Enabled   bool                 `mapstructure:"enabled"`
}

func (*CamForwarder) MakeCamForwarder

func (cf *CamForwarder) MakeCamForwarder()

func (*CamForwarder) Start

func (forwarder *CamForwarder) Start()

type CamForwarderCamera

type CamForwarderCamera struct {
	Url   string `mapstructure:"snap_url"`
	Topic string `mapstructure:"topic"`
}

type HAAdvertisement

type HAAdvertisement struct {
	HAAvdvertisementAvailability []HAAvdvertisementAvailability `json:"availability"`
	Device                       HADeviceSpec                   `json:"device"`      // Device info
	UniqueID                     string                         `json:"uniq_id"`     // "window_contact_sensor_1"
	Name                         string                         `json:"name"`        // : "Window Contact Sensor"
	StateTopic                   string                         `json:"state_topic"` // : "home-assistant/window/contact"
	PayloadOn                    string                         `json:"payload_on"`  // : "ON"
	PayloadOff                   string                         `json:"payload_off"`
	DeviceClass                  string                         `json:"device_class"` // : "occupancy"
	Platform                     string                         `json:"platform"`     // "binary-sensor"
	Qos                          int                            `json:"qos"`
}

func ConstructHAAdvertisement

func ConstructHAAdvertisement(name, stateTopic string) HAAdvertisement

func (HAAdvertisement) ToJson

func (ha HAAdvertisement) ToJson() string

type HAAvdvertisementAvailability

type HAAvdvertisementAvailability struct {
	Topic               string `json:"topic"`                 // : "home-assistant/window/availability"
	PayloadAvailable    string `json:"payload_available"`     // : "online"
	PayloadNotAvailable string `json:"payload_not_available"` // : "offline"
}

type HADeviceSpec

type HADeviceSpec struct {
	Name        string   `json:"name"` // : "Window Contact Sensor"
	Identifiers []string `json:"ids"`  // : ["window_contact_sensor"]
}

type Location

type Location struct {
	Name string  `mapstructure:"name"`
	Lat  float64 `mapstructure:"latitude"`
	Lon  float64 `mapstructure:"longitude"`
}

func (Location) GetCoordinates

func (l Location) GetCoordinates() (latitude float64, longitude float64)

type Model

type Model struct {
	Rooms    []Room   `mapstructure:"rooms"`
	People   []Person `mapstructure:"people"`
	Location Location `mapstructure:"location"`
}

func (*Model) BuildModel

func (m *Model) BuildModel() error

func (Model) FindOccupancyTopicByRoom

func (m Model) FindOccupancyTopicByRoom(room string) string

func (Model) FindRoomByTopic

func (m Model) FindRoomByTopic(topic string) string

func (Model) FindTopicType

func (m Model) FindTopicType(topic string) int

func (Model) ModelStatus

func (m Model) ModelStatus() *ModelStatus

func (*Model) RoomOccupancyPeriod

func (m *Model) RoomOccupancyPeriod(room string) int64

func (Model) SubscribeTopics

func (m Model) SubscribeTopics() []string

func (*Model) UpdateRoomStatus

func (m *Model) UpdateRoomStatus(room string, item RoomStatus)

type ModelStatus

type ModelStatus struct {
	Room_status map[string]RoomStatus
}

type MonitorServer

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

func NewMonitorServer

func NewMonitorServer() *MonitorServer

func (*MonitorServer) AddHandler

func (s *MonitorServer) AddHandler(path string, handler func(http.ResponseWriter, *http.Request))

func (*MonitorServer) AddRawHandler

func (s *MonitorServer) AddRawHandler(path string, handler http.Handler)

func (*MonitorServer) Restart

func (s *MonitorServer) Restart()

func (*MonitorServer) Start

func (s *MonitorServer) Start() error

type Person

type Person struct {
	Location_topic string `mapstructure:"location_topic"`
	Name           string `mapstructure:"name"`
}

type Room

type Room struct {
	Name             string   `mapstructure:"name"`
	Occupancy_topic  string   `mapstructure:"occupancy_topic"`
	Motion_topics    []string `mapstructure:"motion_topics"`
	Pic_topics       []string `mapstructure:"pic_topics"`
	Door_topics      []string `mapstructure:"door_dopics"`
	Occupancy_period int64    `mapstructure:"occupancy_period"`
}

type RoomStatus

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

func (*RoomStatus) GetLastOccupied

func (m *RoomStatus) GetLastOccupied() int64

func (*RoomStatus) GetMotionState

func (m *RoomStatus) GetMotionState() bool

func (*RoomStatus) Motion

func (m *RoomStatus) Motion(state bool)

func (*RoomStatus) Occupied

func (m *RoomStatus) Occupied()

func (*RoomStatus) Unoccupied

func (m *RoomStatus) Unoccupied()

type TritonClient

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

TritonClient manages the gRPC connection to a Triton Inference Server.

type TritonDetection

type TritonDetection struct {
	Label      string
	Confidence float32
	XMin       int
	YMin       int
	XMax       int
	YMax       int
}

TritonDetection holds a single object detection result.

func DetectObjects

func DetectObjects(jpegData []byte) ([]TritonDetection, error)

DetectObjects submits a JPEG image to the Triton Inference Server running YOLO11 and returns the detected objects above the configured confidence threshold. The caller is responsible for converting the raw JPEG bytes.

Jump to

Keyboard shortcuts

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