Skip to content

Commit ebecd9f

Browse files
committed
Make titles linkable
1 parent 53c3ff3 commit ebecd9f

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

source/developers/websocket_api.markdown

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Home Assistant contains a websocket API. This API can be used to stream informat
1313

1414
- [JavaScript](https://github.com/home-assistant/home-assistant-js-websocket) - powers the frontend
1515

16-
# Server states
16+
# {% linkable_title Server states %}
1717

1818
1. Client connects
1919
2. Authentication phase starts
@@ -31,20 +31,20 @@ Home Assistant contains a websocket API. This API can be used to stream informat
3131

3232
During the command phase, the client attaches a unique identifier to each message. The server will add this identifier to each message so that the client can link each message to it's origin.
3333

34-
# Message format
34+
# {% linkable_title Message format %}
3535

3636
Each API message is a JSON serialized object containing a `type` key. After the authentication phase messages also must contain an `id`, an integer that contains the number of interactions.
3737

3838
Example of an auth message:
3939

40-
```json5
40+
```json
4141
{
4242
"type": "auth",
4343
"api_password": "supersecret"
4444
}
4545
```
4646

47-
```json5
47+
```json
4848
{
4949
"id" 5,
5050
"type":"event",
@@ -57,29 +57,29 @@ Example of an auth message:
5757
}
5858
```
5959

60-
# Authentication phase
60+
# {% linkable_title Authentication phase %}
6161

6262
When a client connects to the server, the server will test if the client is authenticated. Authentication will not be necessary if no api_password is set or if the user fulfills one of the other criteria for authentication (trusted network, password in url/header).
6363

6464
If no authentication is needed, the authentication phase will complete and the server will send an `auth_ok` message.
6565

66-
```json5
66+
```json
6767
{
6868
"type": "auth_ok"
6969
}
7070
```
7171

7272
If authentication is necessary, the server sends out `auth_required`.
7373

74-
```json5
74+
```json
7575
{
7676
"type": "auth_required"
7777
}
7878
```
7979

8080
This means that the next message from the client should be an auth message:
8181

82-
```json5
82+
```json
8383
{
8484
"type": "auth",
8585
"api_password": "supersecret"
@@ -88,26 +88,26 @@ This means that the next message from the client should be an auth message:
8888

8989
If the client supplies valid authentication, the authentication phase will complete by the server sending the `auth_ok` message:
9090

91-
```json5
91+
```json
9292
{
9393
"type": "auth_ok"
9494
}
9595
```
9696

9797
If the data is incorrect, the server will reply with `auth_invalid` message and disconnect the session.
9898

99-
```json5
99+
```json
100100
{
101101
"type": "auth_invalid",
102102
"message": "Invalid password"
103103
}
104104
```
105105

106-
# Command phase
106+
# {% linkable_title Command phase %}
107107

108108
During this phase the client can give commands to the server. The server will respond to each command with a `result` message indicating when the command is done and if it was successful.
109109

110-
```json5
110+
```json
111111
{
112112
"id": 6.
113113
"type": "result",
@@ -117,11 +117,11 @@ During this phase the client can give commands to the server. The server will re
117117
}
118118
```
119119

120-
## Subscribe to events
120+
## {% linkable_title Subscribe to events %}
121121

122122
The command `subscribe_events` will subscribe your client to the event bus. You can either listen to all events or to a specific event type. If you want to listen to multiple event types, you will have to send multiple `subscribe_events` commands.
123123

124-
```json5
124+
```json
125125
{
126126
"id": 18,
127127
"type": "subscribe_events",
@@ -132,7 +132,7 @@ The command `subscribe_events` will subscribe your client to the event bus. You
132132

133133
The server will respond with a result message to indicate that the subscription is active.
134134

135-
```json5
135+
```json
136136
{
137137
"id": 18,
138138
"type": "result",
@@ -143,7 +143,7 @@ The server will respond with a result message to indicate that the subscription
143143

144144
For each event that matches, the server will send a message of type `event`. The `id` in the message will point at the original `id` of the `listen_event` command.
145145

146-
```json5
146+
```json
147147
{
148148
"id": 18,
149149
"type":"event",
@@ -190,11 +190,11 @@ For each event that matches, the server will send a message of type `event`. The
190190
}
191191
```
192192

193-
## Unsubscribing from events
193+
## {% linkable_title Unsubscribing from events %}
194194

195195
You can unsubscribe from previously created subscription events. Pass the id of the original subscription command as value to the subscription field.
196196

197-
```json5
197+
```json
198198
{
199199
"id": 19,
200200
"type": "unsubscribe_events",
@@ -204,7 +204,7 @@ You can unsubscribe from previously created subscription events. Pass the id of
204204

205205
The server will respond with a result message to indicate that unsubscribing was successful.
206206

207-
```json5
207+
```json
208208
{
209209
"id": 19,
210210
"type": "result",
@@ -214,7 +214,7 @@ The server will respond with a result message to indicate that unsubscribing was
214214
```
215215

216216

217-
## Calling a service
217+
## {% linkable_title Calling a service %}
218218

219219
This will call a service in Home Assistant. Right now there is no return value. The client can listen to `state_changed` events if it is interested in changed entities as a result of a service call.
220220

@@ -233,7 +233,7 @@ This will call a service in Home Assistant. Right now there is no return value.
233233

234234
The server will indicate with a message indicating that the service is done executing.
235235

236-
```json5
236+
```json
237237
{
238238
"id": 24,
239239
"type": "result",
@@ -242,11 +242,11 @@ The server will indicate with a message indicating that the service is done exec
242242
}
243243
```
244244

245-
## Fetching states
245+
## {% linkable_title Fetching states %}
246246

247247
This will get a dump of all the current states in Home Assistant.
248248

249-
```json5
249+
```json
250250
{
251251
"id": 19,
252252
"type": "get_states"
@@ -255,20 +255,20 @@ This will get a dump of all the current states in Home Assistant.
255255

256256
The server will respond with a result message containing the states.
257257

258-
```json5
258+
```json
259259
{
260260
"id": 19,
261261
"type": "result",
262262
"success": true,
263-
"result": [ ]
263+
"result": [ ... ]
264264
}
265265
```
266266

267-
## Fetching config
267+
## {% linkable_title Fetching config %}
268268

269269
This will get a dump of the current config in Home Assistant.
270270

271-
```json5
271+
```json
272272
{
273273
"id": 19,
274274
"type": "get_config"
@@ -277,20 +277,20 @@ This will get a dump of the current config in Home Assistant.
277277

278278
The server will respond with a result message containing the config.
279279

280-
```json5
280+
```json
281281
{
282282
"id": 19,
283283
"type": "result",
284284
"success": true,
285-
"result": { }
285+
"result": { ... }
286286
}
287287
```
288288

289-
## Fetching services
289+
## {% linkable_title Fetching services %}
290290

291291
This will get a dump of the current services in Home Assistant.
292292

293-
```json5
293+
```json
294294
{
295295
"id": 19,
296296
"type": "get_config"
@@ -299,20 +299,20 @@ This will get a dump of the current services in Home Assistant.
299299

300300
The server will respond with a result message containing the services.
301301

302-
```json5
302+
```json
303303
{
304304
"id": 19,
305305
"type": "result",
306306
"success": true,
307-
"result": { }
307+
"result": { ... }
308308
}
309309
```
310310

311-
## Fetching panels
311+
## {% linkable_title Fetching panels %}
312312

313313
This will get a dump of the current registered panels in Home Assistant.
314314

315-
```json5
315+
```json
316316
{
317317
"id": 19,
318318
"type": "get_panels"
@@ -321,16 +321,16 @@ This will get a dump of the current registered panels in Home Assistant.
321321

322322
The server will respond with a result message containing the current registered panels.
323323

324-
```json5
324+
```json
325325
{
326326
"id": 19,
327327
"type": "result",
328328
"success": true,
329-
"result": [ ]
329+
"result": [ ... ]
330330
}
331331
```
332332

333-
# Error handling
333+
# {% linkable_title Error handling %}
334334

335335
If an error occurs, the `success` key in the `result` message will be set to `false`. It will contain an `error` key containing an object with two keys: `code` and `message`.
336336

@@ -340,7 +340,7 @@ If an error occurs, the `success` key in the `result` message will be set to `fa
340340
| 2 | Received message is not in expected format (voluptuous validation error).
341341
| 3 | Requested item cannot be found
342342

343-
```json5
343+
```json
344344
{
345345
"id": 12,
346346
"type":"result",

0 commit comments

Comments
 (0)