util

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PolygonGeofenceType   = "PolygonGeofence"   // custom polygon geofence defined by multiple lat/long points
	CircularGeofenceType  = "CircularGeofence"  // circular geofence with center point and radius
	TeslamateGeofenceType = "TeslamateGeofence" // geofence defined in teslamate
)

Variables

This section is empty.

Functions

func LoadConfig

func LoadConfig(configFile string)

load yaml config

Types

type Car

type Car struct {
	ID                 int         `yaml:"teslamate_car_id"` // mqtt identifier for vehicle
	GarageDoor         *GarageDoor // bidirectional pointer to GarageDoor containing car
	CurrentLocation    Point       // current vehicle location
	LocationUpdate     chan Point  // channel to receive location updates
	CurDistance        float64     // current distance from garagedoor location
	PrevGeofence       string      // geofence previously ascribed to car
	CurGeofence        string      // updated geofence ascribed to car when published to mqtt
	InsidePolyOpenGeo  bool        // indicates if car is currently inside the polygon_open_geofence
	InsidePolyCloseGeo bool        // indicates if car is currently inside the polygon_close_geofence
}

type CircularGeofence added in v0.2.0

type CircularGeofence struct {
	Center        Point   `yaml:"center"`
	CloseDistance float64 `yaml:"close_distance"` // defines a radius from the center point; when vehicle moves from < distance to > distance, garage will close
	OpenDistance  float64 `yaml:"open_distance"`  // defines a radius from the center point; when vehicle moves from > distance to < distance, garage will open
}

defines a center point and two radii (distances) to define open and close geofences

type ConfigStruct

type ConfigStruct struct {
	Global struct {
		MqttHost          string `yaml:"mqtt_host"`
		MqttPort          int    `yaml:"mqtt_port"`
		MqttClientID      string `yaml:"mqtt_client_id"`
		MqttUser          string `yaml:"mqtt_user"`
		MqttPass          string `yaml:"mqtt_pass"`
		MqttUseTls        bool   `yaml:"mqtt_use_tls"`
		MqttSkipTlsVerify bool   `yaml:"mqtt_skip_tls_verify"`
		OpCooldown        int    `yaml:"cooldown"`
		MyQEmail          string `yaml:"myq_email"`
		MyQPass           string `yaml:"myq_pass"`
		CacheTokenFile    string `yaml:"cache_token_file"`
	} `yaml:"global"`
	GarageDoors []*GarageDoor `yaml:"garage_doors"`
	Testing     bool
}
var Config ConfigStruct

type CustomFormatter added in v0.2.4

type CustomFormatter struct {
	logger.TextFormatter
}

func (*CustomFormatter) Format added in v0.2.4

func (f *CustomFormatter) Format(entry *logger.Entry) ([]byte, error)

custom formatter for logrus package 01/02/2006 15:04:05 [LEVEL] Message...

type GarageDoor

type GarageDoor struct {
	CircularGeofence  *CircularGeofence  `yaml:"circular_geofence"`
	TeslamateGeofence *TeslamateGeofence `yaml:"teslamate_geofence"`
	PolygonGeofence   *PolygonGeofence   `yaml:"polygon_geofence"`
	MyQSerial         string             `yaml:"myq_serial"`
	Cars              []*Car             `yaml:"cars"` // cars housed within this garage
	OpLock            bool               // controls if garagedoor has been operated recently to prevent flapping
	GeofenceType      string             //indicates whether garage door uses teslamate's geofence or not (checked during runtime)
}

defines a garage door with one unique geofence type: circular, teslamate, or polygon only one geofence type may be defined per garage door if more than one defined, priority will be polygon > circular > teslamate

func (GarageDoor) GetGeofenceType added in v0.2.0

func (g GarageDoor) GetGeofenceType() string

checks for valid geofence values for a garage door preferred priority is polygon > circular > teslamate at least one open OR one close must be defined to identify a geofence type

type KML added in v0.2.1

type KML struct {
	Document struct {
		Placemarks []struct {
			Name    string `xml:"name"`
			Polygon struct {
				OuterBoundary struct {
					LinearRing struct {
						Coordinates string `xml:"coordinates"`
					} `xml:"linearring"`
				} `xml:"outerboundaryis"`
			} `xml:"polygon"`
		} `xml:"placemark"`
	} `xml:"document"`
}

kml schema to parse coordinates from kml file for polygon geofences

type Point

type Point struct {
	Lat float64 `yaml:"lat"`
	Lng float64 `yaml:"lng"`
}

func (Point) IsPointDefined added in v0.1.2

func (p Point) IsPointDefined() bool

type PolygonGeofence added in v0.2.0

type PolygonGeofence struct {
	Close   []Point `yaml:"close"` // list of points defining a polygon; when vehicle moves from inside this geofence to outside, garage will close
	Open    []Point `yaml:"open"`  // list of points defining a polygon; when vehicle moves from outside this geofence to inside, garage will open
	KMLFile string  `yaml:"kml_file"`
}

contains 2 geofences, open and close, each of which are a list of lat/long points defining the polygon

type TeslamateGeofence added in v0.2.0

type TeslamateGeofence struct {
	Close TeslamateGeofenceTrigger `yaml:"close_trigger"` // garage will close when vehicle moves from `from` to `to`
	Open  TeslamateGeofenceTrigger `yaml:"open_trigger"`  // garage will open when vehicle moves from `from` to `to`
}

defines triggers for open and close action for teslamate geofences

type TeslamateGeofenceTrigger added in v0.2.0

type TeslamateGeofenceTrigger struct {
	From string `yaml:"from"`
	To   string `yaml:"to"`
}

defines which teslamate defined geofence change will trigger an event, e.g. "home" to "not_home"

func (TeslamateGeofenceTrigger) IsTriggerDefined added in v0.2.4

func (t TeslamateGeofenceTrigger) IsTriggerDefined() bool

Jump to

Keyboard shortcuts

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