Documentation
¶
Index ¶
- Constants
- Variables
- func TlvErrorFromCode(code byte) error
- type Accessories
- type Accessory
- type CharacteristicDescription
- type CharacteristicEvent
- type CharacteristicPut
- type Controller
- func (c *Controller) GetAllDevices() []*Device
- func (c *Controller) GetDevice(deviceName string) *Device
- func (c *Controller) GetPairedDevices() []*Device
- func (c *Controller) GetVerifiedDevices() []*Device
- func (c *Controller) LoadPairings() error
- func (c *Controller) StartDiscovery() (<-chan *Device, <-chan *Device)
- func (c *Controller) StartDiscoveryWithContext(ctx context.Context) (<-chan *Device, <-chan *Device)
- func (c *Controller) StopDiscovery()
- type Device
- func (d *Device) Accessories() []*Accessory
- func (d *Device) Close() error
- func (d *Device) CloseReason() error
- func (d *Device) GetAccessories() error
- func (d *Device) GetCharacteristic(aid uint64, cid uint64) (CharacteristicDescription, error)
- func (d *Device) GetDnssdEntry() dnssd.BrowseEntry
- func (d *Device) GetPairingInfo() Pairing
- func (d *Device) IsDiscovered() bool
- func (d *Device) IsPaired() bool
- func (d *Device) IsVerified() bool
- func (d *Device) ListPairings() ([]Pairing, error)
- func (d *Device) OffClose(ch <-chan emitter.Event)
- func (d *Device) OffDiscovered(ch <-chan emitter.Event)
- func (d *Device) OffLost(ch <-chan emitter.Event)
- func (d *Device) OffPaired(ch <-chan emitter.Event)
- func (d *Device) OffUnpaired(ch <-chan emitter.Event)
- func (d *Device) OffVerified(ch <-chan emitter.Event)
- func (d *Device) OnClose() <-chan emitter.Event
- func (d *Device) OnDiscovered() <-chan emitter.Event
- func (d *Device) OnLost() <-chan emitter.Event
- func (d *Device) OnPaired() <-chan emitter.Event
- func (d *Device) OnUnpaired() <-chan emitter.Event
- func (d *Device) OnVerified() <-chan emitter.Event
- func (d *Device) PairAdd(p Pairing) error
- func (d *Device) PairRemove(controllerId string) error
- func (d *Device) PairSetup(pin string) error
- func (d *Device) PairVerify() error
- func (d *Device) PutCharacteristic(aid uint64, cid uint64, val interface{}) error
- func (d *Device) SubscribeToAccessoryEvents(aid uint64) (<-chan emitter.Event, error)
- func (d *Device) SubscribeToAllEvents() (<-chan emitter.Event, error)
- func (d *Device) SubscribeToEvents(aid uint64, iid uint64) (<-chan emitter.Event, error)
- func (d *Device) Unpair() error
- func (d *Device) UnsubscribeFromAccessoryEvents(aid uint64, channels ...<-chan emitter.Event) error
- func (d *Device) UnsubscribeFromAllEvents(channels ...<-chan emitter.Event) error
- func (d *Device) UnsubscribeFromEvents(aid uint64, iid uint64, channels ...<-chan emitter.Event) error
- type HapCharacteristicType
- type HapServiceType
- type KeyPair
- type PairSetupError
- type PairVerifyError
- type Pairing
- type ServiceDescription
- type Store
- type TlvError
Constants ¶
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.
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" )
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 )
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 )
Variables ¶
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"} TlvErrorBusy = TlvError{0x7, "server is busy and cannot accept a pairing request at this time"} )
Error codes for TLV8 communication.
Functions ¶
func TlvErrorFromCode ¶
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 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 ¶
Accessories return list of previously discovered accessories. GetAccessories should be called prior to this call.
func (*Device) CloseReason ¶
CloseReason returns last close reason if connection is closed
func (*Device) GetAccessories ¶
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 (*Device) IsDiscovered ¶
IsDiscovered indicates if device is advertised via multicast dns
func (*Device) IsPaired ¶
IsPaired returns true if device is paired by this controller. If another client is paired with device it will return false.
func (*Device) IsVerified ¶
IsVerified returns true if /pair-verify step was completed by this controller.
func (*Device) ListPairings ¶
ListPairings should list all controllers of device.
func (*Device) OffDiscovered ¶
func (*Device) OffUnpaired ¶
func (*Device) OffVerified ¶
func (*Device) OnDiscovered ¶
func (*Device) OnUnpaired ¶
func (*Device) OnVerified ¶
func (*Device) PairRemove ¶
func (*Device) PutCharacteristic ¶
PutCharacteristic makes PUT /characteristic request to control characteristic value.
func (*Device) SubscribeToAccessoryEvents ¶
func (*Device) SubscribeToAllEvents ¶
func (*Device) SubscribeToEvents ¶
func (*Device) UnsubscribeFromAccessoryEvents ¶
func (*Device) UnsubscribeFromAllEvents ¶
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 ¶
func (h HapCharacteristicType) ToShort() HapCharacteristicType
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 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 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 NewMemStore ¶
func NewMemStore() Store
Source Files
¶
- accessory.go
- characteristic.go
- conn.go
- const-service-characteristic-types.go
- controller-pair-add.go
- controller-pair-list.go
- controller-pair-remove.go
- controller-pair-setup.go
- controller-pair-verify.go
- controller.go
- device.go
- errors.go
- fs.go
- hap.go
- keypair.go
- mem_store.go
- misc.go
- pair-setup-client-session.go
- pairing.go
- service.go
- session.go
- store.go