Skip to content

Commit

Permalink
Merge pull request #233 from Swatto/actions/runHomeScene
Browse files Browse the repository at this point in the history
Add runHomeScene action and tweak facetime action
  • Loading branch information
joshfarrant committed Nov 19, 2019
2 parents 9fee11f + fa464ce commit b89e53c
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 37 deletions.
10 changes: 3 additions & 7 deletions __tests__/actions/facetime.spec.ts
@@ -1,4 +1,5 @@
import { facetime } from '../../src/actions';
import { askWhenRun } from '../../src/variables';

describe('facetime function', () => {
it('is a function', () => {
Expand All @@ -9,12 +10,7 @@ describe('facetime function', () => {
const expected = {
WFWorkflowActionIdentifier: 'com.apple.facetime.facetime',
WFWorkflowActionParameters: {
WFFaceTimeType: {
Value: {
Type: 'Video',
},
WFSerializationType: 'WFTextTokenAttachment',
},
WFFaceTimeType: 'Video',
},
};
const actual = facetime({});
Expand All @@ -34,7 +30,7 @@ describe('facetime function', () => {
},
},
};
const actual = facetime({ type: 'Ask' });
const actual = facetime({ type: askWhenRun });

expect(actual).toEqual(expected);
});
Expand Down
46 changes: 46 additions & 0 deletions __tests__/actions/runHomeScene.spec.ts
@@ -0,0 +1,46 @@
import { runHomeScene } from '../../src/actions';
import { askWhenRun } from '../../src/variables';

describe('runHomeScene function', () => {
it('is a function', () => {
expect(typeof runHomeScene).toBe('function');
});

it('builds a runHomeScene action with specified arguments', () => {
const homeName = 'My test home';
const sceneName = 'My great test scene';
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.runscene',
WFWorkflowActionParameters: {
WFHomeName: homeName,
WFHomeSceneName: sceneName,
},
};
const actual = runHomeScene({ homeName, sceneName });

expect(actual).toEqual(expected);
});

it('builds a runHomeScene action with user choice on run', () => {
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.runscene',
WFWorkflowActionParameters: {
WFHomeName: {
Value: {
Type: 'Ask',
},
WFSerializationType: 'WFTextTokenAttachment',
},
WFHomeSceneName: {
Value: {
Type: 'Ask',
},
WFSerializationType: 'WFTextTokenAttachment',
},
},
};
const actual = runHomeScene({ homeName: askWhenRun, sceneName: askWhenRun });

expect(actual).toEqual(expected);
});
});
24 changes: 9 additions & 15 deletions src/actions/facetime.ts
@@ -1,4 +1,5 @@
import FaceTimeType from '../interfaces/WF/FaceTimeType';
import WFSerialization from '../interfaces/WF/WFSerialization';
import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction';

/**
Expand All @@ -10,27 +11,20 @@ import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction';
*
* ```js
* facetime({}); // Default type is Video
* facetime({ type: 'Ask' }); // type could be 'Audio' or 'Video' also
* facetime({ type: askWhenRun }); // type could be 'Audio' or 'Video'
* ```
*/

const facetime = ({
type = 'Video',
}: {
/** Define the type to use for the FaceTime. Default to 'Video' */
type?: FaceTimeType,
}): WFWorkflowAction => {
return {
WFWorkflowActionIdentifier: 'com.apple.facetime.facetime',
WFWorkflowActionParameters: {
WFFaceTimeType: {
Value: {
Type: type,
},
WFSerializationType: 'WFTextTokenAttachment',
},
},
};
};
type?: WFSerialization | FaceTimeType,
}): WFWorkflowAction => ({
WFWorkflowActionIdentifier: 'com.apple.facetime.facetime',
WFWorkflowActionParameters: {
WFFaceTimeType: type,
},
});

