Skip to content

Commit

Permalink
Improved README.md example
Browse files Browse the repository at this point in the history
  • Loading branch information
WesSouza committed Dec 31, 2023
1 parent 40f1066 commit 16f4887
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions packages/lgtv-ip-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,26 @@ yarn add lgtv-ip-control

Here's a very basic example of how to control the TV:

```ts
import { LGTV } from 'lgtv-ip-control';
```js
import { Inputs, LGTV } from 'lgtv-ip-control';

const tv = new LGTV('192.168.1.100', '1a:2b:3c:4d:5e:6f', 'KEY1C0DE');
const lgtv = new LGTV('192.168.1.100', '1a:2b:3c:4d:5e:6f', 'KEY1C0DE');

tv.connect()
lgtv
.connect()
.then(async () => {
console.log('Disconnect now');
await new Promise((resolve) => setTimeout(resolve, 5000));
console.log('Unmutting...');
await tv.setVolumeMute(false);
console.log('Setting volume to 15...');
await tv.setVolume(50);
await lgtv.setVolumeMute(false);
console.log('Select HDMI1 input...');
await lgtv.setInput(Inputs.hdmi1);
console.log('Done!');
})
.catch(console.error);
// Log any errors
.catch(console.error)
// Tries disconnecting once done
.finally(() => lgtv.disconnect());
```

To use `import`, you need to make sure to save the file as `.mjs` or to specify `"type": "module"` on your `package.json`. [Learn more about Node.js' support for ESM.](https://nodejs.org/api/esm.html)
Expand All @@ -61,7 +67,7 @@ const { LGTV } = require('lgtv-ip-control');

Returns a new instance to control a TV.

```ts
```js
const lgtv = new LGTV(
/**
* TV IP Address
Expand Down Expand Up @@ -96,15 +102,15 @@ Connects to the TV using TCP.

Required before sending any commands.

```ts
```js
await lgtv.connect();
```

### `.disconnect(): Promise<void>`

Disconnects from the TV.

```ts
```js
await lgtv.disconnect();
```

Expand All @@ -114,47 +120,47 @@ Gets the current app. May be one of the `Apps` enum or an arbitrary string if
the app type is unknown. Might return `null` if the TV is powered off but still
responding.

```ts
```js
const currentApp = await lgtv.getCurrentApp();
```

### `.getCurrentVolume(): Promise<number>`

Gets the current volume as an integer from `0` to `100`.

```ts
```js
const currentVolume = await lgtv.getCurrentVolume();
```

### `.getIpControlState(): Promise<boolean>`

Gets the ip control state.

```ts
```js
const ipControlState = await lgtv.getIpControlState();
```

### `.getMacAddress(type: 'wired' | 'wifi'): Promise<string>`

Gets the MAC address by network interface.

```ts
```js
const macAddress = await lgtv.getMacAddress('wired');
```

### `.getMuteState(): Promise<boolean>`

Gets the mute state.

```ts
```js
const muteState = await lgtv.getMuteState();
```

### `.powerOff(): Promise<void>`

Powers the TV off.

```ts
```js
await lgtv.powerOff();
```

Expand All @@ -163,7 +169,7 @@ await lgtv.powerOff();
Powers the TV on, using Wake On Lan. Requires MAC address to be set when
creating the `LGTV` instance.

```ts
```js
lgtv.powerOn();
```

Expand All @@ -173,15 +179,15 @@ Powers the TV on, using Wake On Lan, and connects to it. Requires MAC address to
be set when creating the `LGTV` instance. Returns a promise that resolves once
the connection is established, or rejects after a number of retries.

```ts
```js
await lgtv.powerOnAndConnect();
```

### `.sendKey(key: Keys): Promise<void>`

Sends a `key`, as if it was pressed on the TV remote control.

```ts
```js
await lgtv.sendKey(Keys.menu);
```

Expand All @@ -192,7 +198,7 @@ See [`Keys`](#Keys) for available keys.
Sets the current energy saving level. Note that `screenOff` is known not to
work for some models.

```ts
```js
await lgtv.setEnergySaving(EnergySavingLevels.maximum);
```

Expand All @@ -202,7 +208,7 @@ See [`EnergySavingLevels`](#EnergySavingLevels) for available levels.

Sets the current TV input.

```ts
```js
await lgtv.setInput(Inputs.hdmi1);
```

Expand All @@ -212,15 +218,15 @@ See [`Inputs`](#Inputs) for available inputs.

Sets the volume level as an integer from `0` to `100`.

```ts
```js
await lgtv.setVolume(15);
```

### `.setVolumeMute(isMuted: boolean): Promise<void>`

Sets the volume mute state.

```ts
```js
await lgtv.setVolumeMute(false);
```

Expand All @@ -230,7 +236,7 @@ Sets the current screen mute mode. This can be used to either completely blank
the screen or just blank the video feed while leaving the OSD visible.
Returns a promise.

```ts
```js
await lgtv.setScreenMute(ScreenMuteModes.screenmuteon);
```

Expand Down

0 comments on commit 16f4887

Please sign in to comment.