Skip to content

Commit 64f265e

Browse files
committed
update README with hb logo and formatting
1 parent c6a0157 commit 64f265e

2 files changed

Lines changed: 56 additions & 48 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ All notable changes to `@homebridge/plugin-ui-utils` will be documented in this
1010
- update example folder package json files
1111
- update LICENSE file to match hb repo formats
1212
- spelling and grammar in code comments
13+
- update README with hb logo and formatting
1314

1415
## v1.0.2 (2024-03-30)
1516

README.md

Lines changed: 55 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
<p align="center">
2+
<a href="https://homebridge.io"><img src="https://raw.githubusercontent.com/homebridge/branding/latest/logos/homebridge-color-round-stylized.png" height="140"></a>
3+
</p>
4+
<span align="center">
5+
6+
# Plugin UI Utils
7+
18
[![npm](https://badgen.net/npm/v/@homebridge/plugin-ui-utils)](https://www.npmjs.com/package/@homebridge/plugin-ui-utils)
29
[![npm](https://badgen.net/npm/dt/@homebridge/plugin-ui-utils)](https://www.npmjs.com/package/@homebridge/plugin-ui-utils)
310
[![Discord](https://img.shields.io/discord/432663330281226270?color=728ED5&logo=discord&label=discord)](https://discord.gg/kqNCe2D)
411

5-
# Homebridge Plugin Custom UI Utils
12+
</span>
613

714
The package assists plugin developers creating fully customisable configuration user interfaces for their plugins.
815

@@ -25,14 +32,14 @@ The package assists plugin developers creating fully customisable configuration
2532
- [Examples](#examples)
2633
- [Development](#development)
2734

28-
# Implementation
35+
## Implementation
2936

3037
A plugin's custom user interface has two main components:
3138

3239
* [User Interface](#user-interface-api) - this is the HTML / CSS / JavaScript code the users interact with
3340
* [Server](#server-api) - this is an optional server side script that provides endpoints the UI can call
3441

35-
## Project Layout
42+
### Project Layout
3643

3744
A custom UI should be published under a directory named `homebridge-ui`:
3845

@@ -55,7 +62,7 @@ homebridge-example-plugin/
5562

5663
You may customise the location of the `homebridge-ui` by setting the `customUiPath` property in the `config.schema.json`. For example: `"customUiPath": "./dist/homebridge-ui"`.
5764

58-
# User Interface API
65+
## User Interface API
5966

6067
A plugin's custom user interface is displayed inside an iframe in the settings modal, in place of the schema-generated form.
6168

@@ -96,9 +103,9 @@ Example `index.html`:
96103
</script>
97104
```
98105

99-
## Config
106+
### Config
100107

101-
### `homebridge.getPluginConfig`
108+
#### `homebridge.getPluginConfig`
102109

103110
> `homebridge.getPluginConfig(): Promise<PluginConfig[]>;`
104111
@@ -111,7 +118,7 @@ const pluginConfigBlocks = await homebridge.getPluginConfig();
111118
// [{ platform: 'ExamplePlatform', name: 'example' }]
112119
```
113120

114-
### `homebridge.updatePluginConfig`
121+
#### `homebridge.updatePluginConfig`
115122

116123
> `homebridge.updatePluginConfig(pluginConfig: PluginConfig[]): Promise<PluginConfig[]>;`
117124
@@ -140,7 +147,7 @@ const pluginConfig = [
140147
await homebridge.updatePluginConfig(pluginConfig);
141148
```
142149

143-
### `homebridge.savePluginConfig`
150+
#### `homebridge.savePluginConfig`
144151

145152
> `homebridge.savePluginConfig(): Promise<void>`
146153
@@ -158,7 +165,7 @@ await homebridge.updatePluginConfig(pluginConfig);
158165
await homebridge.savePluginConfig();
159166
```
160167

161-
### `homebridge.getPluginConfigSchema`
168+
#### `homebridge.getPluginConfigSchema`
162169

163170
> `homebridge.getPluginConfigSchema(): Promise<PluginSchema>;`
164171
@@ -168,7 +175,7 @@ Returns the plugin's config.schema.json.
168175
const schema = await homebridge.getPluginConfigSchema();
169176
```
170177

171-
### `homebridge.getCachedAccessories`
178+
#### `homebridge.getCachedAccessories`
172179

173180
> `homebridge.getCachedAccessories(): Promise<CachedAccessory[]>;`
174181
@@ -178,11 +185,11 @@ Returns the any cached accessories for the plugin
178185
const cachedAccessories = await homebridge.getCachedAccessories();
179186
```
180187

181-
## Requests
188+
### Requests
182189

183190
This allows the custom UI to make API requests to their `server.js` script.
184191

185-
### `homebridge.request`
192+
#### `homebridge.request`
186193

187194
> `homebridge.request(path: string, body?: any): Promise<any>`
188195
@@ -210,15 +217,15 @@ this.onRequest('/hello', async (payload) => {
210217
});
211218
```
212219

213-
## Toast Notifications
220+
### Toast Notifications
214221

215222
Toast notifications are the pop-up notifications displayed in the bottom right corner. A plugin's custom UI can generate custom notifications with custom content.
216223

217224
<p align="center">
218225
<img src="https://user-images.githubusercontent.com/3979615/97829910-7e97c780-1d1f-11eb-95ff-7d85d883b44c.png">
219226
</p>
220227

221-
### `homebridge.toast.success`
228+
#### `homebridge.toast.success`
222229

223230
> `homebridge.toast.success(message: string, title?: string): void`
224231
@@ -227,7 +234,7 @@ Shows a green "success" notification.
227234
* `message`: the toast content
228235
* `title`: an optional title
229236

230-
### `homebridge.toast.error`
237+
#### `homebridge.toast.error`
231238

232239
> `homebridge.toast.error(message: string, title?: string): void`
233240
@@ -236,7 +243,7 @@ Shows a red "error" notification.
236243
* `message`: the toast content
237244
* `title`: an optional title
238245

239-
### `homebridge.toast.warning`
246+
#### `homebridge.toast.warning`
240247

241248
> `homebridge.toast.warning(message: string, title?: string): void`
242249
@@ -245,7 +252,7 @@ Shows an amber "warning" notification.
245252
* `message`: the toast content
246253
* `title`: an optional title
247254

248-
### `homebridge.toast.info`
255+
#### `homebridge.toast.info`
249256

250257
> `homebridge.toast.info(message: string, title?: string): void`
251258
@@ -254,9 +261,9 @@ Shows a blue "info" notification.
254261
* `message`: the toast content
255262
* `title`: an optional title
256263

257-
## Modal
264+
### Modal
258265

259-
### `homebridge.closeSettings`
266+
#### `homebridge.closeSettings`
260267

261268
> `homebridge.closeSettings(): void`
262269
@@ -268,7 +275,7 @@ This action does not save any config changes.
268275
homebridge.closeSettings();
269276
```
270277

271-
### `homebridge.showSpinner`
278+
#### `homebridge.showSpinner`
272279

273280
> `homebridge.showSpinner(): void`
274281
@@ -285,7 +292,7 @@ await homebridge.request('/hello');
285292
homebridge.hideSpinner();
286293
```
287294

288-
### `homebridge.hideSpinner`
295+
#### `homebridge.hideSpinner`
289296

290297
> `homebridge.hideSpinner(): void`
291298
@@ -295,7 +302,7 @@ Hide the spinner / loading overlay.
295302
homebridge.hideSpinner();
296303
```
297304

298-
## Forms
305+
### Forms
299306

300307
The custom user interface allows you to create two types of forms:
301308

@@ -310,7 +317,7 @@ The custom user interface allows you to create two types of forms:
310317

311318
Developers are also able to create their own forms using HTML.
312319

313-
### `homebridge.showSchemaForm`
320+
#### `homebridge.showSchemaForm`
314321

315322
> `homebridge.showSchemaForm(): void`
316323
@@ -329,7 +336,7 @@ window.homebridge.addEventListener('configChanged', (event: MessageEvent) => {
329336
});
330337
```
331338

332-
### `homebridge.hideSchemaForm`
339+
#### `homebridge.hideSchemaForm`
333340

334341
> `homebridge.hideSchemaForm(): void`
335342
@@ -339,7 +346,7 @@ Hides the schema-generated form.
339346
homebridge.hideSchemaForm();
340347
```
341348

342-
### `homebridge.createForm`
349+
#### `homebridge.createForm`
343350

344351
> `homebridge.createForm(schema: FormSchema, data: any, submitButton?: string, cancelButton?: string): IHomebridgeUiFormHelper;`
345352
@@ -395,11 +402,11 @@ myForm.onCancel((form) => {
395402
myForm.end();
396403
```
397404

398-
## Events
405+
### Events
399406

400407
The `homebridge` object is an [EventTarget](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget), this allows you to use the browsers built in [addEventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener) and [removeEventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener) functions to subscribe and unsubscribe from events.
401408

402-
### Ready Event
409+
#### Ready Event
403410

404411
Called when the Homebridge UI has completed rendering the plugin's custom UI.
405412

@@ -409,7 +416,7 @@ homebridge.addEventListener('ready', () => {
409416
});
410417
```
411418

412-
### Custom Events
419+
#### Custom Events
413420

414421
Custom events can be pushed from the plugin's `server.js` script.
415422

@@ -427,9 +434,9 @@ The corresponding code in the `server.js` file would look like this:
427434
this.pushEvent('my-event', { some: 'data' });
428435
```
429436

430-
## Plugin / Server Information
437+
### Plugin / Server Information
431438

432-
### `homebridge.plugin`
439+
#### `homebridge.plugin`
433440

434441
> `homebridge.plugin`
435442
@@ -451,7 +458,7 @@ Is an object that contains plugin metadata.
451458
}
452459
```
453460

454-
### homebridge.serverEnv
461+
#### homebridge.serverEnv
455462

456463
> `homebridge.serverEnv`
457464
@@ -466,7 +473,7 @@ Is an object containing some server metadata
466473
}
467474
```
468475

469-
# Server API
476+
## Server API
470477

471478
To provide server API endpoints that can be called from the custom UI, a plugin must place a `server.js` file in the `homebridge-ui` directory.
472479

@@ -515,9 +522,9 @@ class UiServer extends HomebridgePluginUiServer {
515522
})();
516523
```
517524

518-
## Setup
525+
### Setup
519526

520-
### `this.ready`
527+
#### `this.ready`
521528

522529
> `this.ready(): void`
523530
@@ -527,9 +534,9 @@ Let the UI know the server is ready to accept requests.
527534
this.ready();
528535
```
529536

530-
## Request Handling
537+
### Request Handling
531538

532-
### `this.onRequest`
539+
#### `this.onRequest`
533540

534541
> `this.onRequest(path: string, fn: RequestHandler)`
535542
@@ -558,7 +565,7 @@ const response = await homebridge.request('/hello', { who: 'world' });
558565
console.log(response); // the response from the server
559566
```
560567

561-
## Request Error Handling
568+
### Request Error Handling
562569

563570
If you need to throw an error during your request, you should throw an instance of `RequestError` instead of a normal `Error`:
564571

@@ -587,9 +594,9 @@ try {
587594

588595
Uncaught errors in event handlers, or errors thrown using `new Error` will still result in the waiting promise in the UI being rejected, however the error stack trace will also be shown in the Homebridge logs which should be avoided.
589596

590-
## Push Events
597+
### Push Events
591598

592-
### `this.pushEvent`
599+
#### `this.pushEvent`
593600

594601
> `this.pushEvent(event: string, data: any)`
595602
@@ -612,9 +619,9 @@ homebridge.addEventListener('my-event', (event) => {
612619
});
613620
```
614621

615-
## Server Information
622+
### Server Information
616623

617-
### `this.homebridgeStoragePath`
624+
#### `this.homebridgeStoragePath`
618625

619626
> `this.homebridgeStoragePath: string`
620627
@@ -624,7 +631,7 @@ Returns the Homebridge instance's current storage path.
624631
const storagePath = this.homebridgeStoragePath;
625632
```
626633

627-
### `this.homebridgeConfigPath`
634+
#### `this.homebridgeConfigPath`
628635

629636
> `this.homebridgeConfigPath: string`
630637
@@ -634,7 +641,7 @@ Returns the path to the Homebridge `config.json` file:
634641
const configPath = this.homebridgeConfigPath;
635642
```
636643

637-
### `this.homebridgeUiVersion`
644+
#### `this.homebridgeUiVersion`
638645

639646
> `this.homebridgeUiVersion: string`
640647
@@ -644,38 +651,38 @@ Returns the version of the Homebridge UI:
644651
const uiVersion = this.homebridgeUiVersion;
645652
```
646653

647-
# Examples
654+
## Examples
648655

649656
* [Basic Example](./examples/basic-ui-server) - demos a minimal custom user interface, interacting with server side scripts, updating the plugin config, and using toast notifications.
650657
* [Push Events](./examples/push-events) - demos how to send push events from the server, and listen for them in the custom user interface.
651658

652659

653660
A full list of plugins that have implemented the custom user interface can be found [here](https://www.npmjs.com/package/@homebridge/plugin-ui-utils?activeTab=dependents).
654661

655-
#### homebridge-mercedesme
662+
##### homebridge-mercedesme
656663

657664
The [homebridge-mercedesme](https://github.com/SeydX/homebridge-mercedesme) plugin by [@SeydX](https://github.com/SeydX) allows users to pair their vehicle using a custom user interface:
658665

659666
<p align="center">
660667
<img src="https://raw.githubusercontent.com/SeydX/homebridge-mercedesme/beta/images/hb_mercedesme_ui.gif" width="600px">
661668
</p>
662669

663-
#### homebridge-bravia-tvos
670+
##### homebridge-bravia-tvos
664671

665672
The [homebridge-bravia-tvos](https://github.com/SeydX/homebridge-bravia-tvos) plugin by [@SeydX](https://github.com/SeydX) allows users to pair and dynamically configure a user's TV using a custom user interface:
666673

667674
<p align="center">
668675
<img src="https://user-images.githubusercontent.com/3979615/99958753-0a13ee00-2dde-11eb-95fb-69a896d37545.png" width="600px">
669676
</p>
670677

671-
#### homebridge-electra-smart
678+
##### homebridge-electra-smart
672679

673680
The [homebridge-electra-smart](https://github.com/nitaybz/homebridge-electra-smart) plugin by [nitaybz](https://github.com/nitaybz) allows users to request a OTP and enter it in exchange for an authentication token:
674681

675682
<p align="center">
676683
<img src="https://user-images.githubusercontent.com/3979615/99959242-be157900-2dde-11eb-8114-6394da2a2e14.png" width="600px">
677684
</p>
678685

679-
# Development
686+
## Development
680687

681688
For hints and tips on how to develop your custom user interface, see [DEVELOPMENT.md](./DEVELOPMENT.md).

0 commit comments

Comments
 (0)