hkontroller

package module
v0.0.0-...-4df431f Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: Apache-2.0 Imports: 32 Imported by: 4 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

hkontrol

Derivative work from github.com/brutella/hap, library to create HomeKit accessories.

This module (hkontrol) provides functional of HomeKit Controller.

contributing

This project currently is early draft and there is a lot to do. Any contribution is welcome. If you want to help you may open issue, create pull request or spread a word about this project.

Documentation

Index

Constants

View Source
const (
	JsonStatusSuccess                     = 0
	JsonStatusInsufficientPrivileges      = -70401
	JsonStatusServiceCommunicationFailure = -70402
	JsonStatusResourceBusy                = -70403
	JsonStatusReadOnlyCharacteristic      = -70404
	JsonStatusWriteOnlyCharacteristic     = -70405
	JsonStatusNotificationNotSupported    = -70406
	JsonStatusOutOfResource               = -70407
	JsonStatusOperationTimedOut           = -70408
	JsonStatusResourceDoesNotExist        = -70409
	JsonStatusInvalidValueInRequest       = -70410
)

Status codes for json communication.

View Source
const (
	// HTTPContentTypePairingTLV8 is the HTTP content type for tlv8 data
	HTTPContentTypePairingTLV8 = "application/pairing+tlv8"

	// HTTPContentTypeHAPJson is the HTTP content type for json data
	HTTPContentTypeHAPJson = "application/hap+json"
)
View Source
const (
	MethodPair          byte = 0x0 // pair
	MethodPairMFi       byte = 0x1 // MFi compliant accessory
	MethodVerifyPair    byte = 0x2 // verify a pairing
	MethodAddPairing    byte = 0x3 // add client through secure connection
	MethodDeletePairing byte = 0x4 // delete pairing through secure connection
	MethodListPairings  byte = 0x5
)
View Source
const (
	// PermissionUser is the user permission for a devices controller.
	PermissionUser byte = 0x0
	// PermissionAdmin is the administrator permission for a devices controller.
	PermissionAdmin byte = 0x1
)
View Source
const (
	M1 byte = 0x1
	M2 byte = 0x2
	M3 byte = 0x3
	M4 byte = 0x4
	M5 byte = 0x5
	M6 byte = 0x6
)

Variables

View Source
var (
	TlvErrorUnknown        = TlvError{0x1, "unknown"}
	TlvErrorAuthentication = TlvError{0x2, "setup code or signature verification failed"}
	TlvErrorBackoff        = TlvError{0x3,
		"client must look at the retry delay TLV item and wait that many seconds before retrying"}
	TlvErrorMaxPeers    = TlvError{0x4, "server cannot accept any more pairings"}
	TlvErrorMaxTries    = TlvError{0x5, "server reached its maximum number of authentication attempts"}
	TlvErrorUnavailable = TlvError{0x6, "server pairing method is unavailable"}
	TlvErrorBusy        = TlvError{0x7, "server is busy and cannot accept a pairing request at this time"}
)

Error codes for TLV8 communication.

Functions

func TlvErrorFromCode

func TlvErrorFromCode(code byte) error

Types

type Accessories

type Accessories struct {
	Accs []*Accessory `json:"accessories,omitempty"`
}

type Accessory

type Accessory struct {
	Id uint64                `json:"aid"`
	Ss []*ServiceDescription `json:"services"`
}

func (*Accessory) GetService

func (a *Accessory) GetService(serviceType HapServiceType) *ServiceDescription

type CharacteristicDescription

type CharacteristicDescription struct {
	Aid         uint64                `json:"aid"`
	Iid         uint64                `json:"iid"`
	Type        HapCharacteristicType `json:"type"`
	Value       interface{}           `json:"value"`
	Permissions []string              `json:"perms"`

	// optional values
	Format      *string     `json:"format,omitempty"`
	Status      *int        `json:"status,omitempty"`
	Events      *bool       `json:"ev,omitempty"`
	Unit        *string     `json:"unit,omitempty"`
	MinValue    interface{} `json:"minValue,omitempty"`
	MaxValue    interface{} `json:"maxValue,omitempty"`
	MinStep     interface{} `json:"minStep,omitempty"`
	MaxLen      *int        `json:"maxLen,omitempty"`
	ValidValues []int       `json:"valid-values,omitempty"`
	ValidRange  []int       `json:"valid-values-range,omitempty"`
}

