Add bluelink api back in (#741)

This commit is contained in:
andig 2021-03-10 09:25:47 +01:00 • committed by GitHub
parent 32032e94a7
commit 8b0384e44e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 2053 additions and 4 deletions

View file

@ -245,8 +245,8 @@ Available vehicle remote interface implementations are:
- `bmw`: BMW (i3)
- `citroen`, `opel`, `peugeot`: Follow this [tutorial](https://github.com/flobz/psa_car_controller) to obtain client credentials for PSA.
- `ford`: Ford (Kuga, Mustang)
- `kia`: Kia (Bluelink vehicles like Soul 2019) **temporarily removed due to incompatible api changes**
- `hyundai`: Hyundai (Bluelink vehicles like Kona or Ioniq) **temporarily removed due to incompatible api changes**
- `kia`: Kia (Bluelink vehicles like Soul 2019)
- `hyundai`: Hyundai (Bluelink vehicles like Kona or Ioniq)
- `nissan`: Nissan (Leaf)
- `tesla`: Tesla (any model)
- `renault`: Renault (all ZE models: Zoe, Twingo Electric, Master, Kangoo)

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -121,6 +121,10 @@ func New(log *util.Logger, user, password string, cache time.Duration, config Co
// Credits to https://openwb.de/forum/viewtopic.php?f=5&t=1215&start=10#p11877
func (v *API) stamp() string {
return stamps.New(v.config.CCSPApplicationID)
}
func (v *API) getDeviceID() (string, error) {
uniID, _ := uuid.NewUUID()
data := map[string]interface{}{
@ -133,6 +137,7 @@ func (v *API) getDeviceID() (string, error) {
"ccsp-service-id": v.config.CCSPServiceID,
"Content-type": "application/json;charset=UTF-8",
"User-Agent": "okhttp/3.10.0",
"Stamp": v.stamp(),
}
var resp response
@ -246,6 +251,7 @@ func (v *API) getVehicles(accToken, did string) (string, error) {
"ccsp-application-id": v.config.CCSPApplicationID,
"offset": "1",
"User-Agent": "okhttp/3.10.0",
"Stamp": v.stamp(),
}
req, err := request.New(http.MethodGet, v.config.URI+v.config.Vehicles, nil, headers)
@ -304,6 +310,7 @@ func (v *API) getStatus() (response, error) {
"ccsp-application-id": v.config.CCSPApplicationID,
"offset": "1",
"User-Agent": "okhttp/3.10.0",
"Stamp": v.stamp(),
}
uri := fmt.Sprintf(v.config.URI+v.config.Status, v.auth.vehicleID)

View file

@ -0,0 +1,42 @@
package bluelink
import (
"bufio"
_ "embed" // embedded files
"math/rand"
"strings"
)
//go:embed 693a33fa-c117-43f2-ae3b-61a02d24f417
var kia string
//go:embed 99cfff84-f4e2-4be8-a5ed-e5b755eb6581
var hyundai string
// Stamps collects stamps for a single brand
type Stamps map[string][]string
var stamps = Stamps{
"693a33fa-c117-43f2-ae3b-61a02d24f417": unpack(kia),
"99cfff84-f4e2-4be8-a5ed-e5b755eb6581": unpack(hyundai),
}
func unpack(source string) (res []string) {
scanner := bufio.NewScanner(strings.NewReader(source))
for scanner.Scan() {
res = append(res, scanner.Text())
}
if err := scanner.Err(); err != nil {
panic(err)
}
return
}
// New creates a new stamp
func (s Stamps) New(id string) string {
source, ok := s[id]
if !ok {
panic(id)
}
return source[rand.Intn(len(source))]
}

View file

@ -15,7 +15,7 @@ type Hyundai struct {
}
func init() {
// registry.Add("hyundai", NewHyundaiFromConfig)
registry.Add("hyundai", NewHyundaiFromConfig)
}
// NewHyundaiFromConfig creates a new Vehicle

View file

@ -15,7 +15,7 @@ type Kia struct {
}
func init() {
// registry.Add("kia", NewKiaFromConfig)
registry.Add("kia", NewKiaFromConfig)
}
// NewKiaFromConfig creates a new Vehicle