Skip to content

Commit

Permalink
Implement screen mute functionality (#90)
Browse files Browse the repository at this point in the history
* Implement screen mute functionality.

* Screen mute converted to new API.
  • Loading branch information
jadoc authored Dec 16, 2023
1 parent 1aa744a commit 372f7c0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,18 @@ Sets the volume mute state.
await lgtv.setVolumeMute(false);
```

### `.setScreenMute(mode: ScreenMuteModes): Promise<void>`

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
await lgtv.setScreenMute(ScreenMuteModes.screenmuteon);
```

See [`ScreenMuteModes`](#ScreenMuteModes) for available modes.

## Available Lists

### EnergySavingLevels
Expand Down Expand Up @@ -300,6 +312,14 @@ await lgtv.setVolumeMute(false);
| volumeUp | Volume Up |
| yellowButton | Yellow Button |

### ScreenMuteModes

| Key | Effect |
| ------------ | ------------------------ |
| screenMuteOn | Blank screen |
| videoMuteOn | Blank video, OSD visible |
| allMuteOff | Normal Operation |

## Development

Install
Expand Down
6 changes: 6 additions & 0 deletions src/classes/LGTV.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Inputs,
Keys,
PictureModes,
ScreenMuteModes,
} from '../constants/TV.js';
import { LGEncryption } from './LGEncryption.js';
import { TinySocket } from './TinySocket.js';
Expand Down Expand Up @@ -104,6 +105,11 @@ export class LGTV {
throwIfNotOK(await this.sendCommand(`KEY_ACTION ${key}`));
}

async setScreenMute(mode: ScreenMuteModes) {
assert(Object.values(ScreenMuteModes).includes(mode), 'mode must be valid');
throwIfNotOK(await this.sendCommand(`SCREEN_MUTE ${mode}`));
}

async setEnergySaving(level: EnergySavingLevels): Promise<void> {
assert(
Object.values(EnergySavingLevels).includes(level),
Expand Down
6 changes: 6 additions & 0 deletions src/constants/TV.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,9 @@ export enum PictureModes {
sports = 'sports',
vivid = 'vivid',
}

export enum ScreenMuteModes {
screenMuteOn = 'screenmuteon',
videoMuteOn = 'videomuteon',
allMuteOff = 'allmuteoff',
}
14 changes: 14 additions & 0 deletions test/LGTV.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Inputs,
Keys,
PictureModes,
ScreenMuteModes,
} from '../src/constants/TV.js';

const CRYPT_KEY = 'M9N0AZ62';
Expand Down Expand Up @@ -188,6 +189,19 @@ describe.each([
else await expect(actual).resolves.not.toThrow();
});

it.each([
{ mode: ScreenMuteModes.screenMuteOn, error: false },
{ mode: 'foobar', error: true },
])('sets picture mode: $mode', async ({ mode, error }) => {
let mocking: Promise<void> | null = null;
if (!error) mocking = mockResponse(`SCREEN_MUTE ${mode}`, 'OK');
await testTV.connect();
const actual = testTV.setScreenMute(mode as ScreenMuteModes);
if (!error) await expect(mocking).resolves.not.toThrow();
if (error) await expect(actual).rejects.toThrow();
else await expect(actual).resolves.not.toThrow();
});

it.each([
{ level: EnergySavingLevels.maximum, error: false },
{ level: 'foobar', error: true },
Expand Down

0 comments on commit 372f7c0

Please sign in to comment.