type CharacteristicEvent

type CharacteristicEvent struct {
	Characteristics []CharacteristicDescription `json:"characteristics"`
}

type CharacteristicPut

type CharacteristicPut struct {
	Aid uint64 `json:"aid"`
	Iid uint64 `json:"iid"`

	Value  interface{} `json:"value,omitempty"`
	Status *int        `json:"status,omitempty"`
	Events *bool       `json:"ev,omitempty"`

	Remote   *bool `json:"remote,omitempty"`
	Response *bool `json:"r,omitempty"`
}

type Controller

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

func NewController

func NewController(store Store, name string) (*Controller, error)

func (*Controller) GetAllDevices

func (c *Controller) GetAllDevices() []*Device

GetAllDevices returns list of all devices loaded or discovered by controller.

func (*Controller) GetDevice

func (c *Controller) GetDevice(deviceName string) *Device

func (*Controller) GetPairedDevices

func (c *Controller) GetPairedDevices() []*Device

GetPairedDevices returns list of devices that has been paired. Connected or not.

func (*Controller) GetVerifiedDevices

func (c *Controller) GetVerifiedDevices() []*Device

GetVerifiedDevices returns list of devices with established encrypted session.

func (*Controller) LoadPairings

func (c *Controller) LoadPairings() error

func (*Controller) StartDiscovery

func (c *Controller) StartDiscovery() (<-chan *Device, <-chan *Device)

func (*Controller) StartDiscoveryWithContext

func (c *Controller) StartDiscoveryWithContext(ctx context.Context) (<-chan *Device, <-chan *Device)

func (*Controller) StopDiscovery

func (c *Controller) StopDiscovery()

type Device

type Device struct {
	Name string
	// contains filtered or unexported fields
}

func (*Device) Accessories

func (d *Device) Accessories() []*Accessory

Accessories return list of previously discovered accessories. GetAccessories should be called prior to this call.

func (*Device) Close

func (d *Device) Close() error

func (*Device) CloseReason

func (d *Device) CloseReason() error

CloseReason returns last close reason if connection is closed

func (*Device) GetAccessories

func (d *Device) GetAccessories() error

GetAccessories sends GET /accessories request and store result that can be retrieved with Accessories() method.

func (*Device) GetCharacteristic

func (d *Device) GetCharacteristic(aid uint64, cid uint64) (CharacteristicDescription, error)

GetCharacteristic sends GET /characteristic request and return characteristic description and value.

func (*Device) GetDnssdEntry

func (d *Device) GetDnssdEntry() dnssd.BrowseEntry

func (*Device) GetPairingInfo

func (d *Device) GetPairingInfo() Pairing

func (*Device) IsDiscovered

func (d *Device) IsDiscovered() bool

IsDiscovered indicates if device is advertised via multicast dns

func (*Device) IsPaired

func (d *Device) IsPaired() bool

IsPaired returns true if device is paired by this controller. If another client is paired with device it will return false.

func (*Device) IsVerified

func (d *Device) IsVerified() bool

IsVerified returns true if /pair-verify step was completed by this controller.

func (*Device) ListPairings

func (d *Device) ListPairings() ([]Pairing, error)

ListPairings should list all controllers of device.

func (*Device) OffClose

func (d *Device) OffClose(ch <-chan emitter.Event)

func (*Device) OffDiscovered

func (d *Device) OffDiscovered(ch <-chan emitter.Event)

func (*Device) OffLost

func (d *Device) OffLost(ch <-chan emitter.Event)

func (*Device) OffPaired

func (d *Device) OffPaired(ch <-chan emitter.Event)

func (*Device) OffUnpaired

func (d *Device) OffUnpaired(ch <-chan emitter.Event)

func (*Device) OffVerified

func (d *Device) OffVerified(ch <-chan emitter.Event)

func (*Device) OnClose

func (d *Device) OnClose() <-chan emitter.Event

