From 7548d5dbaaa5bbd88b577362023083dfa2971b1f Mon Sep 17 00:00:00 2001 From: Tobias Lindberg Date: Mon, 4 Mar 2024 11:39:41 +0100 Subject: [PATCH] Add tire pressure warning and active route from mqtt (#270) --- src/v1_TeslaMateAPICarsStatus.go | 55 ++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/src/v1_TeslaMateAPICarsStatus.go b/src/v1_TeslaMateAPICarsStatus.go index e5afcf8..b517736 100644 --- a/src/v1_TeslaMateAPICarsStatus.go +++ b/src/v1_TeslaMateAPICarsStatus.go @@ -71,6 +71,13 @@ type statusInfo struct { MQTTDataTpmsPressureFR float64 MQTTDataTpmsPressureRL float64 MQTTDataTpmsPressureRR float64 + MQTTDataTpmsSoftWarningFL bool + MQTTDataTpmsSoftWarningFR bool + MQTTDataTpmsSoftWarningRL bool + MQTTDataTpmsSoftWarningRR bool + MQTTDataActiveRouteDestination string + MQTTDataActiveRouteLatitude float64 + MQTTDataActiveRouteLongitude float64 } type statusCache struct { @@ -330,6 +337,20 @@ func (s *statusCache) newMessage(c mqtt.Client, msg mqtt.Message) { stat.MQTTDataTpmsPressureRL = convertStringToFloat(string(msg.Payload())) case "tpms_pressure_rr": stat.MQTTDataTpmsPressureRR = convertStringToFloat(string(msg.Payload())) + case "tpms_soft_warning_fl": + stat.MQTTDataTpmsSoftWarningFL = convertStringToBool(string(msg.Payload())) + case "tpms_soft_warning_fr": + stat.MQTTDataTpmsSoftWarningFR = convertStringToBool(string(msg.Payload())) + case "tpms_soft_warning_rl": + 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())) default: log.Printf("[warning] TeslaMateAPICarsStatusV1 mqtt.MessageHandler issue.. extraction of data for %s not implemented!", MqttTopic) } @@ -430,18 +451,25 @@ func (s *statusCache) TeslaMateAPICarsStatusV1(c *gin.Context) { } // DrivingDetails struct - child of MQTTInformation type DrivingDetails struct { - 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 + 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 } - // TpmsDetails struct - child of MQTTInformatiojn + // TpmsDetails struct - child of MQTTInformation type TpmsDetails struct { - TpmsPressureFL float64 `json:"tpms_pressure_fl"` // 2.9 - Tire pressure measure in BAR, front left tire - TpmsPressureFR float64 `json:"tpms_pressure_fr"` // 2.8 - Tire pressure measure in BAR, front right tire - TpmsPressureRL float64 `json:"tpms_pressure_rl"` // 2.9 - Tire pressure measure in BAR, rear left tire - TpmsPressureRR float64 `json:"tpms_pressure_rr"` // 2.8 - Tire pressure measure in BAR, rear right tire + TpmsPressureFL float64 `json:"tpms_pressure_fl"` // 2.9 - Tire pressure measure in BAR, front left tire + TpmsPressureFR float64 `json:"tpms_pressure_fr"` // 2.8 - Tire pressure measure in BAR, front right tire + TpmsPressureRL float64 `json:"tpms_pressure_rl"` // 2.9 - Tire pressure measure in BAR, rear left tire + TpmsPressureRR float64 `json:"tpms_pressure_rr"` // 2.8 - Tire pressure measure in BAR, rear right tire + TpmsSoftWarningFL bool `json:"tpms_soft_warning_fl"` // true - Indicates if the Tire pressure measure is soft warning, front left tire + TpmsSoftWarningFR bool `json:"tpms_soft_warning_fr"` // false - Indicates if the Tire pressure measure is soft warning, front right tire + TpmsSoftWarningRL bool `json:"tpms_soft_warning_rl"` // false - Indicates if the Tire pressure measure is soft warning, rear left tire + TpmsSoftWarningRR bool `json:"tpms_soft_warning_rr"` // false - Indicates if the Tire pressure measure is soft warning, rear right tire } // MQTTInformation struct - child of Cars type MQTTInformation struct { @@ -525,6 +553,9 @@ func (s *statusCache) TeslaMateAPICarsStatusV1(c *gin.Context) { 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.DrivingDetails.ShiftState = stat.MQTTDataShiftState MQTTInformationData.DrivingDetails.Power = stat.MQTTDataPower MQTTInformationData.DrivingDetails.Speed = stat.MQTTDataSpeed @@ -563,6 +594,10 @@ func (s *statusCache) TeslaMateAPICarsStatusV1(c *gin.Context) { MQTTInformationData.TpmsDetails.TpmsPressureFR = stat.MQTTDataTpmsPressureFR MQTTInformationData.TpmsDetails.TpmsPressureRL = stat.MQTTDataTpmsPressureRL MQTTInformationData.TpmsDetails.TpmsPressureRR = stat.MQTTDataTpmsPressureRR + MQTTInformationData.TpmsDetails.TpmsSoftWarningFL = stat.MQTTDataTpmsSoftWarningFL + MQTTInformationData.TpmsDetails.TpmsSoftWarningFR = stat.MQTTDataTpmsSoftWarningFR + MQTTInformationData.TpmsDetails.TpmsSoftWarningRL = stat.MQTTDataTpmsSoftWarningRL + MQTTInformationData.TpmsDetails.TpmsSoftWarningRR = stat.MQTTDataTpmsSoftWarningRR // converting values based of settings UnitsLength if UnitsLength == "mi" {