philtv-js
Version:
A simple library to pair and interact with Philips TV
339 lines (332 loc) • 15 kB
TypeScript
import { g as getDeviceObject, P as PhilTVApiParams, F as FlatNode } from './index-C4ZF9Z0-.js';
import * as urllib from 'urllib';
import { HttpClient, RequestOptions } from 'urllib';
import { J as JOINTSPACE_CONSTANTS } from './jointspace-CgodV7lK.js';
type InputKeys = (typeof JOINTSPACE_CONSTANTS.inputKeys)[number];
type AmbilightFollowVideoMode = (typeof JOINTSPACE_CONSTANTS.ambilight.followVideoMode)[number] | string;
type AmbilightFollowAudioMode = (typeof JOINTSPACE_CONSTANTS.ambilight.followAudioMode)[number];
type AmbilightChangeBrightnessAvailableValues = (typeof JOINTSPACE_CONSTANTS.ambilight.ambilightChangeBrightnessAvailableValues)[number];
type AmbilightSetBrightnessAvailableValues = (typeof JOINTSPACE_CONSTANTS.ambilight.ambilightBrightnessAvailableValues)[number];
declare function getInformationSystem(apiUrl: string): Promise<readonly [Error, undefined] | readonly [undefined, {
readonly apiVersion: any;
readonly systemFeatures: any;
readonly isSecureTransport: boolean;
readonly isGoodPairingType: boolean;
readonly isReady: boolean;
}]>;
type PhilTVPairingParams = {
/**
* The IP address of the Philips TV to connect to.
* Without the protocol and port number.
* @example 192.168.1.2
*/
tvIp: string;
/**
* The port number of the Philips TV API to connect to.
* Default is `1926`.
*/
apiPort?: number;
};
declare class PhilTVPairing {
private tvBase;
readonly deviceId: string;
readonly apiUrls: {
secure: string;
};
readonly deviceInformation: ReturnType<typeof getDeviceObject>;
private httpClients;
private startPairingResponse;
private credentials;
private apiVersion;
pairingRequestUrl: string;
constructor(initParams: PhilTVPairingParams);
init(): Promise<readonly [Error | undefined, {
readonly apiVersion: any;
readonly systemFeatures: any;
readonly isSecureTransport: boolean;
readonly isGoodPairingType: boolean;
readonly isReady: boolean;
} | undefined]>;
startPairing(): Promise<readonly [Error, undefined] | readonly [undefined, {
authKey: any;
authTimestamp: any;
timeout: any;
}]>;
completePairing(pin: string): Promise<readonly [Error, undefined] | readonly [undefined, {
user: string;
password: any;
apiUrl: string;
apiVersion: number;
fullApiUrl: string;
}]>;
}
type GetHttpDigestClient = {
user: string;
password: string;
baseUrl: string;
options?: {
rejectUnauthorized?: boolean;
};
};
declare function getHttpDigestClient(config: GetHttpDigestClient): {
client: HttpClient;
request: (url: string, reqOptions?: RequestOptions) => Promise<readonly [Error, undefined, urllib.HttpClientResponse<any>] | readonly [Error, undefined, undefined] | readonly [undefined, any, {
readonly data: any;
readonly opaque: unknown;
readonly status: number;
readonly statusCode: number;
readonly statusText: string;
readonly headers: urllib.IncomingHttpHeaders;
readonly url: string;
readonly redirected: boolean;
readonly requestUrls: string[];
readonly res: urllib.RawResponseWithMeta;
readonly ok: true;
}]>;
};
/**
* Class representing the base API for interacting with Philips TV.
*/
declare class PhilTVApiBase {
protected digestClient: ReturnType<typeof getHttpDigestClient>;
constructor(params: PhilTVApiParams);
/**
* Gets the digest client instance.
*
* @returns The digest client instance used for API requests.
*/
getDigestClient(): {
client: urllib.HttpClient;
request: (url: string, reqOptions?: urllib.RequestOptions) => Promise<readonly [Error, undefined, urllib.HttpClientResponse<any>] | readonly [Error, undefined, undefined] | readonly [undefined, any, {
readonly data: any;
readonly opaque: unknown;
readonly status: number;
readonly statusCode: number;
readonly statusText: string;
readonly headers: urllib.IncomingHttpHeaders;
readonly url: string;
readonly redirected: boolean;
readonly requestUrls: string[];
readonly res: urllib.RawResponseWithMeta;
readonly ok: true;
}]>;
};
protected renderResponse(error: Error | undefined, body: unknown | undefined): readonly [Error | undefined, unknown];
getMenuStructure(opts?: {
flat?: boolean;
}): Promise<readonly [undefined, any, {
readonly data: any;
readonly opaque: unknown;
readonly status: number;
readonly statusCode: number;
readonly statusText: string;
readonly headers: urllib.IncomingHttpHeaders;
readonly url: string;
readonly redirected: boolean;
readonly requestUrls: string[];
readonly res: urllib.RawResponseWithMeta;
readonly ok: true;
}] | readonly [Error, undefined]>;
getMenuStructureItem(context: string | undefined, nodeId: number | undefined): Promise<[Error, undefined] | [undefined, FlatNode]>;
getMenuStructureItemByContext(context: string): Promise<[Error, undefined] | [undefined, FlatNode]>;
getMenuStructureItemByNodeId(nodeId: number): Promise<[Error, undefined] | [undefined, FlatNode]>;
setMenuItemSetting(item: FlatNode | undefined, value: any): Promise<readonly [Error, undefined] | readonly [Error | undefined, {
status: number | undefined;
statusText: string | undefined;
body: any;
item: FlatNode;
originalResponse: urllib.HttpClientResponse<any> | {
readonly data: any;
readonly opaque: unknown;
readonly status: number;
readonly statusCode: number;
readonly statusText: string;
readonly headers: urllib.IncomingHttpHeaders;
readonly url: string;
readonly redirected: boolean;
readonly requestUrls: string[];
readonly res: urllib.RawResponseWithMeta;
readonly ok: true;
} | undefined;
}]>;
protected handleSetMenuItemSetting(contextName: string, value: unknown): Promise<readonly [Error | undefined, {
status: number | undefined;
statusText: string | undefined;
body: any;
item: FlatNode;
originalResponse: urllib.HttpClientResponse<any> | {
readonly data: any;
readonly opaque: unknown;
readonly status: number;
readonly statusCode: number;
readonly statusText: string;
readonly headers: urllib.IncomingHttpHeaders;
readonly url: string;
readonly redirected: boolean;
readonly requestUrls: string[];
readonly res: urllib.RawResponseWithMeta;
readonly ok: true;
} | undefined;
} | undefined]>;
}
declare class PhilTVApi extends PhilTVApiBase {
getSystem(): Promise<readonly [Error | undefined, unknown] | readonly [undefined, any]>;
setAmbilightBrightness(brightness: AmbilightSetBrightnessAvailableValues): Promise<readonly [Error | undefined, unknown]>;
changeAmbilightBrightness(move: AmbilightChangeBrightnessAvailableValues): Promise<readonly [Error | undefined, unknown]>;
increaseAmbilightBrightness(): Promise<readonly [Error | undefined, unknown]>;
decreaseAmbilightBrightness(): Promise<readonly [Error | undefined, unknown]>;
getAmbilightConfiguration(): Promise<readonly [Error, undefined, urllib.HttpClientResponse<any>] | readonly [Error, undefined, undefined] | readonly [undefined, any, {
readonly data: any;
readonly opaque: unknown;
readonly status: number;
readonly statusCode: number;
readonly statusText: string;
readonly headers: urllib.IncomingHttpHeaders;
readonly url: string;
readonly redirected: boolean;
readonly requestUrls: string[];
readonly res: urllib.RawResponseWithMeta;
readonly ok: true;
}]>;
getAmbilightBrightnessInformation(): Promise<readonly [Error | undefined, unknown]>;
getAmbilightBrightnessValue(): Promise<readonly [Error | undefined, number]>;
getAmbilightMode(): Promise<readonly [Error, undefined, urllib.HttpClientResponse<any>] | readonly [Error, undefined, undefined] | readonly [undefined, any, {
readonly data: any;
readonly opaque: unknown;
readonly status: number;
readonly statusCode: number;
readonly statusText: string;
readonly headers: urllib.IncomingHttpHeaders;
readonly url: string;
readonly redirected: boolean;
readonly requestUrls: string[];
readonly res: urllib.RawResponseWithMeta;
readonly ok: true;
}]>;
getAmbilightFullInformation(): Promise<readonly [Error | undefined, {
configuration: any;
mode: any;
brightness: unknown;
cached: any;
ambiHue: any;
}]>;
protected setAmbilightCurrentConfiguration(options: Record<any, any>): Promise<readonly [Error, undefined, urllib.HttpClientResponse<any>] | readonly [Error, undefined, undefined] | readonly [undefined, any, {
readonly data: any;
readonly opaque: unknown;
readonly status: number;
readonly statusCode: number;
readonly statusText: string;
readonly headers: urllib.IncomingHttpHeaders;
readonly url: string;
readonly redirected: boolean;
readonly requestUrls: string[];
readonly res: urllib.RawResponseWithMeta;
readonly ok: true;
}]>;
setAmbilightFollowVideoMode(mode: AmbilightFollowVideoMode): Promise<readonly [Error, undefined, urllib.HttpClientResponse<any>] | readonly [Error, undefined, undefined] | readonly [undefined, any, {
readonly data: any;
readonly opaque: unknown;
readonly status: number;
readonly statusCode: number;
readonly statusText: string;
readonly headers: urllib.IncomingHttpHeaders;
readonly url: string;
readonly redirected: boolean;
readonly requestUrls: string[];
readonly res: urllib.RawResponseWithMeta;
readonly ok: true;
}] | readonly [Error | undefined, unknown]>;
setAmbilightFollowAudioMode(mode: AmbilightFollowAudioMode): Promise<readonly [Error, undefined, urllib.HttpClientResponse<any>] | readonly [Error, undefined, undefined] | readonly [undefined, any, {
readonly data: any;
readonly opaque: unknown;
readonly status: number;
readonly statusCode: number;
readonly statusText: string;
readonly headers: urllib.IncomingHttpHeaders;
readonly url: string;
readonly redirected: boolean;
readonly requestUrls: string[];
readonly res: urllib.RawResponseWithMeta;
readonly ok: true;
}] | readonly [Error | undefined, unknown]>;
setAmbilightMode(mode: 'manual' | 'internal' | 'expert'): Promise<readonly [Error, undefined, urllib.HttpClientResponse<any>] | readonly [Error, undefined, undefined] | readonly [undefined, any, {
readonly data: any;
readonly opaque: unknown;
readonly status: number;
readonly statusCode: number;
readonly statusText: string;
readonly headers: urllib.IncomingHttpHeaders;
readonly url: string;
readonly redirected: boolean;
readonly requestUrls: string[];
readonly res: urllib.RawResponseWithMeta;
readonly ok: true;
}]>;
getAmbilightCached(): Promise<readonly [Error, undefined, urllib.HttpClientResponse<any>] | readonly [Error, undefined, undefined] | readonly [undefined, any, {
readonly data: any;
readonly opaque: unknown;
readonly status: number;
readonly statusCode: number;
readonly statusText: string;
readonly headers: urllib.IncomingHttpHeaders;
readonly url: string;
readonly redirected: boolean;
readonly requestUrls: string[];
readonly res: urllib.RawResponseWithMeta;
readonly ok: true;
}]>;
getCurrentActivity(): Promise<readonly [Error, undefined, urllib.HttpClientResponse<any>] | readonly [Error, undefined, undefined] | readonly [undefined, any, {
readonly data: any;
readonly opaque: unknown;
readonly status: number;
readonly statusCode: number;
readonly statusText: string;
readonly headers: urllib.IncomingHttpHeaders;
readonly url: string;
readonly redirected: boolean;
readonly requestUrls: string[];
readonly res: urllib.RawResponseWithMeta;
readonly ok: true;
}]>;
getApplications(): Promise<readonly [Error, undefined, urllib.HttpClientResponse<any>] | readonly [Error, undefined, undefined] | readonly [undefined, any, {
readonly data: any;
readonly opaque: unknown;
readonly status: number;
readonly statusCode: number;
readonly statusText: string;
readonly headers: urllib.IncomingHttpHeaders;
readonly url: string;
readonly redirected: boolean;
readonly requestUrls: string[];
readonly res: urllib.RawResponseWithMeta;
readonly ok: true;
}]>;
sendKey(key: InputKeys): Promise<readonly [Error, undefined, urllib.HttpClientResponse<any>] | readonly [Error, undefined, undefined] | readonly [undefined, any, {
readonly data: any;
readonly opaque: unknown;
readonly status: number;
readonly statusCode: number;
readonly statusText: string;
readonly headers: urllib.IncomingHttpHeaders;
readonly url: string;
readonly redirected: boolean;
readonly requestUrls: string[];
readonly res: urllib.RawResponseWithMeta;
readonly ok: true;
}]>;
getAmbiHue(): Promise<readonly [Error, undefined, urllib.HttpClientResponse<any>] | readonly [Error, undefined, undefined] | readonly [undefined, any, {
readonly data: any;
readonly opaque: unknown;
readonly status: number;
readonly statusCode: number;
readonly statusText: string;
readonly headers: urllib.IncomingHttpHeaders;
readonly url: string;
readonly redirected: boolean;
readonly requestUrls: string[];
readonly res: urllib.RawResponseWithMeta;
readonly ok: true;
}]>;
getCurrentSetting(nodeId: number): Promise<readonly [Error, undefined] | readonly [undefined, any[]]>;
}
export { type AmbilightChangeBrightnessAvailableValues, type AmbilightFollowAudioMode, type AmbilightFollowVideoMode, type AmbilightSetBrightnessAvailableValues, FlatNode, type InputKeys, PhilTVApi, PhilTVApiParams, PhilTVPairing, type PhilTVPairingParams, getInformationSystem };