本文整理汇总了Golang中github.com/barnybug/gohome/pubsub.Event.Device方法的典型用法代码示例。如果您正苦于以下问题:Golang Event.Device方法的具体用法?Golang Event.Device怎么用?Golang Event.Device使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/barnybug/gohome/pubsub.Event
的用法示例。
在下文中一共展示了Event.Device方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: LookupDeviceName
// Find the device name
func (self *Config) LookupDeviceName(ev *pubsub.Event) string {
// silly question: is device set on the event
if ev.Device() != "" {
return ev.Device()
}
topic := ev.Topic
source := ev.Source()
// try: protocol.id
if device, ok := self.Protocols[topic][source]; ok {
return device
}
// fallback: topic.source
// ignore dynamic topics (prefix _)
if topic != "" && source != "" && !strings.HasPrefix(topic, "_") {
return topic + "." + source
}
return ""
}
示例2: translateCommands
// Translate command messages into rfxtrx packets
func translateCommands(ev *pubsub.Event) (gorfxtrx.OutPacket, error) {
device := ev.Device()
command := ev.Command()
if command != "off" && command != "on" {
log.Println("Command not recognised:", command)
return nil, nil
}
pids := services.Config.LookupDeviceProtocol(device)
if len(pids) == 0 {
log.Println("Device not found for:", device)
return nil, nil
}
switch {
case pids["homeeasy"] != "":
return gorfxtrx.NewLightingHE(0x00, pids["homeeasy"], command)
case pids["x10"] != "":
return gorfxtrx.NewLightingX10(0x01, pids["x10"], command)
}
return nil, nil
}
示例3: eventCommand
func eventCommand(ev *pubsub.Event) {
cam, ok := cameras[ev.Device()]
if !ok {
return
}
p, _ := ev.Fields["preset"].(float64)
preset := int(p)
switch ev.Fields["command"] {
case "position":
log.Printf("%s going to preset %d", ev.Device(), preset)
cam.GotoPreset(preset)
case "snapshot":
log.Printf("%s taking snapshot", ev.Device())
go func() {
if preset != 0 {
log.Printf("Going to preset: %d", preset)
cam.GotoPreset(preset)
time.Sleep(GotoDelay)
}
filename, err := cam.Snapshot()
if err != nil {
log.Println("Error taking snapshot:", err)
} else {
log.Println("Snapshot:", filename)
}
}()
case "video":
timeout, ok := ev.Fields["timeout"].(float64)
if !ok {
timeout = 15
}
duration := time.Duration(timeout) * time.Second
log.Printf("%s recording video for %s", ev.Device(), duration)
go func() {
if preset != 0 {
log.Printf("Going to preset: %d", preset)
cam.GotoPreset(preset)
time.Sleep(GotoDelay)
}
if ir, ok := ev.Fields["ir"].(bool); ok {
err := cam.Ir(ir)
if err != nil {
log.Println("Error setting ir:", err)
}
}
filename, err := cam.Video(duration)
if err != nil {
log.Println("Error taking video:", err)
} else {
log.Println("Video:", filename)
}
}()
case "ir":
on, _ := ev.Fields["on"].(bool)
log.Printf("%s infra-red turned %s", ev.Device(), on)
cam.Ir(on)
case "detection":
on, _ := ev.Fields["on"].(bool)
log.Printf("%s detection %s", ev.Device(), on)
cam.Detect(on)
}
}