func (*Device) OnDiscovered

func (d *Device) OnDiscovered() <-chan emitter.Event

func (*Device) OnLost

func (d *Device) OnLost() <-chan emitter.Event

func (*Device) OnPaired

func (d *Device) OnPaired() <-chan emitter.Event

func (*Device) OnUnpaired

func (d *Device) OnUnpaired() <-chan emitter.Event

func (*Device) OnVerified

func (d *Device) OnVerified() <-chan emitter.Event

func (*Device) PairAdd

func (d *Device) PairAdd(p Pairing) error

PairAdd serves to pair another controller.

func (*Device) PairRemove

func (d *Device) PairRemove(controllerId string) error

func (*Device) PairSetup

func (d *Device) PairSetup(pin string) error

func (*Device) PairVerify

func (d *Device) PairVerify() error

PairVerify

func (*Device) PutCharacteristic

func (d *Device) PutCharacteristic(aid uint64, cid uint64, val interface{}) error

PutCharacteristic makes PUT /characteristic request to control characteristic value.

func (*Device) SubscribeToAccessoryEvents

func (d *Device) SubscribeToAccessoryEvents(aid uint64) (<-chan emitter.Event, error)

func (*Device) SubscribeToAllEvents

func (d *Device) SubscribeToAllEvents() (<-chan emitter.Event, error)

func (*Device) SubscribeToEvents

func (d *Device) SubscribeToEvents(aid uint64, iid uint64) (<-chan emitter.Event, error)

func (*Device) Unpair

func (d *Device) Unpair() error

func (*Device) UnsubscribeFromAccessoryEvents

func (d *Device) UnsubscribeFromAccessoryEvents(aid uint64, channels ...<-chan emitter.Event) error

func (*Device) UnsubscribeFromAllEvents

func (d *Device) UnsubscribeFromAllEvents(channels ...<-chan emitter.Event) error

func (*Device) UnsubscribeFromEvents

func (d *Device) UnsubscribeFromEvents(aid uint64, iid uint64, channels ...<-chan emitter.Event) error

type HapCharacteristicType

