-
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 generic automation builder * Add BinarySensor, LightSensor, LightGroup * Add LightInterface and move towards that * Add Timer helper * Add more logging * Fix decoding JSON attributes
- Loading branch information
Showing
14 changed files
with
277 additions
and
33 deletions.
There are no files selected for viewing
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,31 @@ | ||
package halautomations | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/dansimau/hal" | ||
) | ||
|
||
// PrintDebug prints state changes for the specified entities. | ||
type PrintDebug struct { | ||
name string | ||
entities hal.Entities | ||
} | ||
|
||
func NewPrintDebug(name string, entities ...hal.EntityInterface) *PrintDebug { | ||
return &PrintDebug{name: name, entities: entities} | ||
} | ||
|
||
func (p *PrintDebug) Name() string { | ||
return p.name | ||
} | ||
|
||
func (p *PrintDebug) Entities() hal.Entities { | ||
return p.entities | ||
} | ||
|
||
func (p *PrintDebug) Action() { | ||
for _, entity := range p.entities { | ||
log.Printf("[%s] Entity %s state: %+v", p.name, entity.GetID(), entity.GetState()) | ||
} | ||
} |
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
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,18 @@ | ||
package hal | ||
|
||
// BinarySensor is any sensor with a state of "on" or "off". | ||
type BinarySensor struct { | ||
*Entity | ||
} | ||
|
||
func NewBinarySensor(id string) *BinarySensor { | ||
return &BinarySensor{Entity: NewEntity(id)} | ||
} | ||
|
||
func (s *BinarySensor) IsOff() bool { | ||
return s.GetState().State == "off" | ||
} | ||
|
||
func (s *BinarySensor) IsOn() bool { | ||
return s.GetState().State == "on" | ||
} |
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
Oops, something went wrong.