initial commit
This commit is contained in:
32
example/config.mq.yaml
Normal file
32
example/config.mq.yaml
Normal file
@ -0,0 +1,32 @@
|
||||
---
|
||||
mqtt:
|
||||
host: mqtt.savin.nyc
|
||||
port: 1884
|
||||
username: mysubaru
|
||||
password: 7GhKjqNqq7cZDXHL
|
||||
client_id: mysubaru
|
||||
retained: true
|
||||
mysubaru:
|
||||
credentials:
|
||||
username: alex@savin.nyc
|
||||
password: Er1csso0n
|
||||
pin: "2008"
|
||||
device_id: JddMBQXvAkgutSmEP6uFsThbq4QgEBBQ
|
||||
device_name: Hassio Golang Integration
|
||||
region: USA
|
||||
hassio:
|
||||
auto_discovery: true
|
||||
listeners:
|
||||
stats:
|
||||
port: 8889
|
||||
consul:
|
||||
host: consul.savin.nyc
|
||||
port: 443
|
||||
datacenter: dc1
|
||||
token: CONSUL-TOKEN-HERE
|
||||
interface:
|
||||
timezone: America/New_York
|
||||
logging:
|
||||
level: DEBUG
|
||||
output: JSON
|
||||
source: false
|
15
example/config.sample.yml
Normal file
15
example/config.sample.yml
Normal file
@ -0,0 +1,15 @@
|
||||
credentials:
|
||||
username: user@email.com
|
||||
password: "Secr#TPassW0rd"
|
||||
pin: "PIN"
|
||||
deviceId: GENERATE-DEVICE-ID
|
||||
deviceName: Golang Integration
|
||||
mysubaru:
|
||||
region: USA
|
||||
mqtt:
|
||||
client_id: mysubaru
|
||||
username: mysubaru
|
||||
password:
|
||||
host: mqtt.hostname.com
|
||||
port: 1883
|
||||
log: info
|
135
example/example.go
Normal file
135
example/example.go
Normal file
@ -0,0 +1,135 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
mysubaru "git.savin.nyc/alex/go-mysubaru"
|
||||
)
|
||||
|
||||
// var log = *slog.Logger
|
||||
var cfg = &mysubaru.Config{}
|
||||
|
||||
const (
|
||||
LoggingOutputJson = "JSON"
|
||||
LoggingOutputText = "TEXT"
|
||||
)
|
||||
|
||||
func configureLogging(config *mysubaru.Logging) *slog.Logger { //nolint:unparam
|
||||
if config == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var level slog.Level
|
||||
if err := level.UnmarshalText([]byte(config.Level)); err != nil {
|
||||
slog.Warn(err.Error())
|
||||
slog.Warn(fmt.Sprintf("logging level not recognized, defaulting to level %s", slog.LevelInfo.String()))
|
||||
level = slog.LevelInfo
|
||||
}
|
||||
|
||||
var handler slog.Handler
|
||||
switch config.Output {
|
||||
case LoggingOutputJson:
|
||||
handler = slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{AddSource: cfg.Logging.Source, Level: level})
|
||||
case LoggingOutputText:
|
||||
handler = slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{AddSource: cfg.Logging.Source, Level: level})
|
||||
default:
|
||||
handler = slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{AddSource: cfg.Logging.Source, Level: level})
|
||||
}
|
||||
|
||||
return slog.New(handler)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
var err error
|
||||
cfg, err = mysubaru.NewConfig()
|
||||
if err != nil { // Handle errors reading the config file
|
||||
slog.Error("Fatal error config file", "error", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logger := configureLogging(cfg.Logging)
|
||||
logger.Debug("printting config", "config", cfg)
|
||||
|
||||
ms, _ := mysubaru.NewMySubaru(logger, cfg)
|
||||
|
||||
for i, vehicle := range ms.GetVehicles() {
|
||||
// vehicle.GetLocation(true)
|
||||
fmt.Printf("Vehicle #%d -- %v", i+1, vehicle)
|
||||
vehicle.GetVehicleHealth()
|
||||
}
|
||||
// mysubaru.selectVehicle("4S4BTGPD0P3199198")
|
||||
|
||||
// 11.6MMAN ABS_MIL ACCS AHBL_MIL ATF_MIL AWD_MIL BSD BSDRCT_MIL CEL_MIL EBD_MIL EOL_MIL EPAS_MIL EPB_MIL ESS_MIL EYESIGHT ISS_MIL NAV_TOMTOM OPL_MIL RAB_MIL RCC REARBRK RES RESCC RHSF RPOI RPOIA SRS_MIL TEL_MIL TIF_35 TIR_33 TPMS_MIL VDC_MIL WASH_MIL g2
|
||||
// subaru1 := mysubaru.GetVehicleByVIN("4S4BTGND8L3137058")
|
||||
// fmt.Printf("SUBARU #2 (Vehicle Status):\n")
|
||||
// subaru1.GetVehicleStatus()
|
||||
// fmt.Printf("SUBARU #2 (Vehicle Condition):\n")
|
||||
// subaru1.GetVehicleCondition()
|
||||
// fmt.Printf("SUBARU #1: %+v\n", subaru1)
|
||||
// fmt.Printf("GEN #1: %+v\n\n", subaru1.getAPIGen())
|
||||
|
||||
// ABS_MIL ACCS AHBL_MIL ATF_MIL AWD_MIL BSD BSDRCT_MIL CEL_MIL EBD_MIL EOL_MIL EPAS_MIL EPB_MIL ESS_MIL EYESIGHT ISS_MIL OPL_MIL PANPM-TUIRWAOC PWAAADWWAP RAB_MIL RCC REARBRK RES RESCC RHSF RPOI RPOIA RTGU RVFS SRH_MIL SRS_MIL TEL_MIL TIF_35 TIR_33 TLD TPMS_MIL VALET VDC_MIL WASH_MIL g3
|
||||
// subaru := ms.GetVehicleByVIN("4S4BTGPD0P3199198")
|
||||
// subaru.GetLocation(true)
|
||||
// subaru.EngineStart()
|
||||
// fmt.Printf("SUBARU #1 (Vehicle Status):\n")
|
||||
// subaru.GetVehicleStatus()
|
||||
// subaru.GetVehicleCondition()
|
||||
// fmt.Printf("SUBARU #1: %+v\n", subaru)
|
||||
// fmt.Printf("SUBARU #1 (Vehicle Condition):\n")
|
||||
// subaru.GetVehicleCondition()
|
||||
// fmt.Printf("SUBARU #1: %+v\n", subaru)
|
||||
// subaru.GetClimatePresets()
|
||||
// subaru.GetClimateUserPresets()
|
||||
// fmt.Printf("SUBARU #2: %+v\n", subaru)
|
||||
// subaru.GetVehicleHealth()
|
||||
// subaru.GetFeaturesList()
|
||||
|
||||
// subaru.LightsStart()
|
||||
// time.Sleep(10 * time.Second)
|
||||
// subaru.LightsStop()
|
||||
|
||||
// subaru := mysubaru.GetVehicles()[0]
|
||||
|
||||
// fmt.Printf("SUBARU: %+v\n", subaru)
|
||||
|
||||
// fmt.Printf("Subaru Gen: %+v\n\n", subaru.getAPIGen())
|
||||
|
||||
// subaru.EngineOn()
|
||||
// subaru.GetLocation(false)
|
||||
|
||||
// subaru.GetVehicleStatus()
|
||||
// subaru.GetVehicleCondition()
|
||||
// fmt.Printf("SUBARU: %+v\n", subaru)
|
||||
|
||||
// subaru.GetClimateQuickPresets()
|
||||
// subaru.GetClimatePresets()
|
||||
// subaru.GetClimateUserPresets()
|
||||
|
||||
// subaru.LightsStart()
|
||||
// time.Sleep(15 * time.Second)
|
||||
// subaru.LightsStop()
|
||||
|
||||
// subaru.listDevices()
|
||||
|
||||
// subaru.GetVehicleStatus()
|
||||
|
||||
// subaru.GetClimateSettings()
|
||||
|
||||
// subaru.EngineStart()
|
||||
// time.Sleep(15 * time.Second)
|
||||
// subaru.EngineStop()
|
||||
|
||||
// subaru.Unlock()
|
||||
// time.Sleep(20 * time.Second)
|
||||
// subaru.Lock()
|
||||
|
||||
// subaru.LightsStart()
|
||||
// time.Sleep(15 * time.Second)
|
||||
// subaru.LightsStop()
|
||||
|
||||
// subaru.GetLocation()
|
||||
}
|
3
example/go.mod
Normal file
3
example/go.mod
Normal file
@ -0,0 +1,3 @@
|
||||
module example
|
||||
|
||||
go 1.23
|
Reference in New Issue
Block a user