type HapCharacteristicType string
const (
	CType_Identify                                  HapCharacteristicType = "14"
	CType_Manufacturer                              HapCharacteristicType = "20"
	CType_Model                                     HapCharacteristicType = "21"
	CType_Name                                      HapCharacteristicType = "23"
	CType_SerialNumber                              HapCharacteristicType = "30"
	CType_Version                                   HapCharacteristicType = "37"
	CType_FirmwareRevision                          HapCharacteristicType = "52"
	CType_HardwareRevision                          HapCharacteristicType = "53"
	CType_On                                        HapCharacteristicType = "25"
	CType_Brightness                                HapCharacteristicType = "8"
	CType_AccessoryFlags                            HapCharacteristicType = "A6"
	CType_Active                                    HapCharacteristicType = "B0"
	CType_ActiveIdentifier                          HapCharacteristicType = "E7"
	CType_AdministratorOnlyAccess                   HapCharacteristicType = "1"
	CType_AudioFeedback                             HapCharacteristicType = "5"
	CType_AirParticulateSize                        HapCharacteristicType = "65"
	CType_AirQuality                                HapCharacteristicType = "95"
	CType_BatteryLevel                              HapCharacteristicType = "68"
	CType_ButtonEvent                               HapCharacteristicType = "126"
	CType_CarbonMonoxideLevel                       HapCharacteristicType = "90"
	CType_CarbonMonoxidePeakLevel                   HapCharacteristicType = "91"
	CType_CarbonMonoxideDetected                    HapCharacteristicType = "69"
	CType_CarbonDioxideLevel                        HapCharacteristicType = "93"
	CType_CarbonDioxidePeakLevel                    HapCharacteristicType = "94"
	CType_CarbonDioxideDetected                     HapCharacteristicType = "92"
	CType_ChargingState                             HapCharacteristicType = "8F"
	CType_CoolingThresholdTemperature               HapCharacteristicType = "D"
	CType_ColorTemperature                          HapCharacteristicType = "CE"
	CType_ContactSensorState                        HapCharacteristicType = "6A"
	CType_CurrentAmbientLightLevel                  HapCharacteristicType = "6B"
	CType_CurrentHorizontalTiltAngle                HapCharacteristicType = "6C"
	CType_CurrentAirPurifierState                   HapCharacteristicType = "A9"
	CType_CurrentSlatState                          HapCharacteristicType = "AA"
	CType_CurrentPosition                           HapCharacteristicType = "6D"
	CType_CurrentVerticalTiltAngle                  HapCharacteristicType = "6E"
	CType_CurrentHumidifierDehumidifierState        HapCharacteristicType = "B3"
	CType_CurrentDoorState                          HapCharacteristicType = "E"
	CType_CurrentFanState                           HapCharacteristicType = "AF"
	CType_CurrentHeatingCoolingState                HapCharacteristicType = "F"
	CType_CurrentHeaterCoolerState                  HapCharacteristicType = "B1"
	CType_CurrentRelativeHumidity                   HapCharacteristicType = "10"
	CType_CurrentTemperature                        HapCharacteristicType = "11"
	CType_CurrentTiltAngle                          HapCharacteristicType = "C1"
	CType_DigitalZoom                               HapCharacteristicType = "11D"
	CType_FilterLifeLevel                           HapCharacteristicType = "AB"
	CType_FilterChangeIndication                    HapCharacteristicType = "AC"
	CType_HeatingThresholdTemperature               HapCharacteristicType = "12"
	CType_HoldPosition                              HapCharacteristicType = "6F"
	CType_Hue                                       HapCharacteristicType = "13"
	CType_ImageRotation                             HapCharacteristicType = "11E"
	CType_ImageMirroring                            HapCharacteristicType = "11F"
	CType_InUse                                     HapCharacteristicType = "D2"
	CType_IsConfigured                              HapCharacteristicType = "D6"
	CType_LeakDetected                              HapCharacteristicType = "70"
	CType_LockControlPoint                          HapCharacteristicType = "19"
	CType_LockCurrentState                          HapCharacteristicType = "1D"
	CType_LockLastKnownAction                       HapCharacteristicType = "1C"
	CType_LockManagementAutoSecurityTimeout         HapCharacteristicType = "1A"
	CType_LockPhysicalControls                      HapCharacteristicType = "A7"
	CType_LockTargetState                           HapCharacteristicType = "1E"
	CType_Logs                                      HapCharacteristicType = "1F"
	CType_MotionDetected                            HapCharacteristicType = "22"
	CType_Mute                                      HapCharacteristicType = "11A"
	CType_NightVision                               HapCharacteristicType = "11B"
	CType_NitrogenDioxideDensity                    HapCharacteristicType = "C4"
	CType_ObstructionDetected                       HapCharacteristicType = "24"
	CType_PM25Density                               HapCharacteristicType = "C6"
	CType_OccupancyDetected                         HapCharacteristicType = "71"
	CType_OpticalZoom                               HapCharacteristicType = "11C"
	CType_OutletInUse                               HapCharacteristicType = "26"
	CType_OzoneDensity                              HapCharacteristicType = "C3"
	CType_PM10Density                               HapCharacteristicType = "C7"
	CType_PositionState                             HapCharacteristicType = "72"
	CType_ProgramMode                               HapCharacteristicType = "D1"
	CType_ProgrammableSwitchEvent                   HapCharacteristicType = "73"
	CType_RelativeHumidityDehumidifierThreshold     HapCharacteristicType = "C9"
	CType_RelativeHumidityHumidifierThreshold       HapCharacteristicType = "CA"
	CType_RemainingDuration                         HapCharacteristicType = "D4"
	CType_ResetFilterIndication                     HapCharacteristicType = "AD"
	CType_RotationDirection                         HapCharacteristicType = "28"
	CType_RotationSpeed                             HapCharacteristicType = "29"
	CType_Saturation                                HapCharacteristicType = "2F"
	CType_SecuritySystemAlarmType                   HapCharacteristicType = "BE"
	CType_SecuritySystemCurrentState                HapCharacteristicType = "66"
	CType_SecuritySystemTargetState                 HapCharacteristicType = "67"
	CType_SelectedAudioStreamConfiguration          HapCharacteristicType = "128"
	CType_ServiceLabelIndex                         HapCharacteristicType = "CB"
	CType_ServiceLabelNamespace                     HapCharacteristicType = "CD"
	CType_SetupDataStreamTransport                  HapCharacteristicType = "131"
	CType_SelectedRTPStreamConfiguration            HapCharacteristicType = "117"
	CType_SetupEndpoints                            HapCharacteristicType = "118"
	CType_SiriInputType                             HapCharacteristicType = "132"
	CType_SlatType                                  HapCharacteristicType = "C0"
	CType_SmokeDetected                             HapCharacteristicType = "76"
	CType_StatusActive                              HapCharacteristicType = "75"
	CType_StatusFault                               HapCharacteristicType = "77"
	CType_StatusJammed                              HapCharacteristicType = "78"
	CType_StatusLowBattery                          HapCharacteristicType = "79"
	CType_StatusTampered                            HapCharacteristicType = "7A"
	CType_StreamingStatus                           HapCharacteristicType = "120"
	CType_SupportedAudioStreamConfiguration         HapCharacteristicType = "115"
	CType_SupportedDataStreamTransportConfiguration HapCharacteristicType = "130"
	CType_SupportedRTPConfiguration                 HapCharacteristicType = "116"
	CType_SupportedVideoStreamConfiguration         HapCharacteristicType = "114"
	CType_SulphurDioxideDensity                     HapCharacteristicType = "C5"
	CType_SwingMode                                 HapCharacteristicType = "B6"
	CType_TargetAirPurifierState                    HapCharacteristicType = "A8"
	CType_TargetFanState                            HapCharacteristicType = "BF"
	CType_TargetTiltAngle                           HapCharacteristicType = "C2"
	CType_TargetHeaterCoolerState                   HapCharacteristicType = "B2"
	CType_SetDuration                               HapCharacteristicType = "D3"
	CType_TargetControlSupportedConfiguration       HapCharacteristicType = "123"
	CType_TargetControlList                         HapCharacteristicType = "124"
	CType_TargetHorizontalTiltAngle                 HapCharacteristicType = "7B"
	CType_TargetHumidifierDehumidifierState         HapCharacteristicType = "B4"
	CType_TargetPosition                            HapCharacteristicType = "7C"
	CType_TargetDoorState                           HapCharacteristicType = "32"
	CType_TargetHeatingCoolingState                 HapCharacteristicType = "33"
	CType_TargetRelativeHumidity                    HapCharacteristicType = "34"
	CType_TargetTemperature                         HapCharacteristicType = "35"
	CType_TemperatureDisplayUnits                   HapCharacteristicType = "36"
	CType_TargetVerticalTiltAngle                   HapCharacteristicType = "7D"
	CType_ValveType                                 HapCharacteristicType = "D5"
	CType_VOCDensity                                HapCharacteristicType = "C8"
	CType_Volume                                    HapCharacteristicType = "119"
	CType_WaterLevel                                HapCharacteristicType = "B5"
)

