camect_go

package module
v0.0.0-...-0f5add5 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2024 License: MIT Imports: 14 Imported by: 0

README

Camect-Go

A Go library for communicating to a Camect hub

Sources

This library is based off of publicly available code and documentation, all of which will be listed below:

  1. camect-py

Documentation

Index

Constants

View Source
const (
	ModeDefault = "DEFAULT"
	ModeHome    = "HOME"

	// ModeDisarmed is what the Camect V2 UI shows ModeDefault as
	ModeDisarmed = ModeDefault
	// ModeNormal is what the Camect V2 UI shows ModeHome as
	ModeNormal = ModeHome
)

Variables

View Source
var (
	ErrAlreadyListeningForEvents = errors.New("already listening for events")
	ErrFailedToSetMode           = errors.New("failed to set mode")
	ErrReasonNotProvided         = errors.New("reason was not provided")
	ErrFailedToGetCamera         = errors.New("failed to get cameras")
	ErrUnexpectedDataShape       = errors.New("the hub returned JSON in an unexpected shape")
)

Functions

This section is empty.

Types

type CamectEvents

type CamectEvents struct {
	// AlertChan receives detection alerts from the hub
	AlertChan chan *events.Alert
	// ModeChangeChan receives hub mode (DEFAULT or HOME) changes from the hub
	ModeChangeChan chan *events.ModeChange
	// AlertDisabledChan receives camera alert disabled messages from the hub
	AlertDisabledChan chan *events.AlertDisabled
	// AlertEnabledChan receives camera alert disabled messages from the hub
	AlertEnabledChan chan *events.AlertEnabled
	// CameraOnlineChan receives camera alert disabled messages from the hub
	CameraOnlineChan chan *events.CameraOnline
	// CameraOfflineChan receives camera alert disabled messages from the hub
	CameraOfflineChan chan *events.CameraOffline
	// UnknownEventChan receives unmarshalled JSON when an unknown event type is sent from the hub.
	UnknownEventChan chan []byte
}

type Camera

type Camera struct {
	// Id is the hub's internal ID for this logical camera
	Id string `json:"id"`
	// Name is the user friendly name for this logical camera
	Name string `json:"name"`
	// Make is the type of camera;
	// Example: ONVIF
	Make string `json:"make"`
	// Model is the model of this camera, if reported it
	Model string `json:"model"`
	// Url is the url to the camera, if reported
	Url string `json:"url"`
	// Width is the current width of the stream in pixels
	Width uint `json:"width"`
	// Height is the current height of the stream in pixels
	Height uint `json:"height"`
	// Wifi is if the hub has determined this camera is on wifi
	Wifi bool `json:"is_on_wifi"`
	// Disabled if the hub is ignoring this camera
	Disabled bool `json:"disabled"`
	// MacAddr reported mac address of this camera
	// Example:x-singlemac-e4:30:22:99:e9:64
	MacAddr string `json:"mac_addr"`
	// IPAddr is the IP address of this camera
	// Example: 192.168.1.221
	IPAddr string `json:"ip_addr"`
	// Streaming is if the hub is currently streaming from this camera
	Streaming bool `json:"is_streaming"`
	// StreamingUrl is the RTSP stream the hub is currently using to stream from this camera
	// Example: rtsp://REDACTED_USERNAME:REDACTED_PASSWORD@192.168.1.221:554/0/onvif/profile2/media.smp
	StreamingUrl string `json:"streaming_url"`
	// AlertsDisabled is if the hub is looking for objects on this camera and will send alerts
	AlertsDisabled bool `json:"is_alerts_disabled"`
	SaveEncoded    uint `json:"save_encoded"`
}

type DiskPartition

type DiskPartition struct {
	// DevPath is which physical device and partition the hub's operating system reports itself as
	// Example: `/dev/sdb1`
	DevPath string `json:"dev_path"`
	// MountPoint is where in the filesystem this device is mounted
	// Example: `/var/camect/home/mnt/dev_sdb1`
	MountPoint string `json:"mount_point"`
	// Model is what the model this disk reports itself as
	// Example: `ST1000LM048-2E7172`
	Model string `json:"model"`
	// NumCapacityBytes is the total number of bytes this partition can hold
	// Example: `984373075968`
	NumCapacityBytes uint64 `json:"num_capacity_bytes"`
	// NumFreeBytes is the currently free space currently available
	// Example: `934212239360`
	NumFreeBytes uint64 `json:"num_free_bytes"`
}

type Hub

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

func New

func New(ip, username, password string, logger *slog.Logger) *Hub

func (*Hub) Cameras

func (h *Hub) Cameras() ([]Camera, error)

func (*Hub) Events

func (h *Hub) Events(ctx context.Context, buffer int) (*CamectEvents, error)

func (*Hub) Info

func (h *Hub) Info() (*Info, error)

func (*Hub) SetMode

func (h *Hub) SetMode(newMode HubMode, reason string) error

type HubMode

type HubMode string

func (HubMode) String

func (hm HubMode) String() string

type Info

type Info struct {
	// Name is the hub's currently configured name
	Name string `json:"name"`
	// Id is the ID this hub uses to identify itself to Camect's cloud
	Id string `json:"id"`
	// Mode is the current operating mode
	Mode string `json:"mode"`

	// CloudUrl is the url to connect to this hub via Camect cloud
	CloudUrl string `json:"cloud_url"`
	//LocalHttpsUrl is the url needed to connect directly to this hub's local web interface
	LocalHttpsUrl string `json:"local_https_url"`

	ObjectName      []string `json:"object_name"`
	DependentObject []string `json:"dependent_object"`

	TimestampMs uint64 `json:"timestamp_ms"`

	// DiskPartitions is a slice of all of the hub's configured disks, not counting its OS disk
	DiskPartitions []DiskPartition `json:"disk_partitions"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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