export default facetime;
2 changes: 2 additions & 0 deletions src/actions/index.ts
Expand Up @@ -85,6 +85,7 @@ import quickLook from './quickLook';
import randomNumber from './randomNumber';
import removeReminders from './removeReminders';
import repeat from './repeat';
import runHomeScene from './runHomeScene';
import runJavaScriptOnWebPage from './runJavaScriptOnWebPage';
import runScriptOverSSH from './runScriptOverSSH';
import runShortcut from './runShortcut';
Expand Down Expand Up @@ -216,6 +217,7 @@ export {
randomNumber,
removeReminders,
repeat,
runHomeScene,
runJavaScriptOnWebPage,
runScriptOverSSH,
runShortcut,
Expand Down
42 changes: 42 additions & 0 deletions src/actions/runHomeScene.ts
@@ -0,0 +1,42 @@
import WFSerialization from '../interfaces/WF/WFSerialization';
import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction';

/**
* @action Run Home Scene
* @section Home > Home >
* @icon Home
*
* Runs a specific or user selected Home scene
*
* ```js
* // Run a specific scene at home
* runHomeScene({
* homeName: 'My House', // You can find your name in the Home app
* sceneName: 'Workday'
* });
* // Let the user select the scene for a spefiic home
* runHomeScene({
* homeName: 'My House',
* sceneName: askWhenRun
* });
* ```
*/

const runHomeScene = (
{
homeName,
sceneName,
}: {
/** String of the home's name. */
homeName: WFSerialization | string,
/** String of the scene's name. */
sceneName: WFSerialization | string,
}): WFWorkflowAction => ({
WFWorkflowActionIdentifier: 'is.workflow.actions.runscene',
WFWorkflowActionParameters: {
WFHomeName: homeName,
WFHomeSceneName: sceneName,
},
});

export default runHomeScene;
3 changes: 1 addition & 2 deletions src/interfaces/WF/FaceTimeType.ts
@@ -1,6 +1,5 @@
type FaceTimeType = (
'Ask'
| 'Audio'
'Audio'
| 'Video'
);

Expand Down
11 changes: 0 additions & 11 deletions src/interfaces/WF/WFFaceTimeType.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/interfaces/WF/WFWorkflowActionIdentifier.ts
Expand Up @@ -93,6 +93,7 @@ type WFWorkflowActionIdentifier = (
| 'is.workflow.actions.removereminders'
| 'is.workflow.actions.runextension'
| 'is.workflow.actions.runjavascriptonwebpage'
| 'is.workflow.actions.runscene'
| 'is.workflow.actions.runsshscript'
| 'is.workflow.actions.runworkflow'
| 'is.workflow.actions.scanbarcode'
Expand Down
6 changes: 4 additions & 2 deletions src/interfaces/WF/WFWorkflowActionParameters.ts
@@ -1,4 +1,5 @@
import AssertionType from './AssertionType';
import FaceTimeType from './FaceTimeType';
import WFArchiveFormat from './WFArchiveFormat';
import WFAskActionDateGranularity from './WFAskActionDateGranularity';
import WFBase64LineBreakMode from './WFBase64LineBreakMode';
Expand All @@ -8,7 +9,6 @@ import WFDateActionMode from './WFDateActionMode';
import WFDateFormatStyle from './WFDateFormatStyle';
import WFDeviceDetail from './WFDeviceDetail';
import WFEncodeMode from './WFEncodeMode';
import WFFaceTimeType from './WFFaceTimeType';
import WFFlashlightSetting from './WFFlashlightSetting';
import WFFrequency from './WFFrequency';
import WFGetDictionaryValueType from './WFGetDictionaryValueType';
Expand Down Expand Up @@ -70,13 +70,15 @@ interface WFWorkflowActionParameters {
WFDictionaryValue?: string;
WFDontIncludeFileExtension?: boolean;
WFEncodeMode?: WFEncodeMode;
WFFaceTimeType?: WFFaceTimeType;
WFFaceTimeType?: WFSerialization | FaceTimeType;
WFFlashlightSetting?: WFFlashlightSetting;
WFFrequency?: WFFrequency[];
WFFormValues?: WFSerialization;
WFGetDictionaryValueType?: WFGetDictionaryValueType;
WFGetLatestPhotoCount?: number;
WFHashType?: WFSerialization | WFHashType;
WFHomeName?: WFSerialization | string;
WFHomeSceneName?: WFSerialization | string;
WFHTTPBodyType?: WFHTTPBodyType;
WFHTTPHeaders?: WFSerialization;
WFHTTPMethod?: WFHTTPMethod;
Expand Down

0 comments on commit b89e53c

Please sign in to comment.