func (HapCharacteristicType) String

func (h HapCharacteristicType) String() string

func (HapCharacteristicType) ToShort

type HapServiceType

type HapServiceType string
const (
	SType_HapProtocolInfo               HapServiceType = "A2"
	SType_AccessoryInfo                 HapServiceType = "3E"
	SType_AirPurifier                   HapServiceType = "BB"
	SType_AirQualitySensor              HapServiceType = "8D"
	SType_AudioStreamManagement         HapServiceType = "127"
	SType_BatteryService                HapServiceType = "96"
	SType_CameraRTPStreamManagement     HapServiceType = "110"
	SType_CarbonDioxideSensor           HapServiceType = "97"
	SType_CarbonMonoxideSensor          HapServiceType = "7F"
	SType_ContactSensor                 HapServiceType = "80"
	SType_DataStreamTransportManagement HapServiceType = "129"
	SType_Door                          HapServiceType = "81"
	SType_Doorbell                      HapServiceType = "121"
	SType_Fan                           HapServiceType = "B7"
	SType_Faucet                        HapServiceType = "D7"
	SType_FilterMaintenance             HapServiceType = "BA"
	SType_GarageDoorOpener              HapServiceType = "41"
	SType_HeaterCooler                  HapServiceType = "BC"
	SType_HumidifierDehumidifier        HapServiceType = "BD"
	SType_HumiditySensor                HapServiceType = "82"
	SType_IrrigationSystem              HapServiceType = "CF"
	SType_LeakSensor                    HapServiceType = "83"
	SType_LightBulb                     HapServiceType = "43"
	SType_LightSensor                   HapServiceType = "84"
	SType_LockManagement                HapServiceType = "44"
	SType_LockMechanism                 HapServiceType = "45"
	SType_Microphone                    HapServiceType = "112"
	SType_MotionSensor                  HapServiceType = "85"
	SType_OccupancySensor               HapServiceType = "86"
	SType_Outlet                        HapServiceType = "47"
	SType_SecuritySystem                HapServiceType = "7E"
	SType_ServiceLabel                  HapServiceType = "CC"
	SType_Siri                          HapServiceType = "133"
	SType_Slat                          HapServiceType = "B9"
	SType_SmokeSensor                   HapServiceType = "87"
	SType_Speaker                       HapServiceType = "113"
	SType_StatelessProgrammableSwitch   HapServiceType = "89"
	SType_Switch                        HapServiceType = "49"
	SType_TargetControl                 HapServiceType = "125"
	SType_TargetControlManagement       HapServiceType = "122"
	SType_TemperatureSensor             HapServiceType = "8A"
	SType_Thermostat                    HapServiceType = "4A"
	SType_Valve                         HapServiceType = "D0"
	SType_Window                        HapServiceType = "8B"
	SType_WindowCovering                HapServiceType = "8C"
)

