mirror of
https://github.com/tobiasehlert/teslamateapi.git
synced 2026-02-27 09:54:18 +08:00
Add and update of MQTT topics (#289)
This commit is contained in:
@@ -2,11 +2,13 @@ package main
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -31,8 +33,6 @@ type statusInfo struct {
|
||||
MQTTDataWheelType string
|
||||
MQTTDataSpoilerType string
|
||||
MQTTDataGeofence string
|
||||
MQTTDataLatitude float64
|
||||
MQTTDataLongitude float64
|
||||
MQTTDataShiftState string
|
||||
MQTTDataPower int
|
||||
MQTTDataSpeed int
|
||||
@@ -42,6 +42,10 @@ type statusInfo struct {
|
||||
MQTTDataSentryMode bool
|
||||
MQTTDataWindowsOpen bool
|
||||
MQTTDataDoorsOpen bool
|
||||
MQTTDataDriverFrontDoorOpen bool
|
||||
MQTTDataDriverRearDoorOpen bool
|
||||
MQTTDataPassengerFrontDoorOpen bool
|
||||
MQTTDataPassengerRearDoorOpen bool
|
||||
MQTTDataTrunkOpen bool
|
||||
MQTTDataFrunkOpen bool
|
||||
MQTTDataIsUserPresent bool
|
||||
@@ -49,6 +53,7 @@ type statusInfo struct {
|
||||
MQTTDataInsideTemp float64
|
||||
MQTTDataOutsideTemp float64
|
||||
MQTTDataIsPreconditioning bool
|
||||
MQTTDataClimateKeeperMode string
|
||||
MQTTDataOdometer float64
|
||||
MQTTDataEstBatteryRange float64
|
||||
MQTTDataRatedBatteryRange float64
|
||||
@@ -56,6 +61,7 @@ type statusInfo struct {
|
||||
MQTTDataBatteryLevel int
|
||||
MQTTDataUsableBatteryLevel int
|
||||
MQTTDataPluggedIn bool
|
||||
MQTTDataChargingState string
|
||||
MQTTDataChargeEnergyAdded float64
|
||||
MQTTDataChargeLimitSoc int
|
||||
MQTTDataChargePortDoorOpen bool
|
||||
@@ -75,9 +81,21 @@ type statusInfo struct {
|
||||
MQTTDataTpmsSoftWarningFR bool
|
||||
MQTTDataTpmsSoftWarningRL bool
|
||||
MQTTDataTpmsSoftWarningRR bool
|
||||
MQTTDataActiveRouteDestination string
|
||||
MQTTDataActiveRouteLatitude float64
|
||||
MQTTDataActiveRouteLongitude float64
|
||||
MQTTDataLocation statusInfoLocation
|
||||
MQTTDataActiveRoute statusInfoActiveRoute
|
||||
}
|
||||
|
||||
type statusInfoActiveRoute struct {
|
||||
Destination string
|
||||
EnergyAtArrival int
|
||||
DistanceToArrival float64
|
||||
MinutesToArrival float64
|
||||
TrafficMinutesDelay float64
|
||||
Location statusInfoLocation
|
||||
}
|
||||
type statusInfoLocation struct {
|
||||
Latitude float64
|
||||
Longitude float64
|
||||
}
|
||||
|
||||
type statusCache struct {
|
||||
@@ -187,7 +205,7 @@ func connectingHandler(broker *url.URL, tlsCfg *tls.Config) *tls.Config {
|
||||
}
|
||||
|
||||
func (s *statusCache) connectedHandler(c mqtt.Client) {
|
||||
log.Println("[info] mqtt connected...")
|
||||
log.Println("[info] mqtt connected.")
|
||||
s.mqttConnected = true
|
||||
|
||||
// Subscribe - we will accept info on any car...
|
||||
@@ -257,10 +275,6 @@ func (s *statusCache) newMessage(c mqtt.Client, msg mqtt.Message) {
|
||||
stat.MQTTDataSpoilerType = string(msg.Payload())
|
||||
case "geofence":
|
||||
stat.MQTTDataGeofence = string(msg.Payload())
|
||||
case "latitude":
|
||||
stat.MQTTDataLatitude = convertStringToFloat(string(msg.Payload()))
|
||||
case "longitude":
|
||||
stat.MQTTDataLongitude = convertStringToFloat(string(msg.Payload()))
|
||||
case "shift_state":
|
||||
stat.MQTTDataShiftState = string(msg.Payload())
|
||||
case "power":
|
||||
@@ -279,6 +293,14 @@ func (s *statusCache) newMessage(c mqtt.Client, msg mqtt.Message) {
|
||||
stat.MQTTDataWindowsOpen = convertStringToBool(string(msg.Payload()))
|
||||
case "doors_open":
|
||||
stat.MQTTDataDoorsOpen = convertStringToBool(string(msg.Payload()))
|
||||
case "driver_front_door_open":
|
||||
stat.MQTTDataDriverFrontDoorOpen = convertStringToBool(string(msg.Payload()))
|
||||
case "driver_rear_door_open":
|
||||
stat.MQTTDataDriverRearDoorOpen = convertStringToBool(string(msg.Payload()))
|
||||
case "passenger_front_door_open":
|
||||
stat.MQTTDataPassengerFrontDoorOpen = convertStringToBool(string(msg.Payload()))
|
||||
case "passenger_rear_door_open":
|
||||
stat.MQTTDataPassengerRearDoorOpen = convertStringToBool(string(msg.Payload()))
|
||||
case "trunk_open":
|
||||
stat.MQTTDataTrunkOpen = convertStringToBool(string(msg.Payload()))
|
||||
case "frunk_open":
|
||||
@@ -293,6 +315,8 @@ func (s *statusCache) newMessage(c mqtt.Client, msg mqtt.Message) {
|
||||
stat.MQTTDataOutsideTemp = convertStringToFloat(string(msg.Payload()))
|
||||
case "is_preconditioning":
|
||||
stat.MQTTDataIsPreconditioning = convertStringToBool(string(msg.Payload()))
|
||||
case "climate_keeper_mode":
|
||||
stat.MQTTDataClimateKeeperMode = string(msg.Payload())
|
||||
case "odometer":
|
||||
stat.MQTTDataOdometer = convertStringToFloat(string(msg.Payload()))
|
||||
case "est_battery_range_km":
|
||||
@@ -307,6 +331,8 @@ func (s *statusCache) newMessage(c mqtt.Client, msg mqtt.Message) {
|
||||
stat.MQTTDataUsableBatteryLevel = convertStringToInteger(string(msg.Payload()))
|
||||
case "plugged_in":
|
||||
stat.MQTTDataPluggedIn = convertStringToBool(string(msg.Payload()))
|
||||
case "charging_state":
|
||||
stat.MQTTDataChargingState = strings.ToLower(string(msg.Payload()))
|
||||
case "charge_energy_added":
|
||||
stat.MQTTDataChargeEnergyAdded = convertStringToFloat(string(msg.Payload()))
|
||||
case "charge_limit_soc":
|
||||
@@ -345,14 +371,40 @@ func (s *statusCache) newMessage(c mqtt.Client, msg mqtt.Message) {
|
||||
stat.MQTTDataTpmsSoftWarningRL = convertStringToBool(string(msg.Payload()))
|
||||
case "tpms_soft_warning_rr":
|
||||
stat.MQTTDataTpmsSoftWarningRR = convertStringToBool(string(msg.Payload()))
|
||||
case "active_route_destination":
|
||||
stat.MQTTDataActiveRouteDestination = string(msg.Payload())
|
||||
case "active_route_latitude":
|
||||
stat.MQTTDataActiveRouteLatitude = convertStringToFloat(string(msg.Payload()))
|
||||
case "active_route_longitude":
|
||||
stat.MQTTDataActiveRouteLongitude = convertStringToFloat(string(msg.Payload()))
|
||||
|
||||
case "location":
|
||||
// doing nothing, since this is identical data to latitude and longitude topics
|
||||
var tmp struct {
|
||||
Latitude float64 `json:"latitude"`
|
||||
Longitude float64 `json:"longitude"`
|
||||
}
|
||||
_ = json.Unmarshal(msg.Payload(), &tmp)
|
||||
stat.MQTTDataLocation = statusInfoLocation(tmp)
|
||||
|
||||
case "active_route":
|
||||
var tmp struct {
|
||||
Destination string `json:"destination"`
|
||||
EnergyAtArrival int `json:"energy_at_arrival"`
|
||||
DistanceToArrival float64 `json:"miles_to_arrival"`
|
||||
MinutesToArrival float64 `json:"minutes_to_arrival"`
|
||||
TrafficMinutesDelay float64 `json:"traffic_minutes_delay"`
|
||||
Location struct {
|
||||
Latitude float64 `json:"latitude"`
|
||||
Longitude float64 `json:"longitude"`
|
||||
} `json:"location"`
|
||||
}
|
||||
_ = json.Unmarshal(msg.Payload(), &tmp)
|
||||
stat.MQTTDataActiveRoute.Destination = tmp.Destination
|
||||
stat.MQTTDataActiveRoute.EnergyAtArrival = tmp.EnergyAtArrival
|
||||
stat.MQTTDataActiveRoute.DistanceToArrival = milesToKilometers(tmp.DistanceToArrival)
|
||||
stat.MQTTDataActiveRoute.MinutesToArrival = tmp.MinutesToArrival
|
||||
stat.MQTTDataActiveRoute.TrafficMinutesDelay = tmp.TrafficMinutesDelay
|
||||
stat.MQTTDataActiveRoute.Location = statusInfoLocation(tmp.Location)
|
||||
|
||||
// deprecated
|
||||
case "latitude", "longitude", "active_route_destination", "active_route_latitude", "active_route_longitude":
|
||||
// doing nothing
|
||||
|
||||
// default
|
||||
default:
|
||||
log.Printf("[warning] TeslaMateAPICarsStatusV1 mqtt.MessageHandler issue.. extraction of data for %s not implemented!", MqttTopic)
|
||||
}
|
||||
@@ -406,22 +458,32 @@ func (s *statusCache) TeslaMateAPICarsStatusV1(c *gin.Context) {
|
||||
SpoilerType string `json:"spoiler_type"` // None - The spoiler type
|
||||
WheelType string `json:"wheel_type"` // Pinwheel18 - The wheel type
|
||||
}
|
||||
// CarGeodata struct - child of MQTTInformation
|
||||
type CarGeodata struct {
|
||||
Geofence string `json:"geofence"` // Home - The name of the Geo-fence, if one exists at the current position
|
||||
// CarLocation struct - child of multiple structs
|
||||
type CarLocation struct {
|
||||
Latitude float64 `json:"latitude"` // 35.278131 - Last reported car latitude
|
||||
Longitude float64 `json:"longitude"` // 29.744801 - Last reported car longitude
|
||||
}
|
||||
// CarGeodata struct - child of MQTTInformation
|
||||
type CarGeodata struct {
|
||||
Geofence string `json:"geofence"` // Home - The name of the Geo-fence, if one exists at the current position
|
||||
Location CarLocation `json:"location"` // struct
|
||||
Latitude float64 `json:"latitude"` // DEPRECATED 35.278131 - Last reported car latitude
|
||||
Longitude float64 `json:"longitude"` // DEPRECATED 29.744801 - Last reported car longitude
|
||||
}
|
||||
// CarStatus struct - child of MQTTInformation
|
||||
type CarStatus struct {
|
||||
Healthy bool `json:"healthy"` // true - Health status of the logger for that vehicle
|
||||
Locked bool `json:"locked"` // true - Indicates if the car is locked
|
||||
SentryMode bool `json:"sentry_mode"` // false - Indicates if Sentry Mode is active
|
||||
WindowsOpen bool `json:"windows_open"` // false - Indicates if any of the windows are open
|
||||
DoorsOpen bool `json:"doors_open"` // false - Indicates if any of the doors are open
|
||||
TrunkOpen bool `json:"trunk_open"` // false - Indicates if the trunk is open
|
||||
FrunkOpen bool `json:"frunk_open"` // false - Indicates if the frunk is open
|
||||
IsUserPresent bool `json:"is_user_present"` // false - Indicates if a user is present in the vehicle
|
||||
Healthy bool `json:"healthy"` // true - Health status of the logger for that vehicle
|
||||
Locked bool `json:"locked"` // true - Indicates if the car is locked
|
||||
SentryMode bool `json:"sentry_mode"` // false - Indicates if Sentry Mode is active
|
||||
WindowsOpen bool `json:"windows_open"` // false - Indicates if any of the windows are open
|
||||
DoorsOpen bool `json:"doors_open"` // false - Indicates if any of the doors are open
|
||||
DriverFrontDoorOpen bool `json:"driver_front_door_open"` // false - Indicates if the driver-side front door is open
|
||||
DriverRearDoorOpen bool `json:"driver_rear_door_open"` // false - Indicates if the driver-side rear door is open
|
||||
PassengerFrontDoorOpen bool `json:"passenger_front_door_open"` // false - Indicates if the passenger-side front door is open
|
||||
PassengerRearDoorOpen bool `json:"passenger_rear_door_open"` // false - Indicates if the passenger-side rear door is open
|
||||
TrunkOpen bool `json:"trunk_open"` // false - Indicates if the trunk is open
|
||||
FrunkOpen bool `json:"frunk_open"` // false - Indicates if the frunk is open
|
||||
IsUserPresent bool `json:"is_user_present"` // false - Indicates if a user is present in the vehicle
|
||||
}
|
||||
// CarVersions struct - child of MQTTInformation
|
||||
type CarVersions struct {
|
||||
@@ -432,6 +494,7 @@ func (s *statusCache) TeslaMateAPICarsStatusV1(c *gin.Context) {
|
||||
// ChargingDetails struct - child of MQTTInformation
|
||||
type ChargingDetails struct {
|
||||
PluggedIn bool `json:"plugged_in"` // true - If car is currently plugged into a charger
|
||||
ChargingState string `json:"charging_state"` // "Charging" - Indicates if the car is currently charging
|
||||
ChargeEnergyAdded float64 `json:"charge_energy_added"` // 5.06 - Last added energy in kWh
|
||||
ChargeLimitSoc int `json:"charge_limit_soc"` // 90 - Charge Limit Configured in Percentage
|
||||
ChargePortDoorOpen bool `json:"charge_port_door_open"` // true - Indicates if the charger door is open
|
||||
@@ -446,21 +509,32 @@ func (s *statusCache) TeslaMateAPICarsStatusV1(c *gin.Context) {
|
||||
}
|
||||
// ClimateDetails struct - child of MQTTInformation
|
||||
type ClimateDetails struct {
|
||||
IsClimateOn bool `json:"is_climate_on"` // true - Indicates if the climate control is on
|
||||
InsideTemp float64 `json:"inside_temp"` // 20.8 - Inside Temperature in °C
|
||||
OutsideTemp float64 `json:"outside_temp"` // 18.4 - Temperature in °C
|
||||
IsPreconditioning bool `json:"is_preconditioning"` // false - Indicates if the vehicle is being preconditioned
|
||||
IsClimateOn bool `json:"is_climate_on"` // true - Indicates if the climate control is on
|
||||
InsideTemp float64 `json:"inside_temp"` // 20.8 - Inside Temperature in °C
|
||||
OutsideTemp float64 `json:"outside_temp"` // 18.4 - Temperature in °C
|
||||
IsPreconditioning bool `json:"is_preconditioning"` // false - Indicates if the vehicle is being preconditioned
|
||||
ClimateKeeperMode string `json:"climate_keeper_mode"` // dog - Climate Keeper Mode
|
||||
}
|
||||
// ActiveRouteDetails struct - child of DrivingDetails
|
||||
type ActiveRouteDetails struct {
|
||||
Destination string `json:"destination"` // Home - Navigation destination name
|
||||
EnergyAtArrival int `json:"energy_at_arrival"` // 73 - Energy at arrival in kWh
|
||||
DistanceToArrival float64 `json:"distance_to_arrival"` // 10.437077034 - Distance to arrival in km
|
||||
MinutesToArrival float64 `json:"minutes_to_arrival"` // 23.466667 - Minutes to arrival
|
||||
TrafficMinutesDelay float64 `json:"traffic_minutes_delay"` // 0.0 - Traffic delay in minutes
|
||||
Location CarLocation `json:"location"` // struct
|
||||
}
|
||||
// DrivingDetails struct - child of MQTTInformation
|
||||
type DrivingDetails struct {
|
||||
ActiveRouteDestination string `json:"active_route_destination"` // Home - Navigation destination name
|
||||
ActiveRouteLatitude float64 `json:"active_route_latitude"` // 35.278131 - Navigation destination latitude
|
||||
ActiveRouteLongitude float64 `json:"active_route_longitude"` // 29.744801 - Navigation destination longitude
|
||||
ShiftState string `json:"shift_state"` // D - Current/Last Shift State (D/N/R/P)
|
||||
Power int `json:"power"` // -9 Current battery power in watts. Positive value on discharge, negative value on charge
|
||||
Speed int `json:"speed"` // 12 - Current Speed in km/h
|
||||
Heading int `json:"heading"` // 340 - Last reported car direction
|
||||
Elevation int `json:"elevation"` // 70 - Current elevation above sea level in meters
|
||||
ActiveRoute ActiveRouteDetails `json:"active_route"` // struct
|
||||
ActiveRouteDestination string `json:"active_route_destination"` // DEPRECATED Home - Navigation destination name
|
||||
ActiveRouteLatitude float64 `json:"active_route_latitude"` // DEPRECATED 35.278131 - Navigation destination latitude
|
||||
ActiveRouteLongitude float64 `json:"active_route_longitude"` // DEPRECATED 29.744801 - Navigation destination longitude
|
||||
ShiftState string `json:"shift_state"` // D - Current/Last Shift State (D/N/R/P)
|
||||
Power int `json:"power"` // -9 Current battery power in watts. Positive value on discharge, negative value on charge
|
||||
Speed int `json:"speed"` // 12 - Current Speed in km/h
|
||||
Heading int `json:"heading"` // 340 - Last reported car direction
|
||||
Elevation int `json:"elevation"` // 70 - Current elevation above sea level in meters
|
||||
}
|
||||
// TpmsDetails struct - child of MQTTInformation
|
||||
type TpmsDetails struct {
|
||||
@@ -498,6 +572,7 @@ func (s *statusCache) TeslaMateAPICarsStatusV1(c *gin.Context) {
|
||||
// TeslaMateUnits struct - child of Data
|
||||
type TeslaMateUnits struct {
|
||||
UnitsLength string `json:"unit_of_length"` // string
|
||||
UnitsPressure string `json:"unit_of_pressure"` // string
|
||||
UnitsTemperature string `json:"unit_of_temperature"` // string
|
||||
}
|
||||
// Data struct - child of JSONData
|
||||
@@ -513,9 +588,9 @@ func (s *statusCache) TeslaMateAPICarsStatusV1(c *gin.Context) {
|
||||
|
||||
// creating required vars
|
||||
var (
|
||||
CarData Car
|
||||
MQTTInformationData MQTTInformation
|
||||
UnitsLength, UnitsTemperature string
|
||||
CarData Car
|
||||
MQTTInformationData MQTTInformation
|
||||
UnitsLength, UnitsPressure, UnitsTemperature string
|
||||
)
|
||||
|
||||
// getting data from database (assume that carID is unique!)
|
||||
@@ -524,6 +599,7 @@ func (s *statusCache) TeslaMateAPICarsStatusV1(c *gin.Context) {
|
||||
id,
|
||||
name,
|
||||
(SELECT unit_of_length FROM settings LIMIT 1) as unit_of_length,
|
||||
(SELECT unit_of_pressure FROM settings LIMIT 1) as unit_of_pressure,
|
||||
(SELECT unit_of_temperature FROM settings LIMIT 1) as unit_of_temperature
|
||||
FROM cars
|
||||
WHERE id=$1
|
||||
@@ -531,6 +607,7 @@ func (s *statusCache) TeslaMateAPICarsStatusV1(c *gin.Context) {
|
||||
err := db.QueryRow(query, carID).Scan(&CarData.CarID,
|
||||
&CarData.CarName,
|
||||
&UnitsLength,
|
||||
&UnitsPressure,
|
||||
&UnitsTemperature)
|
||||
|
||||
// checking for errors in query (this will include no rows found)
|
||||
@@ -553,11 +630,13 @@ func (s *statusCache) TeslaMateAPICarsStatusV1(c *gin.Context) {
|
||||
MQTTInformationData.CarExterior.WheelType = stat.MQTTDataWheelType
|
||||
MQTTInformationData.CarExterior.SpoilerType = stat.MQTTDataSpoilerType
|
||||
MQTTInformationData.CarGeodata.Geofence = stat.MQTTDataGeofence
|
||||
MQTTInformationData.CarGeodata.Latitude = stat.MQTTDataLatitude
|
||||
MQTTInformationData.CarGeodata.Longitude = stat.MQTTDataLongitude
|
||||
MQTTInformationData.DrivingDetails.ActiveRouteDestination = stat.MQTTDataActiveRouteDestination
|
||||
MQTTInformationData.DrivingDetails.ActiveRouteLatitude = stat.MQTTDataActiveRouteLatitude
|
||||
MQTTInformationData.DrivingDetails.ActiveRouteLongitude = stat.MQTTDataActiveRouteLongitude
|
||||
MQTTInformationData.CarGeodata.Location = CarLocation(stat.MQTTDataLocation)
|
||||
MQTTInformationData.DrivingDetails.ActiveRoute.Destination = stat.MQTTDataActiveRoute.Destination
|
||||
MQTTInformationData.DrivingDetails.ActiveRoute.EnergyAtArrival = stat.MQTTDataActiveRoute.EnergyAtArrival
|
||||
MQTTInformationData.DrivingDetails.ActiveRoute.DistanceToArrival = stat.MQTTDataActiveRoute.DistanceToArrival
|
||||
MQTTInformationData.DrivingDetails.ActiveRoute.MinutesToArrival = stat.MQTTDataActiveRoute.MinutesToArrival
|
||||
MQTTInformationData.DrivingDetails.ActiveRoute.TrafficMinutesDelay = stat.MQTTDataActiveRoute.TrafficMinutesDelay
|
||||
MQTTInformationData.DrivingDetails.ActiveRoute.Location = CarLocation(stat.MQTTDataActiveRoute.Location)
|
||||
MQTTInformationData.DrivingDetails.ShiftState = stat.MQTTDataShiftState
|
||||
MQTTInformationData.DrivingDetails.Power = stat.MQTTDataPower
|
||||
MQTTInformationData.DrivingDetails.Speed = stat.MQTTDataSpeed
|
||||
@@ -567,6 +646,10 @@ func (s *statusCache) TeslaMateAPICarsStatusV1(c *gin.Context) {
|
||||
MQTTInformationData.CarStatus.SentryMode = stat.MQTTDataSentryMode
|
||||
MQTTInformationData.CarStatus.WindowsOpen = stat.MQTTDataWindowsOpen
|
||||
MQTTInformationData.CarStatus.DoorsOpen = stat.MQTTDataDoorsOpen
|
||||
MQTTInformationData.CarStatus.DriverFrontDoorOpen = stat.MQTTDataDriverFrontDoorOpen
|
||||
MQTTInformationData.CarStatus.DriverRearDoorOpen = stat.MQTTDataDriverRearDoorOpen
|
||||
MQTTInformationData.CarStatus.PassengerFrontDoorOpen = stat.MQTTDataPassengerFrontDoorOpen
|
||||
MQTTInformationData.CarStatus.PassengerRearDoorOpen = stat.MQTTDataPassengerRearDoorOpen
|
||||
MQTTInformationData.CarStatus.TrunkOpen = stat.MQTTDataTrunkOpen
|
||||
MQTTInformationData.CarStatus.FrunkOpen = stat.MQTTDataFrunkOpen
|
||||
MQTTInformationData.CarStatus.IsUserPresent = stat.MQTTDataIsUserPresent
|
||||
@@ -574,6 +657,7 @@ func (s *statusCache) TeslaMateAPICarsStatusV1(c *gin.Context) {
|
||||
MQTTInformationData.ClimateDetails.InsideTemp = stat.MQTTDataInsideTemp
|
||||
MQTTInformationData.ClimateDetails.OutsideTemp = stat.MQTTDataOutsideTemp
|
||||
MQTTInformationData.ClimateDetails.IsPreconditioning = stat.MQTTDataIsPreconditioning
|
||||
MQTTInformationData.ClimateDetails.ClimateKeeperMode = stat.MQTTDataClimateKeeperMode
|
||||
MQTTInformationData.Odometer = stat.MQTTDataOdometer
|
||||
MQTTInformationData.BatteryDetails.EstBatteryRange = stat.MQTTDataEstBatteryRange
|
||||
MQTTInformationData.BatteryDetails.RatedBatteryRange = stat.MQTTDataRatedBatteryRange
|
||||
@@ -581,6 +665,7 @@ func (s *statusCache) TeslaMateAPICarsStatusV1(c *gin.Context) {
|
||||
MQTTInformationData.BatteryDetails.BatteryLevel = stat.MQTTDataBatteryLevel
|
||||
MQTTInformationData.BatteryDetails.UsableBatteryLevel = stat.MQTTDataUsableBatteryLevel
|
||||
MQTTInformationData.ChargingDetails.PluggedIn = stat.MQTTDataPluggedIn
|
||||
MQTTInformationData.ChargingDetails.ChargingState = stat.MQTTDataChargingState
|
||||
MQTTInformationData.ChargingDetails.ChargeEnergyAdded = stat.MQTTDataChargeEnergyAdded
|
||||
MQTTInformationData.ChargingDetails.ChargeLimitSoc = stat.MQTTDataChargeLimitSoc
|
||||
MQTTInformationData.ChargingDetails.ChargePortDoorOpen = stat.MQTTDataChargePortDoorOpen
|
||||
@@ -601,14 +686,29 @@ func (s *statusCache) TeslaMateAPICarsStatusV1(c *gin.Context) {
|
||||
MQTTInformationData.TpmsDetails.TpmsSoftWarningRL = stat.MQTTDataTpmsSoftWarningRL
|
||||
MQTTInformationData.TpmsDetails.TpmsSoftWarningRR = stat.MQTTDataTpmsSoftWarningRR
|
||||
|
||||
// DEPRECATAD - setting values for deprecated fields
|
||||
MQTTInformationData.CarGeodata.Latitude = stat.MQTTDataLocation.Latitude
|
||||
MQTTInformationData.CarGeodata.Longitude = stat.MQTTDataLocation.Longitude
|
||||
MQTTInformationData.DrivingDetails.ActiveRouteDestination = stat.MQTTDataActiveRoute.Destination
|
||||
MQTTInformationData.DrivingDetails.ActiveRouteLatitude = stat.MQTTDataActiveRoute.Location.Latitude
|
||||
MQTTInformationData.DrivingDetails.ActiveRouteLongitude = stat.MQTTDataActiveRoute.Location.Longitude
|
||||
|
||||
// converting values based of settings UnitsLength
|
||||
if UnitsLength == "mi" {
|
||||
// drive.OdometerDetails.OdometerStart = kilometersToMiles(drive.OdometerDetails.OdometerStart)
|
||||
MQTTInformationData.Odometer = kilometersToMiles(MQTTInformationData.Odometer)
|
||||
MQTTInformationData.DrivingDetails.ActiveRoute.DistanceToArrival = kilometersToMiles(MQTTInformationData.DrivingDetails.ActiveRoute.DistanceToArrival)
|
||||
MQTTInformationData.BatteryDetails.EstBatteryRange = kilometersToMiles(MQTTInformationData.BatteryDetails.EstBatteryRange)
|
||||
MQTTInformationData.BatteryDetails.RatedBatteryRange = kilometersToMiles(MQTTInformationData.BatteryDetails.RatedBatteryRange)
|
||||
MQTTInformationData.BatteryDetails.IdealBatteryRange = kilometersToMiles(MQTTInformationData.BatteryDetails.IdealBatteryRange)
|
||||
}
|
||||
// converting values based of settings UnitsPressure
|
||||
if UnitsPressure == "psi" {
|
||||
MQTTInformationData.TpmsDetails.TpmsPressureFL = barToPsi(MQTTInformationData.TpmsDetails.TpmsPressureFL)
|
||||
MQTTInformationData.TpmsDetails.TpmsPressureFR = barToPsi(MQTTInformationData.TpmsDetails.TpmsPressureFR)
|
||||
MQTTInformationData.TpmsDetails.TpmsPressureRL = barToPsi(MQTTInformationData.TpmsDetails.TpmsPressureRL)
|
||||
MQTTInformationData.TpmsDetails.TpmsPressureRR = barToPsi(MQTTInformationData.TpmsDetails.TpmsPressureRR)
|
||||
}
|
||||
// converting values based of settings UnitsTemperature
|
||||
if UnitsTemperature == "F" {
|
||||
MQTTInformationData.ClimateDetails.InsideTemp = celsiusToFahrenheit(MQTTInformationData.ClimateDetails.InsideTemp)
|
||||
@@ -627,6 +727,7 @@ func (s *statusCache) TeslaMateAPICarsStatusV1(c *gin.Context) {
|
||||
MQTTInformation: MQTTInformationData,
|
||||
TeslaMateUnits: TeslaMateUnits{
|
||||
UnitsLength: UnitsLength,
|
||||
UnitsPressure: UnitsPressure,
|
||||
UnitsTemperature: UnitsTemperature,
|
||||
},
|
||||
},
|
||||
|
||||
+13
-1
@@ -370,12 +370,12 @@ func kilometersToMilesNilSupport(km NullFloat64) NullFloat64 {
|
||||
return (km)
|
||||
}
|
||||
|
||||
/*
|
||||
// milesToKilometers func
|
||||
func milesToKilometers(mi float64) float64 {
|
||||
return (mi * 1.609344)
|
||||
}
|
||||
|
||||
/*
|
||||
// milesToKilometersNilSupport func
|
||||
func milesToKilometersNilSupport(mi NullFloat64) NullFloat64 {
|
||||
mi.Float64 = (mi.Float64 * 1.609344)
|
||||
@@ -383,6 +383,18 @@ func milesToKilometersNilSupport(mi NullFloat64) NullFloat64 {
|
||||
}
|
||||
*/
|
||||
|
||||
// barToPsi func
|
||||
func barToPsi(bar float64) float64 {
|
||||
return (bar * 14.503773800722)
|
||||
}
|
||||
|
||||
/*
|
||||
// psiToBar func
|
||||
func psiToBar(psi float64) float64 {
|
||||
return (psi * 0.068947572932)
|
||||
}
|
||||
*/
|
||||
|
||||
// celsiusToFahrenheit func
|
||||
func celsiusToFahrenheit(c float64) float64 {
|
||||
return (c*9/5 + 32)
|
||||
|
||||
Reference in New Issue
Block a user