<commit_before>package cmd

import (
	"fmt"
	"log"

	"github.com/sgrimee/godomus"
	"github.com/spf13/cobra"
)

var listenCmd = &cobra.Command{
	Use:   "listen",
	Short: "Continuously listen for device update events",
	Run: func(cmd *cobra.Command, args []string) {
		domusLogin()

		events := make(chan godomus.EventMsg, 1)
		errs := make(chan error, 1)
		go domus.ListenForEvents(events, errs)

		fmt.Println("Waiting for events, Ctrl+C to exit")
		for {
			select {
			case ev := <-events:
				//fmt.Printf("Event received: %+v\n", ev)
				d, err := domus.GetDeviceState(ev.DeviceKey)
				if err != nil {
					log.Fatal(err)
				}
				fmt.Printf("%20s: %5d - %25s - %+v\n",
					d.RoomLabel, d.Key.Num(), d.Label, d.States.State[0].Values.Value[0].Value)
			case err := <-errs:
				log.Fatal(err)
			}
		}
	},
}

func init() {
	RootCmd.AddCommand(listenCmd)
}<commit_msg>nicer formatting of events<commit_after>package cmd

import (
	"fmt"
	"log"

	"github.com/sgrimee/godomus"
	"github.com/spf13/cobra"
)

var listenCmd = &cobra.Command{
	Use:   "listen",
	Short: "Continuously listen for device update events",
	Run: func(cmd *cobra.Command, args []string) {
		domusLogin()

		events := make(chan godomus.EventMsg, 1)
		errs := make(chan error, 1)
		go domus.ListenForEvents(events, errs)

		fmt.Println("Waiting for events, Ctrl+C to exit")
		for {
			select {
			case ev := <-events:
				//fmt.Printf("Event received: %+v\n", ev)
				d, err := domus.GetDeviceState(ev.DeviceKey)
				if err != nil {
					log.Fatal(err)
				}
				val := d.States.State[0].Values.Value[0]
				fmt.Printf("%20s: %5d - %25s - %s %s %s\n",
					d.RoomLabel, d.Key.Num(), d.Label, val.Label, val.Value, val.Unit)
			case err := <-errs:
				log.Fatal(err)
			}
		}
	},
}

func init() {
	RootCmd.AddCommand(listenCmd)
}
{'fraction_non_alphanumeric': 0.17055555555555554, 'fraction_numerical': 0.012222222222222223, 'mean_word_length': 3.198135198135198, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7211313', 'n_tokens_mistral': 836, 'n_tokens_neox': 724, 'n_words': 155}