func (HapServiceType) String

func (h HapServiceType) String() string

func (HapServiceType) ToShort

func (h HapServiceType) ToShort() HapServiceType

type KeyPair

type KeyPair struct {
	Public  []byte
	Private []byte
}

KeyPair holds public and private key.

func GenerateKeyPair

func GenerateKeyPair() (KeyPair, error)

type PairSetupError

type PairSetupError struct {
	Step string
	// contains filtered or unexported fields
}

func (*PairSetupError) Error

func (p *PairSetupError) Error() string

func (*PairSetupError) Unwrap

func (p *PairSetupError) Unwrap() error

type PairVerifyError

type PairVerifyError struct {
	Step string
	// contains filtered or unexported fields
}

func (*PairVerifyError) Error

func (e *PairVerifyError) Error() string

func (*PairVerifyError) Unwrap

func (e *PairVerifyError) Unwrap() error

type Pairing

type Pairing struct {
	Name       string `json:"name"`
	Id         string `json:"id"`
	PublicKey  []byte `json:"pubk"`
	Permission byte   `json:"permission,omitempty"`
}

type ServiceDescription

type ServiceDescription struct {
	Id      uint64                       `json:"iid"`
	Type    HapServiceType               `json:"type"`
	Cs      []*CharacteristicDescription `json:"characteristics"`
	Hidden  *bool                        `json:"hidden,omitempty"`
	Primary *bool                        `json:"primary,omitempty"`
	Linked  []uint64                     `json:"linked,omitempty"`
}

func (*ServiceDescription) GetCharacteristic

func (s *ServiceDescription) GetCharacteristic(characteristicType HapCharacteristicType) *CharacteristicDescription

type Store

type Store interface {

	// Set sets the value for the given key.
	Set(key string, value []byte) error

	// Get returns the value for the given key.
	Get(key string) ([]byte, error)

	// Delete deletes the value for the given key.
	Delete(key string) error

	// KeysWithSuffix returns a list keys with the give suffix.
	KeysWithSuffix(suffix string) ([]string, error)
}

A Store lets you store key-value pairs.

func NewFsStore

func NewFsStore(dir string) Store

func NewMemStore

func NewMemStore() Store

type TlvError

type TlvError struct {
	Code    byte
	Message string
}

func (*TlvError) Error

func (t *TlvError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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