Skip to content

Commit 909eac2

Browse files
committed
Add Step 4 and QR
1 parent bc2d49a commit 909eac2

File tree

6 files changed

+243
-34
lines changed

6 files changed

+243
-34
lines changed

app/pages/index.vue

Lines changed: 108 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ useSeoMeta({
1010
ogDescription: page.value.description,
1111
});
1212
13+
const toast = useToast();
1314
const pem = useState("publicKey", () => "");
1415
1516
const id = useState("id", () => Math.random().toString(36).substring(2, 7));
@@ -25,12 +26,61 @@ const upload = () =>
2526
$fetch("/api/create", {
2627
method: "POST",
2728
body: { id: id.value, pem: pem.value },
28-
}).then(() =>
29-
window.open(
30-
`https://${id.value}.fleetkey.cc/.well-known/appspecific/com.tesla.3p.public-key.pem`,
31-
"_blank",
32-
),
29+
}).then(
30+
({ success, error }) =>
31+
toast.add(
32+
success
33+
? {
34+
title: "Success",
35+
color: "green",
36+
}
37+
: {
38+
title: error,
39+
color: "red",
40+
},
41+
),
42+
() =>
43+
toast.add({
44+
title: "Server Error",
45+
color: "red",
46+
}),
3347
);
48+
49+
const clientId = useState("clientId", () => "");
50+
const clientSecret = useState("clientSecret", () => "");
51+
const loading = useState("loading", () => "");
52+
const register = (region) => {
53+
loading.value = region;
54+
return $fetch("/api/register", {
55+
method: "POST",
56+
body: {
57+
id: id.value,
58+
clientId: clientId.value,
59+
clientSecret: clientSecret.value,
60+
region,
61+
},
62+
})
63+
.then(
64+
({ success, error }) =>
65+
toast.add(
66+
success
67+
? {
68+
title: "Success",
69+
color: "green",
70+
}
71+
: {
72+
title: error,
73+
color: "red",
74+
},
75+
),
76+
() =>
77+
toast.add({
78+
title: "Server Error",
79+
color: "red",
80+
}),
81+
)
82+
.finally(() => (loading.value = ""));
83+
};
3484
</script>
3585

3686
<template>
@@ -68,11 +118,11 @@ const upload = () =>
68118
</ULandingHero>
69119

70120
<ULandingCTA
71-
:title="`Your origin domain is https://${id}.fleetkey.cc`"
121+
:title="`Your unique origin domain is https://${id}.fleetkey.cc`"
72122
card
73123
/>
74124
<ULandingSection
75-
title="Step 2"
125+
title="Step 1 & 2"
76126
:description="`Create a Tesla Fleet application and set its origin to https://${id}.fleetkey.cc, and redirect to https://my.home-assistant.io/redirect/oauth.`"
77127
>
78128
<UButton
@@ -88,19 +138,18 @@ const upload = () =>
88138
>
89139
<div>
90140
<div>
91-
To generate a public key use
141+
First generate a private key. This needs to be placed in your Home
142+
Assistant config directory for command signing.
92143
<br />
93144
<span class="font-mono font-bold">
94-
openssl ecparam -name prime256v1 -genkey -noout -out private-key.pem
145+
openssl ecparam -name prime256v1 -genkey -noout -out tesla_fleet.key
95146
</span>
96-
<br />
97-
then
147+
<br /><br />
148+
Then generate a public key. This needs to be pasted below.
98149
<br />
99150
<span class="font-mono font-bold">
100-
openssl ec -in private-key.pem -pubout -out public-key.pem
151+
openssl ec -in tesla_fleet.key -pubout -out public_key.pem
101152
</span>
102-
<br />
103-
then paste the public key contents below.
104153
</div>
105154

106155
<UTextarea
@@ -123,13 +172,52 @@ m5+vb6BWO6+bItnWq3dO5zjyFEi7N1RCigc9hgKtWPMZSLBi9rvoepv7fQ==
123172
</ULandingSection>
124173
<ULandingSection
125174
title="Step 4"
126-
description="Generate a partner authentication token and use it to call the register endpoint to complete registration with Fleet API."
127-
:links="{
128-
label: 'Documentation',
129-
to: 'https://developer.tesla.com/docs/fleet-api/getting-started/what-is-fleet-api#step-3-generate-a-public-private-key-pair',
130-
}"
175+
description="Generate a partner authentication token and use it to call the register endpoint to complete registration with Fleet API. You can run these commands manually if you prefer, however these details are not stored."
131176
>
132-
More on this step coming soon
177+
<div class="flex gap-4 flex-col">
178+
<UFormGroup label="Client ID">
179+
<UInput placeholder="abc-123" v-model="clientId" />
180+
</UFormGroup>
181+
<UFormGroup label="Client Secret">
182+
<UInput placeholder="secret-password" v-model="clientSecret" />
183+
</UFormGroup>
184+
<div class="flex gap-4 w-full">
185+
<UButton
186+
class="flex-1"
187+
label="Register in North America & Asia-Pacific"
188+
block
189+
:loading="loading == 'na'"
190+
:disabled="!!loading || !clientId || !clientSecret"
191+
@click="register('na')"
192+
/>
193+
<UButton
194+
class="flex-1"
195+
label="Register in Europe, Middle East & Africa"
196+
block
197+
:loading="loading == 'eu'"
198+
:disabled="!!loading || !clientId || !clientSecret"
199+
@click="register('eu')"
200+
/>
201+
</div>
202+
</div>
203+
</ULandingSection>
204+
<ULandingSection
205+
title="Virtual key"
206+
:description="`Install your virtual key with the Tesla App by scanning or touching the QR code.`"
207+
>
208+
<NuxtLink :to="`https://tesla.com/_ak/${id}.fleetkey.cc`" target="_blank">
209+
<Qrcode
210+
:value="`https://tesla.com/_ak/${id}.fleetkey.cc`"
211+
style="max-height: 20em; margin: 0 auto"
212+
/>
213+
</NuxtLink>
133214
</ULandingSection>
215+
<NuxtLink to="https://teslemetry.com" target="_blank">
216+
<ULandingCTA
217+
title="Is this too hard or confusing?"
218+
description="Teslemetry is the easy way to get real-time data into Home Assistant. Click here to check it out."
219+
/>
220+
</NuxtLink>
221+
<UNotifications :timeout="30000" pause-timeout-on-hover />
134222
</div>
135223
</template>

nuxt.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default defineNuxtConfig({
99
"@nuxt/image",
1010
"@nuxt/ui",
1111
"@nuxthub/core",
12+
"nuxt-qrcode",
1213
],
1314

1415
hub: {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"devDependencies": {
2525
"@nuxt/eslint": "^0.7.4",
2626
"eslint": "^9.17.0",
27+
"nuxt-qrcode": "^0.4.1",
2728
"vue-tsc": "^2.2.0",
2829
"wrangler": "^3.99.0"
2930
},

pnpm-lock.yaml

Lines changed: 87 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)