homekit

package module
v0.0.0-...-bc2160c Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2020 License: Apache-2.0 Imports: 24 Imported by: 0

README

homekit

CI License codecov Made by Alexey Burmistrov

Usage

package main

import (
    "context"
    "net/http"

    "github.com/MrEhbr/homekit"
    "github.com/brutella/hc"
    "github.com/brutella/hc/accessory"
    "github.com/brutella/hc/log"
)

func main() {
    // create an accessory
    info := accessory.Info{Name: "Lamp"}
    ac := accessory.NewSwitch(info)

    t, err := homekit.NewTransport(12345, "config", "00102003", ac.Accessory)
    if err != nil {
        log.Info.Panic(err)
    }

    ctx, cancel := context.WithCancel(context.Background())

    hc.OnTermination(func() {
        cancel()
    })

    if err := t.Run(ctx); err != nil && err != http.ErrServerClosed {
        log.Info.Printf("transport Run error: %s", err)
    }
}
Using go
go get -u github.com/MrEhbr/homekit

Attribution

transport.go, config.go are forked from the github.com/brutella/hc package.

Those files are Copyright (c) 2017, Matthias Hochgatterer and subject to the conditions in LICENSE.

Any added files (such as storage.go) are subject to the conditions in the Homekit LICENSE file

License

© 2020 [Alexey Burmistrov]

Licensed under the Apache License, Version 2.0 (LICENSE). See the COPYRIGHT file for more details.

SPDX-License-Identifier: Apache-2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Name         string `json:"name"`
	ID           string `json:"id"`
	ServePort    int    `json:"server_port"`
	Pin          string `json:"pin"`
	Version      int    `json:"version"`
	CategoryID   uint8  `json:"category_id"`
	State        int    `json:"state"`
	Protocol     string `json:"protocol"`
	Discoverable bool   `json:"discoverable"`
	MfiCompliant bool   `json:"mfi_compliant"`
	ConfigHash   []byte `json:"config_hash"`
	SetupID      string `json:"setup_id"`
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(name string, storage configStorage) *Config

func (*Config) Load

func (cfg *Config) Load() error

func (Config) MDNSRecords

func (cfg Config) MDNSRecords() map[string]string

func (*Config) Save

func (cfg *Config) Save() error

type Storage

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

func NewDatabase

func NewDatabase(dir string) (*Storage, error)

func (*Storage) DeleteEntity

func (store *Storage) DeleteEntity(entity db.Entity)

func (*Storage) Entities

func (store *Storage) Entities() ([]db.Entity, error)

func (*Storage) EntityWithName

func (store *Storage) EntityWithName(name string) (db.Entity, error)

func (*Storage) Get

func (store *Storage) Get(key []byte) ([]byte, error)

func (*Storage) SaveEntity

func (store *Storage) SaveEntity(entity db.Entity) error

func (*Storage) Set

func (store *Storage) Set(key, data []byte) error

type Transport

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

func NewTransport

func NewTransport(port int, path, pin string, acc ...*accessory.Accessory) (*Transport, error)

func (*Transport) AddAccessory

func (t *Transport) AddAccessory(acc *accessory.Accessory) error

func (*Transport) Handle

func (t *Transport) Handle(ev interface{})

func (*Transport) IsPaired

func (t *Transport) IsPaired() bool

func (*Transport) RemoveAccessory

func (t *Transport) RemoveAccessory(acc *accessory.Accessory)

func (*Transport) Run

func (t *Transport) Run(ctx context.Context) error

func (*Transport) UpdateReachability

func (t *Transport) UpdateReachability()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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