{"id":13414946,"url":"https://github.com/brutella/hc","last_synced_at":"2025-05-15T02:06:15.005Z","repository":{"id":27814113,"uuid":"31303615","full_name":"brutella/hc","owner":"brutella","description":"hc is a lightweight framework to develop HomeKit accessories in Go.","archived":false,"fork":false,"pushed_at":"2023-07-18T09:59:09.000Z","size":2775,"stargazers_count":1745,"open_issues_count":17,"forks_count":187,"subscribers_count":51,"default_branch":"master","last_synced_at":"2025-04-13T23:54:24.722Z","etag":null,"topics":["go","hap","homekit"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brutella.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-02-25T08:14:23.000Z","updated_at":"2025-04-08T16:58:02.000Z","dependencies_parsed_at":"2024-01-07T21:02:35.329Z","dependency_job_id":"d41e0a2f-92ab-4327-aac6-e667718ef002","html_url":"https://github.com/brutella/hc","commit_stats":{"total_commits":483,"total_committers":19,"mean_commits":25.42105263157895,"dds":0.06418219461697727,"last_synced_commit":"dfb7ee9aad34263b2703e5734bc1521efe7dfa9b"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brutella%2Fhc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brutella%2Fhc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brutella%2Fhc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brutella%2Fhc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brutella","download_url":"https://codeload.github.com/brutella/hc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254259370,"owners_count":22040819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","hap","homekit"],"created_at":"2024-07-30T21:00:40.211Z","updated_at":"2025-05-15T02:06:14.987Z","avatar_url":"https://github.com/brutella.png","language":"Go","readme":"# Not Maintained Anymore\n\n**This library is not maintained anymore. Please switch to the new [hap](https://github.com/brutella/hap) library.**\n\n---\n\n[![GoDoc Widget]][GoDoc]\n\n`hc` is a lightweight framework to develop HomeKit accessories in Go.\nIt abstracts the **H**omeKit **A**ccessory **P**rotocol (HAP) and makes it easy to work with [services](service/README.md) and [characteristics](characteristic/README.md).\n\n`hc` handles the underlying communication between HomeKit accessories and clients.\nYou can focus on implementing the business logic for your accessory, without having to worry about the protocol.\n\nHere are some projects which use `hc`.\n\n- [hkknx](https://hochgatterer.me/hkknx)\n- [hkcam](https://github.com/brutella/hkcam)\n- [hklifx](https://github.com/brutella/hklifx/)\n- [hkuvr](https://github.com/brutella/hkuvr)\n- [hksymo](https://github.com/brutella/hksymo)\n\n**What is HomeKit?**\n\n[HomeKit][homekit] is a set of protocols and libraries from Apple. It is used by Apple's platforms to communicate with smart home appliances. A non-commercial version of the documentation is now available on the [HomeKit developer website](https://developer.apple.com/homekit/).\n\nHomeKit is fully integrated into iOS since iOS 8. Developers can use [HomeKit.framework](https://developer.apple.com/documentation/homekit) to communicate with accessories using high-level APIs.\n\n\u003cimg alt=\"Home+.app\" src=\"_img/home-icon.png?raw=true\" width=\"87\" /\u003e\n\nI've developed the [Home+][home+] app to control HomeKit accessories from iPhone, iPad, and Apple Watch.\nIf you want to support `hc`, please purchase Home from the [App Store][home-appstore]. That would be awesome. ❤️\n\nCheckout the official [website][home+].\n\n[home+]: https://hochgatterer.me/home/\n[home-appstore]: http://itunes.apple.com/app/id995994352\n[GoDoc]: https://godoc.org/github.com/brutella/hc\n[GoDoc Widget]: https://godoc.org/github.com/brutella/hc?status.svg\n\n## Features\n\n- Supports Go modules (requires Go 1.13)\n- Full implementation of the HAP in Go\n- Supports all HomeKit [services and characteristics](service/README.md)\n- Built-in service announcement via DNS-SD using [dnssd](http://github.com/brutella/dnssd)\n- Runs on linux and macOS\n- Documentation: http://godoc.org/github.com/brutella/hc\n\n## Getting Started\n\n1. [Install](http://golang.org/doc/install) and [set up](http://golang.org/doc/code.html#Organization) Go\n2. Create your own HomeKit accessory or clone an existing one (e.g.  [hklight](https://github.com/brutella/hklight))\n\n        cd $GOPATH/src\n\n        # Clone project\n        git clone https://github.com/brutella/hklight \u0026\u0026 cd hklight\n\n        # Run the project\n        make run\n\n3. Pair with your HomeKit App of choice (e.g. [Home][home-appstore])\n\n**Go Modules**\n\n`hc` supports [Go module](https://github.com/golang/go/wiki/Modules) since `v1.0.0`.\nMake sure to set the environment variable `GO111MODULE=on`.\n\n## Example\n\nSee [_example](_example) for a variety of examples.\n\n**Basic switch accessory**\n\nCreate a simple on/off switch, which is accessible via IP and secured using the pin *00102003*.\n\n```go\npackage main\n\nimport (\n    \"log\"\n    \"github.com/brutella/hc\"\n    \"github.com/brutella/hc/accessory\"\n)\n\nfunc main() {\n    // create an accessory\n    info := accessory.Info{Name: \"Lamp\"}\n    ac := accessory.NewSwitch(info)\n\n    // configure the ip transport\n    config := hc.Config{Pin: \"00102003\"}\n    t, err := hc.NewIPTransport(config, ac.Accessory)\n    if err != nil {\n        log.Panic(err)\n    }\n\n    hc.OnTermination(func(){\n        \u003c-t.Stop()\n    })\n\n    t.Start()\n}\n```\n\nYou can define more specific accessory info, if you want.\n\n```go\ninfo := accessory.Info{\n    Name: \"Lamp\",\n    SerialNumber: \"051AC-23AAM1\",\n    Manufacturer: \"Apple\",\n    Model: \"AB\",\n    FirmwareRevision: \"1.0.1\",\n}\n```\n\n### Events\n\nThe library provides callback functions, which let you know when a clients updates a characteristic value.\nThe following example shows how to get notified when the [On](characteristic/on.go) characteristic value changes.\n\n```go\nac.Switch.On.OnValueRemoteUpdate(func(on bool) {\n    if on == true {\n        log.Println(\"Switch is on\")\n    } else {\n        log.Println(\"Switch is off\")\n    }\n})\n```\n\nWhen the switch is turned on \"the analog way\", you should set the state of the accessory.\n\n```go\nac.Switch.On.SetValue(true)\n```\n\n## Multiple Accessories\n\nWhen you create an IP transport, you can specify more than one accessory like this\n\n```go\nbridge := accessory.NewBridge(...)\noutlet := accessory.NewOutlet(...)\nlightbulb := accessory.NewColoredLightbulb(...)\n\nhc.NewIPTransport(config, bridge.Accessory, outlet.Accessory, lightbulb.Accessory)\n```\n\nBy doing so, the *bridge* accessory will become a HomeKit bridge.\nThe *outlet* and *lightbulb* are the bridged accessories.\n\nWhen adding the accessories to HomeKit, iOS only shows the *bridge* accessory.\nOnce the bridge was added, the other accessories appear automatically.\n\nHomeKit requires that every accessory has a unique id, which must not change between system restarts.\n`hc` automatically assigns the ids for you based on the order in which the accessories are added to the bridge.\n\nBut I recommend that you specify the accessory id yourself, via the [accessory.Config.ID](https://github.com/brutella/hc/blob/master/accessory/accessory.go#L13) field, like this.\n\n```go\nbridge := accessory.NewBridge(accessory.Info{Name: \"Bridge\", ID: 1})\noutlet := accessory.NewOutlet(accessory.Info{Name: \"Outlet\", ID: 2})\nlightbulb := accessory.NewColoredLightbulb(accessory.Info{Name: \"Light\", ID: 3})\n```\n\n## Accessory Architecture\n\nHomeKit uses a hierarchical architecture to define accessories, services and characeristics.\nAt the root level there is an accessory.\nEvery accessory contains services.\nAnd every service contains characteristics.\n\nFor example a [lightbulb accessory](accessory/lightbulb.go) contains a [lightbulb service](service/lightbulb.go).\nThis service contains characteristics like [on](characteristic/on.go) and [brightness](characteristic/brightness.go).\n\nThere are predefined accessories, services and characteristics available in HomeKit.\nThose types are defined in the packages [accessory](accessory), [service](service), [characteristic](characteristic).\n\n# Contact\n\nMatthias Hochgatterer\n\nWebsite: [https://hochgatterer.me](https://hochgatterer.me)\n\nGithub: [https://github.com/brutella](https://github.com/brutella/)\n\nTwitter: [https://twitter.com/brutella](https://twitter.com/brutella)\n\n\n# License\n\n`hc` is available under the Apache License 2.0 license. See the LICENSE file for more info.\n\n[homekit]: https://developer.apple.com/homekit/\n","funding_links":[],"categories":["Uncategorized","开源类库","Open source library","Go"],"sub_categories":["Uncategorized","未归类","Not Categorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrutella%2Fhc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrutella%2Fhc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrutella%2Fhc/lists"}