-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add wemo emulation via github.com/forfuncsake/smartswitch
- Loading branch information
1 parent
969d9c8
commit 87b7713
Showing
35 changed files
with
3,775 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/brutella/hc/characteristic" | ||
"github.com/forfuncsake/smartswitch" | ||
) | ||
|
||
// true == Switch On == Open Door | ||
// false == Switch off == Close Door | ||
func boolToTargetState(v bool) int { | ||
if v { | ||
return characteristic.TargetDoorStateOpen | ||
} | ||
return characteristic.TargetDoorStateClosed | ||
} | ||
|
||
// 1 == Door Closed == Switch Off == false | ||
// Otherwise the door is fully or partially open, so the switch shows "on" | ||
func stateToBool(i int) bool { | ||
return i != characteristic.TargetDoorStateClosed | ||
} | ||
|
||
// Set changes the target state of the door | ||
// satisfying the smartswitch.Switch interface | ||
func (d *GarageDoor) Set(on bool) error { | ||
d.setState(boolToTargetState(on)) | ||
return nil | ||
} | ||
|
||
// Status returns the status of the door (true=on=open, false=off=closed) | ||
// satisfying the smartswitch.Switch interface | ||
func (d *GarageDoor) Status() (bool, error) { | ||
return stateToBool(d.getState()), nil | ||
} | ||
|
||
func (d *GarageDoor) enableWemo() error { | ||
wemo := smartswitch.NewController(d.Name, d, smartswitch.WithMinissdpSocket("/var/run/minissdpd.sock")) | ||
loc, err := wemo.Start() | ||
if err != nil { | ||
return err | ||
} | ||
log.Printf("Wemo handler listening on %s\n", loc) | ||
return nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.