├── hap-characteristic ├── hapc.go ├── current_transport.go ├── wifi_capabilities.go ├── wan_status_list.go ├── wan_configuration_list.go ├── supported_router_configuration.go ├── wifi_configuration_control.go ├── network_client_statusc_control.go ├── network_client_profile_control.go ├── network_access_violation_control.go ├── router_status.go ├── wifi_satellite_status.go └── managed_network_enable.go ├── example ├── outlet │ ├── README.md │ └── main.go ├── window │ ├── README.md │ └── main.go ├── sensor_leak │ ├── README.md │ └── main.go ├── sensor_light │ ├── README.md │ └── main.go ├── sensor_smoke │ ├── README.md │ └── main.go ├── sensor_contact │ ├── README.md │ └── main.go ├── sensor_dioxide │ ├── README.md │ └── main.go ├── sensor_humidity │ ├── README.md │ └── main.go ├── sensor_monaxide │ ├── README.md │ └── main.go ├── sensor_motion │ ├── README.md │ └── main.go ├── lightbulb_dimmer │ ├── README.md │ └── main.go ├── security_system │ ├── README.md │ └── main.go ├── sensor_temp │ ├── README.md │ └── main.go ├── window_covering │ ├── README.md │ └── main.go ├── sensor_air_quality │ ├── README.md │ └── main.go ├── thermostat_climate │ └── README.md ├── thermostat_heating │ └── README.md ├── thermostat_uncontrol │ ├── README.md │ └── main.go ├── wifi_router │ ├── README.md │ └── main.go ├── gate │ ├── README.md │ └── main.go ├── faucet │ ├── README.md │ └── main.go ├── smart_speaker │ ├── README.md │ └── main.go ├── irrigation │ ├── README.md │ └── main.go ├── lock │ ├── README.md │ └── main.go ├── air_purifier │ ├── README.md │ └── main.go ├── fan_rs │ ├── README.md │ └── main.go ├── humidifier_dehumidifier │ ├── README.md │ └── main.go ├── lightbulb_colored │ ├── README.md │ └── main.go ├── television │ └── README.md ├── door │ ├── README.md │ └── main.go └── switch │ ├── README.md │ └── main.go ├── gallery ├── tv_1.png ├── tv_2.png ├── tv_3.png ├── tv_4.png ├── tv_5.png ├── tv_6.png ├── tv_7.png ├── tv_8.jpg ├── tv_9.jpg ├── door_1.png ├── door_2.png ├── door_3.png ├── door_4.png ├── door_5.png ├── door_6.png ├── door_7.png ├── door_8.png ├── door_9.png ├── gate_1.png ├── gate_2.png ├── gate_3.png ├── gate_4.png ├── gate_5.png ├── lock_1.png ├── lock_2.png ├── lock_3.png ├── lock_4.png ├── lock_5.png ├── lock_6.png ├── lock_7.png ├── tv_10.jpg ├── door_10.png ├── faucet_1.png ├── faucet_2.png ├── faucet_3.png ├── faucet_4.png ├── faucet_5.png ├── home_off.png ├── home_on.png ├── homekit.jpg ├── homekit_1.png ├── homekit_2.png ├── switch_1.png ├── switch_10.png ├── switch_2.png ├── switch_3.png ├── switch_4.png ├── switch_5.png ├── switch_6.png ├── switch_7.png ├── switch_8.png ├── switch_9.png ├── air_purifier_1.png ├── air_purifier_2.png ├── air_purifier_3.png ├── air_purifier_4.png ├── air_purifier_5.png ├── air_purifier_6.png ├── air_purifier_7.png ├── irrigation_1.png ├── irrigation_2.png ├── irrigation_3.png ├── irrigation_4.png ├── irrigation_5.png ├── irrigation_6.png ├── wifi_router_1.png ├── wifi_router_2.png ├── fan_controlled_1.png ├── fan_controlled_2.png ├── fan_controlled_3.png ├── fan_controlled_4.png ├── fan_controlled_5.png ├── fan_controlled_6.png ├── fan_controlled_7.png ├── smart_speaker_1.png ├── smart_speaker_2.png ├── smart_speaker_3.png ├── smart_speaker_4.png ├── smart_speaker_5.png ├── lightbulb_colored_1.png ├── lightbulb_colored_2.png ├── lightbulb_colored_3.png ├── lightbulb_colored_4.png ├── lightbulb_colored_5.png ├── lightbulb_colored_6.png ├── lightbulb_colored_7.png ├── lightbulb_colored_8.png ├── humidifier_dehumidifier_1.png ├── humidifier_dehumidifier_2.png ├── humidifier_dehumidifier_3.png ├── humidifier_dehumidifier_4.png ├── humidifier_dehumidifier_5.png ├── humidifier_dehumidifier_6.png └── humidifier_dehumidifier_7.png ├── hap-service ├── haps.go ├── fan_rs.go ├── lightbulb_dimmer.go ├── wifi_satellite.go ├── fan2_rs.go ├── door.go ├── wifi_transport.go ├── air_purifier.go ├── television_speaker.go ├── smart_speaker.go ├── security_system_full.go ├── input_source.go ├── humidifier_dehumidifier.go ├── television.go ├── wifi_router.go └── thermostat_middle.go ├── .gitignore ├── homekit_convert.go ├── go.mod ├── accessory_bridge.go ├── accessory_switch.go ├── accessory_lock.go ├── accessory_sensor_leak.go ├── accessory_fan2_rs.go ├── accessory_sensor_smoke.go ├── accessory_sensor_light.go ├── accessory_sensor_motion.go ├── accessory_smart_speaker.go ├── accessory_sensor_contact.go ├── accessory_wifi_router.go ├── accessory_outlet.go ├── accessory_sensor_humidity.go ├── accessory_sensor_dioxide.go ├── accessory_gate.go ├── accessory_sensor_monoxide.go ├── accessory_irrigation.go ├── accessory_sensor_air_quality.go ├── accessory_lightbulb_switch.go ├── accessory_programmable_switch.go ├── accessory_lightbulb_dimmer.go ├── accessory_faucet.go ├── accessory_lightbulb_colored.go ├── accessory_sensor_temperarure.go ├── accessory_camera.go ├── accessory_doorbell.go ├── accessory_door.go ├── accessory_fan_rs.go ├── README.md ├── accessory_window.go ├── homekit_convert_test.go └── accessory_window_covering.go /hap-characteristic/hapc.go: -------------------------------------------------------------------------------- 1 | package hapc 2 | -------------------------------------------------------------------------------- /example/outlet/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Outlet 2 | -------------------------------------------------------------------------------- /example/window/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Window 2 | -------------------------------------------------------------------------------- /example/sensor_leak/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Sensor 2 | -------------------------------------------------------------------------------- /example/sensor_light/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Sensor 2 | -------------------------------------------------------------------------------- /example/sensor_smoke/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Sensor 2 | -------------------------------------------------------------------------------- /example/sensor_contact/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Sensor 2 | -------------------------------------------------------------------------------- /example/sensor_dioxide/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Sensor 2 | -------------------------------------------------------------------------------- /example/sensor_humidity/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Sensor 2 | -------------------------------------------------------------------------------- /example/sensor_monaxide/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Sensor 2 | -------------------------------------------------------------------------------- /example/sensor_motion/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Sensor 2 | -------------------------------------------------------------------------------- /example/lightbulb_dimmer/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Lightbulb Dimmer 2 | -------------------------------------------------------------------------------- /example/security_system/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Security System 2 | -------------------------------------------------------------------------------- /example/sensor_temp/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Sensor Temperature 2 | -------------------------------------------------------------------------------- /example/window_covering/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Window Covering 2 | -------------------------------------------------------------------------------- /example/sensor_air_quality/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Sensor Air Quality 2 | -------------------------------------------------------------------------------- /example/thermostat_climate/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Thermostat Climate 2 | -------------------------------------------------------------------------------- /example/thermostat_heating/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Thermostat Heating 2 | -------------------------------------------------------------------------------- /example/thermostat_uncontrol/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Thermostat Uncontrol 2 | -------------------------------------------------------------------------------- /gallery/tv_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/tv_1.png -------------------------------------------------------------------------------- /gallery/tv_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/tv_2.png -------------------------------------------------------------------------------- /gallery/tv_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/tv_3.png -------------------------------------------------------------------------------- /gallery/tv_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/tv_4.png -------------------------------------------------------------------------------- /gallery/tv_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/tv_5.png -------------------------------------------------------------------------------- /gallery/tv_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/tv_6.png -------------------------------------------------------------------------------- /gallery/tv_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/tv_7.png -------------------------------------------------------------------------------- /gallery/tv_8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/tv_8.jpg -------------------------------------------------------------------------------- /gallery/tv_9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/tv_9.jpg -------------------------------------------------------------------------------- /hap-service/haps.go: -------------------------------------------------------------------------------- 1 | package haps 2 | 3 | // const TypeSprinkler string = "D7" 4 | -------------------------------------------------------------------------------- /gallery/door_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/door_1.png -------------------------------------------------------------------------------- /gallery/door_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/door_2.png -------------------------------------------------------------------------------- /gallery/door_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/door_3.png -------------------------------------------------------------------------------- /gallery/door_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/door_4.png -------------------------------------------------------------------------------- /gallery/door_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/door_5.png -------------------------------------------------------------------------------- /gallery/door_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/door_6.png -------------------------------------------------------------------------------- /gallery/door_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/door_7.png -------------------------------------------------------------------------------- /gallery/door_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/door_8.png -------------------------------------------------------------------------------- /gallery/door_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/door_9.png -------------------------------------------------------------------------------- /gallery/gate_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/gate_1.png -------------------------------------------------------------------------------- /gallery/gate_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/gate_2.png -------------------------------------------------------------------------------- /gallery/gate_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/gate_3.png -------------------------------------------------------------------------------- /gallery/gate_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/gate_4.png -------------------------------------------------------------------------------- /gallery/gate_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/gate_5.png -------------------------------------------------------------------------------- /gallery/lock_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/lock_1.png -------------------------------------------------------------------------------- /gallery/lock_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/lock_2.png -------------------------------------------------------------------------------- /gallery/lock_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/lock_3.png -------------------------------------------------------------------------------- /gallery/lock_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/lock_4.png -------------------------------------------------------------------------------- /gallery/lock_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/lock_5.png -------------------------------------------------------------------------------- /gallery/lock_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/lock_6.png -------------------------------------------------------------------------------- /gallery/lock_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/lock_7.png -------------------------------------------------------------------------------- /gallery/tv_10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/tv_10.jpg -------------------------------------------------------------------------------- /gallery/door_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/door_10.png -------------------------------------------------------------------------------- /gallery/faucet_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/faucet_1.png -------------------------------------------------------------------------------- /gallery/faucet_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/faucet_2.png -------------------------------------------------------------------------------- /gallery/faucet_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/faucet_3.png -------------------------------------------------------------------------------- /gallery/faucet_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/faucet_4.png -------------------------------------------------------------------------------- /gallery/faucet_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/faucet_5.png -------------------------------------------------------------------------------- /gallery/home_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/home_off.png -------------------------------------------------------------------------------- /gallery/home_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/home_on.png -------------------------------------------------------------------------------- /gallery/homekit.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/homekit.jpg -------------------------------------------------------------------------------- /gallery/homekit_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/homekit_1.png -------------------------------------------------------------------------------- /gallery/homekit_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/homekit_2.png -------------------------------------------------------------------------------- /gallery/switch_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/switch_1.png -------------------------------------------------------------------------------- /gallery/switch_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/switch_10.png -------------------------------------------------------------------------------- /gallery/switch_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/switch_2.png -------------------------------------------------------------------------------- /gallery/switch_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/switch_3.png -------------------------------------------------------------------------------- /gallery/switch_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/switch_4.png -------------------------------------------------------------------------------- /gallery/switch_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/switch_5.png -------------------------------------------------------------------------------- /gallery/switch_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/switch_6.png -------------------------------------------------------------------------------- /gallery/switch_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/switch_7.png -------------------------------------------------------------------------------- /gallery/switch_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/switch_8.png -------------------------------------------------------------------------------- /gallery/switch_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/switch_9.png -------------------------------------------------------------------------------- /gallery/air_purifier_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/air_purifier_1.png -------------------------------------------------------------------------------- /gallery/air_purifier_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/air_purifier_2.png -------------------------------------------------------------------------------- /gallery/air_purifier_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/air_purifier_3.png -------------------------------------------------------------------------------- /gallery/air_purifier_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/air_purifier_4.png -------------------------------------------------------------------------------- /gallery/air_purifier_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/air_purifier_5.png -------------------------------------------------------------------------------- /gallery/air_purifier_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/air_purifier_6.png -------------------------------------------------------------------------------- /gallery/air_purifier_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/air_purifier_7.png -------------------------------------------------------------------------------- /gallery/irrigation_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/irrigation_1.png -------------------------------------------------------------------------------- /gallery/irrigation_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/irrigation_2.png -------------------------------------------------------------------------------- /gallery/irrigation_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/irrigation_3.png -------------------------------------------------------------------------------- /gallery/irrigation_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/irrigation_4.png -------------------------------------------------------------------------------- /gallery/irrigation_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/irrigation_5.png -------------------------------------------------------------------------------- /gallery/irrigation_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/irrigation_6.png -------------------------------------------------------------------------------- /gallery/wifi_router_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/wifi_router_1.png -------------------------------------------------------------------------------- /gallery/wifi_router_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/wifi_router_2.png -------------------------------------------------------------------------------- /gallery/fan_controlled_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/fan_controlled_1.png -------------------------------------------------------------------------------- /gallery/fan_controlled_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/fan_controlled_2.png -------------------------------------------------------------------------------- /gallery/fan_controlled_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/fan_controlled_3.png -------------------------------------------------------------------------------- /gallery/fan_controlled_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/fan_controlled_4.png -------------------------------------------------------------------------------- /gallery/fan_controlled_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/fan_controlled_5.png -------------------------------------------------------------------------------- /gallery/fan_controlled_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/fan_controlled_6.png -------------------------------------------------------------------------------- /gallery/fan_controlled_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/fan_controlled_7.png -------------------------------------------------------------------------------- /gallery/smart_speaker_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/smart_speaker_1.png -------------------------------------------------------------------------------- /gallery/smart_speaker_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/smart_speaker_2.png -------------------------------------------------------------------------------- /gallery/smart_speaker_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/smart_speaker_3.png -------------------------------------------------------------------------------- /gallery/smart_speaker_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/smart_speaker_4.png -------------------------------------------------------------------------------- /gallery/smart_speaker_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/smart_speaker_5.png -------------------------------------------------------------------------------- /gallery/lightbulb_colored_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/lightbulb_colored_1.png -------------------------------------------------------------------------------- /gallery/lightbulb_colored_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/lightbulb_colored_2.png -------------------------------------------------------------------------------- /gallery/lightbulb_colored_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/lightbulb_colored_3.png -------------------------------------------------------------------------------- /gallery/lightbulb_colored_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/lightbulb_colored_4.png -------------------------------------------------------------------------------- /gallery/lightbulb_colored_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/lightbulb_colored_5.png -------------------------------------------------------------------------------- /gallery/lightbulb_colored_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/lightbulb_colored_6.png -------------------------------------------------------------------------------- /gallery/lightbulb_colored_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/lightbulb_colored_7.png -------------------------------------------------------------------------------- /gallery/lightbulb_colored_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/lightbulb_colored_8.png -------------------------------------------------------------------------------- /gallery/humidifier_dehumidifier_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/humidifier_dehumidifier_1.png -------------------------------------------------------------------------------- /gallery/humidifier_dehumidifier_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/humidifier_dehumidifier_2.png -------------------------------------------------------------------------------- /gallery/humidifier_dehumidifier_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/humidifier_dehumidifier_3.png -------------------------------------------------------------------------------- /gallery/humidifier_dehumidifier_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/humidifier_dehumidifier_4.png -------------------------------------------------------------------------------- /gallery/humidifier_dehumidifier_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/humidifier_dehumidifier_5.png -------------------------------------------------------------------------------- /gallery/humidifier_dehumidifier_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/humidifier_dehumidifier_6.png -------------------------------------------------------------------------------- /gallery/humidifier_dehumidifier_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxandev/homekit/HEAD/gallery/humidifier_dehumidifier_7.png -------------------------------------------------------------------------------- /example/wifi_router/README.md: -------------------------------------------------------------------------------- 1 | # Accessory WiFi Router 2 | 3 | ![](https://github.com/xxandev/homekit/blob/main/gallery/wifi_router_1.png) 4 | 5 | ![](https://github.com/xxandev/homekit/blob/main/gallery/wifi_router_2.png) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Dependency directories (remove the comment below to include it) 15 | # vendor/ 16 | -------------------------------------------------------------------------------- /example/gate/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Gate 2 | 3 | ![](https://github.com/xxandev/homekit/blob/main/gallery/gate_1.png) 4 | 5 | ![](https://github.com/xxandev/homekit/blob/main/gallery/gate_2.png) 6 | 7 | ![](https://github.com/xxandev/homekit/blob/main/gallery/gate_3.png) 8 | 9 | ![](https://github.com/xxandev/homekit/blob/main/gallery/gate_4.png) 10 | 11 | ![](https://github.com/xxandev/homekit/blob/main/gallery/gate_5.png) -------------------------------------------------------------------------------- /example/faucet/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Faucet 2 | 3 | ![](https://github.com/xxandev/homekit/blob/main/gallery/faucet_1.png) 4 | 5 | ![](https://github.com/xxandev/homekit/blob/main/gallery/faucet_2.png) 6 | 7 | ![](https://github.com/xxandev/homekit/blob/main/gallery/faucet_3.png) 8 | 9 | ![](https://github.com/xxandev/homekit/blob/main/gallery/faucet_4.png) 10 | 11 | ![](https://github.com/xxandev/homekit/blob/main/gallery/faucet_5.png) -------------------------------------------------------------------------------- /example/smart_speaker/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Smart Speaker 2 | 3 | ![](https://github.com/xxandev/homekit/blob/main/gallery/smart_speaker_1.png) 4 | 5 | ![](https://github.com/xxandev/homekit/blob/main/gallery/smart_speaker_2.png) 6 | 7 | ![](https://github.com/xxandev/homekit/blob/main/gallery/smart_speaker_3.png) 8 | 9 | ![](https://github.com/xxandev/homekit/blob/main/gallery/smart_speaker_4.png) 10 | 11 | ![](https://github.com/xxandev/homekit/blob/main/gallery/smart_speaker_5.png) -------------------------------------------------------------------------------- /example/irrigation/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Irrigation 2 | 3 | ![](https://github.com/xxandev/homekit/blob/main/gallery/irrigation_1.png) 4 | 5 | ![](https://github.com/xxandev/homekit/blob/main/gallery/irrigation_2.png) 6 | 7 | ![](https://github.com/xxandev/homekit/blob/main/gallery/irrigation_3.png) 8 | 9 | ![](https://github.com/xxandev/homekit/blob/main/gallery/irrigation_4.png) 10 | 11 | ![](https://github.com/xxandev/homekit/blob/main/gallery/irrigation_5.png) 12 | 13 | ![](https://github.com/xxandev/homekit/blob/main/gallery/irrigation_6.png) -------------------------------------------------------------------------------- /example/lock/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Lock 2 | 3 | ![](https://github.com/xxandev/homekit/blob/main/gallery/lock_1.png) 4 | 5 | ![](https://github.com/xxandev/homekit/blob/main/gallery/lock_2.png) 6 | 7 | ![](https://github.com/xxandev/homekit/blob/main/gallery/lock_3.png) 8 | 9 | ![](https://github.com/xxandev/homekit/blob/main/gallery/lock_4.png) 10 | 11 | ![](https://github.com/xxandev/homekit/blob/main/gallery/lock_5.png) 12 | 13 | ![](https://github.com/xxandev/homekit/blob/main/gallery/lock_6.png) 14 | 15 | ![](https://github.com/xxandev/homekit/blob/main/gallery/lock_7.png) -------------------------------------------------------------------------------- /example/air_purifier/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Air Purifier 2 | 3 | ![](https://github.com/xxandev/homekit/blob/main/gallery/air_purifier_1.png) 4 | 5 | ![](https://github.com/xxandev/homekit/blob/main/gallery/air_purifier_2.png) 6 | 7 | ![](https://github.com/xxandev/homekit/blob/main/gallery/air_purifier_3.png) 8 | 9 | ![](https://github.com/xxandev/homekit/blob/main/gallery/air_purifier_4.png) 10 | 11 | ![](https://github.com/xxandev/homekit/blob/main/gallery/air_purifier_5.png) 12 | 13 | ![](https://github.com/xxandev/homekit/blob/main/gallery/air_purifier_6.png) 14 | 15 | ![](https://github.com/xxandev/homekit/blob/main/gallery/air_purifier_7.png) -------------------------------------------------------------------------------- /example/fan_rs/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Fan Controlled 2 | 3 | ![](https://github.com/xxandev/homekit/blob/main/gallery/fan_controlled_1.png) 4 | 5 | ![](https://github.com/xxandev/homekit/blob/main/gallery/fan_controlled_2.png) 6 | 7 | ![](https://github.com/xxandev/homekit/blob/main/gallery/fan_controlled_3.png) 8 | 9 | ![](https://github.com/xxandev/homekit/blob/main/gallery/fan_controlled_4.png) 10 | 11 | ![](https://github.com/xxandev/homekit/blob/main/gallery/fan_controlled_5.png) 12 | 13 | ![](https://github.com/xxandev/homekit/blob/main/gallery/fan_controlled_6.png) 14 | 15 | ![](https://github.com/xxandev/homekit/blob/main/gallery/fan_controlled_7.png) -------------------------------------------------------------------------------- /hap-service/fan_rs.go: -------------------------------------------------------------------------------- 1 | package haps 2 | 3 | import ( 4 | "github.com/brutella/hap/characteristic" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //FanRS 9 | // ◈ On 10 | // ◇ RotationSpeed 11 | type FanRS struct { 12 | *service.S 13 | On *characteristic.On 14 | RotationSpeed *characteristic.RotationSpeed 15 | } 16 | 17 | //NewFanRS return *FanRS 18 | func NewFanRS() *FanRS { 19 | svc := FanRS{} 20 | svc.S = service.New(service.TypeFan) 21 | 22 | svc.On = characteristic.NewOn() 23 | svc.AddC(svc.On.C) 24 | 25 | svc.RotationSpeed = characteristic.NewRotationSpeed() 26 | svc.AddC(svc.RotationSpeed.C) 27 | 28 | return &svc 29 | } 30 | -------------------------------------------------------------------------------- /homekit_convert.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | func tob(v any, def bool) bool { 4 | if r, ok := v.(bool); ok { 5 | return r 6 | } 7 | return def 8 | } 9 | 10 | func toi(v any, def int) int { 11 | switch r := v.(type) { 12 | case int: 13 | return r 14 | case int8: 15 | return int(r) 16 | case int16: 17 | return int(r) 18 | case int32: 19 | return int(r) 20 | case int64: 21 | return int(r) 22 | } 23 | return def 24 | } 25 | 26 | func tof64(v any, def float64) float64 { 27 | switch r := v.(type) { 28 | case float64: 29 | return r 30 | case float32: 31 | return float64(r) 32 | case int: 33 | return float64(r) 34 | } 35 | return def 36 | } 37 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/xxandev/homekit 2 | 3 | go 1.18 4 | 5 | require github.com/brutella/hap v0.0.20 6 | 7 | require ( 8 | github.com/brutella/dnssd v1.2.4 // indirect 9 | github.com/go-chi/chi v1.5.4 // indirect 10 | github.com/miekg/dns v1.1.50 // indirect 11 | github.com/tadglines/go-pkgs v0.0.0-20210623144937-b983b20f54f9 // indirect 12 | github.com/xiam/to v0.0.0-20200126224905-d60d31e03561 // indirect 13 | golang.org/x/crypto v0.1.0 // indirect 14 | golang.org/x/mod v0.6.0 // indirect 15 | golang.org/x/net v0.1.0 // indirect 16 | golang.org/x/sys v0.1.0 // indirect 17 | golang.org/x/text v0.4.0 // indirect 18 | golang.org/x/tools v0.2.0 // indirect 19 | ) 20 | -------------------------------------------------------------------------------- /hap-characteristic/current_transport.go: -------------------------------------------------------------------------------- 1 | package hapc 2 | 3 | import "github.com/brutella/hap/characteristic" 4 | 5 | //TypeCurrentTransport - 0000021E-0000-1000-8000-0000022B 6 | const TypeCurrentTransport = "22B" 7 | 8 | //CurrentTransport - Formats BOOL 9 | type CurrentTransport struct { 10 | *characteristic.Bool 11 | } 12 | 13 | //NewCurrentTransport return *CurrentTransport 14 | func NewCurrentTransport() *CurrentTransport { 15 | char := characteristic.NewBool(TypeCurrentTransport) 16 | char.Format = characteristic.FormatBool 17 | char.Permissions = []string{characteristic.PermissionRead} 18 | 19 | char.SetValue(false) 20 | 21 | return &CurrentTransport{char} 22 | } 23 | -------------------------------------------------------------------------------- /hap-characteristic/wifi_capabilities.go: -------------------------------------------------------------------------------- 1 | package hapc 2 | 3 | import "github.com/brutella/hap/characteristic" 4 | 5 | //TypeWifiCapabilities - 0000021E-0000-1000-8000-0000022D 6 | //const TypeWifiCapabilities = "22D" 7 | const TypeWifiCapabilities = "22C" 8 | 9 | //WifiCapabilities - Formats UINT32 10 | type WifiCapabilities struct { 11 | *characteristic.Int 12 | } 13 | 14 | //NewWifiCapabilities return *WifiCapabilities 15 | func NewWifiCapabilities() *WifiCapabilities { 16 | char := characteristic.NewInt(TypeWifiCapabilities) 17 | char.Format = characteristic.FormatUInt32 18 | char.Permissions = []string{characteristic.PermissionRead} 19 | 20 | char.SetValue(1) 21 | return &WifiCapabilities{char} 22 | } 23 | -------------------------------------------------------------------------------- /hap-characteristic/wan_status_list.go: -------------------------------------------------------------------------------- 1 | package hapc 2 | 3 | import "github.com/brutella/hap/characteristic" 4 | 5 | //TypeWANStatusList - 00000212-0000-1000-8000-0026BB765291 6 | const TypeWANStatusList string = "212" 7 | 8 | //WANStatusList - Formats TLV8 9 | type WANStatusList struct { 10 | *characteristic.Bytes 11 | } 12 | 13 | //NewWANStatusList return *WANStatusList 14 | func NewWANStatusList() *WANStatusList { 15 | char := characteristic.NewBytes(TypeWANStatusList) 16 | char.Format = characteristic.FormatTLV8 17 | char.Permissions = []string{ 18 | characteristic.PermissionRead, 19 | characteristic.PermissionEvents, 20 | } 21 | 22 | char.SetValue([]byte{}) 23 | 24 | return &WANStatusList{char} 25 | } 26 | -------------------------------------------------------------------------------- /hap-service/lightbulb_dimmer.go: -------------------------------------------------------------------------------- 1 | package haps 2 | 3 | import ( 4 | "github.com/brutella/hap/characteristic" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //LightbulbDimmer 9 | // ◈ On 10 | // ◇ Brightness 11 | type LightbulbDimmer struct { 12 | *service.S 13 | On *characteristic.On 14 | Brightness *characteristic.Brightness 15 | } 16 | 17 | //NewLightbulbDimmer return *LightbulbDimmer 18 | func NewLightbulbDimmer() *LightbulbDimmer { 19 | svc := LightbulbDimmer{} 20 | svc.S = service.New(service.TypeLightbulb) 21 | 22 | svc.On = characteristic.NewOn() 23 | svc.AddC(svc.On.C) 24 | 25 | svc.Brightness = characteristic.NewBrightness() 26 | svc.AddC(svc.Brightness.C) 27 | 28 | return &svc 29 | } 30 | -------------------------------------------------------------------------------- /hap-service/wifi_satellite.go: -------------------------------------------------------------------------------- 1 | package haps 2 | 3 | import ( 4 | "github.com/brutella/hap/service" 5 | hapc "github.com/xxandev/homekit/hap-characteristic" 6 | ) 7 | 8 | //TypeWiFiSatellite - 0000020F-0000-1000-8000-0026BB765291 9 | const TypeWiFiSatellite string = "20F" 10 | 11 | //WiFiSatellite 12 | // ◈ WiFiSatelliteStatus 13 | type WiFiSatellite struct { 14 | *service.S 15 | WiFiSatelliteStatus *hapc.WiFiSatelliteStatus 16 | } 17 | 18 | //NewWiFiSatellite return *WiFiSatellite 19 | func NewWiFiSatellite() *WiFiSatellite { 20 | svc := WiFiSatellite{} 21 | svc.S = service.New(TypeWiFiSatellite) 22 | 23 | svc.WiFiSatelliteStatus = hapc.NewWiFiSatelliteStatus() 24 | svc.AddC(svc.WiFiSatelliteStatus.C) 25 | 26 | return &svc 27 | } 28 | -------------------------------------------------------------------------------- /example/humidifier_dehumidifier/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Humidifier Dehumidifier 2 | 3 | ![](https://github.com/xxandev/homekit/blob/main/gallery/humidifier_dehumidifier_1.png) 4 | 5 | ![](https://github.com/xxandev/homekit/blob/main/gallery/humidifier_dehumidifier_2.png) 6 | 7 | ![](https://github.com/xxandev/homekit/blob/main/gallery/humidifier_dehumidifier_3.png) 8 | 9 | ![](https://github.com/xxandev/homekit/blob/main/gallery/humidifier_dehumidifier_4.png) 10 | 11 | ![](https://github.com/xxandev/homekit/blob/main/gallery/humidifier_dehumidifier_5.png) 12 | 13 | ![](https://github.com/xxandev/homekit/blob/main/gallery/humidifier_dehumidifier_6.png) 14 | 15 | ![](https://github.com/xxandev/homekit/blob/main/gallery/humidifier_dehumidifier_7.png) -------------------------------------------------------------------------------- /example/lightbulb_colored/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Lightbulb Colored 2 | 3 | ![](https://github.com/xxandev/homekit/blob/main/gallery/lightbulb_colored_1.png) 4 | 5 | ![](https://github.com/xxandev/homekit/blob/main/gallery/lightbulb_colored_2.png) 6 | 7 | ![](https://github.com/xxandev/homekit/blob/main/gallery/lightbulb_colored_3.png) 8 | 9 | ![](https://github.com/xxandev/homekit/blob/main/gallery/lightbulb_colored_4.png) 10 | 11 | ![](https://github.com/xxandev/homekit/blob/main/gallery/lightbulb_colored_5.png) 12 | 13 | ![](https://github.com/xxandev/homekit/blob/main/gallery/lightbulb_colored_6.png) 14 | 15 | ![](https://github.com/xxandev/homekit/blob/main/gallery/lightbulb_colored_7.png) 16 | 17 | ![](https://github.com/xxandev/homekit/blob/main/gallery/lightbulb_colored_8.png) -------------------------------------------------------------------------------- /hap-characteristic/wan_configuration_list.go: -------------------------------------------------------------------------------- 1 | package hapc 2 | 3 | import "github.com/brutella/hap/characteristic" 4 | 5 | //TypeWANConfigurationList - 00000211-0000-1000-8000-0026BB765291 6 | const TypeWANConfigurationList string = "211" 7 | 8 | //WANConfigurationList - Formats TLV8 9 | type WANConfigurationList struct { 10 | *characteristic.Bytes 11 | } 12 | 13 | //NewWANConfigurationList return *WANConfigurationList 14 | func NewWANConfigurationList() *WANConfigurationList { 15 | char := characteristic.NewBytes(TypeWANConfigurationList) 16 | char.Format = characteristic.FormatTLV8 17 | char.Permissions = []string{ 18 | characteristic.PermissionRead, 19 | characteristic.PermissionEvents, 20 | } 21 | 22 | char.SetValue([]byte{}) 23 | 24 | return &WANConfigurationList{char} 25 | } 26 | -------------------------------------------------------------------------------- /example/television/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Television 2 | 3 | ![](https://github.com/xxandev/homekit/blob/main/gallery/tv_1.png) 4 | 5 | ![](https://github.com/xxandev/homekit/blob/main/gallery/tv_2.png) 6 | 7 | ![](https://github.com/xxandev/homekit/blob/main/gallery/tv_3.png) 8 | 9 | ![](https://github.com/xxandev/homekit/blob/main/gallery/tv_4.png) 10 | 11 | ![](https://github.com/xxandev/homekit/blob/main/gallery/tv_5.png) 12 | 13 | ![](https://github.com/xxandev/homekit/blob/main/gallery/tv_6.png) 14 | 15 | ![](https://github.com/xxandev/homekit/blob/main/gallery/tv_7.png) 16 | 17 | ![](https://github.com/xxandev/homekit/blob/main/gallery/tv_8.jpg) 18 | 19 | ![](https://github.com/xxandev/homekit/blob/main/gallery/tv_9.jpg) 20 | 21 | ![](https://github.com/xxandev/homekit/blob/main/gallery/tv_10.jpg) 22 | -------------------------------------------------------------------------------- /example/door/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Door 2 | 3 | ![](https://github.com/xxandev/homekit/blob/main/gallery/door_1.png) 4 | 5 | ![](https://github.com/xxandev/homekit/blob/main/gallery/door_2.png) 6 | 7 | ![](https://github.com/xxandev/homekit/blob/main/gallery/door_3.png) 8 | 9 | ![](https://github.com/xxandev/homekit/blob/main/gallery/door_4.png) 10 | 11 | ![](https://github.com/xxandev/homekit/blob/main/gallery/door_5.png) 12 | 13 | ![](https://github.com/xxandev/homekit/blob/main/gallery/door_6.png) 14 | 15 | ![](https://github.com/xxandev/homekit/blob/main/gallery/door_7.png) 16 | 17 | ![](https://github.com/xxandev/homekit/blob/main/gallery/door_8.png) 18 | 19 | ![](https://github.com/xxandev/homekit/blob/main/gallery/door_9.png) 20 | 21 | ![](https://github.com/xxandev/homekit/blob/main/gallery/door_10.png) -------------------------------------------------------------------------------- /hap-service/fan2_rs.go: -------------------------------------------------------------------------------- 1 | package haps 2 | 3 | import ( 4 | "github.com/brutella/hap/characteristic" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //Fan2RS 9 | // ◈ Active 10 | // ◇ CurrentFanState 11 | // ◇ TargetFanState 12 | // ◇ RotationDirection 13 | // ◇ RotationSpeed 14 | // ◇ SwingMode 15 | // ◇ LockPhysicalControls 16 | type Fan2RS struct { 17 | *service.S 18 | Active *characteristic.Active 19 | RotationSpeed *characteristic.RotationSpeed 20 | } 21 | 22 | //NewFanV2RS return *Fan2RS 23 | func NewFanV2RS() *Fan2RS { 24 | svc := Fan2RS{} 25 | svc.S = service.New(service.TypeFanV2) 26 | 27 | svc.Active = characteristic.NewActive() 28 | svc.AddC(svc.Active.C) 29 | 30 | svc.RotationSpeed = characteristic.NewRotationSpeed() 31 | svc.AddC(svc.RotationSpeed.C) 32 | 33 | return &svc 34 | } 35 | -------------------------------------------------------------------------------- /hap-characteristic/supported_router_configuration.go: -------------------------------------------------------------------------------- 1 | package hapc 2 | 3 | import "github.com/brutella/hap/characteristic" 4 | 5 | //TypeSupportedRouterConfiguration - 00000210-0000-1000-8000-0026BB765291 6 | const TypeSupportedRouterConfiguration string = "210" 7 | 8 | //SupportedRouterConfiguration - Formats TLV8 9 | type SupportedRouterConfiguration struct { 10 | *characteristic.Bytes 11 | } 12 | 13 | //NewSupportedRouterConfiguration return *SupportedRouterConfiguration 14 | func NewSupportedRouterConfiguration() *SupportedRouterConfiguration { 15 | char := characteristic.NewBytes(TypeSupportedRouterConfiguration) 16 | char.Format = characteristic.FormatTLV8 17 | char.Permissions = []string{characteristic.PermissionRead} 18 | 19 | char.SetValue([]byte{}) 20 | 21 | return &SupportedRouterConfiguration{char} 22 | } 23 | -------------------------------------------------------------------------------- /hap-characteristic/wifi_configuration_control.go: -------------------------------------------------------------------------------- 1 | package hapc 2 | 3 | import "github.com/brutella/hap/characteristic" 4 | 5 | //TypeWifiConfigurationControl - 0000021E-0000-1000-8000-0000022D 6 | const TypeWifiConfigurationControl string = "22D" 7 | 8 | //WifiConfigurationControl - Formats TLV8 9 | type WifiConfigurationControl struct { 10 | *characteristic.Bytes 11 | } 12 | 13 | //NewWifiConfigurationControl return *WifiConfigurationControl 14 | func NewWifiConfigurationControl() *WifiConfigurationControl { 15 | char := characteristic.NewBytes(TypeWifiCapabilities) 16 | char.Format = characteristic.FormatTLV8 17 | char.Permissions = []string{ 18 | characteristic.PermissionRead, 19 | characteristic.PermissionWrite, 20 | characteristic.PermissionEvents, 21 | } 22 | 23 | return &WifiConfigurationControl{char} 24 | } 25 | -------------------------------------------------------------------------------- /example/switch/README.md: -------------------------------------------------------------------------------- 1 | # Accessory Switch 2 | 3 | ![](https://github.com/xxandev/homekit/blob/main/gallery/switch_1.png) 4 | 5 | ![](https://github.com/xxandev/homekit/blob/main/gallery/switch_2.png) 6 | 7 | ![](https://github.com/xxandev/homekit/blob/main/gallery/switch_3.png) 8 | 9 | ![](https://github.com/xxandev/homekit/blob/main/gallery/switch_4.png) 10 | 11 | ![](https://github.com/xxandev/homekit/blob/main/gallery/switch_5.png) 12 | 13 | ![](https://github.com/xxandev/homekit/blob/main/gallery/switch_6.png) 14 | 15 | ![](https://github.com/xxandev/homekit/blob/main/gallery/switch_7.png) 16 | 17 | ![](https://github.com/xxandev/homekit/blob/main/gallery/switch_8.png) 18 | 19 | ![](https://github.com/xxandev/homekit/blob/main/gallery/switch_9.png) 20 | 21 | ![](https://github.com/xxandev/homekit/blob/main/gallery/switch_10.png) -------------------------------------------------------------------------------- /hap-characteristic/network_client_statusc_control.go: -------------------------------------------------------------------------------- 1 | package hapc 2 | 3 | import "github.com/brutella/hap/characteristic" 4 | 5 | //TypeNetworkClientStatusControl - 0000020D-0000-1000-8000-0026BB765291 6 | const TypeNetworkClientStatusControl string = "20D" 7 | 8 | //NetworkClientStatusControl - Formats TLV8 9 | type NetworkClientStatusControl struct { 10 | *characteristic.Bytes 11 | } 12 | 13 | //NewNetworkClientStatusControl return *NetworkClientStatusControl 14 | func NewNetworkClientStatusControl() *NetworkClientStatusControl { 15 | char := characteristic.NewBytes(TypeNetworkClientStatusControl) 16 | char.Format = characteristic.FormatTLV8 17 | char.Permissions = []string{ 18 | characteristic.PermissionRead, 19 | characteristic.PermissionWrite, 20 | characteristic.PermissionEvents, 21 | } 22 | 23 | char.SetValue([]byte{}) 24 | 25 | return &NetworkClientStatusControl{char} 26 | } 27 | -------------------------------------------------------------------------------- /hap-characteristic/network_client_profile_control.go: -------------------------------------------------------------------------------- 1 | package hapc 2 | 3 | import "github.com/brutella/hap/characteristic" 4 | 5 | //TypeNetworkClientProfileControl - 0000020C-0000-1000-8000-0026BB765291 6 | const TypeNetworkClientProfileControl string = "20C" 7 | 8 | //NetworkClientProfileControl - Formats TLV8 9 | type NetworkClientProfileControl struct { 10 | *characteristic.Bytes 11 | } 12 | 13 | //NewNetworkClientProfileControl return *NetworkClientProfileControl 14 | func NewNetworkClientProfileControl() *NetworkClientProfileControl { 15 | char := characteristic.NewBytes(TypeNetworkClientProfileControl) 16 | char.Format = characteristic.FormatTLV8 17 | char.Permissions = []string{ 18 | characteristic.PermissionRead, 19 | characteristic.PermissionWrite, 20 | characteristic.PermissionEvents, 21 | } 22 | 23 | char.SetValue([]byte{}) 24 | 25 | return &NetworkClientProfileControl{char} 26 | } 27 | -------------------------------------------------------------------------------- /hap-characteristic/network_access_violation_control.go: -------------------------------------------------------------------------------- 1 | package hapc 2 | 3 | import "github.com/brutella/hap/characteristic" 4 | 5 | //TypeNetworkAccessViolationControl - 0000021F-0000-1000-8000-0026BB765291 6 | const TypeNetworkAccessViolationControl string = "21F" 7 | 8 | //NetworkAccessViolationControl - Formats TLV8 9 | type NetworkAccessViolationControl struct { 10 | *characteristic.Bytes 11 | } 12 | 13 | //NewNetworkAccessViolationControl return *NetworkAccessViolationControl 14 | func NewNetworkAccessViolationControl() *NetworkAccessViolationControl { 15 | char := characteristic.NewBytes(TypeNetworkAccessViolationControl) 16 | char.Format = characteristic.FormatTLV8 17 | char.Permissions = []string{ 18 | characteristic.PermissionRead, 19 | characteristic.PermissionWrite, 20 | characteristic.PermissionEvents, 21 | } 22 | 23 | char.SetValue([]byte{}) 24 | 25 | return &NetworkAccessViolationControl{char} 26 | } 27 | -------------------------------------------------------------------------------- /hap-characteristic/router_status.go: -------------------------------------------------------------------------------- 1 | package hapc 2 | 3 | import "github.com/brutella/hap/characteristic" 4 | 5 | const ( 6 | //RouterStatusRead - read(0) 7 | RouterStatusRead int = 0 8 | 9 | //RouterStatusNotRead - not read(1) 10 | RouterStatusNotRead int = 1 11 | ) 12 | 13 | //TypeRouterStatus - 0000020E-0000-1000-8000-0026BB765291 14 | const TypeRouterStatus string = "20E" 15 | 16 | //RouterStatus - Formats UINT8 17 | type RouterStatus struct { 18 | *characteristic.Int 19 | } 20 | 21 | //NewRouterStatus return *RouterStatus 22 | func NewRouterStatus() *RouterStatus { 23 | char := characteristic.NewInt(TypeRouterStatus) 24 | char.Format = characteristic.FormatUInt8 25 | char.Permissions = []string{ 26 | characteristic.PermissionRead, 27 | characteristic.PermissionEvents, 28 | } 29 | 30 | char.SetMinValue(0) 31 | char.SetMaxValue(1) 32 | char.SetStepValue(1) 33 | char.SetValue(0) 34 | 35 | return &RouterStatus{char} 36 | } 37 | -------------------------------------------------------------------------------- /hap-service/door.go: -------------------------------------------------------------------------------- 1 | package haps 2 | 3 | import ( 4 | "github.com/brutella/hap/characteristic" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //Door 9 | // ◈ CurrentPosition 10 | // ◈ TargetPosition 11 | // ◈ PositionState 12 | // ◇ ObstructionDetected 13 | type Door struct { 14 | *service.S 15 | CurrentPosition *characteristic.CurrentPosition 16 | TargetPosition *characteristic.TargetPosition 17 | PositionState *characteristic.PositionState 18 | ObstructionDetected *characteristic.ObstructionDetected 19 | } 20 | 21 | //NewDoor return *Door 22 | func NewDoor() *Door { 23 | svc := Door{} 24 | svc.S = service.New(service.TypeDoor) 25 | 26 | svc.CurrentPosition = characteristic.NewCurrentPosition() 27 | svc.AddC(svc.CurrentPosition.C) 28 | 29 | svc.PositionState = characteristic.NewPositionState() 30 | svc.AddC(svc.PositionState.C) 31 | 32 | svc.TargetPosition = characteristic.NewTargetPosition() 33 | svc.AddC(svc.TargetPosition.C) 34 | 35 | svc.ObstructionDetected = characteristic.NewObstructionDetected() 36 | svc.AddC(svc.ObstructionDetected.C) 37 | 38 | return &svc 39 | } 40 | -------------------------------------------------------------------------------- /hap-service/wifi_transport.go: -------------------------------------------------------------------------------- 1 | package haps 2 | 3 | import ( 4 | "github.com/brutella/hap/service" 5 | hapc "github.com/xxandev/homekit/hap-characteristic" 6 | ) 7 | 8 | //TypeWifiTransport - 00000203-0000-1000-8000-0000022A 9 | const TypeWiFiTransport string = "22A" 10 | 11 | //WiFiTransport 12 | // ◈ CurrentTransport 13 | // ◈ WifiCapabilities 14 | // ◇ WifiConfigurationControl 15 | type WiFiTransport struct { 16 | *service.S 17 | 18 | CurrentTransport *hapc.CurrentTransport 19 | WifiCapabilities *hapc.WifiCapabilities 20 | WifiConfigurationControl *hapc.WifiConfigurationControl 21 | } 22 | 23 | //NewWifiTransport return *WiFiTransport 24 | func NewWifiTransport() *WiFiTransport { 25 | svc := WiFiTransport{} 26 | svc.S = service.New(TypeWiFiTransport) 27 | 28 | svc.CurrentTransport = hapc.NewCurrentTransport() 29 | svc.AddC(svc.CurrentTransport.C) 30 | 31 | svc.WifiCapabilities = hapc.NewWifiCapabilities() 32 | svc.AddC(svc.WifiCapabilities.C) 33 | 34 | svc.WifiConfigurationControl = hapc.NewWifiConfigurationControl() 35 | svc.AddC(svc.WifiConfigurationControl.C) 36 | 37 | return &svc 38 | } 39 | -------------------------------------------------------------------------------- /hap-characteristic/wifi_satellite_status.go: -------------------------------------------------------------------------------- 1 | package hapc 2 | 3 | import "github.com/brutella/hap/characteristic" 4 | 5 | const ( 6 | //WiFiSatelliteStatusUnknown - unknown(0) 7 | WiFiSatelliteStatusUnknown int = 0 8 | 9 | //WiFiSatelliteStatusConnect - connect(1) 10 | WiFiSatelliteStatusConnect int = 1 11 | 12 | //WiFiSatelliteStatusNotConnect - not connect(2) 13 | WiFiSatelliteStatusNotConnect int = 2 14 | ) 15 | 16 | //TypeWiFiSatelliteStatus - 0000021E-0000-1000-8000-0026BB765291 17 | const TypeWiFiSatelliteStatus string = "21E" 18 | 19 | //WiFiSatelliteStatus - Formats UINT8 20 | type WiFiSatelliteStatus struct { 21 | *characteristic.Int 22 | } 23 | 24 | //NewWiFiSatelliteStatus return *WiFiSatelliteStatus 25 | func NewWiFiSatelliteStatus() *WiFiSatelliteStatus { 26 | char := characteristic.NewInt(TypeWiFiSatelliteStatus) 27 | char.Format = characteristic.FormatUInt8 28 | char.Permissions = []string{characteristic.PermissionRead, characteristic.PermissionWrite, characteristic.PermissionEvents} 29 | 30 | char.SetMinValue(0) 31 | char.SetMaxValue(2) 32 | char.SetStepValue(1) 33 | char.SetValue(0) 34 | 35 | return &WiFiSatelliteStatus{char} 36 | } 37 | -------------------------------------------------------------------------------- /hap-characteristic/managed_network_enable.go: -------------------------------------------------------------------------------- 1 | package hapc 2 | 3 | import "github.com/brutella/hap/characteristic" 4 | 5 | const ( 6 | //ManagedNetworkEnableDisable - disable(0) 7 | ManagedNetworkEnableDisable int = 0 8 | 9 | //ManagedNetworkEnableEnable - enable(1) 10 | ManagedNetworkEnableEnable int = 1 11 | 12 | //ManagedNetworkEnableUnknown - unknown(2) 13 | ManagedNetworkEnableUnknown int = 2 14 | ) 15 | 16 | //TypeManagedNetworkEnable - 00000215-0000-1000-8000-0026BB765291 17 | const TypeManagedNetworkEnable string = "215" 18 | 19 | //ManagedNetworkEnable - Formats UINT8 20 | type ManagedNetworkEnable struct { 21 | *characteristic.Int 22 | } 23 | 24 | //NewManagedNetworkEnable return *ManagedNetworkEnable 25 | func NewManagedNetworkEnable() *ManagedNetworkEnable { 26 | char := characteristic.NewInt(TypeManagedNetworkEnable) 27 | char.Format = characteristic.FormatUInt8 28 | char.Permissions = []string{ 29 | characteristic.PermissionRead, 30 | characteristic.PermissionWrite, 31 | characteristic.PermissionEvents, 32 | } 33 | 34 | char.SetMinValue(0) 35 | char.SetMaxValue(1) 36 | char.SetStepValue(1) 37 | char.SetValue(0) 38 | 39 | return &ManagedNetworkEnable{char} 40 | } 41 | -------------------------------------------------------------------------------- /hap-service/air_purifier.go: -------------------------------------------------------------------------------- 1 | package haps 2 | 3 | import ( 4 | "github.com/brutella/hap/characteristic" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AirPurifier 9 | // ◈ Active 10 | // ◈ CurrentAirPurifierState 11 | // ◈ TargetAirPurifierState 12 | // ◇ RotationSpeed 13 | type AirPurifier struct { 14 | *service.S 15 | Active *characteristic.Active 16 | CurrentAirPurifierState *characteristic.CurrentAirPurifierState 17 | TargetAirPurifierState *characteristic.TargetAirPurifierState 18 | RotationSpeed *characteristic.RotationSpeed 19 | } 20 | 21 | //NewAirPurifier return *AirPurifier 22 | func NewAirPurifier() *AirPurifier { 23 | svc := AirPurifier{} 24 | svc.S = service.New(service.TypeAirPurifier) 25 | 26 | svc.Active = characteristic.NewActive() 27 | svc.AddC(svc.Active.C) 28 | 29 | svc.CurrentAirPurifierState = characteristic.NewCurrentAirPurifierState() 30 | svc.AddC(svc.CurrentAirPurifierState.C) 31 | 32 | svc.TargetAirPurifierState = characteristic.NewTargetAirPurifierState() 33 | svc.AddC(svc.TargetAirPurifierState.C) 34 | 35 | svc.RotationSpeed = characteristic.NewRotationSpeed() 36 | svc.AddC(svc.RotationSpeed.C) 37 | 38 | return &svc 39 | } 40 | -------------------------------------------------------------------------------- /hap-service/television_speaker.go: -------------------------------------------------------------------------------- 1 | package haps 2 | 3 | import ( 4 | "github.com/brutella/hap/characteristic" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //TelevisionSpeaker 9 | // ◈ Mute 10 | // ◇ Active 11 | // ◇ Volume 12 | // ◇ VolumeControlType 13 | // ◇ VolumeSelector 14 | type TelevisionSpeaker struct { 15 | *service.S 16 | 17 | Mute *characteristic.Mute 18 | //Active *characteristic.Active 19 | Volume *characteristic.Volume 20 | VolumeControlType *characteristic.VolumeControlType 21 | VolumeSelector *characteristic.VolumeSelector 22 | } 23 | 24 | //NewTelevisionSpeaker return *TelevisionSpeaker 25 | func NewTelevisionSpeaker() *TelevisionSpeaker { 26 | svc := TelevisionSpeaker{} 27 | svc.S = service.New(service.TypeSpeaker) 28 | 29 | svc.Mute = characteristic.NewMute() 30 | svc.AddC(svc.Mute.C) 31 | 32 | // svc.Active = characteristic.NewActive() 33 | // svc.AddCharacteristic(svc.Active.Characteristic) 34 | 35 | svc.Volume = characteristic.NewVolume() 36 | svc.AddC(svc.Volume.C) 37 | 38 | svc.VolumeControlType = characteristic.NewVolumeControlType() 39 | svc.AddC(svc.VolumeControlType.C) 40 | 41 | svc.VolumeSelector = characteristic.NewVolumeSelector() 42 | svc.AddC(svc.VolumeSelector.C) 43 | 44 | return &svc 45 | } 46 | -------------------------------------------------------------------------------- /hap-service/smart_speaker.go: -------------------------------------------------------------------------------- 1 | package haps 2 | 3 | import ( 4 | "github.com/brutella/hap/characteristic" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //TypeSmartSpeaker - 00000228-0000-1000-8000-0026BB765291 9 | const TypeSmartSpeaker string = "228" 10 | 11 | //SmartSpeaker 12 | // ◈ CurrentMediaState 13 | // ◈ TargetMediaState 14 | // ◇ Name 15 | // ◇ ConfiguredName 16 | // ◇ Mute 17 | // ◇ Volume 18 | type SmartSpeaker struct { 19 | *service.S 20 | CurrentMediaState *characteristic.CurrentMediaState 21 | TargetMediaState *characteristic.TargetMediaState 22 | Name *characteristic.Name 23 | ConfiguredName *characteristic.ConfiguredName 24 | Mute *characteristic.Mute 25 | Volume *characteristic.Volume 26 | } 27 | 28 | //NewSmartSpeaker return *SmartSpeaker 29 | func NewSmartSpeaker() *SmartSpeaker { 30 | svc := SmartSpeaker{} 31 | svc.S = service.New(TypeSmartSpeaker) 32 | 33 | svc.TargetMediaState = characteristic.NewTargetMediaState() 34 | svc.AddC(svc.TargetMediaState.C) 35 | 36 | svc.CurrentMediaState = characteristic.NewCurrentMediaState() 37 | svc.AddC(svc.CurrentMediaState.C) 38 | 39 | svc.Name = characteristic.NewName() 40 | svc.AddC(svc.Name.C) 41 | 42 | svc.ConfiguredName = characteristic.NewConfiguredName() 43 | svc.AddC(svc.ConfiguredName.C) 44 | 45 | svc.Mute = characteristic.NewMute() 46 | svc.AddC(svc.Mute.C) 47 | 48 | svc.Volume = characteristic.NewVolume() 49 | svc.AddC(svc.Volume.C) 50 | 51 | return &svc 52 | } 53 | -------------------------------------------------------------------------------- /hap-service/security_system_full.go: -------------------------------------------------------------------------------- 1 | package haps 2 | 3 | import ( 4 | "github.com/brutella/hap/characteristic" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //SecuritySystemMultifunc 9 | // ◈ SecuritySystemCurrentState 10 | // ◈ SecuritySystemTargetState 11 | // ◇ SecuritySystemAlarmType 12 | // ◇ StatusFault 13 | // ◇ StatusTampered 14 | type SecuritySystemFull struct { 15 | *service.S 16 | SecuritySystemCurrentState *characteristic.SecuritySystemCurrentState 17 | SecuritySystemTargetState *characteristic.SecuritySystemTargetState 18 | SecuritySystemAlarmType *characteristic.SecuritySystemAlarmType 19 | StatusFault *characteristic.StatusFault 20 | StatusTampered *characteristic.StatusTampered 21 | } 22 | 23 | //NewSecuritySystemMultifunc return *SecuritySystemMultifunc 24 | func NewSecuritySystemMultifunc() *SecuritySystemFull { 25 | svc := SecuritySystemFull{} 26 | svc.S = service.New(service.TypeSecuritySystem) 27 | 28 | svc.SecuritySystemCurrentState = characteristic.NewSecuritySystemCurrentState() 29 | svc.AddC(svc.SecuritySystemCurrentState.C) 30 | 31 | svc.SecuritySystemTargetState = characteristic.NewSecuritySystemTargetState() 32 | svc.AddC(svc.SecuritySystemTargetState.C) 33 | 34 | svc.SecuritySystemAlarmType = characteristic.NewSecuritySystemAlarmType() 35 | svc.AddC(svc.SecuritySystemAlarmType.C) 36 | 37 | svc.StatusFault = characteristic.NewStatusFault() 38 | svc.AddC(svc.StatusFault.C) 39 | 40 | svc.StatusTampered = characteristic.NewStatusTampered() 41 | svc.AddC(svc.StatusTampered.C) 42 | 43 | return &svc 44 | } 45 | -------------------------------------------------------------------------------- /hap-service/input_source.go: -------------------------------------------------------------------------------- 1 | package haps 2 | 3 | import ( 4 | "github.com/brutella/hap/characteristic" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | const TypeInputSource = "D9" 9 | 10 | type InputSource struct { 11 | *service.S 12 | 13 | ConfiguredName *characteristic.ConfiguredName 14 | InputSourceType *characteristic.InputSourceType 15 | IsConfigured *characteristic.IsConfigured 16 | CurrentVisibilityState *characteristic.CurrentVisibilityState 17 | Identifier *characteristic.Identifier 18 | InputDeviceType *characteristic.InputDeviceType 19 | TargetVisibilityState *characteristic.TargetVisibilityState 20 | Name *characteristic.Name 21 | } 22 | 23 | func NewInputSource() *InputSource { 24 | svc := InputSource{} 25 | svc.S = service.New(TypeInputSource) 26 | 27 | svc.ConfiguredName = characteristic.NewConfiguredName() 28 | svc.AddC(svc.ConfiguredName.C) 29 | 30 | svc.InputSourceType = characteristic.NewInputSourceType() 31 | svc.AddC(svc.InputSourceType.C) 32 | 33 | svc.IsConfigured = characteristic.NewIsConfigured() 34 | svc.AddC(svc.IsConfigured.C) 35 | 36 | svc.CurrentVisibilityState = characteristic.NewCurrentVisibilityState() 37 | svc.AddC(svc.CurrentVisibilityState.C) 38 | 39 | svc.Identifier = characteristic.NewIdentifier() 40 | svc.AddC(svc.Identifier.C) 41 | 42 | svc.InputDeviceType = characteristic.NewInputDeviceType() 43 | svc.AddC(svc.InputDeviceType.C) 44 | 45 | svc.TargetVisibilityState = characteristic.NewTargetVisibilityState() 46 | svc.AddC(svc.TargetVisibilityState.C) 47 | 48 | svc.Name = characteristic.NewName() 49 | svc.AddC(svc.Name.C) 50 | 51 | return &svc 52 | } 53 | -------------------------------------------------------------------------------- /accessory_bridge.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | ) 6 | 7 | // NewBridge returns a bridge which implements model.Bridge. 8 | type AccessoryBridge struct { 9 | *accessory.A 10 | } 11 | 12 | func (acc *AccessoryBridge) GetType() byte { 13 | return acc.A.Type 14 | } 15 | 16 | func (acc *AccessoryBridge) GetID() uint64 { 17 | return acc.A.Id 18 | } 19 | 20 | func (acc *AccessoryBridge) SetID(id uint64) { 21 | acc.A.Id = id 22 | } 23 | 24 | func (acc *AccessoryBridge) GetSN() string { 25 | return acc.A.Info.SerialNumber.Value() 26 | } 27 | 28 | func (acc *AccessoryBridge) GetName() string { 29 | return acc.A.Info.Name.Value() 30 | } 31 | 32 | func (acc *AccessoryBridge) GetAccessory() *accessory.A { 33 | return acc.A 34 | } 35 | 36 | //NewAccessoryBridge returns *Bridge. 37 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 38 | // 39 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 40 | // args... are not used 41 | func NewAccessoryBridge(info accessory.Info, args ...interface{}) *AccessoryBridge { 42 | a := AccessoryBridge{} 43 | a.A = accessory.New(info, accessory.TypeBridge) 44 | return &a 45 | } 46 | 47 | //NewAccBridge returns *Bridge. 48 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 49 | // The best would be to specify the unique id for every accessory yourself. 50 | // 51 | // id (uint64) - accessory aid 52 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 53 | // args... are not used 54 | func NewAccBridge(id uint64, info accessory.Info, args ...interface{}) *AccessoryBridge { 55 | a := AccessoryBridge{} 56 | a.A = accessory.New(info, accessory.TypeBridge) 57 | a.A.Id = id 58 | return &a 59 | } 60 | 61 | func (acc *AccessoryBridge) OnValuesRemoteUpdates(fn func()) {} 62 | -------------------------------------------------------------------------------- /example/wifi_router/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | 12 | "github.com/brutella/hap" 13 | "github.com/xxandev/homekit" 14 | ) 15 | 16 | type Config struct{ homekit.AccessoryConfig } 17 | 18 | var ( 19 | debug bool 20 | config Config 21 | ) 22 | 23 | func init() { 24 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 25 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 26 | 27 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 28 | flag.StringVar(&config.Name, "n", "WifiRouter", "homekit accessory name") 29 | flag.StringVar(&config.SN, "sn", "Ex-WifiRouter", "homekit accessory serial number") 30 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 31 | flag.UintVar(&config.Port, "p", 10730, "homekit port, example: 10101, 10102...") 32 | flag.StringVar(&config.Pin, "pin", "19378246", "homekit pin, example: 82143697, 13974682") 33 | flag.Parse() 34 | 35 | homekit.OnLog(debug) 36 | } 37 | 38 | func main() { 39 | acc := homekit.NewAccessoryWifiRouter(config.GetInfo("Ex-WifiRouter")) 40 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 41 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 42 | server, err := hap.NewServer(storage, acc.GetAccessory()) 43 | if err != nil { 44 | log.Fatalf("error create hap server: %v\n", err) 45 | } 46 | log.Printf("hap server create successful.\n") 47 | 48 | sig := make(chan os.Signal) 49 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 50 | ctx, cancel := context.WithCancel(context.Background()) 51 | go func() { 52 | <-sig 53 | log.Println("program stop.") 54 | signal.Stop(sig) 55 | cancel() 56 | }() 57 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 58 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 59 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 60 | } 61 | -------------------------------------------------------------------------------- /example/smart_speaker/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | 12 | "github.com/brutella/hap" 13 | "github.com/xxandev/homekit" 14 | ) 15 | 16 | type Config struct{ homekit.AccessoryConfig } 17 | 18 | var ( 19 | debug bool 20 | config Config 21 | ) 22 | 23 | func init() { 24 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 25 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 26 | 27 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 28 | flag.StringVar(&config.Name, "n", "Speaker", "homekit accessory name") 29 | flag.StringVar(&config.SN, "sn", "Ex-SSpeaker", "homekit accessory serial number") 30 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 31 | flag.UintVar(&config.Port, "p", 10724, "homekit port, example: 10101, 10102...") 32 | flag.StringVar(&config.Pin, "pin", "19378246", "homekit pin, example: 82143697, 13974682") 33 | flag.Parse() 34 | 35 | homekit.OnLog(debug) 36 | } 37 | 38 | func main() { 39 | acc := homekit.NewAccessorySmartSpeaker(config.GetInfo("Ex-SSpeaker")) 40 | acc.SmartSpeaker.ConfiguredName.SetValue("Smart Speaker") 41 | acc.SmartSpeaker.Mute.SetValue(false) 42 | acc.SmartSpeaker.Volume.SetValue(100) 43 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 44 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 45 | server, err := hap.NewServer(storage, acc.GetAccessory()) 46 | if err != nil { 47 | log.Fatalf("error create hap server: %v\n", err) 48 | } 49 | log.Printf("hap server create successful.\n") 50 | 51 | sig := make(chan os.Signal) 52 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 53 | ctx, cancel := context.WithCancel(context.Background()) 54 | go func() { 55 | <-sig 56 | log.Println("program stop.") 57 | signal.Stop(sig) 58 | cancel() 59 | }() 60 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 61 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 62 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 63 | } 64 | -------------------------------------------------------------------------------- /hap-service/humidifier_dehumidifier.go: -------------------------------------------------------------------------------- 1 | package haps 2 | 3 | import ( 4 | "github.com/brutella/hap/characteristic" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //HumidifierDehumidifier 9 | // ◈ Active 10 | // ◈ CurrentRelativeHumidity 11 | // ◈ CurrentHumidifierDehumidifierState 12 | // ◈ TargetHumidifierDehumidifierState 13 | // ◇ RelativeHumidityDehumidifierThreshold 14 | // ◇ RelativeHumidityHumidifierThreshold 15 | type HumidifierDehumidifier struct { 16 | *service.S 17 | Active *characteristic.Active 18 | CurrentHumidifierDehumidifierState *characteristic.CurrentHumidifierDehumidifierState 19 | TargetHumidifierDehumidifierState *characteristic.TargetHumidifierDehumidifierState 20 | CurrentRelativeHumidity *characteristic.CurrentRelativeHumidity 21 | RelativeHumidityDehumidifierThreshold *characteristic.RelativeHumidityDehumidifierThreshold 22 | RelativeHumidityHumidifierThreshold *characteristic.RelativeHumidityHumidifierThreshold 23 | } 24 | 25 | //NewHumidifierDehumidifier return *HumidifierDehumidifier 26 | func NewHumidifierDehumidifier() *HumidifierDehumidifier { 27 | svc := HumidifierDehumidifier{} 28 | svc.S = service.New(service.TypeHumidifierDehumidifier) 29 | 30 | svc.Active = characteristic.NewActive() 31 | svc.AddC(svc.Active.C) 32 | 33 | svc.CurrentHumidifierDehumidifierState = characteristic.NewCurrentHumidifierDehumidifierState() 34 | svc.AddC(svc.CurrentHumidifierDehumidifierState.C) 35 | 36 | svc.TargetHumidifierDehumidifierState = characteristic.NewTargetHumidifierDehumidifierState() 37 | svc.AddC(svc.TargetHumidifierDehumidifierState.C) 38 | 39 | svc.CurrentRelativeHumidity = characteristic.NewCurrentRelativeHumidity() 40 | svc.AddC(svc.CurrentRelativeHumidity.C) 41 | 42 | svc.RelativeHumidityDehumidifierThreshold = characteristic.NewRelativeHumidityDehumidifierThreshold() 43 | svc.AddC(svc.RelativeHumidityDehumidifierThreshold.C) 44 | 45 | svc.RelativeHumidityHumidifierThreshold = characteristic.NewRelativeHumidityHumidifierThreshold() 46 | svc.AddC(svc.RelativeHumidityHumidifierThreshold.C) 47 | 48 | return &svc 49 | } 50 | -------------------------------------------------------------------------------- /accessory_switch.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessorySwitch struct 9 | type AccessorySwitch struct { 10 | *accessory.A 11 | Switch *service.Switch 12 | } 13 | 14 | func (acc *AccessorySwitch) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessorySwitch) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessorySwitch) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessorySwitch) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessorySwitch) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessorySwitch) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | // NewAccessorySwitch returns *Switch. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args... are not used 43 | func NewAccessorySwitch(info accessory.Info, args ...interface{}) *AccessorySwitch { 44 | acc := AccessorySwitch{} 45 | acc.A = accessory.New(info, accessory.TypeSwitch) 46 | acc.Switch = service.NewSwitch() 47 | acc.AddS(acc.Switch.S) 48 | return &acc 49 | } 50 | 51 | // NewAccSwitch returns *Switch. 52 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 53 | // The best would be to specify the unique id for every accessory yourself. 54 | // 55 | // id (uint64) - accessory aid 56 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 57 | // args... are not used 58 | func NewAccSwitch(id uint64, info accessory.Info, args ...interface{}) *AccessorySwitch { 59 | acc := AccessorySwitch{} 60 | acc.A = accessory.New(info, accessory.TypeSwitch) 61 | acc.Switch = service.NewSwitch() 62 | acc.AddS(acc.Switch.S) 63 | acc.A.Id = id 64 | return &acc 65 | } 66 | 67 | func (acc *AccessorySwitch) OnValuesRemoteUpdates(fn func()) { 68 | acc.Switch.On.OnValueRemoteUpdate(func(bool) { fn() }) 69 | } 70 | -------------------------------------------------------------------------------- /example/lock/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | 12 | "github.com/brutella/hap" 13 | "github.com/xxandev/homekit" 14 | ) 15 | 16 | type Config struct{ homekit.AccessoryConfig } 17 | 18 | var ( 19 | debug bool 20 | config Config 21 | ) 22 | 23 | func init() { 24 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 25 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 26 | 27 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 28 | flag.StringVar(&config.Name, "n", "Lock", "homekit accessory name") 29 | flag.StringVar(&config.SN, "sn", "Ex-Lock", "homekit accessory serial number") 30 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 31 | flag.UintVar(&config.Port, "p", 10711, "homekit port, example: 10101, 10102...") 32 | flag.StringVar(&config.Pin, "pin", "19736428", "homekit pin, example: 82143697, 13974682") 33 | flag.Parse() 34 | 35 | homekit.OnLog(debug) 36 | } 37 | 38 | func main() { 39 | acc := homekit.NewAccessoryLock(config.GetInfo("Ex-Lock")) 40 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 41 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 42 | server, err := hap.NewServer(storage, acc.GetAccessory()) 43 | if err != nil { 44 | log.Fatalf("error create hap server: %v\n", err) 45 | } 46 | log.Printf("hap server create successful.\n") 47 | 48 | acc.LockMechanism.LockTargetState.OnValueRemoteUpdate(func(v int) { 49 | acc.LockMechanism.LockCurrentState.SetValue(v) 50 | log.Printf("remote update position, current: %[1]T - %[1]v, target: %[2]T - %[2]v\n", acc.LockMechanism.LockCurrentState.Value(), v) 51 | }) 52 | 53 | sig := make(chan os.Signal) 54 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 55 | ctx, cancel := context.WithCancel(context.Background()) 56 | go func() { 57 | <-sig 58 | log.Println("program stop.") 59 | signal.Stop(sig) 60 | cancel() 61 | }() 62 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 63 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 64 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 65 | } 66 | -------------------------------------------------------------------------------- /example/security_system/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | 12 | "github.com/brutella/hap" 13 | "github.com/xxandev/homekit" 14 | ) 15 | 16 | type Config struct{ homekit.AccessoryConfig } 17 | 18 | var ( 19 | debug bool 20 | config Config 21 | ) 22 | 23 | func init() { 24 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 25 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 26 | 27 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 28 | flag.StringVar(&config.Name, "n", "Securit", "homekit accessory name") 29 | flag.StringVar(&config.SN, "sn", "Ex-SecurSys", "homekit accessory serial number") 30 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 31 | flag.UintVar(&config.Port, "p", 10713, "homekit port, example: 10101, 10102...") 32 | flag.StringVar(&config.Pin, "pin", "19378246", "homekit pin, example: 82143697, 13974682") 33 | flag.Parse() 34 | 35 | homekit.OnLog(debug) 36 | } 37 | 38 | func main() { 39 | acc := homekit.NewAccessorySecuritySystem(config.GetInfo("Ex-SecurSys")) 40 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 41 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 42 | server, err := hap.NewServer(storage, acc.GetAccessory()) 43 | if err != nil { 44 | log.Fatalf("error create hap server: %v\n", err) 45 | } 46 | log.Printf("hap server create successful.\n") 47 | 48 | acc.SecuritySystem.SecuritySystemTargetState.OnValueRemoteUpdate(func(v int) { 49 | log.Printf("remote update state, current: %[1]T - %[1]T, target: %[2]T - %[2]T\n", acc.SecuritySystem.SecuritySystemCurrentState.Value(), v) 50 | }) 51 | 52 | sig := make(chan os.Signal) 53 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 54 | ctx, cancel := context.WithCancel(context.Background()) 55 | go func() { 56 | <-sig 57 | log.Println("program stop.") 58 | signal.Stop(sig) 59 | cancel() 60 | }() 61 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 62 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 63 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 64 | } 65 | -------------------------------------------------------------------------------- /accessory_lock.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessoryLock struct 9 | type AccessoryLock struct { 10 | *accessory.A 11 | LockMechanism *service.LockMechanism 12 | } 13 | 14 | func (acc *AccessoryLock) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessoryLock) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessoryLock) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessoryLock) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessoryLock) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessoryLock) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessoryLock return *DoorLock. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args... are not used 43 | func NewAccessoryLock(info accessory.Info, args ...interface{}) *AccessoryLock { 44 | acc := AccessoryLock{} 45 | acc.A = accessory.New(info, accessory.TypeDoorLock) 46 | acc.LockMechanism = service.NewLockMechanism() 47 | acc.AddS(acc.LockMechanism.S) 48 | return &acc 49 | } 50 | 51 | //NewAccLock return *DoorLock. 52 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 53 | // The best would be to specify the unique id for every accessory yourself. 54 | // 55 | // id (uint64) - accessory aid 56 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 57 | // args... are not used 58 | func NewAccLock(id uint64, info accessory.Info, args ...interface{}) *AccessoryLock { 59 | acc := AccessoryLock{} 60 | acc.A = accessory.New(info, accessory.TypeDoorLock) 61 | acc.LockMechanism = service.NewLockMechanism() 62 | acc.AddS(acc.LockMechanism.S) 63 | acc.A.Id = id 64 | return &acc 65 | } 66 | 67 | func (acc *AccessoryLock) OnValuesRemoteUpdates(fn func()) { 68 | acc.LockMechanism.LockTargetState.OnValueRemoteUpdate(func(int) { fn() }) 69 | } 70 | -------------------------------------------------------------------------------- /accessory_sensor_leak.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessorySensorLeak struct 9 | type AccessorySensorLeak struct { 10 | *accessory.A 11 | LeakSensor *service.LeakSensor 12 | } 13 | 14 | func (acc *AccessorySensorLeak) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessorySensorLeak) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessorySensorLeak) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessorySensorLeak) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessorySensorLeak) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessorySensorLeak) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessorySensorLeak return *SensorLeak. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args... are not used 43 | func NewAccessorySensorLeak(info accessory.Info, args ...interface{}) *AccessorySensorLeak { 44 | acc := AccessorySensorLeak{} 45 | acc.A = accessory.New(info, accessory.TypeSensor) 46 | acc.LeakSensor = service.NewLeakSensor() 47 | acc.AddS(acc.LeakSensor.S) 48 | return &acc 49 | } 50 | 51 | //NewAccSensorLeak return *SensorLeak. 52 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 53 | // The best would be to specify the unique id for every accessory yourself. 54 | // 55 | // id (uint64) - accessory aid 56 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 57 | // args... are not used 58 | func NewAccSensorLeak(id uint64, info accessory.Info, args ...interface{}) *AccessorySensorLeak { 59 | acc := AccessorySensorLeak{} 60 | acc.A = accessory.New(info, accessory.TypeSensor) 61 | acc.LeakSensor = service.NewLeakSensor() 62 | acc.AddS(acc.LeakSensor.S) 63 | acc.A.Id = id 64 | return &acc 65 | } 66 | 67 | func (acc *AccessorySensorLeak) OnValuesRemoteUpdates(fn func()) {} 68 | -------------------------------------------------------------------------------- /hap-service/television.go: -------------------------------------------------------------------------------- 1 | package haps 2 | 3 | import ( 4 | "github.com/brutella/hap/characteristic" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | const TypeTelevision = "D8" 9 | 10 | type Television struct { 11 | *service.S 12 | 13 | Active *characteristic.Active 14 | ActiveIdentifier *characteristic.ActiveIdentifier 15 | ConfiguredName *characteristic.ConfiguredName 16 | SleepDiscoveryMode *characteristic.SleepDiscoveryMode 17 | Brightness *characteristic.Brightness 18 | ClosedCaptions *characteristic.ClosedCaptions 19 | DisplayOrder *characteristic.DisplayOrder 20 | CurrentMediaState *characteristic.CurrentMediaState 21 | TargetMediaState *characteristic.TargetMediaState 22 | PictureMode *characteristic.PictureMode 23 | PowerModeSelection *characteristic.PowerModeSelection 24 | RemoteKey *characteristic.RemoteKey 25 | } 26 | 27 | func NewTelevision() *Television { 28 | svc := Television{} 29 | svc.S = service.New(TypeTelevision) 30 | 31 | svc.Active = characteristic.NewActive() 32 | svc.AddC(svc.Active.C) 33 | 34 | svc.ActiveIdentifier = characteristic.NewActiveIdentifier() 35 | svc.AddC(svc.ActiveIdentifier.C) 36 | 37 | svc.ConfiguredName = characteristic.NewConfiguredName() 38 | svc.AddC(svc.ConfiguredName.C) 39 | 40 | svc.SleepDiscoveryMode = characteristic.NewSleepDiscoveryMode() 41 | svc.AddC(svc.SleepDiscoveryMode.C) 42 | 43 | svc.Brightness = characteristic.NewBrightness() 44 | svc.AddC(svc.Brightness.C) 45 | 46 | svc.ClosedCaptions = characteristic.NewClosedCaptions() 47 | svc.AddC(svc.ClosedCaptions.C) 48 | 49 | svc.DisplayOrder = characteristic.NewDisplayOrder() 50 | svc.AddC(svc.DisplayOrder.C) 51 | 52 | svc.CurrentMediaState = characteristic.NewCurrentMediaState() 53 | svc.AddC(svc.CurrentMediaState.C) 54 | 55 | svc.TargetMediaState = characteristic.NewTargetMediaState() 56 | svc.AddC(svc.TargetMediaState.C) 57 | 58 | svc.PictureMode = characteristic.NewPictureMode() 59 | svc.AddC(svc.PictureMode.C) 60 | 61 | svc.PowerModeSelection = characteristic.NewPowerModeSelection() 62 | svc.AddC(svc.PowerModeSelection.C) 63 | 64 | svc.RemoteKey = characteristic.NewRemoteKey() 65 | svc.AddC(svc.RemoteKey.C) 66 | 67 | return &svc 68 | } 69 | -------------------------------------------------------------------------------- /example/sensor_motion/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | "time" 12 | 13 | "github.com/brutella/hap" 14 | "github.com/xxandev/homekit" 15 | ) 16 | 17 | type Config struct{ homekit.AccessoryConfig } 18 | 19 | var ( 20 | debug bool 21 | config Config 22 | ) 23 | 24 | func init() { 25 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 26 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 27 | 28 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 29 | flag.StringVar(&config.Name, "n", "SMotion", "homekit accessory name") 30 | flag.StringVar(&config.SN, "sn", "Ex-SMotion", "homekit accessory serial number") 31 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 32 | flag.UintVar(&config.Port, "p", 10721, "homekit port, example: 10101, 10102...") 33 | flag.StringVar(&config.Pin, "pin", "19378246", "homekit pin, example: 82143697, 13974682") 34 | flag.Parse() 35 | 36 | homekit.OnLog(debug) 37 | } 38 | 39 | func main() { 40 | acc := homekit.NewAccessorySensorMotion(config.GetInfo("Ex-SMotion")) 41 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 42 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 43 | server, err := hap.NewServer(storage, acc.GetAccessory()) 44 | if err != nil { 45 | log.Fatalf("error create hap server: %v\n", err) 46 | } 47 | log.Printf("hap server create successful.\n") 48 | 49 | go func() { 50 | for range time.Tick(time.Millisecond * 3000000) { 51 | acc.MotionSensor.MotionDetected.SetValue(!acc.MotionSensor.MotionDetected.Value()) 52 | log.Printf("update motion detected: %[1]T - %[1]v\n", acc.MotionSensor.MotionDetected.Value()) 53 | } 54 | }() 55 | 56 | sig := make(chan os.Signal) 57 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 58 | ctx, cancel := context.WithCancel(context.Background()) 59 | go func() { 60 | <-sig 61 | log.Println("program stop.") 62 | signal.Stop(sig) 63 | cancel() 64 | }() 65 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 66 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 67 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 68 | } 69 | -------------------------------------------------------------------------------- /accessory_fan2_rs.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | haps "github.com/xxandev/homekit/hap-service" 6 | ) 7 | 8 | //AccessoryFanV2Multifunc struct 9 | type AccessoryFan2RS struct { 10 | *accessory.A 11 | Fan2 *haps.Fan2RS 12 | } 13 | 14 | func (acc *AccessoryFan2RS) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessoryFan2RS) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessoryFan2RS) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessoryFan2RS) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessoryFan2RS) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessoryFan2RS) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessoryFan2RS return *FanV2RS. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args... are not used 43 | func NewAccessoryFan2RS(info accessory.Info, args ...interface{}) *AccessoryFan2RS { 44 | acc := AccessoryFan2RS{} 45 | acc.A = accessory.New(info, accessory.TypeFan) 46 | acc.Fan2 = haps.NewFanV2RS() 47 | acc.AddS(acc.Fan2.S) 48 | return &acc 49 | } 50 | 51 | //NewAccFan2RS return *FanV2RS. 52 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 53 | // The best would be to specify the unique id for every accessory yourself. 54 | // 55 | // id (uint64) - accessory aid 56 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 57 | // args... are not used 58 | func NewAccFan2RS(id uint64, info accessory.Info, args ...interface{}) *AccessoryFan2RS { 59 | acc := AccessoryFan2RS{} 60 | acc.A = accessory.New(info, accessory.TypeFan) 61 | acc.Fan2 = haps.NewFanV2RS() 62 | acc.AddS(acc.Fan2.S) 63 | acc.A.Id = id 64 | return &acc 65 | } 66 | 67 | func (acc *AccessoryFan2RS) OnValuesRemoteUpdates(fn func()) { 68 | acc.Fan2.Active.OnValueRemoteUpdate(func(int) { fn() }) 69 | acc.Fan2.RotationSpeed.OnValueRemoteUpdate(func(float64) { fn() }) 70 | } 71 | -------------------------------------------------------------------------------- /accessory_sensor_smoke.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessorySensorSmoke struct 9 | type AccessorySensorSmoke struct { 10 | *accessory.A 11 | SmokeSensor *service.SmokeSensor 12 | } 13 | 14 | func (acc *AccessorySensorSmoke) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessorySensorSmoke) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessorySensorSmoke) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessorySensorSmoke) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessorySensorSmoke) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessorySensorSmoke) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessorySensorSmoke return *SensorSmoke. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args... are not used 43 | func NewAccessorySensorSmoke(info accessory.Info, args ...interface{}) *AccessorySensorSmoke { 44 | acc := AccessorySensorSmoke{} 45 | acc.A = accessory.New(info, accessory.TypeSensor) 46 | acc.SmokeSensor = service.NewSmokeSensor() 47 | acc.AddS(acc.SmokeSensor.S) 48 | return &acc 49 | } 50 | 51 | //NewAccSensorSmoke return *SensorSmoke. 52 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 53 | // The best would be to specify the unique id for every accessory yourself. 54 | // 55 | // id (uint64) - accessory aid 56 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 57 | // args... are not used 58 | func NewAccSensorSmoke(id uint64, info accessory.Info, args ...interface{}) *AccessorySensorSmoke { 59 | acc := AccessorySensorSmoke{} 60 | acc.A = accessory.New(info, accessory.TypeSensor) 61 | acc.SmokeSensor = service.NewSmokeSensor() 62 | acc.AddS(acc.SmokeSensor.S) 63 | acc.A.Id = id 64 | return &acc 65 | } 66 | 67 | func (acc *AccessorySensorSmoke) OnValuesRemoteUpdates(fn func()) {} 68 | -------------------------------------------------------------------------------- /accessory_sensor_light.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessorySensorLight struct 9 | type AccessorySensorLight struct { 10 | *accessory.A 11 | LightSensor *service.LightSensor 12 | } 13 | 14 | func (acc *AccessorySensorLight) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessorySensorLight) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessorySensorLight) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessorySensorLight) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessorySensorLight) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessorySensorLight) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessorySensorLight returns *SensorLight. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args... are not used 43 | func NewAccessorySensorLight(info accessory.Info, args ...interface{}) *AccessorySensorLight { 44 | acc := AccessorySensorLight{} 45 | acc.A = accessory.New(info, accessory.TypeSensor) 46 | acc.LightSensor = service.NewLightSensor() 47 | acc.AddS(acc.LightSensor.S) 48 | return &acc 49 | } 50 | 51 | //NewAccSensorLight returns *SensorLight. 52 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 53 | // The best would be to specify the unique id for every accessory yourself. 54 | // 55 | // id (uint64) - accessory aid 56 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 57 | // args... are not used 58 | func NewAccSensorLight(id uint64, info accessory.Info, args ...interface{}) *AccessorySensorLight { 59 | acc := AccessorySensorLight{} 60 | acc.A = accessory.New(info, accessory.TypeSensor) 61 | acc.LightSensor = service.NewLightSensor() 62 | acc.AddS(acc.LightSensor.S) 63 | acc.A.Id = id 64 | return &acc 65 | } 66 | 67 | func (acc *AccessorySensorLight) OnValuesRemoteUpdates(fn func()) {} 68 | -------------------------------------------------------------------------------- /example/sensor_leak/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "math" 9 | "os" 10 | "os/signal" 11 | "syscall" 12 | "time" 13 | 14 | "github.com/brutella/hap" 15 | "github.com/xxandev/homekit" 16 | ) 17 | 18 | type Config struct{ homekit.AccessoryConfig } 19 | 20 | var ( 21 | debug bool 22 | config Config 23 | ) 24 | 25 | func init() { 26 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 27 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 28 | 29 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 30 | flag.StringVar(&config.Name, "n", "SLeak", "homekit accessory name") 31 | flag.StringVar(&config.SN, "sn", "Ex-SLeak", "homekit accessory serial number") 32 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 33 | flag.UintVar(&config.Port, "p", 10718, "homekit port, example: 10101, 10102...") 34 | flag.StringVar(&config.Pin, "pin", "19378246", "homekit pin, example: 82143697, 13974682") 35 | flag.Parse() 36 | 37 | homekit.OnLog(debug) 38 | } 39 | 40 | func main() { 41 | acc := homekit.NewAccessorySensorLeak(config.GetInfo("Ex-SLeak")) 42 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 43 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 44 | server, err := hap.NewServer(storage, acc.GetAccessory()) 45 | if err != nil { 46 | log.Fatalf("error create hap server: %v\n", err) 47 | } 48 | log.Printf("hap server create successful.\n") 49 | 50 | go func() { 51 | for range time.Tick(time.Millisecond * 3000000) { 52 | acc.LeakSensor.LeakDetected.SetValue(int(math.Pow(0, float64(acc.LeakSensor.LeakDetected.Value())))) 53 | fmt.Printf("update current state: %[1]T - %[1]v \n", acc.LeakSensor.LeakDetected.Value()) 54 | } 55 | }() 56 | 57 | sig := make(chan os.Signal) 58 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 59 | ctx, cancel := context.WithCancel(context.Background()) 60 | go func() { 61 | <-sig 62 | log.Println("program stop.") 63 | signal.Stop(sig) 64 | cancel() 65 | }() 66 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 67 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 68 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 69 | } 70 | -------------------------------------------------------------------------------- /example/window/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | 12 | "github.com/brutella/hap" 13 | "github.com/xxandev/homekit" 14 | ) 15 | 16 | type Config struct{ homekit.AccessoryConfig } 17 | 18 | var ( 19 | debug bool 20 | config Config 21 | ) 22 | 23 | func init() { 24 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 25 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 26 | 27 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 28 | flag.StringVar(&config.Name, "n", "Window", "homekit accessory name") 29 | flag.StringVar(&config.SN, "sn", "Ex-Window", "homekit accessory serial number") 30 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 31 | flag.UintVar(&config.Port, "p", 10731, "homekit port, example: 10101, 10102...") 32 | flag.StringVar(&config.Pin, "pin", "19378246", "homekit pin, example: 82143697, 13974682") 33 | flag.Parse() 34 | 35 | homekit.OnLog(debug) 36 | } 37 | 38 | func main() { 39 | acc := homekit.NewAccessoryWindow(config.GetInfo("Ex-Window")) 40 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 41 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 42 | server, err := hap.NewServer(storage, acc.GetAccessory()) 43 | if err != nil { 44 | log.Fatalf("error create hap server: %v\n", err) 45 | } 46 | log.Printf("hap server create successful.\n") 47 | 48 | acc.Window.TargetPosition.OnValueRemoteUpdate(func(v int) { 49 | acc.Window.CurrentPosition.SetValue(v) 50 | log.Printf("remote update target position: %[1]T - %[1]v\n", v) 51 | }) 52 | 53 | acc.Window.PositionState.OnValueRemoteUpdate(func(v int) { 54 | log.Printf("remote update position state: %[1]T - %[1]v\n", v) 55 | }) 56 | 57 | sig := make(chan os.Signal) 58 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 59 | ctx, cancel := context.WithCancel(context.Background()) 60 | go func() { 61 | <-sig 62 | log.Println("program stop.") 63 | signal.Stop(sig) 64 | cancel() 65 | }() 66 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 67 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 68 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 69 | } 70 | -------------------------------------------------------------------------------- /example/sensor_smoke/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "math" 9 | "os" 10 | "os/signal" 11 | "syscall" 12 | "time" 13 | 14 | "github.com/brutella/hap" 15 | "github.com/xxandev/homekit" 16 | ) 17 | 18 | type Config struct{ homekit.AccessoryConfig } 19 | 20 | var ( 21 | debug bool 22 | config Config 23 | ) 24 | 25 | func init() { 26 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 27 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 28 | 29 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 30 | flag.StringVar(&config.Name, "n", "SSmoke", "homekit accessory name") 31 | flag.StringVar(&config.SN, "sn", "Ex-SSmoke", "homekit accessory serial number") 32 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 33 | flag.UintVar(&config.Port, "p", 10722, "homekit port, example: 10101, 10102...") 34 | flag.StringVar(&config.Pin, "pin", "19378246", "homekit pin, example: 82143697, 13974682") 35 | flag.Parse() 36 | 37 | homekit.OnLog(debug) 38 | } 39 | 40 | func main() { 41 | acc := homekit.NewAccessorySensorSmoke(config.GetInfo("Ex-SSmoke")) 42 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 43 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 44 | server, err := hap.NewServer(storage, acc.GetAccessory()) 45 | if err != nil { 46 | log.Fatalf("error create hap server: %v\n", err) 47 | } 48 | log.Printf("hap server create successful.\n") 49 | 50 | go func() { 51 | for range time.Tick(time.Millisecond * 3000000) { 52 | acc.SmokeSensor.SmokeDetected.SetValue(int(math.Pow(0, float64(acc.SmokeSensor.SmokeDetected.Value())))) 53 | fmt.Printf("update detected state: %[1]T - %[1]v \n", acc.SmokeSensor.SmokeDetected.Value()) 54 | } 55 | }() 56 | 57 | sig := make(chan os.Signal) 58 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 59 | ctx, cancel := context.WithCancel(context.Background()) 60 | go func() { 61 | <-sig 62 | log.Println("program stop.") 63 | signal.Stop(sig) 64 | cancel() 65 | }() 66 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 67 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 68 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 69 | } 70 | -------------------------------------------------------------------------------- /accessory_sensor_motion.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessorySensorMotion struct 9 | type AccessorySensorMotion struct { 10 | *accessory.A 11 | MotionSensor *service.MotionSensor 12 | } 13 | 14 | func (acc *AccessorySensorMotion) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessorySensorMotion) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessorySensorMotion) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessorySensorMotion) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessorySensorMotion) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessorySensorMotion) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessorySensorMotion returns *SensorMotion. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args... are not used 43 | func NewAccessorySensorMotion(info accessory.Info, args ...interface{}) *AccessorySensorMotion { 44 | acc := AccessorySensorMotion{} 45 | acc.A = accessory.New(info, accessory.TypeSensor) 46 | acc.MotionSensor = service.NewMotionSensor() 47 | acc.AddS(acc.MotionSensor.S) 48 | return &acc 49 | } 50 | 51 | //NewAccSensorMotion returns *SensorMotion. 52 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 53 | // The best would be to specify the unique id for every accessory yourself. 54 | // 55 | // id (uint64) - accessory aid 56 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 57 | // args... are not used 58 | func NewAccSensorMotion(id uint64, info accessory.Info, args ...interface{}) *AccessorySensorMotion { 59 | acc := AccessorySensorMotion{} 60 | acc.A = accessory.New(info, accessory.TypeSensor) 61 | acc.MotionSensor = service.NewMotionSensor() 62 | acc.AddS(acc.MotionSensor.S) 63 | acc.A.Id = id 64 | return &acc 65 | } 66 | 67 | func (acc *AccessorySensorMotion) OnValuesRemoteUpdates(fn func()) {} 68 | -------------------------------------------------------------------------------- /accessory_smart_speaker.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | haps "github.com/xxandev/homekit/hap-service" 6 | ) 7 | 8 | //AccessorySmartSpeaker struct 9 | type AccessorySmartSpeaker struct { 10 | *accessory.A 11 | SmartSpeaker *haps.SmartSpeaker 12 | } 13 | 14 | func (acc *AccessorySmartSpeaker) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessorySmartSpeaker) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessorySmartSpeaker) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessorySmartSpeaker) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessorySmartSpeaker) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessorySmartSpeaker) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessorySmartSpeaker returns *SmartSpeaker. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args... are not used 43 | func NewAccessorySmartSpeaker(info accessory.Info, args ...interface{}) *AccessorySmartSpeaker { 44 | acc := AccessorySmartSpeaker{} 45 | acc.A = accessory.New(info, AccessoryTypeSpeaker) 46 | acc.SmartSpeaker = haps.NewSmartSpeaker() 47 | acc.AddS(acc.SmartSpeaker.S) 48 | return &acc 49 | } 50 | 51 | //NewAccSmartSpeaker returns *SmartSpeaker. 52 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 53 | // The best would be to specify the unique id for every accessory yourself. 54 | // 55 | // id (uint64) - accessory aid 56 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 57 | // args... are not used 58 | func NewAccSmartSpeaker(id uint64, info accessory.Info, args ...interface{}) *AccessorySmartSpeaker { 59 | acc := AccessorySmartSpeaker{} 60 | acc.A = accessory.New(info, AccessoryTypeSpeaker) 61 | acc.SmartSpeaker = haps.NewSmartSpeaker() 62 | acc.AddS(acc.SmartSpeaker.S) 63 | acc.A.Id = id 64 | return &acc 65 | } 66 | 67 | func (acc *AccessorySmartSpeaker) OnValuesRemoteUpdates(fn func()) {} 68 | -------------------------------------------------------------------------------- /example/outlet/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | "time" 12 | 13 | "github.com/brutella/hap" 14 | "github.com/xxandev/homekit" 15 | ) 16 | 17 | type Config struct{ homekit.AccessoryConfig } 18 | 19 | var ( 20 | debug bool 21 | config Config 22 | ) 23 | 24 | func init() { 25 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 26 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 27 | 28 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 29 | flag.StringVar(&config.Name, "n", "Outlet", "homekit accessory name") 30 | flag.StringVar(&config.SN, "sn", "Ex-Outlet", "homekit accessory serial number") 31 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 32 | flag.UintVar(&config.Port, "p", 10712, "homekit port, example: 10101, 10102...") 33 | flag.StringVar(&config.Pin, "pin", "19736428", "homekit pin, example: 82143697, 13974682") 34 | flag.Parse() 35 | 36 | homekit.OnLog(debug) 37 | } 38 | 39 | func main() { 40 | acc := homekit.NewAccessoryOutlet(config.GetInfo("Ex-Outlet")) 41 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 42 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 43 | server, err := hap.NewServer(storage, acc.GetAccessory()) 44 | if err != nil { 45 | log.Fatalf("error create hap server: %v\n", err) 46 | } 47 | log.Printf("hap server create successful.\n") 48 | 49 | go func() { 50 | for range time.Tick(time.Millisecond * 300000) { 51 | acc.Outlet.On.SetValue(!acc.Outlet.On.Value()) 52 | log.Printf("update on: %[1]T - %[1]v\n", acc.Outlet.On.Value()) 53 | } 54 | }() 55 | acc.Outlet.On.OnValueRemoteUpdate(func(v bool) { 56 | log.Printf("remote update on: %[1]T - %[1]v\n", v) 57 | }) 58 | 59 | sig := make(chan os.Signal) 60 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 61 | ctx, cancel := context.WithCancel(context.Background()) 62 | go func() { 63 | <-sig 64 | log.Println("program stop.") 65 | signal.Stop(sig) 66 | cancel() 67 | }() 68 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 69 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 70 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 71 | } 72 | -------------------------------------------------------------------------------- /example/switch/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | "time" 12 | 13 | "github.com/brutella/hap" 14 | "github.com/xxandev/homekit" 15 | ) 16 | 17 | type Config struct{ homekit.AccessoryConfig } 18 | 19 | var ( 20 | debug bool 21 | config Config 22 | ) 23 | 24 | func init() { 25 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 26 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 27 | 28 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 29 | flag.StringVar(&config.Name, "n", "Switch", "homekit accessory name") 30 | flag.StringVar(&config.SN, "sn", "Ex-Switch", "homekit accessory serial number") 31 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 32 | flag.UintVar(&config.Port, "p", 10725, "homekit port, example: 10101, 10102...") 33 | flag.StringVar(&config.Pin, "pin", "19378246", "homekit pin, example: 82143697, 13974682") 34 | flag.Parse() 35 | 36 | homekit.OnLog(debug) 37 | } 38 | 39 | func main() { 40 | acc := homekit.NewAccessorySwitch(config.GetInfo("Ex-Switch")) 41 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 42 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 43 | server, err := hap.NewServer(storage, acc.GetAccessory()) 44 | if err != nil { 45 | log.Fatalf("error create hap server: %v\n", err) 46 | } 47 | log.Printf("hap server create successful.\n") 48 | 49 | go func() { 50 | for range time.Tick(time.Millisecond * 300000) { 51 | acc.Switch.On.SetValue(!acc.Switch.On.Value()) 52 | log.Printf("update on: %[1]T - %[1]v\n", acc.Switch.On.Value()) 53 | } 54 | }() 55 | acc.Switch.On.OnValueRemoteUpdate(func(v bool) { 56 | log.Printf("remote update on: %[1]T - %[1]v\n", v) 57 | }) 58 | 59 | sig := make(chan os.Signal) 60 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 61 | ctx, cancel := context.WithCancel(context.Background()) 62 | go func() { 63 | <-sig 64 | log.Println("program stop.") 65 | signal.Stop(sig) 66 | cancel() 67 | }() 68 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 69 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 70 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 71 | } 72 | -------------------------------------------------------------------------------- /example/sensor_contact/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "math" 9 | "os" 10 | "os/signal" 11 | "syscall" 12 | "time" 13 | 14 | "github.com/brutella/hap" 15 | "github.com/xxandev/homekit" 16 | ) 17 | 18 | type Config struct{ homekit.AccessoryConfig } 19 | 20 | var ( 21 | debug bool 22 | config Config 23 | ) 24 | 25 | func init() { 26 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 27 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 28 | 29 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 30 | flag.StringVar(&config.Name, "n", "SContact", "homekit accessory name") 31 | flag.StringVar(&config.SN, "sn", "Ex-SContact", "homekit accessory serial number") 32 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 33 | flag.UintVar(&config.Port, "p", 10715, "homekit port, example: 10101, 10102...") 34 | flag.StringVar(&config.Pin, "pin", "19378246", "homekit pin, example: 82143697, 13974682") 35 | flag.Parse() 36 | 37 | homekit.OnLog(debug) 38 | } 39 | 40 | func main() { 41 | acc := homekit.NewAccessorySensorContact(config.GetInfo("Ex-SContact")) 42 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 43 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 44 | server, err := hap.NewServer(storage, acc.GetAccessory()) 45 | if err != nil { 46 | log.Fatalf("error create hap server: %v\n", err) 47 | } 48 | log.Printf("hap server create successful.\n") 49 | 50 | go func() { 51 | for range time.Tick(time.Millisecond * 300000) { 52 | acc.ContactSensor.ContactSensorState.SetValue(int(math.Pow(0, float64(acc.ContactSensor.ContactSensorState.Value())))) 53 | log.Printf("update on: %[1]T - %[1]v\n", acc.ContactSensor.ContactSensorState.Value()) 54 | } 55 | }() 56 | 57 | sig := make(chan os.Signal) 58 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 59 | ctx, cancel := context.WithCancel(context.Background()) 60 | go func() { 61 | <-sig 62 | log.Println("program stop.") 63 | signal.Stop(sig) 64 | cancel() 65 | }() 66 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 67 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 68 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 69 | } 70 | -------------------------------------------------------------------------------- /accessory_sensor_contact.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessorySensorContact struct 9 | type AccessorySensorContact struct { 10 | *accessory.A 11 | ContactSensor *service.ContactSensor 12 | } 13 | 14 | func (acc *AccessorySensorContact) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessorySensorContact) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessorySensorContact) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessorySensorContact) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessorySensorContact) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessorySensorContact) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessorySensorContact return *SensorContact. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args... are not used 43 | func NewAccessorySensorContact(info accessory.Info, args ...interface{}) *AccessorySensorContact { 44 | acc := AccessorySensorContact{} 45 | acc.A = accessory.New(info, accessory.TypeSensor) 46 | acc.ContactSensor = service.NewContactSensor() 47 | acc.AddS(acc.ContactSensor.S) 48 | return &acc 49 | } 50 | 51 | //NewAccSensorContact return *SensorContact. 52 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 53 | // The best would be to specify the unique id for every accessory yourself. 54 | // 55 | // id (uint64) - accessory aid 56 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 57 | // args... are not used 58 | func NewAccSensorContact(id uint64, info accessory.Info, args ...interface{}) *AccessorySensorContact { 59 | acc := AccessorySensorContact{} 60 | acc.A = accessory.New(info, accessory.TypeSensor) 61 | acc.ContactSensor = service.NewContactSensor() 62 | acc.AddS(acc.ContactSensor.S) 63 | acc.A.Id = id 64 | return &acc 65 | } 66 | 67 | func (acc *AccessorySensorContact) OnValuesRemoteUpdates(fn func()) {} 68 | -------------------------------------------------------------------------------- /example/sensor_dioxide/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "math" 9 | "os" 10 | "os/signal" 11 | "syscall" 12 | "time" 13 | 14 | "github.com/brutella/hap" 15 | "github.com/xxandev/homekit" 16 | ) 17 | 18 | type Config struct{ homekit.AccessoryConfig } 19 | 20 | var ( 21 | debug bool 22 | config Config 23 | ) 24 | 25 | func init() { 26 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 27 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 28 | 29 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 30 | flag.StringVar(&config.Name, "n", "SDioxide", "homekit accessory name") 31 | flag.StringVar(&config.SN, "sn", "Ex-SDioxide", "homekit accessory serial number") 32 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 33 | flag.UintVar(&config.Port, "p", 10716, "homekit port, example: 10101, 10102...") 34 | flag.StringVar(&config.Pin, "pin", "19378246", "homekit pin, example: 82143697, 13974682") 35 | flag.Parse() 36 | 37 | homekit.OnLog(debug) 38 | } 39 | 40 | func main() { 41 | acc := homekit.NewAccessorySensorDioxide(config.GetInfo("Ex-SDioxide")) 42 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 43 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 44 | server, err := hap.NewServer(storage, acc.GetAccessory()) 45 | if err != nil { 46 | log.Fatalf("error create hap server: %v\n", err) 47 | } 48 | log.Printf("hap server create successful.\n") 49 | 50 | go func() { 51 | for range time.Tick(time.Millisecond * 3000000) { 52 | acc.CarbonDioxideSensor.CarbonDioxideDetected.SetValue(int(math.Pow(0, float64(acc.CarbonDioxideSensor.CarbonDioxideDetected.Value())))) 53 | log.Printf("update on: %[1]T - %[1]v\n", acc.CarbonDioxideSensor.CarbonDioxideDetected.Value()) 54 | } 55 | }() 56 | sig := make(chan os.Signal) 57 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 58 | ctx, cancel := context.WithCancel(context.Background()) 59 | go func() { 60 | <-sig 61 | log.Println("program stop.") 62 | signal.Stop(sig) 63 | cancel() 64 | }() 65 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 66 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 67 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 68 | } 69 | -------------------------------------------------------------------------------- /accessory_wifi_router.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | haps "github.com/xxandev/homekit/hap-service" 6 | ) 7 | 8 | //AccessoryWifiRouter struct 9 | // 10 | //https://github.com/homebridge/HAP-NodeJS/blob/master/src/accessories/Wi-FiRouter_accessory.ts 11 | type AccessoryWifiRouter struct { 12 | *accessory.A 13 | Router *haps.WiFiRouter 14 | } 15 | 16 | func (acc *AccessoryWifiRouter) GetType() byte { 17 | return acc.A.Type 18 | } 19 | 20 | func (acc *AccessoryWifiRouter) GetID() uint64 { 21 | return acc.A.Id 22 | } 23 | 24 | func (acc *AccessoryWifiRouter) SetID(id uint64) { 25 | acc.A.Id = id 26 | } 27 | 28 | func (acc *AccessoryWifiRouter) GetSN() string { 29 | return acc.A.Info.SerialNumber.Value() 30 | } 31 | 32 | func (acc *AccessoryWifiRouter) GetName() string { 33 | return acc.A.Info.Name.Value() 34 | } 35 | 36 | func (acc *AccessoryWifiRouter) GetAccessory() *accessory.A { 37 | return acc.A 38 | } 39 | 40 | //NewAccessoryWifiRouter returns *WifiRouter. 41 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 42 | // 43 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 44 | // args... are not used 45 | func NewAccessoryWifiRouter(info accessory.Info, args ...interface{}) *AccessoryWifiRouter { 46 | acc := AccessoryWifiRouter{} 47 | acc.A = accessory.New(info, AccessoryTypeWiFiRouter) 48 | acc.Router = haps.NewWiFiRouter() 49 | acc.AddS(acc.Router.S) 50 | return &acc 51 | } 52 | 53 | //NewAccWifiRouter returns *WifiRouter. 54 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 55 | // The best would be to specify the unique id for every accessory yourself. 56 | // 57 | // id (uint64) - accessory aid 58 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 59 | // args... are not used 60 | func NewAccWifiRouter(id uint64, info accessory.Info, args ...interface{}) *AccessoryWifiRouter { 61 | acc := AccessoryWifiRouter{} 62 | acc.A = accessory.New(info, AccessoryTypeWiFiRouter) 63 | acc.Router = haps.NewWiFiRouter() 64 | acc.AddS(acc.Router.S) 65 | acc.A.Id = id 66 | return &acc 67 | } 68 | 69 | func (acc *AccessoryWifiRouter) OnValuesRemoteUpdates(fn func()) {} 70 | -------------------------------------------------------------------------------- /example/window_covering/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | 12 | "github.com/brutella/hap" 13 | "github.com/xxandev/homekit" 14 | ) 15 | 16 | type Config struct{ homekit.AccessoryConfig } 17 | 18 | var ( 19 | debug bool 20 | config Config 21 | ) 22 | 23 | func init() { 24 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 25 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 26 | 27 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 28 | flag.StringVar(&config.Name, "n", "WindowCovering", "homekit accessory name") 29 | flag.StringVar(&config.SN, "sn", "Ex-WindowCovering", "homekit accessory serial number") 30 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 31 | flag.UintVar(&config.Port, "p", 10732, "homekit port, example: 10101, 10102...") 32 | flag.StringVar(&config.Pin, "pin", "19378246", "homekit pin, example: 82143697, 13974682") 33 | flag.Parse() 34 | 35 | homekit.OnLog(debug) 36 | } 37 | 38 | func main() { 39 | acc := homekit.NewAccessoryWindowCovering(config.GetInfo("Ex-WindowCovering")) 40 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 41 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 42 | server, err := hap.NewServer(storage, acc.GetAccessory()) 43 | if err != nil { 44 | log.Fatalf("error create hap server: %v\n", err) 45 | } 46 | log.Printf("hap server create successful.\n") 47 | 48 | acc.WindowCovering.TargetPosition.OnValueRemoteUpdate(func(v int) { 49 | acc.WindowCovering.CurrentPosition.SetValue(v) 50 | log.Printf("remote update target position: %[1]T - %[1]v \n", v) 51 | }) 52 | acc.WindowCovering.PositionState.OnValueRemoteUpdate(func(v int) { 53 | log.Printf("remote update position state: %[1]T - %[1]v \n", v) 54 | }) 55 | 56 | sig := make(chan os.Signal) 57 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 58 | ctx, cancel := context.WithCancel(context.Background()) 59 | go func() { 60 | <-sig 61 | log.Println("program stop.") 62 | signal.Stop(sig) 63 | cancel() 64 | }() 65 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 66 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 67 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 68 | } 69 | -------------------------------------------------------------------------------- /accessory_outlet.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessoryOutlet struct 9 | type AccessoryOutlet struct { 10 | *accessory.A 11 | Outlet *service.Outlet 12 | } 13 | 14 | func (acc *AccessoryOutlet) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessoryOutlet) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessoryOutlet) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessoryOutlet) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessoryOutlet) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessoryOutlet) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessoryOutlet return *Outlet. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args... are not used 43 | func NewAccessoryOutlet(info accessory.Info, args ...interface{}) *AccessoryOutlet { 44 | acc := AccessoryOutlet{} 45 | acc.A = accessory.New(info, accessory.TypeOutlet) 46 | acc.Outlet = service.NewOutlet() 47 | acc.Outlet.OutletInUse.SetValue(true) 48 | acc.AddS(acc.Outlet.S) 49 | return &acc 50 | } 51 | 52 | //NewAccOutlet return *Outlet. 53 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 54 | // The best would be to specify the unique id for every accessory yourself. 55 | // 56 | // id (uint64) - accessory aid 57 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 58 | // args... are not used 59 | func NewAccOutlet(id uint64, info accessory.Info, args ...interface{}) *AccessoryOutlet { 60 | acc := AccessoryOutlet{} 61 | acc.A = accessory.New(info, accessory.TypeOutlet) 62 | acc.Outlet = service.NewOutlet() 63 | acc.Outlet.OutletInUse.SetValue(true) 64 | acc.AddS(acc.Outlet.S) 65 | acc.A.Id = id 66 | return &acc 67 | } 68 | 69 | func (acc *AccessoryOutlet) OnValuesRemoteUpdates(fn func()) { 70 | acc.Outlet.On.OnValueRemoteUpdate(func(bool) { fn() }) 71 | // acc.Outlet.OutletInUse.OnValueRemoteUpdate(func(bool) { fn() }) 72 | } 73 | -------------------------------------------------------------------------------- /accessory_sensor_humidity.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessorySensorHumidity struct 9 | type AccessorySensorHumidity struct { 10 | *accessory.A 11 | HumiditySensor *service.HumiditySensor 12 | } 13 | 14 | func (acc *AccessorySensorHumidity) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessorySensorHumidity) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessorySensorHumidity) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessorySensorHumidity) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessorySensorHumidity) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessorySensorHumidity) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessorySensorHumidity returns *SensorHumidity. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args... are not used 43 | func NewAccessorySensorHumidity(info accessory.Info, args ...interface{}) *AccessorySensorHumidity { 44 | acc := AccessorySensorHumidity{} 45 | acc.A = accessory.New(info, accessory.TypeThermostat) 46 | acc.HumiditySensor = service.NewHumiditySensor() 47 | acc.AddS(acc.HumiditySensor.S) 48 | return &acc 49 | } 50 | 51 | //NewAccSensorHumidity returns *SensorHumidity. 52 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 53 | // The best would be to specify the unique id for every accessory yourself. 54 | // 55 | // id (uint64) - accessory aid 56 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 57 | // args... are not used 58 | func NewAccSensorHumidity(id uint64, info accessory.Info, args ...interface{}) *AccessorySensorHumidity { 59 | acc := AccessorySensorHumidity{} 60 | acc.A = accessory.New(info, accessory.TypeThermostat) 61 | acc.HumiditySensor = service.NewHumiditySensor() 62 | acc.AddS(acc.HumiditySensor.S) 63 | acc.A.Id = id 64 | return &acc 65 | } 66 | 67 | func (acc *AccessorySensorHumidity) OnValuesRemoteUpdates(fn func()) {} 68 | -------------------------------------------------------------------------------- /example/sensor_monaxide/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "math" 9 | "os" 10 | "os/signal" 11 | "syscall" 12 | "time" 13 | 14 | "github.com/brutella/hap" 15 | "github.com/xxandev/homekit" 16 | ) 17 | 18 | type Config struct{ homekit.AccessoryConfig } 19 | 20 | var ( 21 | debug bool 22 | config Config 23 | ) 24 | 25 | func init() { 26 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 27 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 28 | 29 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 30 | flag.StringVar(&config.Name, "n", "SMonoxide", "homekit accessory name") 31 | flag.StringVar(&config.SN, "sn", "Ex-SMonoxide", "homekit accessory serial number") 32 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 33 | flag.UintVar(&config.Port, "p", 10720, "homekit port, example: 10101, 10102...") 34 | flag.StringVar(&config.Pin, "pin", "19378246", "homekit pin, example: 82143697, 13974682") 35 | flag.Parse() 36 | 37 | homekit.OnLog(debug) 38 | } 39 | 40 | func main() { 41 | acc := homekit.NewAccessorySensorMonoxide(config.GetInfo("Ex-SMonoxide")) 42 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 43 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 44 | server, err := hap.NewServer(storage, acc.GetAccessory()) 45 | if err != nil { 46 | log.Fatalf("error create hap server: %v\n", err) 47 | } 48 | log.Printf("hap server create successful.\n") 49 | 50 | go func() { 51 | for range time.Tick(time.Millisecond * 3000000) { 52 | acc.CarbonMonoxideSensor.CarbonMonoxideDetected.SetValue(int(math.Pow(0, float64(acc.CarbonMonoxideSensor.CarbonMonoxideDetected.Value())))) 53 | fmt.Printf("update current state: %[1]T - %[1]v \n", acc.CarbonMonoxideSensor.CarbonMonoxideDetected.Value()) 54 | } 55 | }() 56 | 57 | sig := make(chan os.Signal) 58 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 59 | ctx, cancel := context.WithCancel(context.Background()) 60 | go func() { 61 | <-sig 62 | log.Println("program stop.") 63 | signal.Stop(sig) 64 | cancel() 65 | }() 66 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 67 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 68 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 69 | } 70 | -------------------------------------------------------------------------------- /accessory_sensor_dioxide.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessorySensorDioxide struct 9 | type AccessorySensorDioxide struct { 10 | *accessory.A 11 | CarbonDioxideSensor *service.CarbonDioxideSensor 12 | } 13 | 14 | func (acc *AccessorySensorDioxide) GetType() uint8 { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessorySensorDioxide) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessorySensorDioxide) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessorySensorDioxide) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessorySensorDioxide) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessorySensorDioxide) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessorySensorDioxide return *SensorDioxide. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args... are not used 43 | func NewAccessorySensorDioxide(info accessory.Info, args ...interface{}) *AccessorySensorDioxide { 44 | acc := AccessorySensorDioxide{} 45 | acc.A = accessory.New(info, accessory.TypeSensor) 46 | acc.CarbonDioxideSensor = service.NewCarbonDioxideSensor() 47 | acc.AddS(acc.CarbonDioxideSensor.S) 48 | return &acc 49 | } 50 | 51 | //NewAccSensorDioxide return *SensorDioxide. 52 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 53 | // The best would be to specify the unique id for every accessory yourself. 54 | // 55 | // id (uint64) - accessory aid 56 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 57 | // args... are not used 58 | func NewAccSensorDioxide(id uint64, info accessory.Info, args ...interface{}) *AccessorySensorDioxide { 59 | acc := AccessorySensorDioxide{} 60 | acc.A = accessory.New(info, accessory.TypeSensor) 61 | acc.CarbonDioxideSensor = service.NewCarbonDioxideSensor() 62 | acc.AddS(acc.CarbonDioxideSensor.S) 63 | acc.A.Id = id 64 | return &acc 65 | } 66 | 67 | func (acc *AccessorySensorDioxide) OnValuesRemoteUpdates(fn func()) {} 68 | -------------------------------------------------------------------------------- /accessory_gate.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessoryGate struct 9 | type AccessoryGate struct { 10 | *accessory.A 11 | GarageDoorOpener *service.GarageDoorOpener 12 | } 13 | 14 | func (acc *AccessoryGate) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessoryGate) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessoryGate) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessoryGate) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessoryGate) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessoryGate) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessoryGate return *GarageDoorOpener. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args... are not used 43 | func NewAccessoryGate(info accessory.Info, args ...interface{}) *AccessoryGate { 44 | acc := AccessoryGate{} 45 | acc.A = accessory.New(info, accessory.TypeGarageDoorOpener) 46 | acc.GarageDoorOpener = service.NewGarageDoorOpener() 47 | acc.AddS(acc.GarageDoorOpener.S) 48 | return &acc 49 | } 50 | 51 | //NewAccGate return *GarageDoorOpener. 52 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 53 | // The best would be to specify the unique id for every accessory yourself. 54 | // 55 | // id (uint64) - accessory aid 56 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 57 | // args... are not used 58 | func NewAccGate(id uint64, info accessory.Info, args ...interface{}) *AccessoryGate { 59 | acc := AccessoryGate{} 60 | acc.A = accessory.New(info, accessory.TypeGarageDoorOpener) 61 | acc.GarageDoorOpener = service.NewGarageDoorOpener() 62 | acc.AddS(acc.GarageDoorOpener.S) 63 | acc.A.Id = id 64 | return &acc 65 | } 66 | 67 | func (acc *AccessoryGate) OnValuesRemoteUpdates(fn func()) { 68 | acc.GarageDoorOpener.TargetDoorState.OnValueRemoteUpdate(func(int) { fn() }) 69 | // acc.GarageDoorOpener.ObstructionDetected.OnValueRemoteUpdate(func(bool) { fn() }) 70 | } 71 | -------------------------------------------------------------------------------- /accessory_sensor_monoxide.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessorySensorMonoxide struct 9 | type AccessorySensorMonoxide struct { 10 | *accessory.A 11 | CarbonMonoxideSensor *service.CarbonMonoxideSensor 12 | } 13 | 14 | func (acc *AccessorySensorMonoxide) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessorySensorMonoxide) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessorySensorMonoxide) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessorySensorMonoxide) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessorySensorMonoxide) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessorySensorMonoxide) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessorySensorMonoxide return *SensorMonoxide. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args... are not used 43 | func NewAccessorySensorMonoxide(info accessory.Info, args ...interface{}) *AccessorySensorMonoxide { 44 | acc := AccessorySensorMonoxide{} 45 | acc.A = accessory.New(info, accessory.TypeSensor) 46 | acc.CarbonMonoxideSensor = service.NewCarbonMonoxideSensor() 47 | acc.AddS(acc.CarbonMonoxideSensor.S) 48 | return &acc 49 | } 50 | 51 | //NewAccSensorMonoxide return *SensorMonoxide. 52 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 53 | // The best would be to specify the unique id for every accessory yourself. 54 | // 55 | // id (uint64) - accessory aid 56 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 57 | // args... are not used 58 | func NewAccSensorMonoxide(id uint64, info accessory.Info, args ...interface{}) *AccessorySensorMonoxide { 59 | acc := AccessorySensorMonoxide{} 60 | acc.A = accessory.New(info, accessory.TypeSensor) 61 | acc.CarbonMonoxideSensor = service.NewCarbonMonoxideSensor() 62 | acc.AddS(acc.CarbonMonoxideSensor.S) 63 | acc.A.Id = id 64 | return &acc 65 | } 66 | 67 | func (acc *AccessorySensorMonoxide) OnValuesRemoteUpdates(fn func()) {} 68 | -------------------------------------------------------------------------------- /accessory_irrigation.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessoryIrrigation struct 9 | type AccessoryIrrigation struct { 10 | *accessory.A 11 | Valve *service.Valve 12 | } 13 | 14 | func (acc *AccessoryIrrigation) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessoryIrrigation) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessoryIrrigation) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | func (acc *AccessoryIrrigation) GetSN() string { 26 | return acc.A.Info.SerialNumber.Value() 27 | } 28 | 29 | func (acc *AccessoryIrrigation) GetName() string { 30 | return acc.A.Info.Name.Value() 31 | } 32 | 33 | func (acc *AccessoryIrrigation) GetAccessory() *accessory.A { 34 | return acc.A 35 | } 36 | 37 | //NewAccessoryIrrigation return *Irrigation. 38 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 39 | // 40 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 41 | // args... are not used 42 | func NewAccessoryIrrigation(info accessory.Info, args ...interface{}) *AccessoryIrrigation { 43 | acc := AccessoryIrrigation{} 44 | acc.A = accessory.New(info, accessory.TypeSprinkler) 45 | acc.Valve = service.NewValve() 46 | acc.Valve.ValveType.SetValue(1) 47 | acc.AddS(acc.Valve.S) 48 | return &acc 49 | } 50 | 51 | //NewAccIrrigation return *Irrigation. 52 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 53 | // The best would be to specify the unique id for every accessory yourself. 54 | // 55 | // id (uint64) - accessory aid 56 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 57 | // args... are not used 58 | func NewAccIrrigation(id uint64, info accessory.Info, args ...interface{}) *AccessoryIrrigation { 59 | acc := AccessoryIrrigation{} 60 | acc.A = accessory.New(info, accessory.TypeSprinkler) 61 | acc.Valve = service.NewValve() 62 | acc.Valve.ValveType.SetValue(1) 63 | acc.AddS(acc.Valve.S) 64 | acc.A.Id = id 65 | return &acc 66 | } 67 | 68 | func (acc *AccessoryIrrigation) OnValuesRemoteUpdates(fn func()) { 69 | acc.Valve.Active.OnValueRemoteUpdate(func(int) { fn() }) 70 | // acc.Valve.InUse.OnValueRemoteUpdate(func(int) { fn() }) 71 | } 72 | -------------------------------------------------------------------------------- /accessory_sensor_air_quality.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessorySensorAirQuality struct 9 | type AccessorySensorAirQuality struct { 10 | *accessory.A 11 | AirQualitySensor *service.AirQualitySensor 12 | } 13 | 14 | func (acc *AccessorySensorAirQuality) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessorySensorAirQuality) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessorySensorAirQuality) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessorySensorAirQuality) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessorySensorAirQuality) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessorySensorAirQuality) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessorySensorAirQuality returns *SensorAirQuality. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args... are not used 43 | func NewAccessorySensorAirQuality(info accessory.Info, args ...interface{}) *AccessorySensorAirQuality { 44 | acc := AccessorySensorAirQuality{} 45 | acc.A = accessory.New(info, accessory.TypeSensor) 46 | acc.AirQualitySensor = service.NewAirQualitySensor() 47 | acc.AddS(acc.AirQualitySensor.S) 48 | return &acc 49 | } 50 | 51 | //NewAccSensorAirQuality returns *SensorAirQuality. 52 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 53 | // The best would be to specify the unique id for every accessory yourself. 54 | // 55 | // id (uint64) - accessory aid 56 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 57 | // args... are not used 58 | func NewAccSensorAirQuality(id uint64, info accessory.Info, args ...interface{}) *AccessorySensorAirQuality { 59 | acc := AccessorySensorAirQuality{} 60 | acc.A = accessory.New(info, accessory.TypeSensor) 61 | acc.AirQualitySensor = service.NewAirQualitySensor() 62 | acc.AddS(acc.AirQualitySensor.S) 63 | acc.A.Id = id 64 | return &acc 65 | } 66 | 67 | func (acc *AccessorySensorAirQuality) OnValuesRemoteUpdates(fn func()) {} 68 | -------------------------------------------------------------------------------- /accessory_lightbulb_switch.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessoryLightbulbSwitch struct 9 | type AccessoryLightbulbSwitch struct { 10 | *accessory.A 11 | LightbulbSwitch *service.Lightbulb 12 | } 13 | 14 | func (acc *AccessoryLightbulbSwitch) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessoryLightbulbSwitch) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessoryLightbulbSwitch) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessoryLightbulbSwitch) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessoryLightbulbSwitch) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | func (acc *AccessoryLightbulbSwitch) GetAccessory() *accessory.A { 34 | return acc.A 35 | } 36 | 37 | //NewAccessoryLightbulbSwitch return *LightbulbSwitch. 38 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 39 | // 40 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 41 | // args... are not used 42 | func NewAccessoryLightbulbSwitch(info accessory.Info, args ...interface{}) *AccessoryLightbulbSwitch { 43 | acc := AccessoryLightbulbSwitch{} 44 | acc.A = accessory.New(info, accessory.TypeLightbulb) 45 | acc.LightbulbSwitch = service.NewLightbulb() 46 | acc.AddS(acc.LightbulbSwitch.S) 47 | return &acc 48 | } 49 | 50 | //NewAccLightbulbSwitch return *LightbulbSwitch. 51 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 52 | // The best would be to specify the unique id for every accessory yourself. 53 | // 54 | // id (uint64) - accessory aid 55 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 56 | // args... are not used 57 | func NewAccLightbulbSwitch(id uint64, info accessory.Info, args ...interface{}) *AccessoryLightbulbSwitch { 58 | acc := AccessoryLightbulbSwitch{} 59 | acc.A = accessory.New(info, accessory.TypeLightbulb) 60 | acc.LightbulbSwitch = service.NewLightbulb() 61 | acc.AddS(acc.LightbulbSwitch.S) 62 | acc.A.Id = id 63 | return &acc 64 | } 65 | 66 | func (acc *AccessoryLightbulbSwitch) OnValuesRemoteUpdates(fn func()) { 67 | acc.LightbulbSwitch.On.OnValueRemoteUpdate(func(bool) { fn() }) 68 | } 69 | -------------------------------------------------------------------------------- /example/faucet/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "math" 9 | "os" 10 | "os/signal" 11 | "syscall" 12 | "time" 13 | 14 | "github.com/brutella/hap" 15 | "github.com/xxandev/homekit" 16 | ) 17 | 18 | type Config struct{ homekit.AccessoryConfig } 19 | 20 | var ( 21 | debug bool 22 | config Config 23 | ) 24 | 25 | func init() { 26 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 27 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 28 | 29 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 30 | flag.StringVar(&config.Name, "n", "Faucet", "homekit accessory name") 31 | flag.StringVar(&config.SN, "sn", "Ex-Faucet", "homekit accessory serial number") 32 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 33 | flag.UintVar(&config.Port, "p", 10705, "homekit port, example: 10101, 10102...") 34 | flag.StringVar(&config.Pin, "pin", "19736428", "homekit pin, example: 82143697, 13974682") 35 | flag.Parse() 36 | 37 | homekit.OnLog(debug) 38 | } 39 | 40 | func main() { 41 | acc := homekit.NewAccessoryFaucet(config.GetInfo("Ex-Faucet")) 42 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 43 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 44 | server, err := hap.NewServer(storage, acc.GetAccessory()) 45 | if err != nil { 46 | log.Fatalf("error create hap server: %v\n", err) 47 | } 48 | log.Printf("hap server create successful.\n") 49 | 50 | go func() { 51 | for range time.Tick(time.Millisecond * 300000) { 52 | acc.Valve.Active.SetValue(int(math.Pow(0, float64(acc.Valve.Active.Value())))) 53 | acc.Valve.InUse.SetValue(acc.Valve.Active.Value()) 54 | log.Printf("update active: %[1]T - %[1]v\n", acc.Valve.Active.Value()) 55 | } 56 | }() 57 | acc.Valve.Active.OnValueRemoteUpdate(func(v int) { 58 | acc.Valve.InUse.SetValue(v) 59 | log.Printf("remote update active: %[1]T - %[1]v\n", v) 60 | }) 61 | 62 | sig := make(chan os.Signal) 63 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 64 | ctx, cancel := context.WithCancel(context.Background()) 65 | go func() { 66 | <-sig 67 | log.Println("program stop.") 68 | signal.Stop(sig) 69 | cancel() 70 | }() 71 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 72 | log.Printf("hap server starting set, address %v, pin %v.\n", server.Addr, server.Pin) 73 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 74 | } 75 | -------------------------------------------------------------------------------- /hap-service/wifi_router.go: -------------------------------------------------------------------------------- 1 | package haps 2 | 3 | import ( 4 | "github.com/brutella/hap/characteristic" 5 | "github.com/brutella/hap/service" 6 | hapc "github.com/xxandev/homekit/hap-characteristic" 7 | ) 8 | 9 | //TypeWiFiRouter - 0000020A-0000-1000-8000-0026BB765291 10 | const TypeWiFiRouter string = "20A" 11 | 12 | //WiFiRouter 13 | // ◈ ConfiguredName 14 | // ◈ ManagedNetworkEnable 15 | // ◈ NetworkAccessViolationControl 16 | // ◈ NetworkClientProfileControl 17 | // ◈ NetworkClientStatusControl 18 | // ◈ RouterStatus 19 | // ◈ SupportedRouterConfiguration 20 | // ◈ WANConfigurationList 21 | // ◈ WANStatusList 22 | type WiFiRouter struct { 23 | *service.S 24 | ConfiguredName *characteristic.ConfiguredName 25 | ManagedNetworkEnable *hapc.ManagedNetworkEnable 26 | NetworkAccessViolationControl *hapc.NetworkAccessViolationControl 27 | NetworkClientProfileControl *hapc.NetworkClientProfileControl 28 | NetworkClientStatusControl *hapc.NetworkClientStatusControl 29 | RouterStatus *hapc.RouterStatus 30 | SupportedRouterConfiguration *hapc.SupportedRouterConfiguration 31 | WANConfigurationList *hapc.WANConfigurationList 32 | WANStatusList *hapc.WANStatusList 33 | } 34 | 35 | //NewWiFiRouter return *WiFiRouter 36 | func NewWiFiRouter() *WiFiRouter { 37 | svc := WiFiRouter{} 38 | svc.S = service.New(TypeWiFiRouter) 39 | 40 | svc.ConfiguredName = characteristic.NewConfiguredName() 41 | svc.AddC(svc.ConfiguredName.C) 42 | 43 | svc.ManagedNetworkEnable = hapc.NewManagedNetworkEnable() 44 | svc.AddC(svc.ManagedNetworkEnable.C) 45 | 46 | svc.NetworkAccessViolationControl = hapc.NewNetworkAccessViolationControl() 47 | svc.AddC(svc.NetworkAccessViolationControl.C) 48 | 49 | svc.NetworkClientProfileControl = hapc.NewNetworkClientProfileControl() 50 | svc.AddC(svc.NetworkClientProfileControl.C) 51 | 52 | svc.NetworkClientStatusControl = hapc.NewNetworkClientStatusControl() 53 | svc.AddC(svc.NetworkClientStatusControl.C) 54 | 55 | svc.RouterStatus = hapc.NewRouterStatus() 56 | svc.AddC(svc.RouterStatus.C) 57 | 58 | svc.SupportedRouterConfiguration = hapc.NewSupportedRouterConfiguration() 59 | svc.AddC(svc.SupportedRouterConfiguration.C) 60 | 61 | svc.WANConfigurationList = hapc.NewWANConfigurationList() 62 | svc.AddC(svc.WANConfigurationList.C) 63 | 64 | svc.WANStatusList = hapc.NewWANStatusList() 65 | svc.AddC(svc.WANStatusList.C) 66 | 67 | return &svc 68 | } 69 | -------------------------------------------------------------------------------- /example/irrigation/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "math" 9 | "os" 10 | "os/signal" 11 | "syscall" 12 | "time" 13 | 14 | "github.com/brutella/hap" 15 | "github.com/xxandev/homekit" 16 | ) 17 | 18 | type Config struct{ homekit.AccessoryConfig } 19 | 20 | var ( 21 | debug bool 22 | config Config 23 | ) 24 | 25 | func init() { 26 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 27 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 28 | 29 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 30 | flag.StringVar(&config.Name, "n", "Irrigation", "homekit accessory name") 31 | flag.StringVar(&config.SN, "sn", "Ex-Irrg", "homekit accessory serial number") 32 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 33 | flag.UintVar(&config.Port, "p", 10708, "homekit port, example: 10101, 10102...") 34 | flag.StringVar(&config.Pin, "pin", "19736428", "homekit pin, example: 82143697, 13974682") 35 | flag.Parse() 36 | 37 | homekit.OnLog(debug) 38 | } 39 | 40 | func main() { 41 | acc := homekit.NewAccessoryIrrigation(config.GetInfo("Ex-Irrg")) 42 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 43 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 44 | server, err := hap.NewServer(storage, acc.GetAccessory()) 45 | if err != nil { 46 | log.Fatalf("error create hap server: %v\n", err) 47 | } 48 | log.Printf("hap server create successful.\n") 49 | 50 | go func() { 51 | for range time.Tick(time.Millisecond * 300000) { 52 | acc.Valve.Active.SetValue(int(math.Pow(0, float64(acc.Valve.Active.Value())))) 53 | acc.Valve.InUse.SetValue(acc.Valve.Active.Value()) 54 | log.Printf("update active: %[1]T - %[1]v\n", acc.Valve.Active.Value()) 55 | } 56 | }() 57 | acc.Valve.Active.OnValueRemoteUpdate(func(v int) { 58 | acc.Valve.InUse.SetValue(v) 59 | log.Printf("remote update active: %[1]T - %[1]v\n", v) 60 | }) 61 | 62 | sig := make(chan os.Signal) 63 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 64 | ctx, cancel := context.WithCancel(context.Background()) 65 | go func() { 66 | <-sig 67 | log.Println("program stop.") 68 | signal.Stop(sig) 69 | cancel() 70 | }() 71 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 72 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 73 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 74 | } 75 | -------------------------------------------------------------------------------- /example/sensor_air_quality/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | "time" 12 | 13 | "github.com/brutella/hap" 14 | "github.com/xxandev/homekit" 15 | ) 16 | 17 | type Config struct{ homekit.AccessoryConfig } 18 | 19 | var ( 20 | debug bool 21 | config Config 22 | ) 23 | 24 | func init() { 25 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 26 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 27 | 28 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 29 | flag.StringVar(&config.Name, "n", "AirQuality", "homekit accessory name") 30 | flag.StringVar(&config.SN, "sn", "Ex-AirQlt", "homekit accessory serial number") 31 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 32 | flag.UintVar(&config.Port, "p", 10714, "homekit port, example: 10101, 10102...") 33 | flag.StringVar(&config.Pin, "pin", "19378246", "homekit pin, example: 82143697, 13974682") 34 | flag.Parse() 35 | 36 | homekit.OnLog(debug) 37 | } 38 | 39 | func main() { 40 | acc := homekit.NewAccessorySensorAirQuality(config.GetInfo("Ex-AirQlt")) 41 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 42 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 43 | server, err := hap.NewServer(storage, acc.GetAccessory()) 44 | if err != nil { 45 | log.Fatalf("error create hap server: %v\n", err) 46 | } 47 | log.Printf("hap server create successful.\n") 48 | go func() { 49 | for range time.Tick(time.Millisecond * 300000) { 50 | if acc.AirQualitySensor.AirQuality.Value() >= acc.AirQualitySensor.AirQuality.MaxValue() { 51 | acc.AirQualitySensor.AirQuality.SetValue(acc.AirQualitySensor.AirQuality.MinValue()) 52 | } else { 53 | acc.AirQualitySensor.AirQuality.SetValue(acc.AirQualitySensor.AirQuality.Value() + 1) 54 | } 55 | fmt.Printf("update current state: %[1]T - %[1]v \n", acc.AirQualitySensor.AirQuality.Value()) 56 | } 57 | }() 58 | sig := make(chan os.Signal) 59 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 60 | ctx, cancel := context.WithCancel(context.Background()) 61 | go func() { 62 | <-sig 63 | log.Println("program stop.") 64 | signal.Stop(sig) 65 | cancel() 66 | }() 67 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 68 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 69 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 70 | } 71 | -------------------------------------------------------------------------------- /example/sensor_temp/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | "time" 12 | 13 | "github.com/brutella/hap" 14 | "github.com/xxandev/homekit" 15 | ) 16 | 17 | type Config struct{ homekit.AccessoryConfig } 18 | 19 | var ( 20 | debug bool 21 | config Config 22 | ) 23 | 24 | func init() { 25 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 26 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 27 | 28 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 29 | flag.StringVar(&config.Name, "n", "STemp", "homekit accessory name") 30 | flag.StringVar(&config.SN, "sn", "Ex-STemp", "homekit accessory serial number") 31 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 32 | flag.UintVar(&config.Port, "p", 10723, "homekit port, example: 10101, 10102...") 33 | flag.StringVar(&config.Pin, "pin", "19378246", "homekit pin, example: 82143697, 13974682") 34 | flag.Parse() 35 | 36 | homekit.OnLog(debug) 37 | } 38 | 39 | func main() { 40 | acc := homekit.NewAccessorySensorTemperature(config.GetInfo("Ex-STemp")) 41 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 42 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 43 | server, err := hap.NewServer(storage, acc.GetAccessory()) 44 | if err != nil { 45 | log.Fatalf("error create hap server: %v\n", err) 46 | } 47 | log.Printf("hap server create successful.\n") 48 | 49 | go func() { 50 | for range time.Tick(time.Millisecond * 3000) { 51 | if acc.TempSensor.CurrentTemperature.Value() >= acc.TempSensor.CurrentTemperature.MaxValue() { 52 | acc.TempSensor.CurrentTemperature.SetValue(acc.TempSensor.CurrentTemperature.MinValue()) 53 | } else { 54 | acc.TempSensor.CurrentTemperature.SetValue(acc.TempSensor.CurrentTemperature.Value() + 0.25) 55 | } 56 | log.Printf("update current temp: %[1]T - %[1]v\n", acc.TempSensor.CurrentTemperature.Value()) 57 | } 58 | }() 59 | 60 | sig := make(chan os.Signal) 61 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 62 | ctx, cancel := context.WithCancel(context.Background()) 63 | go func() { 64 | <-sig 65 | log.Println("program stop.") 66 | signal.Stop(sig) 67 | cancel() 68 | }() 69 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 70 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 71 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 72 | } 73 | -------------------------------------------------------------------------------- /accessory_programmable_switch.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessoryProgrammableSwitch struct 9 | type AccessoryProgrammableSwitch struct { 10 | *accessory.A 11 | ProgrammableSwitch *service.StatelessProgrammableSwitch 12 | } 13 | 14 | func (acc *AccessoryProgrammableSwitch) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessoryProgrammableSwitch) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessoryProgrammableSwitch) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessoryProgrammableSwitch) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessoryProgrammableSwitch) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessoryProgrammableSwitch) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | // NewAccessoryProgrammableSwitch returns *ProgrammableSwitch. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args... are not used 43 | func NewAccessoryProgrammableSwitch(info accessory.Info, args ...interface{}) *AccessoryProgrammableSwitch { 44 | acc := AccessoryProgrammableSwitch{} 45 | acc.A = accessory.New(info, accessory.TypeSwitch) 46 | acc.ProgrammableSwitch = service.NewStatelessProgrammableSwitch() 47 | acc.AddS(acc.ProgrammableSwitch.S) 48 | return &acc 49 | } 50 | 51 | // NewAccessoryProgrammableSwitch returns *ProgrammableSwitch. 52 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 53 | // The best would be to specify the unique id for every accessory yourself. 54 | // 55 | // id (uint64) - accessory aid 56 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 57 | // args... are not used 58 | func NewAccProgrammableSwitch(id uint64, info accessory.Info, args ...interface{}) *AccessoryProgrammableSwitch { 59 | acc := AccessoryProgrammableSwitch{} 60 | acc.A = accessory.New(info, accessory.TypeSwitch) 61 | acc.ProgrammableSwitch = service.NewStatelessProgrammableSwitch() 62 | acc.AddS(acc.ProgrammableSwitch.S) 63 | acc.A.Id = id 64 | return &acc 65 | } 66 | 67 | func (acc *AccessoryProgrammableSwitch) OnValuesRemoteUpdates(fn func()) {} 68 | -------------------------------------------------------------------------------- /example/lightbulb_dimmer/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | "time" 12 | 13 | "github.com/brutella/hap" 14 | "github.com/xxandev/homekit" 15 | ) 16 | 17 | type Config struct{ homekit.AccessoryConfig } 18 | 19 | var ( 20 | debug bool 21 | config Config 22 | ) 23 | 24 | func init() { 25 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 26 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 27 | 28 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 29 | flag.StringVar(&config.Name, "n", "Dimmer", "homekit accessory name") 30 | flag.StringVar(&config.SN, "sn", "Ex-LbDimm", "homekit accessory serial number") 31 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 32 | flag.UintVar(&config.Port, "p", 10710, "homekit port, example: 10101, 10102...") 33 | flag.StringVar(&config.Pin, "pin", "19736428", "homekit pin, example: 82143697, 13974682") 34 | flag.Parse() 35 | 36 | homekit.OnLog(debug) 37 | } 38 | 39 | func main() { 40 | acc := homekit.NewAccessoryLightbulbDimmer(config.GetInfo("Ex-LbDimm")) 41 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 42 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 43 | server, err := hap.NewServer(storage, acc.GetAccessory()) 44 | if err != nil { 45 | log.Fatalf("error create hap server: %v\n", err) 46 | } 47 | log.Printf("hap server create successful.\n") 48 | 49 | go func() { 50 | for range time.Tick(time.Millisecond * 300000) { 51 | acc.LightbulbDimmer.On.SetValue(!acc.LightbulbDimmer.On.Value()) 52 | log.Printf("update on: %[1]T - %[1]v \n", acc.LightbulbDimmer.On.Value()) 53 | } 54 | }() 55 | acc.LightbulbDimmer.On.OnValueRemoteUpdate(func(v bool) { 56 | log.Printf("remote update on: %[1]T - %[1]v\n", v) 57 | }) 58 | acc.LightbulbDimmer.Brightness.OnValueRemoteUpdate(func(v int) { 59 | log.Printf("remote update brightness: %[1]T - %[1]v\n", v) 60 | }) 61 | 62 | sig := make(chan os.Signal) 63 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 64 | ctx, cancel := context.WithCancel(context.Background()) 65 | go func() { 66 | <-sig 67 | log.Println("program stop.") 68 | signal.Stop(sig) 69 | cancel() 70 | }() 71 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 72 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 73 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 74 | } 75 | -------------------------------------------------------------------------------- /accessory_lightbulb_dimmer.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | haps "github.com/xxandev/homekit/hap-service" 6 | ) 7 | 8 | //AccessoryLightbulbDimmer struct 9 | type AccessoryLightbulbDimmer struct { 10 | *accessory.A 11 | LightbulbDimmer *haps.LightbulbDimmer 12 | } 13 | 14 | func (acc *AccessoryLightbulbDimmer) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessoryLightbulbDimmer) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessoryLightbulbDimmer) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessoryLightbulbDimmer) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessoryLightbulbDimmer) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessoryLightbulbDimmer) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessoryLightbulbDimmer return *LightbulbDimmer. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args... are not used 43 | func NewAccessoryLightbulbDimmer(info accessory.Info, args ...interface{}) *AccessoryLightbulbDimmer { 44 | acc := AccessoryLightbulbDimmer{} 45 | acc.A = accessory.New(info, accessory.TypeLightbulb) 46 | acc.LightbulbDimmer = haps.NewLightbulbDimmer() 47 | acc.AddS(acc.LightbulbDimmer.S) 48 | return &acc 49 | } 50 | 51 | //NewAccLightbulbDimmer return *LightbulbDimmer. 52 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 53 | // The best would be to specify the unique id for every accessory yourself. 54 | // 55 | // id (uint64) - accessory aid 56 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 57 | // args... are not used 58 | func NewAccLightbulbDimmer(id uint64, info accessory.Info, args ...interface{}) *AccessoryLightbulbDimmer { 59 | acc := AccessoryLightbulbDimmer{} 60 | acc.A = accessory.New(info, accessory.TypeLightbulb) 61 | acc.LightbulbDimmer = haps.NewLightbulbDimmer() 62 | acc.AddS(acc.LightbulbDimmer.S) 63 | acc.A.Id = id 64 | return &acc 65 | } 66 | 67 | func (acc *AccessoryLightbulbDimmer) OnValuesRemoteUpdates(fn func()) { 68 | acc.LightbulbDimmer.On.OnValueRemoteUpdate(func(bool) { fn() }) 69 | acc.LightbulbDimmer.Brightness.OnValueRemoteUpdate(func(int) { fn() }) 70 | } 71 | -------------------------------------------------------------------------------- /example/sensor_light/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | "time" 12 | 13 | "github.com/brutella/hap" 14 | "github.com/xxandev/homekit" 15 | ) 16 | 17 | type Config struct{ homekit.AccessoryConfig } 18 | 19 | var ( 20 | debug bool 21 | config Config 22 | ) 23 | 24 | func init() { 25 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 26 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 27 | 28 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 29 | flag.StringVar(&config.Name, "n", "SLight", "homekit accessory name") 30 | flag.StringVar(&config.SN, "sn", "Ex-SLight", "homekit accessory serial number") 31 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 32 | flag.UintVar(&config.Port, "p", 10719, "homekit port, example: 10101, 10102...") 33 | flag.StringVar(&config.Pin, "pin", "19378246", "homekit pin, example: 82143697, 13974682") 34 | flag.Parse() 35 | 36 | homekit.OnLog(debug) 37 | } 38 | 39 | func main() { 40 | acc := homekit.NewAccessorySensorLight(config.GetInfo("Ex-SLight")) 41 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 42 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 43 | server, err := hap.NewServer(storage, acc.GetAccessory()) 44 | if err != nil { 45 | log.Fatalf("error create hap server: %v\n", err) 46 | } 47 | log.Printf("hap server create successful.\n") 48 | 49 | go func() { 50 | for range time.Tick(time.Millisecond * 1000) { 51 | if acc.LightSensor.CurrentAmbientLightLevel.Value() >= acc.LightSensor.CurrentAmbientLightLevel.MaxValue() { 52 | acc.LightSensor.CurrentAmbientLightLevel.SetValue(acc.LightSensor.CurrentAmbientLightLevel.MinValue()) 53 | } else { 54 | acc.LightSensor.CurrentAmbientLightLevel.SetValue(acc.LightSensor.CurrentAmbientLightLevel.Value() + 0.25) 55 | } 56 | log.Printf("update current ambient light: %[1]T - %[1]v\n", acc.LightSensor.CurrentAmbientLightLevel.Value()) 57 | } 58 | }() 59 | 60 | sig := make(chan os.Signal) 61 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 62 | ctx, cancel := context.WithCancel(context.Background()) 63 | go func() { 64 | <-sig 65 | log.Println("program stop.") 66 | signal.Stop(sig) 67 | cancel() 68 | }() 69 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 70 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 71 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 72 | } 73 | -------------------------------------------------------------------------------- /accessory_faucet.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessoryFaucet struct 9 | type AccessoryFaucet struct { 10 | *accessory.A 11 | // Faucet *service.Faucet 12 | Valve *service.Valve 13 | } 14 | 15 | func (acc *AccessoryFaucet) GetType() byte { 16 | return acc.A.Type 17 | } 18 | 19 | func (acc *AccessoryFaucet) GetID() uint64 { 20 | return acc.A.Id 21 | } 22 | 23 | func (acc *AccessoryFaucet) SetID(id uint64) { 24 | acc.A.Id = id 25 | } 26 | 27 | func (acc *AccessoryFaucet) GetSN() string { 28 | return acc.A.Info.SerialNumber.Value() 29 | } 30 | 31 | func (acc *AccessoryFaucet) GetName() string { 32 | return acc.A.Info.Name.Value() 33 | } 34 | 35 | func (acc *AccessoryFaucet) GetAccessory() *accessory.A { 36 | return acc.A 37 | } 38 | 39 | //NewAccessoryFaucet return *Faucet 40 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 41 | // 42 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 43 | // args... are not used 44 | func NewAccessoryFaucet(info accessory.Info, args ...interface{}) *AccessoryFaucet { 45 | acc := AccessoryFaucet{} 46 | acc.A = accessory.New(info, accessory.TypeFaucet) 47 | // acc.Faucet = service.NewFaucet() 48 | acc.Valve = service.NewValve() 49 | 50 | acc.Valve.ValveType.SetValue(0) 51 | 52 | // acc.AddService(acc.Faucet.Service) 53 | acc.AddS(acc.Valve.S) 54 | return &acc 55 | } 56 | 57 | //NewAccFaucet return *Faucet 58 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 59 | // The best would be to specify the unique id for every accessory yourself. 60 | // 61 | // id (uint64) - accessory aid 62 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 63 | // args... are not used 64 | func NewAccFaucet(id uint64, info accessory.Info, args ...interface{}) *AccessoryFaucet { 65 | acc := AccessoryFaucet{} 66 | acc.A = accessory.New(info, accessory.TypeFaucet) 67 | // acc.Faucet = service.NewFaucet() 68 | acc.Valve = service.NewValve() 69 | 70 | acc.Valve.ValveType.SetValue(0) 71 | 72 | // acc.AddService(acc.Faucet.Service) 73 | acc.AddS(acc.Valve.S) 74 | acc.A.Id = id 75 | return &acc 76 | } 77 | 78 | func (acc *AccessoryFaucet) OnValuesRemoteUpdates(fn func()) { 79 | acc.Valve.Active.OnValueRemoteUpdate(func(int) { fn() }) 80 | // acc.Valve.InUse.OnValueRemoteUpdate(func(int) { fn() }) 81 | } 82 | -------------------------------------------------------------------------------- /example/sensor_humidity/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | "time" 12 | 13 | "github.com/brutella/hap" 14 | "github.com/xxandev/homekit" 15 | ) 16 | 17 | type Config struct{ homekit.AccessoryConfig } 18 | 19 | var ( 20 | debug bool 21 | config Config 22 | ) 23 | 24 | func init() { 25 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 26 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 27 | 28 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 29 | flag.StringVar(&config.Name, "n", "SHumidity", "homekit accessory name") 30 | flag.StringVar(&config.SN, "sn", "Ex-SHum", "homekit accessory serial number") 31 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 32 | flag.UintVar(&config.Port, "p", 10717, "homekit port, example: 10101, 10102...") 33 | flag.StringVar(&config.Pin, "pin", "19378246", "homekit pin, example: 82143697, 13974682") 34 | flag.Parse() 35 | 36 | homekit.OnLog(debug) 37 | } 38 | 39 | func main() { 40 | acc := homekit.NewAccessorySensorHumidity(config.GetInfo("Ex-SHum")) 41 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 42 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 43 | server, err := hap.NewServer(storage, acc.GetAccessory()) 44 | if err != nil { 45 | log.Fatalf("error create hap server: %v\n", err) 46 | } 47 | log.Printf("hap server create successful.\n") 48 | 49 | go func() { 50 | for range time.Tick(time.Millisecond * 3000) { 51 | if acc.HumiditySensor.CurrentRelativeHumidity.Value() >= acc.HumiditySensor.CurrentRelativeHumidity.MaxValue() { 52 | acc.HumiditySensor.CurrentRelativeHumidity.SetValue(acc.HumiditySensor.CurrentRelativeHumidity.MinValue()) 53 | } else { 54 | acc.HumiditySensor.CurrentRelativeHumidity.SetValue(acc.HumiditySensor.CurrentRelativeHumidity.Value() + 0.25) 55 | } 56 | log.Printf("update current hum: %[1]T - %[1]v\n", acc.HumiditySensor.CurrentRelativeHumidity.Value()) 57 | } 58 | }() 59 | 60 | sig := make(chan os.Signal) 61 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 62 | ctx, cancel := context.WithCancel(context.Background()) 63 | go func() { 64 | <-sig 65 | log.Println("program stop.") 66 | signal.Stop(sig) 67 | cancel() 68 | }() 69 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 70 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 71 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 72 | } 73 | -------------------------------------------------------------------------------- /example/air_purifier/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | 12 | "github.com/brutella/hap" 13 | "github.com/xxandev/homekit" 14 | ) 15 | 16 | type Config struct{ homekit.AccessoryConfig } 17 | 18 | var ( 19 | debug bool 20 | config Config 21 | ) 22 | 23 | func init() { 24 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 25 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 26 | 27 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 28 | flag.StringVar(&config.Name, "n", "AirPurifier", "homekit accessory name") 29 | flag.StringVar(&config.SN, "sn", "Ex-AirPrf", "homekit accessory serial number") 30 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 31 | flag.UintVar(&config.Port, "p", 10702, "homekit port, example: 10101, 10102...") 32 | flag.StringVar(&config.Pin, "pin", "19736428", "homekit pin, example: 82143697, 13974682") 33 | flag.Parse() 34 | 35 | homekit.OnLog(debug) 36 | } 37 | 38 | func main() { 39 | acc := homekit.NewAccessoryAirPurifier(config.GetInfo("Ex-AirPrf"), 0.0, 0.0, 100.0, 1.0) 40 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 41 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 42 | server, err := hap.NewServer(storage, acc.A) 43 | if err != nil { 44 | log.Fatalf("error create hap server: %v\n", err) 45 | } 46 | log.Printf("hap server create successful.\n") 47 | 48 | acc.AirPurifier.Active.OnValueRemoteUpdate(func(v int) { 49 | if v > 0 { 50 | acc.AirPurifier.CurrentAirPurifierState.SetValue(2) 51 | } else { 52 | acc.AirPurifier.CurrentAirPurifierState.SetValue(0) 53 | } 54 | log.Printf("remote update active: %[1]T - %[1]v\n", v) 55 | }) 56 | acc.AirPurifier.TargetAirPurifierState.OnValueRemoteUpdate(func(v int) { 57 | log.Printf("remote update target state: %[1]T - %[1]v\n", v) 58 | }) 59 | acc.AirPurifier.RotationSpeed.OnValueRemoteUpdate(func(v float64) { 60 | log.Printf("remote update rotation speed: %[1]T - %[1]v\n", v) 61 | }) 62 | 63 | sig := make(chan os.Signal) 64 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 65 | ctx, cancel := context.WithCancel(context.Background()) 66 | go func() { 67 | <-sig 68 | log.Println("program stop.") 69 | signal.Stop(sig) 70 | cancel() 71 | }() 72 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 73 | log.Printf("hap server starting set, address %v, pin %v.\n", server.Addr, server.Pin) 74 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 75 | } 76 | -------------------------------------------------------------------------------- /hap-service/thermostat_middle.go: -------------------------------------------------------------------------------- 1 | package haps 2 | 3 | import ( 4 | "github.com/brutella/hap/characteristic" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //ThermostatMiddle 9 | // ◈ CurrentHeatingCoolingState 10 | // ◈ TargetHeatingCoolingState 11 | // ◈ CurrentTemperature 12 | // ◈ TargetTemperature 13 | // ◈ TemperatureDisplayUnits 14 | // ◇ CoolingThresholdTemperature 15 | // ◇ HeatingThresholdTemperature 16 | // ◇ CurrentRelativeHumidity 17 | // ◇ TargetRelativeHumidity 18 | type ThermostatMiddle struct { 19 | *service.S 20 | CurrentHeatingCoolingState *characteristic.CurrentHeatingCoolingState 21 | TargetHeatingCoolingState *characteristic.TargetHeatingCoolingState 22 | CurrentTemperature *characteristic.CurrentTemperature 23 | TargetTemperature *characteristic.TargetTemperature 24 | TemperatureDisplayUnits *characteristic.TemperatureDisplayUnits 25 | CoolingThresholdTemperature *characteristic.CoolingThresholdTemperature 26 | HeatingThresholdTemperature *characteristic.HeatingThresholdTemperature 27 | CurrentRelativeHumidity *characteristic.CurrentRelativeHumidity 28 | TargetRelativeHumidity *characteristic.TargetRelativeHumidity 29 | } 30 | 31 | //NewThermostatMiddle return *ThermostatMiddle 32 | func NewThermostatMiddle() *ThermostatMiddle { 33 | svc := ThermostatMiddle{} 34 | svc.S = service.New(service.TypeThermostat) 35 | 36 | svc.CurrentHeatingCoolingState = characteristic.NewCurrentHeatingCoolingState() 37 | svc.AddC(svc.CurrentHeatingCoolingState.C) 38 | 39 | svc.TargetHeatingCoolingState = characteristic.NewTargetHeatingCoolingState() 40 | svc.AddC(svc.TargetHeatingCoolingState.C) 41 | 42 | svc.CurrentTemperature = characteristic.NewCurrentTemperature() 43 | svc.AddC(svc.CurrentTemperature.C) 44 | 45 | svc.TargetTemperature = characteristic.NewTargetTemperature() 46 | svc.AddC(svc.TargetTemperature.C) 47 | 48 | svc.TemperatureDisplayUnits = characteristic.NewTemperatureDisplayUnits() 49 | svc.AddC(svc.TemperatureDisplayUnits.C) 50 | 51 | svc.CoolingThresholdTemperature = characteristic.NewCoolingThresholdTemperature() 52 | svc.AddC(svc.CoolingThresholdTemperature.C) 53 | 54 | svc.HeatingThresholdTemperature = characteristic.NewHeatingThresholdTemperature() 55 | svc.AddC(svc.HeatingThresholdTemperature.C) 56 | 57 | svc.CurrentRelativeHumidity = characteristic.NewCurrentRelativeHumidity() 58 | svc.AddC(svc.CurrentRelativeHumidity.C) 59 | 60 | svc.TargetRelativeHumidity = characteristic.NewTargetRelativeHumidity() 61 | svc.AddC(svc.TargetRelativeHumidity.C) 62 | 63 | return &svc 64 | } 65 | -------------------------------------------------------------------------------- /example/humidifier_dehumidifier/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | 12 | "github.com/brutella/hap" 13 | "github.com/xxandev/homekit" 14 | ) 15 | 16 | type Config struct{ homekit.AccessoryConfig } 17 | 18 | var ( 19 | debug bool 20 | config Config 21 | ) 22 | 23 | func init() { 24 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 25 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 26 | 27 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 28 | flag.StringVar(&config.Name, "n", "HumDehum", "homekit accessory name") 29 | flag.StringVar(&config.SN, "sn", "Ex-HumDehum", "homekit accessory serial number") 30 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 31 | flag.UintVar(&config.Port, "p", 10707, "homekit port, example: 10101, 10102...") 32 | flag.StringVar(&config.Pin, "pin", "19736428", "homekit pin, example: 82143697, 13974682") 33 | flag.Parse() 34 | 35 | homekit.OnLog(debug) 36 | } 37 | 38 | func main() { 39 | acc := homekit.NewAccessoryHumidifierDehumidifier(config.GetInfo("Ex-HumDehum")) 40 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 41 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 42 | server, err := hap.NewServer(storage, acc.GetAccessory()) 43 | if err != nil { 44 | log.Fatalf("error create hap server: %v\n", err) 45 | } 46 | log.Printf("hap server create successful.\n") 47 | 48 | acc.HumidifierDehumidifier.Active.OnValueRemoteUpdate(func(v int) { 49 | log.Printf("remote update active: %[1]T - %[1]v\n", v) 50 | }) 51 | acc.HumidifierDehumidifier.TargetHumidifierDehumidifierState.OnValueRemoteUpdate(func(v int) { 52 | log.Printf("remote update target state: %[1]T - %[1]v\n", v) 53 | }) 54 | acc.HumidifierDehumidifier.RelativeHumidityDehumidifierThreshold.OnValueRemoteUpdate(func(v float64) { 55 | log.Printf("remote update relative dehumidifier threshold: %[1]T - %[1]v\n", v) 56 | }) 57 | acc.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold.OnValueRemoteUpdate(func(v float64) { 58 | log.Printf("remote update relative humidifier threshold: %[1]T - %[1]v\n", v) 59 | }) 60 | 61 | sig := make(chan os.Signal) 62 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 63 | ctx, cancel := context.WithCancel(context.Background()) 64 | go func() { 65 | <-sig 66 | log.Println("program stop.") 67 | signal.Stop(sig) 68 | cancel() 69 | }() 70 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 71 | log.Printf("hap server starting set, address %v, pin %v.\n", server.Addr, server.Pin) 72 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 73 | 74 | } 75 | -------------------------------------------------------------------------------- /accessory_lightbulb_colored.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessoryLightbulbColored struct 9 | type AccessoryLightbulbColored struct { 10 | *accessory.A 11 | LightbulbColored *service.ColoredLightbulb 12 | } 13 | 14 | func (acc *AccessoryLightbulbColored) GetType() uint8 { 15 | return uint8(acc.A.Type) 16 | } 17 | 18 | func (acc *AccessoryLightbulbColored) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessoryLightbulbColored) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessoryLightbulbColored) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessoryLightbulbColored) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessoryLightbulbColored) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessoryLightbulbColored return *LightbulbColored. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args... are not used 43 | func NewAccessoryLightbulbColored(info accessory.Info, args ...interface{}) *AccessoryLightbulbColored { 44 | acc := AccessoryLightbulbColored{} 45 | acc.A = accessory.New(info, accessory.TypeLightbulb) 46 | acc.LightbulbColored = service.NewColoredLightbulb() 47 | acc.AddS(acc.LightbulbColored.S) 48 | return &acc 49 | } 50 | 51 | //NewAccLightbulbColored return *LightbulbColored. 52 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 53 | // The best would be to specify the unique id for every accessory yourself. 54 | // 55 | // id (uint64) - accessory aid 56 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 57 | // args... are not used 58 | func NewAccLightbulbColored(id uint64, info accessory.Info, args ...interface{}) *AccessoryLightbulbColored { 59 | acc := AccessoryLightbulbColored{} 60 | acc.A = accessory.New(info, accessory.TypeLightbulb) 61 | acc.LightbulbColored = service.NewColoredLightbulb() 62 | acc.AddS(acc.LightbulbColored.S) 63 | acc.A.Id = id 64 | return &acc 65 | } 66 | 67 | func (acc *AccessoryLightbulbColored) OnValuesRemoteUpdates(fn func()) { 68 | acc.LightbulbColored.On.OnValueRemoteUpdate(func(bool) { fn() }) 69 | acc.LightbulbColored.Brightness.OnValueRemoteUpdate(func(int) { fn() }) 70 | acc.LightbulbColored.Saturation.OnValueRemoteUpdate(func(float64) { fn() }) 71 | acc.LightbulbColored.Hue.OnValueRemoteUpdate(func(float64) { fn() }) 72 | } 73 | -------------------------------------------------------------------------------- /example/lightbulb_colored/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | "time" 12 | 13 | "github.com/brutella/hap" 14 | "github.com/xxandev/homekit" 15 | ) 16 | 17 | type Config struct{ homekit.AccessoryConfig } 18 | 19 | var ( 20 | debug bool 21 | config Config 22 | ) 23 | 24 | func init() { 25 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 26 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 27 | 28 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 29 | flag.StringVar(&config.Name, "n", "Lightbulb", "homekit accessory name") 30 | flag.StringVar(&config.SN, "sn", "Ex-LbColor", "homekit accessory serial number") 31 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 32 | flag.UintVar(&config.Port, "p", 10709, "homekit port, example: 10101, 10102...") 33 | flag.StringVar(&config.Pin, "pin", "19736428", "homekit pin, example: 82143697, 13974682") 34 | flag.Parse() 35 | 36 | homekit.OnLog(debug) 37 | } 38 | 39 | func main() { 40 | acc := homekit.NewAccessoryLightbulbColored(config.GetInfo("Ex-LbColor")) 41 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 42 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 43 | server, err := hap.NewServer(storage, acc.GetAccessory()) 44 | if err != nil { 45 | log.Fatalf("error create hap server: %v\n", err) 46 | } 47 | log.Printf("hap server create successful.\n") 48 | 49 | go func() { 50 | for range time.Tick(time.Millisecond * 300000) { 51 | acc.LightbulbColored.On.SetValue(!acc.LightbulbColored.On.Value()) 52 | log.Printf("update on: %[1]T - %[1]v \n", acc.LightbulbColored.On.Value()) 53 | } 54 | }() 55 | acc.LightbulbColored.On.OnValueRemoteUpdate(func(v bool) { 56 | log.Printf("remote update on: %[1]T - %[1]v\n", v) 57 | }) 58 | acc.LightbulbColored.Brightness.OnValueRemoteUpdate(func(v int) { 59 | log.Printf("remote update brightness: %[1]T - %[1]v\n", v) 60 | }) 61 | acc.LightbulbColored.Saturation.OnValueRemoteUpdate(func(v float64) { 62 | log.Printf("remote update saturation: %[1]T - %[1]v\n", v) 63 | }) 64 | acc.LightbulbColored.Hue.OnValueRemoteUpdate(func(v float64) { 65 | log.Printf("remote update hue: %[1]T - %[1]v\n", v) 66 | }) 67 | 68 | sig := make(chan os.Signal) 69 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 70 | ctx, cancel := context.WithCancel(context.Background()) 71 | go func() { 72 | <-sig 73 | log.Println("program stop.") 74 | signal.Stop(sig) 75 | cancel() 76 | }() 77 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 78 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 79 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 80 | } 81 | -------------------------------------------------------------------------------- /accessory_sensor_temperarure.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessorySensorTemperature struct 9 | type AccessorySensorTemperature struct { 10 | *accessory.A 11 | TempSensor *service.TemperatureSensor 12 | } 13 | 14 | func (acc *AccessorySensorTemperature) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessorySensorTemperature) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessorySensorTemperature) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessorySensorTemperature) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessorySensorTemperature) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessorySensorTemperature) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessorySensorTemperature returns *SensorTemperature. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args... are not used 43 | func NewAccessorySensorTemperature(info accessory.Info, args ...interface{}) *AccessorySensorTemperature { 44 | acc := AccessorySensorTemperature{} 45 | acc.A = accessory.New(info, accessory.TypeThermostat) 46 | acc.TempSensor = service.NewTemperatureSensor() 47 | acc.TempSensor.CurrentTemperature.SetValue(0) 48 | acc.TempSensor.CurrentTemperature.SetMinValue(-99.00) 49 | acc.TempSensor.CurrentTemperature.SetMaxValue(99.00) 50 | acc.TempSensor.CurrentTemperature.SetStepValue(0.1) 51 | acc.AddS(acc.TempSensor.S) 52 | return &acc 53 | } 54 | 55 | //NewAccessorySensorTemperature returns *SensorTemperature. 56 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 57 | // The best would be to specify the unique id for every accessory yourself. 58 | // 59 | // id (uint64) - accessory aid 60 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 61 | // args... are not used 62 | func NewAccSensorTemperature(id uint64, info accessory.Info, args ...interface{}) *AccessorySensorTemperature { 63 | acc := AccessorySensorTemperature{} 64 | acc.A = accessory.New(info, accessory.TypeThermostat) 65 | acc.TempSensor = service.NewTemperatureSensor() 66 | acc.TempSensor.CurrentTemperature.SetValue(0) 67 | acc.TempSensor.CurrentTemperature.SetMinValue(-99.00) 68 | acc.TempSensor.CurrentTemperature.SetMaxValue(99.00) 69 | acc.TempSensor.CurrentTemperature.SetStepValue(0.1) 70 | acc.AddS(acc.TempSensor.S) 71 | acc.A.Id = id 72 | return &acc 73 | } 74 | 75 | func (acc *AccessorySensorTemperature) OnValuesRemoteUpdates(fn func()) {} 76 | -------------------------------------------------------------------------------- /accessory_camera.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessoryCamera provides RTP video streaming. 9 | type AccessoryCamera struct { 10 | *accessory.A 11 | Control *service.CameraControl 12 | StreamManagement1 *service.CameraRTPStreamManagement 13 | StreamManagement2 *service.CameraRTPStreamManagement 14 | } 15 | 16 | func (acc *AccessoryCamera) GetType() byte { 17 | return acc.A.Type 18 | } 19 | 20 | func (acc *AccessoryCamera) GetID() uint64 { 21 | return acc.A.Id 22 | } 23 | 24 | func (acc *AccessoryCamera) SetID(id uint64) { 25 | acc.A.Id = id 26 | } 27 | 28 | func (acc *AccessoryCamera) GetSN() string { 29 | return acc.A.Info.SerialNumber.Value() 30 | } 31 | 32 | func (acc *AccessoryCamera) GetName() string { 33 | return acc.A.Info.Name.Value() 34 | } 35 | 36 | func (acc *AccessoryCamera) GetAccessory() *accessory.A { 37 | return acc.A 38 | } 39 | 40 | //NewAccessoryCamera returns *Camera. 41 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 42 | // 43 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 44 | // args... are not used 45 | func NewAccessoryCamera(info accessory.Info, args ...interface{}) *AccessoryCamera { 46 | acc := AccessoryCamera{} 47 | acc.A = accessory.New(info, accessory.TypeIPCamera) 48 | acc.Control = service.NewCameraControl() 49 | acc.AddS(acc.Control.S) 50 | 51 | // TODO (mah) a camera must support at least 2 rtp streams 52 | acc.StreamManagement1 = service.NewCameraRTPStreamManagement() 53 | acc.StreamManagement2 = service.NewCameraRTPStreamManagement() 54 | acc.AddS(acc.StreamManagement1.S) 55 | // acc.AddService(acc.StreamManagement2.Service) 56 | return &acc 57 | } 58 | 59 | //NewAccCamera returns *Camera. 60 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 61 | // The best would be to specify the unique id for every accessory yourself. 62 | // 63 | // id (uint64) - accessory aid 64 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 65 | // args... are not used 66 | func NewAccCamera(id uint64, info accessory.Info, args ...interface{}) *AccessoryCamera { 67 | acc := AccessoryCamera{} 68 | acc.A = accessory.New(info, accessory.TypeIPCamera) 69 | acc.Control = service.NewCameraControl() 70 | acc.AddS(acc.Control.S) 71 | 72 | // TODO (mah) a camera must support at least 2 rtp streams 73 | acc.StreamManagement1 = service.NewCameraRTPStreamManagement() 74 | acc.StreamManagement2 = service.NewCameraRTPStreamManagement() 75 | acc.AddS(acc.StreamManagement1.S) 76 | // acc.AddService(acc.StreamManagement2.Service) 77 | acc.A.Id = id 78 | return &acc 79 | } 80 | 81 | func (acc *AccessoryCamera) OnValuesRemoteUpdates(fn func()) {} 82 | -------------------------------------------------------------------------------- /example/fan_rs/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | "time" 12 | 13 | "github.com/brutella/hap" 14 | "github.com/xxandev/homekit" 15 | ) 16 | 17 | type Config struct{ homekit.AccessoryConfig } 18 | 19 | var ( 20 | debug bool 21 | config Config 22 | ) 23 | 24 | func init() { 25 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 26 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 27 | 28 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 29 | flag.StringVar(&config.Name, "n", "FanRS", "homekit accessory name") 30 | flag.StringVar(&config.SN, "sn", "Ex-FanRS", "homekit accessory serial number") 31 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 32 | flag.UintVar(&config.Port, "p", 10704, "homekit port, example: 10101, 10102...") 33 | flag.StringVar(&config.Pin, "pin", "19736428", "homekit pin, example: 82143697, 13974682") 34 | flag.Parse() 35 | 36 | homekit.OnLog(debug) 37 | } 38 | 39 | func main() { 40 | acc := homekit.NewAccessoryFanRS(config.GetInfo("Ex-FanRS")) 41 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 42 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 43 | server, err := hap.NewServer(storage, acc.GetAccessory()) 44 | if err != nil { 45 | log.Fatalf("error create hap server: %v\n", err) 46 | } 47 | log.Printf("hap server create successful.\n") 48 | 49 | go func() { 50 | for range time.Tick(time.Millisecond * 180000) { 51 | acc.Fan.On.SetValue(true) 52 | acc.Fan.RotationSpeed.SetValue(50) 53 | log.Printf("update, on: %[1]T - %[1]v, speed %[2]T - %[2]v\n", acc.Fan.On.Value(), acc.Fan.RotationSpeed.Value()) 54 | time.Sleep(time.Millisecond * 30000) 55 | acc.Fan.RotationSpeed.SetValue(100) 56 | log.Printf("update, on: %[1]T - %[1]v, speed %[2]T - %[2]v\n", acc.Fan.On.Value(), acc.Fan.RotationSpeed.Value()) 57 | time.Sleep(time.Millisecond * 60000) 58 | acc.Fan.On.SetValue(false) 59 | log.Printf("update, on: %[1]T - %[1]v, speed %[2]T - %[2]v\n", acc.Fan.On.Value(), acc.Fan.RotationSpeed.Value()) 60 | } 61 | }() 62 | acc.Fan.On.OnValueRemoteUpdate(func(v bool) { 63 | log.Printf("remote update on: %[1]T - %[1]v\n", v) 64 | }) 65 | acc.Fan.RotationSpeed.OnValueRemoteUpdate(func(v float64) { 66 | log.Printf("remote update rotation speed: %[1]T - %[1]v\n", v) 67 | }) 68 | 69 | sig := make(chan os.Signal) 70 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 71 | ctx, cancel := context.WithCancel(context.Background()) 72 | go func() { 73 | <-sig 74 | log.Println("program stop.") 75 | signal.Stop(sig) 76 | cancel() 77 | }() 78 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 79 | log.Printf("hap server starting set, address %v, pin %v.\n", server.Addr, server.Pin) 80 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 81 | } 82 | -------------------------------------------------------------------------------- /accessory_doorbell.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessoryDoorbell provides RTP video streaming, Speaker and Mic controls 9 | type AccessoryDoorbell struct { 10 | *accessory.A 11 | Control *service.Doorbell 12 | StreamManagement *service.CameraRTPStreamManagement 13 | Speaker *service.Speaker 14 | Microphone *service.Microphone 15 | } 16 | 17 | func (acc *AccessoryDoorbell) GetType() byte { 18 | return acc.A.Type 19 | } 20 | 21 | func (acc *AccessoryDoorbell) GetID() uint64 { 22 | return acc.A.Id 23 | } 24 | 25 | func (acc *AccessoryDoorbell) SetID(id uint64) { 26 | acc.A.Id = id 27 | } 28 | 29 | func (acc *AccessoryDoorbell) GetSN() string { 30 | return acc.A.Info.SerialNumber.Value() 31 | } 32 | 33 | func (acc *AccessoryDoorbell) GetName() string { 34 | return acc.A.Info.Name.Value() 35 | } 36 | 37 | func (acc *AccessoryDoorbell) GetAccessory() *accessory.A { 38 | return acc.A 39 | } 40 | 41 | //NewAccessoryDoorbell returns *Doorbell. 42 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(args..) 43 | // 44 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 45 | // args... are not used 46 | func NewAccessoryDoorbell(info accessory.Info, args ...interface{}) *AccessoryDoorbell { 47 | acc := AccessoryDoorbell{} 48 | acc.A = accessory.New(info, accessory.TypeVideoDoorbell) 49 | acc.Control = service.NewDoorbell() 50 | acc.AddS(acc.Control.S) 51 | 52 | acc.StreamManagement = service.NewCameraRTPStreamManagement() 53 | acc.AddS(acc.StreamManagement.S) 54 | 55 | acc.Speaker = service.NewSpeaker() 56 | acc.AddS(acc.Speaker.S) 57 | 58 | acc.Microphone = service.NewMicrophone() 59 | acc.AddS(acc.Microphone.S) 60 | 61 | return &acc 62 | } 63 | 64 | //NewAccDoorbell returns *Doorbell. 65 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 66 | // The best would be to specify the unique id for every accessory yourself. 67 | // 68 | // id (uint64) - accessory aid 69 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 70 | // args... are not used 71 | func NewAccDoorbell(id uint64, info accessory.Info, args ...interface{}) *AccessoryDoorbell { 72 | acc := AccessoryDoorbell{} 73 | acc.A = accessory.New(info, accessory.TypeVideoDoorbell) 74 | acc.Control = service.NewDoorbell() 75 | acc.AddS(acc.Control.S) 76 | 77 | acc.StreamManagement = service.NewCameraRTPStreamManagement() 78 | acc.AddS(acc.StreamManagement.S) 79 | 80 | acc.Speaker = service.NewSpeaker() 81 | acc.AddS(acc.Speaker.S) 82 | 83 | acc.Microphone = service.NewMicrophone() 84 | acc.AddS(acc.Microphone.S) 85 | 86 | acc.A.Id = id 87 | return &acc 88 | } 89 | 90 | func (acc *AccessoryDoorbell) OnValuesRemoteUpdates(fn func()) {} 91 | -------------------------------------------------------------------------------- /example/gate/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | "time" 12 | 13 | "github.com/brutella/hap" 14 | "github.com/xxandev/homekit" 15 | ) 16 | 17 | type Config struct{ homekit.AccessoryConfig } 18 | 19 | var ( 20 | debug bool 21 | config Config 22 | ) 23 | 24 | func init() { 25 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 26 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 27 | 28 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 29 | flag.StringVar(&config.Name, "n", "Gate", "homekit accessory name") 30 | flag.StringVar(&config.SN, "sn", "Ex-Gate", "homekit accessory serial number") 31 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 32 | flag.UintVar(&config.Port, "p", 10706, "homekit port, example: 10101, 10102...") 33 | flag.StringVar(&config.Pin, "pin", "19736428", "homekit pin, example: 82143697, 13974682") 34 | flag.Parse() 35 | 36 | homekit.OnLog(debug) 37 | } 38 | 39 | func main() { 40 | acc := homekit.NewAccessoryGate(config.GetInfo("Ex-Gate")) 41 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 42 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 43 | server, err := hap.NewServer(storage, acc.GetAccessory()) 44 | if err != nil { 45 | log.Fatalf("error create hap server: %v\n", err) 46 | } 47 | log.Printf("hap server create successful.\n") 48 | 49 | acc.GarageDoorOpener.CurrentDoorState.SetValue(4) //unknown current state 50 | timer := time.NewTimer(time.Millisecond * 10000) 51 | go func() { 52 | for range timer.C { 53 | // closed --> Target(1), Current(1) 54 | // closing -> Target(1), Current(2) 55 | // opened --> Target(0), Current(0) 56 | // opening -> Target(0), Current(2) 57 | acc.GarageDoorOpener.CurrentDoorState.SetValue(acc.GarageDoorOpener.TargetDoorState.Value()) 58 | log.Printf("update state, current: %[1]T - %[1]v, target: %[2]T - %[2]v\n", acc.GarageDoorOpener.CurrentDoorState.Value(), acc.GarageDoorOpener.TargetDoorState.Value()) 59 | } 60 | }() 61 | acc.GarageDoorOpener.TargetDoorState.OnValueRemoteUpdate(func(v int) { 62 | timer.Stop() 63 | timer.Reset(time.Millisecond * 10000) 64 | acc.GarageDoorOpener.CurrentDoorState.SetValue(2) 65 | log.Printf("remote update state, current: %[1]T - %[1]v, target: %[2]T - %[2]v\n", acc.GarageDoorOpener.CurrentDoorState.Value(), v) 66 | }) 67 | 68 | sig := make(chan os.Signal) 69 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 70 | ctx, cancel := context.WithCancel(context.Background()) 71 | go func() { 72 | <-sig 73 | log.Println("program stop.") 74 | signal.Stop(sig) 75 | cancel() 76 | }() 77 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 78 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 79 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 80 | } 81 | -------------------------------------------------------------------------------- /example/thermostat_uncontrol/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | "time" 12 | 13 | "github.com/brutella/hap" 14 | "github.com/xxandev/homekit" 15 | ) 16 | 17 | type Config struct{ homekit.AccessoryConfig } 18 | 19 | var ( 20 | debug bool 21 | config Config 22 | ) 23 | 24 | func init() { 25 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 26 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 27 | 28 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 29 | flag.StringVar(&config.Name, "n", "Therm", "homekit accessory name") 30 | flag.StringVar(&config.SN, "sn", "Ex-Therm", "homekit accessory serial number") 31 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 32 | flag.UintVar(&config.Port, "p", 10729, "homekit port, example: 10101, 10102...") 33 | flag.StringVar(&config.Pin, "pin", "19378246", "homekit pin, example: 82143697, 13974682") 34 | flag.Parse() 35 | 36 | homekit.OnLog(debug) 37 | } 38 | 39 | func main() { 40 | acc := homekit.NewAccessoryThermostat(config.GetInfo("Ex-Therm"), 3, 3, 3, 0) 41 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 42 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 43 | server, err := hap.NewServer(storage, acc.GetAccessory()) 44 | if err != nil { 45 | log.Fatalf("error create hap server: %v\n", err) 46 | } 47 | log.Printf("hap server create successful.\n") 48 | 49 | go func() { 50 | acc.Thermostat.CurrentTemperature.SetValue(24.00) 51 | for range time.Tick(time.Millisecond * 5000) { 52 | if acc.Thermostat.TargetTemperature.Value() == acc.Thermostat.CurrentTemperature.Value() { 53 | acc.Thermostat.CurrentHeatingCoolingState.SetValue(0) 54 | } 55 | if acc.Thermostat.TargetTemperature.Value() > acc.Thermostat.CurrentTemperature.Value() { 56 | acc.Thermostat.CurrentHeatingCoolingState.SetValue(1) 57 | } 58 | if acc.Thermostat.TargetTemperature.Value() < acc.Thermostat.CurrentTemperature.Value() { 59 | acc.Thermostat.CurrentHeatingCoolingState.SetValue(2) 60 | } 61 | } 62 | }() 63 | acc.Thermostat.TargetHeatingCoolingState.OnValueRemoteUpdate(func(v int) { 64 | log.Printf("remote update target state: %[1]T - %[1]v\n", v) 65 | }) 66 | acc.Thermostat.TargetTemperature.OnValueRemoteUpdate(func(v float64) { 67 | log.Printf("remote update target temp: %[1]T - %[1]v\n", v) 68 | }) 69 | 70 | sig := make(chan os.Signal) 71 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 72 | ctx, cancel := context.WithCancel(context.Background()) 73 | go func() { 74 | <-sig 75 | log.Println("program stop.") 76 | signal.Stop(sig) 77 | cancel() 78 | }() 79 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 80 | log.Printf("hap server starting set, address: %v, pin: %v.\n", server.Addr, server.Pin) 81 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 82 | } 83 | -------------------------------------------------------------------------------- /example/door/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "log" 8 | "os" 9 | "os/signal" 10 | "syscall" 11 | "time" 12 | 13 | "github.com/brutella/hap" 14 | "github.com/xxandev/homekit" 15 | ) 16 | 17 | type Config struct{ homekit.AccessoryConfig } 18 | 19 | var ( 20 | debug bool 21 | config Config 22 | ) 23 | 24 | func init() { 25 | log.SetOutput(os.Stdout) // log.SetOutput(ioutil.Discard) 26 | log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix) 27 | 28 | flag.BoolVar(&debug, "d", false, "hap debug log activate") 29 | flag.StringVar(&config.Name, "n", "Door", "homekit accessory name") 30 | flag.StringVar(&config.SN, "sn", "Ex-Door", "homekit accessory serial number") 31 | flag.StringVar(&config.Host, "h", "", "homekit host, example: 192.168.1.xxx") 32 | flag.UintVar(&config.Port, "p", 10703, "homekit port, example: 10101, 10102...") 33 | flag.StringVar(&config.Pin, "pin", "19736428", "homekit pin, example: 82143697, 13974682") 34 | flag.Parse() 35 | 36 | homekit.OnLog(debug) 37 | } 38 | 39 | func main() { 40 | acc := homekit.NewAccessoryDoor(config.GetInfo("Ex-Door")) 41 | log.SetPrefix(fmt.Sprintf("[%T] <%v> ", acc, acc.GetSN())) 42 | storage := hap.NewFsStore(fmt.Sprintf("./%s", acc.GetSN())) 43 | server, err := hap.NewServer(storage, acc.GetAccessory()) 44 | if err != nil { 45 | log.Fatalf("error create hap server: %v\n", err) 46 | } 47 | log.Printf("hap server create successful.\n") 48 | command := make(chan int, 5) 49 | go func() { 50 | callbackT := time.NewTimer(time.Millisecond * 10000) 51 | for { 52 | select { 53 | case cmd := <-command: 54 | callbackT.Stop() 55 | callbackT.Reset(time.Millisecond * 10000) 56 | acc.Door.TargetPosition.SetValue(cmd) 57 | acc.Door.CurrentPosition.SetValue(cmd) 58 | log.Printf("remote update target position, current: %[1]T - %[1]v, target: %[2]T - %[2]v\n", acc.Door.CurrentPosition.Value(), acc.Door.TargetPosition.Value()) 59 | case <-callbackT.C: 60 | acc.Door.TargetPosition.SetValue(0) 61 | acc.Door.CurrentPosition.SetValue(0) 62 | log.Printf("update position, current: %[1]T - %[1]v, target: %[2]T - %[2]v\n", acc.Door.CurrentPosition.Value(), acc.Door.TargetPosition.Value()) 63 | case <-time.Tick(time.Millisecond * 320000): 64 | callbackT.Stop() 65 | callbackT.Reset(time.Millisecond * 10000) 66 | acc.Door.TargetPosition.SetValue(100) 67 | acc.Door.CurrentPosition.SetValue(100) 68 | log.Printf("update position, current: %[1]T - %[1]v, target: %[2]T - %[2]v\n", acc.Door.CurrentPosition.Value(), acc.Door.TargetPosition.Value()) 69 | } 70 | } 71 | }() 72 | acc.Door.TargetPosition.OnValueRemoteUpdate(func(v int) { command <- v }) 73 | 74 | sig := make(chan os.Signal) 75 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM) 76 | ctx, cancel := context.WithCancel(context.Background()) 77 | go func() { 78 | <-sig 79 | log.Println("program stop.") 80 | signal.Stop(sig) 81 | cancel() 82 | }() 83 | homekit.SetServer(server, config.GetAddress(), config.GetPin()) 84 | log.Printf("hap server starting set, address %v, pin %v.\n", server.Addr, server.Pin) 85 | log.Fatalf("hap server: %v\n", server.ListenAndServe(ctx)) 86 | } 87 | -------------------------------------------------------------------------------- /accessory_door.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | haps "github.com/xxandev/homekit/hap-service" 6 | ) 7 | 8 | //AccessoryDoor struct 9 | type AccessoryDoor struct { 10 | *accessory.A 11 | Door *haps.Door 12 | } 13 | 14 | func (acc *AccessoryDoor) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessoryDoor) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessoryDoor) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessoryDoor) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessoryDoor) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessoryDoor) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessoryDoor returns *Door. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args[0](int) - TargetPosition.SetValue(args[0]) default(0) 43 | // args[1](int) - TargetPosition.SetMinValue(args[1]) default(0) 44 | // args[2](int) - TargetPosition.SetMaxValue(args[2]) default(100) 45 | // args[3](int) - TargetPosition.SetStepValue(args[3]) default(1) 46 | func NewAccessoryDoor(info accessory.Info, args ...interface{}) *AccessoryDoor { 47 | acc := AccessoryDoor{} 48 | acc.A = accessory.New(info, accessory.TypeDoor) 49 | acc.Door = haps.NewDoor() 50 | n := len(args) 51 | if n > 0 { 52 | acc.Door.TargetPosition.SetValue(toi(args[0], 0)) 53 | } 54 | if n > 1 { 55 | acc.Door.TargetPosition.SetMinValue(toi(args[1], 0)) 56 | } 57 | if n > 2 { 58 | acc.Door.TargetPosition.SetMaxValue(toi(args[2], 100)) 59 | } 60 | if n > 3 { 61 | acc.Door.TargetPosition.SetStepValue(toi(args[3], 1)) 62 | } 63 | acc.AddS(acc.Door.S) 64 | return &acc 65 | } 66 | 67 | //NewAccDoor returns *Door. 68 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 69 | // The best would be to specify the unique id for every accessory yourself. 70 | // 71 | // id (uint64) - accessory aid 72 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 73 | // args[0](int) - TargetPosition.SetValue(args[0]) default(0) 74 | // args[1](int) - TargetPosition.SetMinValue(args[1]) default(0) 75 | // args[2](int) - TargetPosition.SetMaxValue(args[2]) default(100) 76 | // args[3](int) - TargetPosition.SetStepValue(args[3]) default(1) 77 | func NewAccDoor(id uint64, info accessory.Info, args ...interface{}) *AccessoryDoor { 78 | acc := AccessoryDoor{} 79 | acc.A = accessory.New(info, accessory.TypeDoor) 80 | acc.Door = haps.NewDoor() 81 | n := len(args) 82 | if n > 0 { 83 | acc.Door.TargetPosition.SetValue(toi(args[0], 0)) 84 | } 85 | if n > 1 { 86 | acc.Door.TargetPosition.SetMinValue(toi(args[1], 0)) 87 | } 88 | if n > 2 { 89 | acc.Door.TargetPosition.SetMaxValue(toi(args[2], 100)) 90 | } 91 | if n > 3 { 92 | acc.Door.TargetPosition.SetStepValue(toi(args[3], 1)) 93 | } 94 | acc.AddS(acc.Door.S) 95 | acc.A.Id = id 96 | return &acc 97 | } 98 | 99 | func (acc *AccessoryDoor) OnValuesRemoteUpdates(fn func()) { 100 | acc.Door.TargetPosition.OnValueRemoteUpdate(func(int) { fn() }) 101 | } 102 | -------------------------------------------------------------------------------- /accessory_fan_rs.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | haps "github.com/xxandev/homekit/hap-service" 6 | ) 7 | 8 | type AccessoryFanRS struct { 9 | *accessory.A 10 | Fan *haps.FanRS 11 | } 12 | 13 | func (acc *AccessoryFanRS) GetType() byte { 14 | return acc.A.Type 15 | } 16 | 17 | func (acc *AccessoryFanRS) GetID() uint64 { 18 | return acc.A.Id 19 | } 20 | 21 | func (acc *AccessoryFanRS) SetID(id uint64) { 22 | acc.A.Id = id 23 | } 24 | 25 | func (acc *AccessoryFanRS) GetSN() string { 26 | return acc.A.Info.SerialNumber.Value() 27 | } 28 | 29 | func (acc *AccessoryFanRS) GetName() string { 30 | return acc.A.Info.Name.Value() 31 | } 32 | 33 | func (acc *AccessoryFanRS) GetAccessory() *accessory.A { 34 | return acc.A 35 | } 36 | 37 | //NewAccessoryFanRS return *FanRS. 38 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 39 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 40 | // args[0](float64) - RotationSpeed.SetValue(args[0]) default(0) 41 | // args[1](float64) - RotationSpeed.SetMinValue(args[1]) default(0) 42 | // args[2](float64) - RotationSpeed.SetMaxValue(args[2]) default(100) 43 | // args[3](float64) - RotationSpeed.SetStepValue(args[3]) default(1) 44 | func NewAccessoryFanRS(info accessory.Info, args ...interface{}) *AccessoryFanRS { 45 | acc := AccessoryFanRS{} 46 | acc.A = accessory.New(info, accessory.TypeFan) 47 | acc.Fan = haps.NewFanRS() 48 | n := len(args) 49 | if n > 0 { 50 | acc.Fan.RotationSpeed.SetValue(tof64(args[0], 0.0)) 51 | } 52 | if n > 1 { 53 | acc.Fan.RotationSpeed.SetMinValue(tof64(args[1], 0.0)) 54 | } 55 | if n > 2 { 56 | acc.Fan.RotationSpeed.SetMaxValue(tof64(args[2], 100.0)) 57 | } 58 | if n > 3 { 59 | acc.Fan.RotationSpeed.SetStepValue(tof64(args[3], 1.0)) 60 | } 61 | acc.AddS(acc.Fan.S) 62 | return &acc 63 | } 64 | 65 | //NewAccessoryFanRS return *FanRS. 66 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 67 | // The best would be to specify the unique id for every accessory yourself. 68 | // 69 | // id (uint64) - accessory aid 70 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 71 | // args[0](float64) - RotationSpeed.SetValue(args[0]) default(0) 72 | // args[1](float64) - RotationSpeed.SetMinValue(args[1]) default(0) 73 | // args[2](float64) - RotationSpeed.SetMaxValue(args[2]) default(100) 74 | // args[3](float64) - RotationSpeed.SetStepValue(args[3]) default(1) 75 | func NewAccFanRS(id uint64, info accessory.Info, args ...interface{}) *AccessoryFanRS { 76 | acc := AccessoryFanRS{} 77 | acc.A = accessory.New(info, accessory.TypeFan) 78 | acc.Fan = haps.NewFanRS() 79 | n := len(args) 80 | if n > 0 { 81 | acc.Fan.RotationSpeed.SetValue(tof64(args[0], 0.0)) 82 | } 83 | if n > 1 { 84 | acc.Fan.RotationSpeed.SetMinValue(tof64(args[1], 0.0)) 85 | } 86 | if n > 2 { 87 | acc.Fan.RotationSpeed.SetMaxValue(tof64(args[2], 100.0)) 88 | } 89 | if n > 3 { 90 | acc.Fan.RotationSpeed.SetStepValue(tof64(args[3], 1.0)) 91 | } 92 | acc.AddS(acc.Fan.S) 93 | acc.A.Id = id 94 | return &acc 95 | } 96 | 97 | func (acc *AccessoryFanRS) OnValuesRemoteUpdates(fn func()) { 98 | acc.Fan.On.OnValueRemoteUpdate(func(bool) { fn() }) 99 | acc.Fan.RotationSpeed.OnValueRemoteUpdate(func(float64) { fn() }) 100 | } 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HomeKit Accessories 2 | This repository is an add-on to [brutella/hap](https://github.com/brutella/hap) from Matthias Hochgatterer 3 | 4 | ![](https://github.com/xxandev/homekit/blob/main/gallery/homekit.jpg) 5 | 6 | ![](https://github.com/xxandev/homekit/blob/main/gallery/homekit_1.png) 7 | 8 | ![](https://github.com/xxandev/homekit/blob/main/gallery/homekit_2.png) 9 | 10 | 11 | ### Environment 12 | 13 | **OS:** [ubuntu](https://ubuntu.com/) [22.04 lts](https://ubuntu.com/download/desktop/thank-you?version=22.04&architecture=amd64) 14 | 15 | **Lang:** [golang 1.18](https://golang.org/) 16 | 17 | **Lib:** [hap](https://github.com/brutella/hap) 18 | 19 | **APPLE DEVICE:** ipad/iphone (os 16.1) 20 | 21 | ## Accessory List: 22 | - [Bridge](https://github.com/xxandev/homekit/tree/main/example/bridge) 23 | - [Air Purifier](https://github.com/xxandev/homekit/tree/main/example/air_purifier) 24 | - [Humidifier dehumidifier](https://github.com/xxandev/homekit/tree/main/example/humidifier_dehumidifier) 25 | - [Door](https://github.com/xxandev/homekit/tree/main/example/door) 26 | - [Lock](https://github.com/xxandev/homekit/tree/main/example/lock) 27 | - [Fan](https://github.com/xxandev/homekit/tree/main/example/fan_rs) 28 | - [Faucet](https://github.com/xxandev/homekit/tree/main/example/faucet) 29 | - [Gate (GarageDoorOpener)](https://github.com/xxandev/homekit/tree/main/example/gate) 30 | - [Irrigation](https://github.com/xxandev/homekit/tree/main/example/irrigation) 31 | - [Lightbulb](https://github.com/xxandev/homekit/tree/main/example/lightbulb_colored) 32 | - [Outlet](https://github.com/xxandev/homekit/tree/main/example/outlet) 33 | - [Security system](https://github.com/xxandev/homekit/tree/main/example/security_system) 34 | - [Sensor air quality](https://github.com/xxandev/homekit/tree/main/example/sensor_air_quality) 35 | - [Sensor contact](https://github.com/xxandev/homekit/tree/main/example/sensor_contact) 36 | - [Sensor dioxide](https://github.com/xxandev/homekit/tree/main/example/sensor_dioxide) 37 | - [Sensor humidity](https://github.com/xxandev/homekit/tree/main/example/sensor_humidity) 38 | - [Sensor leak](https://github.com/xxandev/homekit/tree/main/example/sensor_leak) 39 | - [Sensor light](https://github.com/xxandev/homekit/tree/main/example/sensor_light) 40 | - [Sensor monoxide](https://github.com/xxandev/homekit/tree/main/example/sensor_monaxide) 41 | - [Sensor motion](https://github.com/xxandev/homekit/tree/main/example/sensor_motion) 42 | - [Sensor smoke](https://github.com/xxandev/homekit/tree/main/example/sensor_smoke) 43 | - [Sensor temperature](https://github.com/xxandev/homekit/tree/main/example/sensor_temp) 44 | - [Switch](https://github.com/xxandev/homekit/tree/main/example/switch) 45 | - [Television](https://github.com/xxandev/homekit/tree/main/example/television) 46 | - [Thermostat](https://github.com/xxandev/homekit/tree/main/example/thermostat_climate) 47 | - [Window covering](https://github.com/xxandev/homekit/tree/main/example/window_covering) 48 | - [Window](https://github.com/xxandev/homekit/tree/main/example/window) 49 | - [Camera](https://github.com/brutella/hkcam) [**rtsp**](https://github.com/dbarrosop/hkcam/tree/rtsp) 50 | - [Doorbell](https://github.com/ra1nb0w/hkdoorbell) 51 | - [Smart speaker](https://github.com/xxandev/homekit/tree/main/example/smart_speaker) [**dev**](https://github.com/homebridge/HAP-NodeJS/blob/master/src/accessories/SmartSpeaker_accessory.ts) 52 | - [WiFi router](https://github.com/xxandev/homekit/tree/main/example/wifi_router) [**dev**](https://github.com/homebridge/HAP-NodeJS/blob/master/src/accessories/Wi-FiRouter_accessory.ts) 53 | -------------------------------------------------------------------------------- /accessory_window.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessoryWindow struct 9 | type AccessoryWindow struct { 10 | *accessory.A 11 | Window *service.Window 12 | } 13 | 14 | func (acc *AccessoryWindow) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessoryWindow) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessoryWindow) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessoryWindow) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessoryWindow) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessoryWindow) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessoryWindow returns *Window. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args[0](int) - TargetPosition.SetValue(args[0]) default(0) 43 | // args[1](int) - TargetPosition.SetMinValue(args[1]) default(0) 44 | // args[2](int) - TargetPosition.SetMaxValue(args[2]) default(100) 45 | // args[3](int) - TargetPosition.SetStepValue(args[3]) default(1) 46 | func NewAccessoryWindow(info accessory.Info, args ...interface{}) *AccessoryWindow { 47 | acc := AccessoryWindow{} 48 | acc.A = accessory.New(info, accessory.TypeWindow) 49 | acc.Window = service.NewWindow() 50 | n := len(args) 51 | if n > 0 { 52 | acc.Window.TargetPosition.SetValue(toi(args[0], 0)) 53 | } 54 | if n > 1 { 55 | acc.Window.TargetPosition.SetMinValue(toi(args[1], 0)) 56 | } 57 | if n > 2 { 58 | acc.Window.TargetPosition.SetMaxValue(toi(args[2], 100)) 59 | } 60 | if n > 3 { 61 | acc.Window.TargetPosition.SetStepValue(toi(args[3], 1)) 62 | } 63 | acc.AddS(acc.Window.S) 64 | return &acc 65 | } 66 | 67 | //NewAccWindow returns *Window. 68 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 69 | // The best would be to specify the unique id for every accessory yourself. 70 | // 71 | // id (uint64) - accessory aid 72 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 73 | // args[0](int) - TargetPosition.SetValue(args[0]) default(0) 74 | // args[1](int) - TargetPosition.SetMinValue(args[1]) default(0) 75 | // args[2](int) - TargetPosition.SetMaxValue(args[2]) default(100) 76 | // args[3](int) - TargetPosition.SetStepValue(args[3]) default(1) 77 | func NewAccWindow(id uint64, info accessory.Info, args ...interface{}) *AccessoryWindow { 78 | acc := AccessoryWindow{} 79 | acc.A = accessory.New(info, accessory.TypeWindow) 80 | acc.Window = service.NewWindow() 81 | n := len(args) 82 | if n > 0 { 83 | acc.Window.TargetPosition.SetValue(toi(args[0], 0)) 84 | } 85 | if n > 1 { 86 | acc.Window.TargetPosition.SetMinValue(toi(args[1], 0)) 87 | } 88 | if n > 2 { 89 | acc.Window.TargetPosition.SetMaxValue(toi(args[2], 100)) 90 | } 91 | if n > 3 { 92 | acc.Window.TargetPosition.SetStepValue(toi(args[3], 1)) 93 | } 94 | acc.AddS(acc.Window.S) 95 | acc.A.Id = id 96 | return &acc 97 | } 98 | 99 | func (acc *AccessoryWindow) OnValuesRemoteUpdates(fn func()) { 100 | acc.Window.TargetPosition.OnValueRemoteUpdate(func(int) { fn() }) 101 | acc.Window.PositionState.OnValueRemoteUpdate(func(int) { fn() }) 102 | } 103 | -------------------------------------------------------------------------------- /homekit_convert_test.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import "testing" 4 | 5 | func TestToBool(t *testing.T) { 6 | type tester struct { 7 | val interface{} 8 | def bool 9 | res bool 10 | } 11 | testik := []tester{ 12 | {val: "val", def: true, res: true}, 13 | {val: "val", def: false, res: false}, 14 | {val: "false", def: true, res: true}, 15 | {val: "false", def: false, res: false}, 16 | {val: "true", def: true, res: true}, 17 | {val: "true", def: false, res: false}, 18 | {val: 1, def: true, res: true}, 19 | {val: 1, def: false, res: false}, 20 | {val: 0, def: true, res: true}, 21 | {val: 0, def: false, res: false}, 22 | {val: 0.1, def: true, res: true}, 23 | {val: 0.1, def: false, res: false}, 24 | {val: -1, def: true, res: true}, 25 | {val: -1, def: false, res: false}, 26 | {val: -0.1, def: true, res: true}, 27 | {val: -0.1, def: false, res: false}, 28 | {val: nil, def: true, res: true}, 29 | {val: nil, def: false, res: false}, 30 | {val: 0x1, def: true, res: true}, 31 | {val: 0x1, def: false, res: false}, 32 | {val: 0x0, def: true, res: true}, 33 | {val: 0x0, def: false, res: false}, 34 | {val: true, def: false, res: true}, 35 | {val: false, def: true, res: false}, 36 | } 37 | for i := range testik { 38 | if tob(testik[i].val, testik[i].def) != testik[i].res { 39 | t.Fatalf("error test func homekit.tob(%[1]v[%[1]T], %[2]v[%[2]T]) != %[3]v[%[3]T]\n", testik[i].val, testik[i].def, testik[i].res) 40 | } 41 | } 42 | } 43 | 44 | func TestToInt(t *testing.T) { 45 | type tester struct { 46 | val interface{} 47 | def int 48 | res int 49 | } 50 | testik := []tester{ 51 | {val: "val", def: 256, res: 256}, 52 | {val: "32", def: 256, res: 256}, 53 | {val: "123.8", def: 256, res: 256}, 54 | {val: true, def: 256, res: 256}, 55 | {val: false, def: 256, res: 256}, 56 | {val: 1, def: 256, res: 1}, 57 | {val: 0, def: 256, res: 0}, 58 | {val: 0.1, def: 256, res: 256}, 59 | {val: -1, def: 256, res: -1}, 60 | {val: -0.1, def: 256, res: 256}, 61 | {val: 128.64, def: 256, res: 256}, 62 | {val: -128.64, def: 256, res: 256}, 63 | {val: nil, def: 256, res: 256}, 64 | {val: 0x1, def: 256, res: 1}, 65 | {val: 0x0, def: 256, res: 0}, 66 | } 67 | for i := range testik { 68 | if toi(testik[i].val, testik[i].def) != testik[i].res { 69 | t.Fatalf("error test func homekit.toi(%[1]v[%[1]T], %[2]v[%[2]T]) != %[3]v[%[3]T]\n", testik[i].val, testik[i].def, testik[i].res) 70 | } 71 | } 72 | } 73 | 74 | func TestToFloat64(t *testing.T) { 75 | type tester struct { 76 | val interface{} 77 | def float64 78 | res float64 79 | } 80 | testik := []tester{ 81 | {val: "val", def: 256.00, res: 256.00}, 82 | {val: "32", def: 256.00, res: 256.00}, 83 | {val: "123.8", def: 256.00, res: 256.00}, 84 | {val: true, def: 256.00, res: 256.00}, 85 | {val: false, def: 256.00, res: 256.00}, 86 | {val: 1, def: 256, res: 1.00}, 87 | {val: 0, def: 256, res: 0.00}, 88 | {val: 0.1, def: 256.00, res: 0.1}, 89 | {val: -1, def: 256.00, res: -1.00}, 90 | {val: -0.1, def: 256.00, res: -0.1}, 91 | {val: 128.64, def: 256.00, res: 128.64}, 92 | {val: -128.64, def: 256.00, res: -128.64}, 93 | {val: nil, def: 256.00, res: 256.00}, 94 | {val: 0x1, def: 256.00, res: 1.00}, 95 | {val: 0x0, def: 256.00, res: 0.00}, 96 | } 97 | for i := range testik { 98 | if tof64(testik[i].val, testik[i].def) != testik[i].res { 99 | t.Fatalf("error test func homekit.tof64(%[1]v[%[1]T], %[2]v[%[2]T]) != %[3]v[%[3]T]\n", testik[i].val, testik[i].def, testik[i].res) 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /accessory_window_covering.go: -------------------------------------------------------------------------------- 1 | package homekit 2 | 3 | import ( 4 | "github.com/brutella/hap/accessory" 5 | "github.com/brutella/hap/service" 6 | ) 7 | 8 | //AccessoryWindowCovering struct 9 | type AccessoryWindowCovering struct { 10 | *accessory.A 11 | WindowCovering *service.WindowCovering 12 | } 13 | 14 | func (acc *AccessoryWindowCovering) GetType() byte { 15 | return acc.A.Type 16 | } 17 | 18 | func (acc *AccessoryWindowCovering) GetID() uint64 { 19 | return acc.A.Id 20 | } 21 | 22 | func (acc *AccessoryWindowCovering) SetID(id uint64) { 23 | acc.A.Id = id 24 | } 25 | 26 | func (acc *AccessoryWindowCovering) GetSN() string { 27 | return acc.A.Info.SerialNumber.Value() 28 | } 29 | 30 | func (acc *AccessoryWindowCovering) GetName() string { 31 | return acc.A.Info.Name.Value() 32 | } 33 | 34 | func (acc *AccessoryWindowCovering) GetAccessory() *accessory.A { 35 | return acc.A 36 | } 37 | 38 | //NewAccessoryWindowCovering returns *WindowCovering. 39 | // (COMPATIBILITY) - left for compatibility, recommended NewAcc...(id, info, args..) 40 | // 41 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 42 | // args[0](int) - TargetPosition.SetValue(args[0]) default(0) 43 | // args[1](int) - TargetPosition.SetMinValue(args[1]) default(0) 44 | // args[2](int) - TargetPosition.SetMaxValue(args[2]) default(100) 45 | // args[3](int) - TargetPosition.SetStepValue(args[3]) default(1) 46 | func NewAccessoryWindowCovering(info accessory.Info, args ...interface{}) *AccessoryWindowCovering { 47 | acc := AccessoryWindowCovering{} 48 | acc.A = accessory.New(info, accessory.TypeWindowCovering) 49 | acc.WindowCovering = service.NewWindowCovering() 50 | 51 | n := len(args) 52 | if n > 0 { 53 | acc.WindowCovering.TargetPosition.SetValue(toi(args[0], 0)) 54 | } 55 | if n > 1 { 56 | acc.WindowCovering.TargetPosition.SetMinValue(toi(args[1], 0)) 57 | } 58 | if n > 2 { 59 | acc.WindowCovering.TargetPosition.SetMaxValue(toi(args[2], 100)) 60 | } 61 | if n > 3 { 62 | acc.WindowCovering.TargetPosition.SetStepValue(toi(args[3], 1)) 63 | } 64 | 65 | acc.AddS(acc.WindowCovering.S) 66 | 67 | return &acc 68 | } 69 | 70 | //NewAccWindowCovering returns *WindowCovering. 71 | // HomeKit requires that every accessory has a unique id, which must not change between system restarts. 72 | // The best would be to specify the unique id for every accessory yourself. 73 | // 74 | // id (uint64) - accessory aid 75 | // info (accessory.Info) - struct accessory.Info{Name, SerialNumber, Manufacturer, Model, Firmware string} 76 | // args[0](int) - TargetPosition.SetValue(args[0]) default(0) 77 | // args[1](int) - TargetPosition.SetMinValue(args[1]) default(0) 78 | // args[2](int) - TargetPosition.SetMaxValue(args[2]) default(100) 79 | // args[3](int) - TargetPosition.SetStepValue(args[3]) default(1) 80 | func NewAccWindowCovering(id uint64, info accessory.Info, args ...interface{}) *AccessoryWindowCovering { 81 | acc := AccessoryWindowCovering{} 82 | acc.A = accessory.New(info, accessory.TypeWindowCovering) 83 | acc.WindowCovering = service.NewWindowCovering() 84 | n := len(args) 85 | if n > 0 { 86 | acc.WindowCovering.TargetPosition.SetValue(toi(args[0], 0)) 87 | } 88 | if n > 1 { 89 | acc.WindowCovering.TargetPosition.SetMinValue(toi(args[1], 0)) 90 | } 91 | if n > 2 { 92 | acc.WindowCovering.TargetPosition.SetMaxValue(toi(args[2], 100)) 93 | } 94 | if n > 3 { 95 | acc.WindowCovering.TargetPosition.SetStepValue(toi(args[3], 1)) 96 | } 97 | acc.AddS(acc.WindowCovering.S) 98 | acc.A.Id = id 99 | return &acc 100 | } 101 | 102 | func (acc *AccessoryWindowCovering) OnValuesRemoteUpdates(fn func()) { 103 | acc.WindowCovering.TargetPosition.OnValueRemoteUpdate(func(int) { fn() }) 104 | acc.WindowCovering.PositionState.OnValueRemoteUpdate(func(int) { fn() }) 105 | } 106 | --------------------------------------------------------------------------------