Skip to content

Commit

Permalink
Simplify to a single enhance option.
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Nov 3, 2023
1 parent 202c500 commit 6b0a6bc
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 118 deletions.
146 changes: 72 additions & 74 deletions src/DeviceInfo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//there are 2 copies of this interface in here. If you add a new field, be sure to add it to both

export interface DeviceInfo<TBoolean = boolean, TNumber = number> {
export interface DeviceInfo {
udn?: string;
serialNumber?: string;
deviceId?: string;
Expand All @@ -9,16 +9,16 @@ export interface DeviceInfo<TBoolean = boolean, TNumber = number> {
modelName?: string;
modelNumber?: string;
modelRegion?: string;
isTv?: TBoolean;
isStick?: TBoolean;
mobileHasLiveTv?: TBoolean;
isTv?: boolean;
isStick?: boolean;
mobileHasLiveTv?: boolean;
uiResolution?: string;
supportsEthernet?: TBoolean;
supportsEthernet?: boolean;
wifiMac?: string;
wifiDriver?: string;
hasWifiExtender?: TBoolean;
hasWifi5GSupport?: TBoolean;
canUseWifiExtender?: TBoolean;
hasWifiExtender?: boolean;
hasWifi5GSupport?: boolean;
canUseWifiExtender?: boolean;
ethernetMac?: string;
networkType?: string;
networkName?: string;
Expand All @@ -29,53 +29,51 @@ export interface DeviceInfo<TBoolean = boolean, TNumber = number> {
userDeviceLocation?: string;
buildNumber?: string;
softwareVersion?: string;
softwareBuild?: TNumber;
secureDevice?: TBoolean;
softwareBuild?: number;
secureDevice?: boolean;
language?: string;
country?: string;
locale?: string;
timeZoneAuto?: TBoolean;
timeZoneAuto?: boolean;
timeZone?: string;
timeZoneName?: string;
timeZoneTz?: string;
timeZoneOffset?: TNumber;
timeZoneOffset?: number;
clockFormat?: string;
uptime?: TNumber;
uptime?: number;
powerMode?: string;
supportsSuspend?: TBoolean;
supportsFindRemote?: TBoolean;
findRemoteIsPossible?: TBoolean;
supportsAudioGuide?: TBoolean;
supportsRva?: TBoolean;
hasHandsFreeVoiceRemote?: TBoolean;
developerEnabled?: TBoolean;
supportsSuspend?: boolean;
supportsFindRemote?: boolean;
findRemoteIsPossible?: boolean;
supportsAudioGuide?: boolean;
supportsRva?: boolean;
hasHandsFreeVoiceRemote?: boolean;
developerEnabled?: boolean;
keyedDeveloperId?: string;
searchEnabled?: TBoolean;
searchChannelsEnabled?: TBoolean;
voiceSearchEnabled?: TBoolean;
notificationsEnabled?: TBoolean;
notificationsFirstUse?: TBoolean;
supportsPrivateListening?: TBoolean;
headphonesConnected?: TBoolean;
supportsAudioSettings?: TBoolean;
supportsEcsTextedit?: TBoolean;
supportsEcsMicrophone?: TBoolean;
supportsWakeOnWlan?: TBoolean;
supportsAirplay?: TBoolean;
hasPlayOnRoku?: TBoolean;
hasMobileScreensaver?: TBoolean;
searchEnabled?: boolean;
searchChannelsEnabled?: boolean;
voiceSearchEnabled?: boolean;
notificationsEnabled?: boolean;
notificationsFirstUse?: boolean;
supportsPrivateListening?: boolean;
headphonesConnected?: boolean;
supportsAudioSettings?: boolean;
supportsEcsTextedit?: boolean;
supportsEcsMicrophone?: boolean;
supportsWakeOnWlan?: boolean;
supportsAirplay?: boolean;
hasPlayOnRoku?: boolean;
hasMobileScreensaver?: boolean;
supportUrl?: string;
grandcentralVersion?: string;
trcVersion?: TNumber;
trcVersion?: number;
trcChannelVersion?: string;
davinciVersion?: string;
avSyncCalibrationEnabled?: TNumber;
avSyncCalibrationEnabled?: number;
brightscriptDebuggerVersion?: string;
// catchall index lookup for keys we weren't aware of
[key: string]: any;
}

export interface DeviceInfoOriginal<TBoolean = boolean, TNumber = number> {
export interface DeviceInfoRaw {
'udn'?: string;
'serialNumber'?: string;
'deviceId'?: string;
Expand All @@ -84,16 +82,16 @@ export interface DeviceInfoOriginal<TBoolean = boolean, TNumber = number> {
'model-name'?: string;
'model-number'?: string;
'model-region'?: string;
'is-tv'?: TBoolean;
'is-stick'?: TBoolean;
'mobile-has-live-tv'?: TBoolean;
'is-tv'?: string;
'is-stick'?: string;
'mobile-has-live-tv'?: string;
'ui-resolution'?: string;
'supports-ethernet'?: TBoolean;
'supports-ethernet'?: string;
'wifi-mac'?: string;
'wifi-driver'?: string;
'has-wifi-extender'?: TBoolean;
'has-wifi-5G-support'?: TBoolean;
'can-use-wifi-extender'?: TBoolean;
'has-wifi-extender'?: string;
'has-wifi-5G-support'?: string;
'can-use-wifi-extender'?: string;
'ethernet-mac'?: string;
'network-type'?: string;
'network-name'?: string;
Expand All @@ -104,47 +102,47 @@ export interface DeviceInfoOriginal<TBoolean = boolean, TNumber = number> {
'user-device-location'?: string;
'build-number'?: string;
'software-version'?: string;
'software-build'?: TNumber;
'secure-device'?: TBoolean;
'software-build'?: string;
'secure-device'?: string;
'language'?: string;
'country'?: string;
'locale'?: string;
'time-zone-auto'?: TBoolean;
'time-zone-auto'?: string;
'time-zone'?: string;
'time-zone-name'?: string;
'time-zone-tz'?: string;
'time-zone-offset'?: TNumber;
'time-zone-offset'?: string;
'clock-format'?: string;
'uptime'?: TNumber;
'uptime'?: string;
'power-mode'?: string;
'supports-suspend'?: TBoolean;
'supports-find-remote'?: TBoolean;
'find-remote-is-possible'?: TBoolean;
'supports-audio-guide'?: TBoolean;
'supports-rva'?: TBoolean;
'has-hands-free-voice-remote'?: TBoolean;
'developer-enabled'?: TBoolean;
'supports-suspend'?: string;
'supports-find-remote'?: string;
'find-remote-is-possible'?: string;
'supports-audio-guide'?: string;
'supports-rva'?: string;
'has-hands-free-voice-remote'?: string;
'developer-enabled'?: string;
'keyed-developer-id'?: string;
'search-enabled'?: TBoolean;
'search-channels-enabled'?: TBoolean;
'voice-search-enabled'?: TBoolean;
'notifications-enabled'?: TBoolean;
'notifications-first-use'?: TBoolean;
'supports-private-listening'?: TBoolean;
'headphones-connected'?: TBoolean;
'supports-audio-settings'?: TBoolean;
'supports-ecs-textedit'?: TBoolean;
'supports-ecs-microphone'?: TBoolean;
'supports-wake-on-wlan'?: TBoolean;
'supports-airplay'?: TBoolean;
'has-play-on-roku'?: TBoolean;
'has-mobile-screensaver'?: TBoolean;
'search-enabled'?: string;
'search-channels-enabled'?: string;
'voice-search-enabled'?: string;
'notifications-enabled'?: string;
'notifications-first-use'?: string;
'supports-private-listening'?: string;
'headphones-connected'?: string;
'supports-audio-settings'?: string;
'supports-ecs-textedit'?: string;
'supports-ecs-microphone'?: string;
'supports-wake-on-wlan'?: string;
'supports-airplay'?: string;
'has-play-on-roku'?: string;
'has-mobile-screensaver'?: string;
'support-url'?: string;
'grandcentral-version'?: string;
'trc-version'?: TNumber;
'trc-version'?: string;
'trc-channel-version'?: string;
'davinci-version'?: string;
'av-sync-calibration-enabled'?: TNumber;
'av-sync-calibration-enabled'?: string;
'brightscript-debugger-version'?: string;
// catchall index lookup for keys we weren't aware of
[key: string]: any;
Expand Down
64 changes: 32 additions & 32 deletions src/RokuDeploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,52 +321,52 @@ describe('index', () => {
<udn>29380007-0800-1025-80a4-d83154332d7e</udn>
</device-info>
`);
const result = await rokuDeploy.getDeviceInfo({ host: '192.168.1.10', remotePort: 8060, sanitizeData: true, format: 'camelCase' });
const result = await rokuDeploy.getDeviceInfo({ host: '192.168.1.10', remotePort: 8060, enhance: true });
expect(result.isStick).not.to.exist;
});

it('should sanitize additional data when the host+param+format signature is triggered', async () => {
mockDoGetRequest(body);
const result = await rokuDeploy.getDeviceInfo({ host: '192.168.1.10', remotePort: 8060, sanitizeData: true });
const result = await rokuDeploy.getDeviceInfo({ host: '192.168.1.10', remotePort: 8060, enhance: true });
expect(result).to.include({
// make sure the number fields are turned into numbers
'software-build': 4170,
'uptime': 19799,
'trc-version': 3.0,
'time-zone-offset': -240,
softwareBuild: 4170,
uptime: 19799,
trcVersion: 3.0,
timeZoneOffset: -240,

// string booleans should be turned into booleans
'is-tv': false,
'is-stick': false,
'supports-ethernet': true,
'has-wifi-extender': false,
'has-wifi-5G-support': true,
'secure-device': true,
'time-zone-auto': true,
'supports-suspend': false,
'supports-find-remote': true,
'find-remote-is-possible': true,
'supports-audio-guide': true,
'supports-rva': true,
'developer-enabled': true,
'search-enabled': true,
'search-channels-enabled': true,
'voice-search-enabled': true,
'notifications-enabled': true,
'notifications-first-use': false,
'supports-private-listening': true,
'headphones-connected': false,
'supports-ecs-textedit': true,
'supports-ecs-microphone': true,
'supports-wake-on-wlan': false,
'has-play-on-roku': true,
'has-mobile-screensaver': true
isTv: false,
isStick: false,
supportsEthernet: true,
hasWifiExtender: false,
hasWifi5GSupport: true,
secureDevice: true,
timeZoneAuto: true,
supportsSuspend: false,
supportsFindRemote: true,
findRemoteIsPossible: true,
supportsAudioGuide: true,
supportsRva: true,
developerEnabled: true,
searchEnabled: true,
searchChannelsEnabled: true,
voiceSearchEnabled: true,
notificationsEnabled: true,
notificationsFirstUse: false,
supportsPrivateListening: true,
headphonesConnected: false,
supportsEcsTextedit: true,
supportsEcsMicrophone: true,
supportsWakeOnWlan: false,
hasPlayOnRoku: true,
hasMobileScreensaver: true
});
});

it('converts keys to camel case when enabled', async () => {
mockDoGetRequest(body);
const result = await rokuDeploy.getDeviceInfo({ host: '192.168.1.10', remotePort: 8060, format: 'camelCase' });
const result = await rokuDeploy.getDeviceInfo({ host: '192.168.1.10', remotePort: 8060, enhance: true });
const props = [
'udn',
'serialNumber',
Expand Down
22 changes: 10 additions & 12 deletions src/RokuDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Logger, LogLevel } from './Logger';
import * as tempDir from 'temp-dir';
import * as dayjs from 'dayjs';
import * as lodash from 'lodash';
import type { DeviceInfo, DeviceInfoOriginal } from './DeviceInfo';
import type { DeviceInfo, DeviceInfoRaw } from './DeviceInfo';

export class RokuDeploy {

Expand Down Expand Up @@ -928,14 +928,10 @@ export class RokuDeploy {
* @param host the host or IP address of the Roku
* @param port the port to use for the ECP request (defaults to 8060)
*/
public async getDeviceInfo(options?: { format: 'camelCase'; sanitizeData: true } & GetDeviceInfoOptions): Promise<DeviceInfo>;
public async getDeviceInfo(options?: { format: 'camelCase'; sanitizeData?: false } & GetDeviceInfoOptions): Promise<DeviceInfo<string, string>>;
public async getDeviceInfo(options?: { sanitizeData: true } & GetDeviceInfoOptions): Promise<DeviceInfoOriginal>;
public async getDeviceInfo(options?: GetDeviceInfoOptions): Promise<DeviceInfoOriginal<string, string>>;
public async getDeviceInfo(options?: { enhance: true } & GetDeviceInfoOptions): Promise<DeviceInfo>;
public async getDeviceInfo(options?: GetDeviceInfoOptions): Promise<DeviceInfoRaw>
public async getDeviceInfo(options: GetDeviceInfoOptions) {
options = this.getOptions(options) as any;
options.sanitizeData ??= false;
options.format ??= 'original';

//if the host is a DNS name, look up the IP address
try {
Expand All @@ -962,7 +958,7 @@ export class RokuDeploy {
...parsedContent['device-info']
} as Record<string, any>;

if (options.sanitizeData) {
if (options.enhance) {
// convert 'true' and 'false' string values to boolean
for (let key in deviceInfo) {
if (deviceInfo[key] === 'true') {
Expand All @@ -979,9 +975,8 @@ export class RokuDeploy {
deviceInfo[field] = parseInt(deviceInfo[field]);
}
}
}

if (options.format === 'camelCase') {
//convert the property names to camel case
const result = {};
for (const key in deviceInfo) {
result[lodash.camelCase(key)] = deviceInfo[key];
Expand Down Expand Up @@ -1165,7 +1160,10 @@ export interface TakeScreenshotOptions {
export interface GetDeviceInfoOptions {
host: string;
remotePort?: number;
sanitizeData?: boolean;
format?: 'original' | 'camelCase';
timeout?: number;
/**
* Should the device-info be enhanced by camel-casing the property names and converting boolean strings to booleans and number strings to numbers?
* @default false
*/
enhance?: boolean;
}

0 comments on commit 6b0a6bc

Please sign in to comment.