cmd

package
v0.0.0-...-31e329b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HKServeCmd = func() *cobra.Command {
	var interval int
	var dbPath string
	fn := func(cmd *cobra.Command, args []string) {
		serve(interval, dbPath)
	}

	cmd := &cobra.Command{
		Use:   "serve",
		Short: "Start HomeKit server. AISEG_USER and AIUSEG_PASSWORD are required as environment variables. PIN code (00102003 by default) can be configured by AISEG_PIN.",
		Run:   fn,
	}
	cmd.Flags().IntVarP(&interval, "interval", "i", 1, "Refresh interval")
	cmd.Flags().StringVarP(&dbPath, "db", "d", "./db", "Database path")

	return cmd
}()
View Source
var ListCmd = &cobra.Command{
	Use:   "list",
	Short: "List all devices",
	Run: func(cmd *cobra.Command, args []string) {
		mgr := aisegmanager.DiscoverNewAiSEGManager()
		for _, d := range mgr.Devices {
			state := " "
			if d.IsOn {
				state = "x"
			}
			fmt.Printf("[%s] [%s] %s\n", d.NodeId, state, d.Name)
		}
	},
}
View Source
var Revision = ""
View Source
var ToggleCmd = func() *cobra.Command {
	fn := func(cmd *cobra.Command, args []string) {
		nodeId := args[0]
		log.D("Toggle device %s", nodeId)

		mgr := aisegmanager.DiscoverNewAiSEGManager()
		if err := mgr.ToggleDevice(nodeId); err != nil {
			log.E("Failed to toggle device due to %s", err.Error())
		}
	}

	cmd := &cobra.Command{
		Use:   "toggle",
		Short: "Toggle device",
		Args:  cobra.ExactArgs(1),
		Run:   fn,
	}

	return cmd
}()
View Source
var TurnAllOffCmd = func() *cobra.Command {
	fn := func(cmd *cobra.Command, args []string) {
		argType := args[0]
		log.D("Turn device %s off", argType)

		var deviceType aisegmanager.DeviceType
		if argType == "light" {
			deviceType = aisegmanager.DeviceTypeLight
		} else if argType == "floorheating" {
			deviceType = aisegmanager.DeviceTypeFloorHeating
		} else {
			log.E("Unsupported device type %d", deviceType)
			return
		}

		mgr := aisegmanager.DiscoverNewAiSEGManager()
		if err := mgr.TurnAllDevices(deviceType, false); err != nil {
			log.E("Failed to turn device off due to %s", err.Error())
		}
	}

	cmd := &cobra.Command{
		Use:   "alloff",
		Short: "Turn all devices off by type",
		Args:  cobra.ExactArgs(1),
		Run:   fn,
	}

	return cmd
}()
View Source
var TurnAllOnCmd = func() *cobra.Command {
	fn := func(cmd *cobra.Command, args []string) {
		argType := args[0]
		log.D("Turn device %s on", argType)

		var deviceType aisegmanager.DeviceType
		if argType == "light" {
			deviceType = aisegmanager.DeviceTypeLight
		} else if argType == "floorheating" {
			deviceType = aisegmanager.DeviceTypeFloorHeating
		} else {
			log.E("Unsupported device type %d", deviceType)
			return
		}

		mgr := aisegmanager.DiscoverNewAiSEGManager()
		if err := mgr.TurnAllDevices(deviceType, true); err != nil {
			log.E("Failed to turn device on due to %s", err.Error())
		}
	}

	cmd := &cobra.Command{
		Use:   "allon",
		Short: "Turn all devices on by type",
		Args:  cobra.ExactArgs(1),
		Run:   fn,
	}

	return cmd
}()
View Source
var TurnOffCmd = func() *cobra.Command {
	fn := func(cmd *cobra.Command, args []string) {
		nodeId := args[0]
		log.D("Turn device %s off", nodeId)

		mgr := aisegmanager.DiscoverNewAiSEGManager()
		if err := mgr.TurnDevice(nodeId, false); err != nil {
			log.E("Failed to turn device off due to %s", err.Error())
		}
	}

	cmd := &cobra.Command{
		Use:   "off",
		Short: "Turn device off",
		Args:  cobra.ExactArgs(1),
		Run:   fn,
	}

	return cmd
}()
View Source
var TurnOnCmd = func() *cobra.Command {
	fn := func(cmd *cobra.Command, args []string) {
		nodeId := args[0]
		log.D("Turn device %s on", nodeId)

		mgr := aisegmanager.DiscoverNewAiSEGManager()
		if err := mgr.TurnDevice(nodeId, true); err != nil {
			log.E("Failed to turn device on due to %s", err.Error())
		}
	}

	cmd := &cobra.Command{
		Use:   "on",
		Short: "Turn device on",
		Args:  cobra.ExactArgs(1),
		Run:   fn,
	}

	return cmd
}()
View Source
var Version = ""
View Source
var VersionCmd = &cobra.Command{
	Use:   "version",
	Short: "Print the version",
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Printf("aiseg v%s+%s\n", Version, Revision)
	},
}

Functions

func Execute

func Execute()

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL