🏡 index : ~doyle/hkbi.git

author Jordan Doyle <jordan@doyle.la> 2022-10-07 1:51:51.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2022-10-07 1:53:33.0 +00:00:00
commit
26bbc85ff306e94cf9fa224df8e7088c4d261449 [patch]
tree
746c1a8c68aace856dd715fa74a765a27064aee7
parent
541b3478cdf4eda7c4c5798b9832e086946e3730
download
26bbc85ff306e94cf9fa224df8e7088c4d261449.tar.gz

Add CameraOperatingMode service



Diff

 characteristic/event_snapshots_active.go    | 19 ++++++++++++++++++-
 characteristic/homekit_camera_active.go     | 19 ++++++++++++++++++-
 characteristic/periodic_snapshots_active.go | 19 ++++++++++++++++++-
 cmd/hkbi/main.go                            | 12 +++++++++--
 service/camera_operating_mode.go            | 32 ++++++++++++++++++++++++++++++-
 service/data_stream_management.go           |  1 +-
 6 files changed, 100 insertions(+), 2 deletions(-)

diff --git a/characteristic/event_snapshots_active.go b/characteristic/event_snapshots_active.go
new file mode 100644
index 0000000..7d030ea
--- /dev/null
+++ b/characteristic/event_snapshots_active.go
@@ -0,0 +1,19 @@
package characteristic

import "github.com/brutella/hap/characteristic"

const TypeEventSnapshotsActive = "223"

type EventSnapshotsActive struct {
	*characteristic.Bool
}

func NewEventSnapshotsActive() *EventSnapshotsActive {
	c := characteristic.NewBool(TypeEventSnapshotsActive)
	c.Format = characteristic.FormatBool
	c.Permissions = []string{characteristic.PermissionRead, characteristic.PermissionWrite, characteristic.PermissionEvents}

	c.SetValue(false)

	return &EventSnapshotsActive{c}
}
diff --git a/characteristic/homekit_camera_active.go b/characteristic/homekit_camera_active.go
new file mode 100644
index 0000000..5e072a1
--- /dev/null
+++ b/characteristic/homekit_camera_active.go
@@ -0,0 +1,19 @@
package characteristic

import "github.com/brutella/hap/characteristic"

const TypeHomeKitCameraActive = "21B"

type HomeKitCameraActive struct {
	*characteristic.Bool
}

func NewHomeKitCameraActive() *HomeKitCameraActive {
	c := characteristic.NewBool(TypeHomeKitCameraActive)
	c.Format = characteristic.FormatBool
	c.Permissions = []string{characteristic.PermissionRead, characteristic.PermissionWrite, characteristic.PermissionEvents}

	c.SetValue(false)

	return &HomeKitCameraActive{c}
}
diff --git a/characteristic/periodic_snapshots_active.go b/characteristic/periodic_snapshots_active.go
new file mode 100644
index 0000000..c758e30
--- /dev/null
+++ b/characteristic/periodic_snapshots_active.go
@@ -0,0 +1,19 @@
package characteristic

import "github.com/brutella/hap/characteristic"

const TypePeriodicSnapshotsActive = "225"

type PeriodicSnapshotsActive struct {
	*characteristic.Bool
}

func NewPeriodicSnapshotsActive() *PeriodicSnapshotsActive {
	c := characteristic.NewBool(TypePeriodicSnapshotsActive)
	c.Format = characteristic.FormatBool
	c.Permissions = []string{characteristic.PermissionRead, characteristic.PermissionWrite, characteristic.PermissionEvents}

	c.SetValue(false)

	return &PeriodicSnapshotsActive{c}
}
diff --git a/cmd/hkbi/main.go b/cmd/hkbi/main.go
index abbface..0cefdbb 100644
--- a/cmd/hkbi/main.go
+++ b/cmd/hkbi/main.go
@@ -15,6 +15,7 @@ import (
	"github.com/brutella/hap/service"
	"github.com/brutella/hap/tlv8"
	"github.com/w4/hkbi/blueiris"
	service2 "github.com/w4/hkbi/service"
	"io"
	"math/rand"
	"net"
@@ -132,9 +133,12 @@ func run(config Config) {
			hasDiscoveredNewCameras = true
		}

		// setup stream request handling on management channels 1 & 2
		// setup stream request handling on channel 1
		startListeningForStreams(camera.Id, cam.StreamManagement1, globalState, &config, bi.BaseUrl)
		startListeningForStreams(camera.Id, cam.StreamManagement2, globalState, &config, bi.BaseUrl)

		// create the camera operating mode service
		cameraOperatingMode := service2.NewCameraOperatingMode()
		cam.AddS(cameraOperatingMode.S)

		// create the HomeKit motion sensor service
		motionSensor := service.NewMotionSensor()
@@ -316,6 +320,10 @@ func run(config Config) {

// sets up a camera accessory for streaming
func startListeningForStreams(cameraName string, mgmt *service.CameraRTPStreamManagement, globalState *GlobalState, config *Config, blueirisBase *url.URL) {
	// add active characteristic to rtpstream
	active := characteristic.NewActive()
	mgmt.AddC(active.C)

	// set up some basic parameters for HomeKit to know that the camera is available
	setTlv8Payload(mgmt.StreamingStatus.Bytes, rtp.StreamingStatus{Status: rtp.StreamingStatusAvailable})
	setTlv8Payload(mgmt.SupportedRTPConfiguration.Bytes, rtp.NewConfiguration(rtp.CryptoSuite_AES_CM_128_HMAC_SHA1_80))
diff --git a/service/camera_operating_mode.go b/service/camera_operating_mode.go
new file mode 100644
index 0000000..3767df4
--- /dev/null
+++ b/service/camera_operating_mode.go
@@ -0,0 +1,32 @@
package service

import (
	"github.com/brutella/hap/service"
	characteristic2 "github.com/w4/hkbi/characteristic"
)

const TypeCameraOperatingMode = "21A"

type CameraOperatingMode struct {
	*service.S

	EventSnapshotsActive    *characteristic2.EventSnapshotsActive
	HomeKitCameraActive     *characteristic2.HomeKitCameraActive
	PeriodicSnapshotsActive *characteristic2.PeriodicSnapshotsActive
}

func NewCameraOperatingMode() *CameraOperatingMode {
	s := CameraOperatingMode{}
	s.S = service.New(TypeCameraOperatingMode)

	s.EventSnapshotsActive = characteristic2.NewEventSnapshotsActive()
	s.AddC(s.EventSnapshotsActive.C)

	s.HomeKitCameraActive = characteristic2.NewHomeKitCameraActive()
	s.AddC(s.HomeKitCameraActive.C)

	s.PeriodicSnapshotsActive = characteristic2.NewPeriodicSnapshotsActive()
	s.AddC(s.PeriodicSnapshotsActive.C)

	return &s
}
diff --git a/service/data_stream_management.go b/service/data_stream_management.go
new file mode 100644
index 0000000..6d43c33
--- /dev/null
+++ b/service/data_stream_management.go
@@ -0,0 +1 @@
package service