175 Commits

Author SHA1 Message Date
Tobias Lindberg b6ce2b89b9 Removing some code smell reported by SonarCloud (#132)
* changing lots of if else to switch in status
* removing logging of user-provided
* removing tons of ifs for a map and a loop
2022-01-11 21:24:31 +01:00
Tobias Lindberg 732fc886a2 Feature: response handler (#110)
Co-authored-by: Alec O'Connor <alecdoconnor@users.noreply.github.com>
2021-12-31 12:27:25 +01:00
Tobias Lindberg e7e3005e57 using of BasePath function in output and redirect (#130) 2021-12-29 10:49:24 +01:00
Tobias Lindberg dbb07937ba changing float64 to NullFloat64 on efficiency (#129) 2021-12-28 22:19:05 +01:00
Tobias Lindberg 7e648a498f adding arg for apiVersion based on git release 2021-12-23 11:27:21 +01:00
Tobias Lindberg 8507392382 bumping new version v1.11.0
updating CHANGELOG
2021-11-08 08:54:48 +01:00
Tobias Lindberg a29eaf0a4d Add support for new endpoints (#113)
* Add support for `set_charging_amps` command (#112)

Per discussion on the timdorr/tesla-api repo https://github.com/timdorr/tesla-api/discussions/455

* removing predefined charge levels

* adding new commands:
- navigation_sc_request
- set_bioweapon_mode
- set_scheduled_charging
- set_scheduled_departure

* adding command section COMMANDS_UNKNOWN
- dashcam_save_clip
- upcoming_calendar_entries

* moving set_scheduled_departure to charging

Co-authored-by: Michael Dyrynda <michael@dyrynda.com.au>
2021-11-08 08:49:19 +01:00
Tobias Lindberg e19a1ac8b5 bumping new version v1.10.2
updating CHANGELOG
2021-10-15 14:34:45 +02:00
Tobias Lindberg 729360c8b1 bumping new version v1.10.1
updating CHANGELOG
2021-09-23 12:27:52 +02:00
Tobias Lindberg a8e352863a bumping new version v1.10.0
updating CHANGELOG
2021-06-30 14:09:57 +02:00
Tobias Lindberg 3b8eb65315 minor code adjustments based on go-staticcheck 2021-06-30 14:09:24 +02:00
Tobias Lindberg a98cad01cf Merge pull request #75 from alecdoconnor/patch-3
Provide better error details
2021-06-24 08:24:58 +02:00
Tobias Lindberg e032d8b3e4 Merge pull request #74 from tobiasehlert/feature-mqtt-addition-of-power
adding of MQTT power int
2021-06-24 08:11:20 +02:00
Alec O'Connor 0b5b2fa5fe Provide better error details 2021-06-23 17:12:25 -04:00
Tobias Lindberg 991e483f48 bumping new version v1.9.0
updating CHANGELOG
2021-06-14 14:48:10 +02:00
Tobias Lindberg 6773a19bd8 removing punctuation in error message
resolve #61
2021-06-07 13:31:36 +02:00
Leland Sindt 1f8089631c allow command auth disable via API_TOKEN_DISABLE 2021-06-03 18:27:13 -05:00
Tobias Lindberg 73ed43a515 adding of MQTT power int 2021-06-01 14:07:58 +02:00
Tobias Lindberg 141b63ecb8 bumping new version v1.8.0
updating CHANGELOG
2021-06-01 10:19:05 +02:00
Tobias Lindberg c41d1a45ba Merge pull request #69 from tobiasehlert/bug-43
Remove charges and drives that have null on end_date
2021-06-01 10:07:06 +02:00
Tobias Lindberg 258e8e4e70 Merge pull request #58 from alecdoconnor/patch-4
Update Charges, Drives, and Updates API to Allow Empty Responses as Valid
2021-06-01 09:59:40 +02:00
Tobias Lindberg e874f25470 bumping new version v1.7.1
updating CHANGELOG
2021-06-01 09:55:50 +02:00
Tobias Lindberg 5aec424900 bumping new version v1.7.0
updating CHANGELOG
2021-05-20 08:15:40 +02:00
Tobias Lindberg cbe1f5892d changing if false statements and commenting out unused functions 2021-05-19 19:54:43 +02:00
Tobias Lindberg 7baecf3a61 moving defer to when error check has passed
go-staticcheck: should check returned error before deferring commandAllowListFile.Close() (SA5001)
2021-05-19 19:53:54 +02:00
Alec O'Connor 8843c64089 Update v1_TeslaMateAPICarsCharges.go
Typo
2021-05-19 13:46:31 -04:00
Tobias Lindberg a9feeee228 Merge pull request #60 from tobiasehlert/feature-10-logging-commands
Feature 10 logging commands
2021-05-19 19:36:06 +02:00
Tobias Lindberg 7754bdcc28 bumping new version v1.6.2
updating CHANGELOG
2021-05-19 19:22:35 +02:00
Tobias Lindberg ef40a91e8d adding sql when end_date is not null to charges 2021-05-19 19:10:05 +02:00
Alec O'Connor 61b2ac0967 Update v1_TeslaMateAPICarsUpdates.go
Continuing updates on Updates API
2021-05-12 17:17:35 -04:00
Alec O'Connor d65dff5aa3 Update v1_TeslaMateAPICarsDrives.go
Continuing updates on Drives API
2021-05-12 17:16:44 -04:00
Alec O'Connor ed1dc4dbb8 Update Charges API to Allow Valid Empty Response
API should fail gracefully if an empty response is sent.
Example reason: an API consumer should be able to traverse the pages until empty data is returned.

Note: currently this is not possible, since a generic error will be thrown if the data set is empty (including on a fresh install of TeslaMate) or if there is an invalid charge in the response. It's impossible to know if all data points were traversed or if an error exists on a single charge (See: https://github.com/tobiasehlert/teslamateapi/issues/43)
2021-05-12 17:13:56 -04:00
Alec O'Connor 27646b2058 Prevent fatal error when detailed charge malformed
Following up on https://github.com/tobiasehlert/teslamateapi/issues/43

*Reason*
A detailed charge is malformed if the end_date is missing in SQL. It's also possible a charge that is in progress will be missing this value as well, in which case this detailed charge isn't populated with data.

*Better Solutions* (long term)
Adjust error handling across the API:
- *Opt 1:* Instead of `ValidResponse` being a boolean, replace with `ResponseError`. Change the if statement at the bottom of each file to check for the `ResponseError`'s existence instead of `if ValidResponse {...} else {...}`. Remove all log.Fatal(err) so that the API can still return responses gracefully, and set status to 200 OK since the response will still technically be HTTP valid. Break execution of further steps and return the meaningful ResponseError in the API
- *Opt 2:* For simplicity, create a functions like this and call it (along with an early `return`) wherever a fatal error is currently used (or `ValidResponse` never set to true). Then remove `ValidResponse` entirely and adjust the `if` statement at the bottom of every API file to only run the first condition.
```
func TeslaMateAPIHandleErrorResponse(c *gin.Context, s string) {
    log.Println("[error] TeslaMateAPICarsChargesDetailsV1 " + c.Request.RequestURI + " error in execution! " + s)
    c.JSON(http.StatusOK, gin.H{"error": s})
}
func TeslaMateAPIHandleSuccessResponse(c *gin.Context, j JSONData) {
    log.Println("[info] TeslaMateAPICarsChargesDetailsV1 " + c.Request.RequestURI + " executed successful.")
    c.JSON(http.StatusOK, j)
}
```

If you're interested, I'd be happy to put together a sample PR
2021-05-10 09:54:30 -04:00
Tobias Lindberg 739f56e1be bumping new version v1.6.1
updating CHANGELOG
2021-05-10 09:41:02 +02:00
Leland Sindt 331a05e1ce SSL: true|false, FQDN -> HOST 2021-05-04 18:25:06 -05:00
Alec O'Connor 36cb82db87 Skip Malformed Rows (those missing an end_date)
*Expected*
The Charges endpoint should still return data, even if a portion of charges have corrupted data.

*How it happens*
Charges can become corrupted if Teslamate does not detect that a charge ever ended, such as if the car or Teslamate goes offline when the charging ends.

*Note*
The charging_processes table's most recent row may be missing an end_date if the charge is in progress. These charges were already being skipped in the chargingDetails endpoint. I am assuming it is safe to skip them here, since they essentially have no data until the charge finishes.

*Please Test*
- Please test that this still builds as I am not entirely familiar with Go and am unsure how to test this on my docker container.
2021-05-04 09:39:07 -04:00
Leland Sindt 6605fde6fb break out teslamate Protocol, FQDN, Port 2021-05-03 20:31:58 -05:00
Leland Sindt 5bebf85e1b rename TeslaMateAPICarsLoggingCommandV1 -> TeslaMateAPICarsLoggingV1 2021-05-03 20:29:31 -05:00
Tobias Lindberg 68a437f724 bumping new version v1.6.0
updating CHANGELOG
2021-05-03 22:33:54 +02:00
Tobias Lindberg 6022c8ef77 Revert "Update v1_TeslaMateAPICarsCharges.go" 2021-05-03 22:21:58 +02:00
Tobias Lindberg ae348eaf8e Merge pull request #39 from alecdoconnor/patch-2
Patch 2
2021-05-03 22:19:26 +02:00
Tobias Lindberg 2ff591e1fa Merge pull request #40 from alecdoconnor/patch-3
Update v1_TeslaMateAPICarsCharges.go
2021-05-03 22:16:25 +02:00
Tobias Lindberg 8f97ff281c Update v1_TeslaMateAPICarsChargesDetails.go
using NullString instead of coalesce function
2021-05-03 22:13:23 +02:00
Tobias Lindberg b3b731b0eb Merge branch 'main' into bug-8 2021-05-03 21:40:39 +02:00
Alec O'Connor bdbe229a5b Update v1_TeslaMateAPICarsCharges.go
It's possible to have incomplete charges with missing EndDate. These aren't always valid objects either, but they shouldn't prevent the Charges endpoint from providing data.
I believe this can happen when TeslaMate is offline when the charging cycle ends. I am not sure if it's also possible if the vehicle is actively charging.

Feel free to edit this PR, not sure that an empty string is the best option.
2021-05-03 13:34:11 -04:00
Alec O'Connor 08840506c9 Update v1_TeslaMateAPICarsChargesDetails.go
Missing comma. Please build and test the SQL, I'm unsure how.
2021-05-03 13:27:56 -04:00
Alec O'Connor ef67d068cc fast_charger_brand can be NULL, causes fatal error
Fatal error detected:
`sql: Scan error on column index 18, name "fast_charger_brand": converting NULL to string is unsupported`

Causes ChargeDetail API endpoint to fail. Solution was to add default string value for `fast_charger_brand`
2021-05-03 13:15:51 -04:00
Tobias Lindberg 381bcb9164 bumping new version v1.5.0
updating CHANGELOG
2021-05-03 19:08:41 +02:00
Alec O'Connor 7693581864 Convert SpeedMax and SpeedAvg in Drive (km->mi)
Already implemented in DriveDetails, logic was duplicated exactly in this pull request
2021-05-03 11:43:20 -04:00
Tobias Lindberg 38c0eb74da bumping new version v1.4.9
updating CHANGELOG
2021-05-03 13:49:04 +02:00