Exemple #1
0
// 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
}