Skip to content

Commit 109bd38

Browse files
committed
feat(devicepreferences): expanded i18n support
1 parent e943245 commit 109bd38

File tree

8 files changed

+218
-65
lines changed

8 files changed

+218
-65
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/README.md

Lines changed: 62 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ that map to the API spec.
137137
* [`smartthings devicepreferences:create`](#smartthings-devicepreferencescreate)
138138
* [`smartthings devicepreferences:translations [PREFERENCEID] [TAG]`](#smartthings-devicepreferencestranslations-preferenceid-tag)
139139
* [`smartthings devicepreferences:translations:create [PREFERENCEID]`](#smartthings-devicepreferencestranslationscreate-preferenceid)
140+
* [`smartthings devicepreferences:translations:update [PREFERENCEID]`](#smartthings-devicepreferencestranslationsupdate-preferenceid)
140141
* [`smartthings devicepreferences:update [ID]`](#smartthings-devicepreferencesupdate-id)
141142
* [`smartthings deviceprofiles [ID]`](#smartthings-deviceprofiles-id)
142143
* [`smartthings deviceprofiles:create`](#smartthings-deviceprofilescreate)
@@ -820,15 +821,15 @@ EXAMPLES
820821
Attributes:
821822
┌────────────────────────┬───────────────────┬────────────────────────────────┬───────────────────────────────────────
822823
─────────────┐
823-
│ Name │ Label │ Description │ Template
824+
│ Name │ Label │ Description │ Template
824825
825826
├────────────────────────┼───────────────────┼────────────────────────────────┼───────────────────────────────────────
826827
─────────────┤
827-
│ outputModulation │ Output Modulation │ Power supply output modulation │ The {{attribute}} of {{device.label}}
828+
│ outputModulation │ Output Modulation │ Power supply output modulation │ The {{attribute}} of {{device.label}}
828829
is {{value}} │
829-
│ outputModulation.50hz │ 50 Hz │ │
830+
│ outputModulation.50hz │ 50 Hz │ │
830831
831-
│ outputModulation.60hz │ 60 Hz │ │
832+
│ outputModulation.60hz │ 60 Hz │ │
832833
833834
└────────────────────────┴───────────────────┴────────────────────────────────┴───────────────────────────────────────
834835
─────────────┘
@@ -872,7 +873,7 @@ OPTIONS
872873
--language=language ISO language code or "NONE" to not specify a language. Defaults to the OS locale
873874

874875
EXAMPLES
875-
$ smartthings capabilities:translations:create custom1.outputModulation 1 -i en.yaml
876+
$ smartthings capabilities:translations:create custom1.outputModulation 1 -i en.yaml
876877
tag: en
877878
label: Output Modulation
878879
attributes:
@@ -950,7 +951,7 @@ OPTIONS
950951
--language=language ISO language code or "NONE" to not specify a language. Defaults to the OS locale
951952

952953
EXAMPLES
953-
$ smartthings capabilities:translations:update custom1.outputModulation 1 -i en.yaml
954+
$ smartthings capabilities:translations:update custom1.outputModulation 1 -i en.yaml
954955
tag: en
955956
label: Output Modulation
956957
attributes:
@@ -1028,7 +1029,7 @@ OPTIONS
10281029
--language=language ISO language code or "NONE" to not specify a language. Defaults to the OS locale
10291030

10301031
EXAMPLES
1031-
$ smartthings capabilities:translations:upsert custom1.outputModulation 1 -i en.yaml
1032+
$ smartthings capabilities:translations:upsert custom1.outputModulation 1 -i en.yaml
10321033
tag: en
10331034
label: Output Modulation
10341035
attributes:
@@ -1200,13 +1201,13 @@ ALIASES
12001201
$ smartthings device-preferences:create
12011202

12021203
EXAMPLES
1203-
$ smartthings devicepreferences:create # create a new device profile by answering
1204+
$ smartthings devicepreferences:create # create a new device profile by answering
12041205
questions
12051206
$ smartthings devicepreferences:create -d # generate a device profile by answering questions
12061207
but do not actually create it
1207-
$ smartthings devicepreferences:create -i dp.json # create a new device profile defined by the file
1208+
$ smartthings devicepreferences:create -i dp.json # create a new device profile defined by the file
12081209
dp.json
1209-
$ smartthings devicepreferences:create -i dp.json -o dp-saved.json # create a new device profile defined by the file
1210+
$ smartthings devicepreferences:create -i dp.json -o dp-saved.json # create a new device profile defined by the file
12101211
dp.json and write the results to dp-saved.json
12111212
```
12121213
@@ -1222,7 +1223,7 @@ USAGE
12221223

12231224
ARGUMENTS
12241225
PREFERENCEID device preference id or index
1225-
TAG [default: en] the locale tag
1226+
TAG the locale tag
12261227

12271228
OPTIONS
12281229
-O, --organization=organization The organization ID to use for this command
@@ -1238,14 +1239,13 @@ OPTIONS
12381239
--language=language ISO language code or "NONE" to not specify a language. Defaults to the OS locale
12391240

12401241
EXAMPLES
1241-
1242-
# let command prompt to choose device preference
1242+
# let command prompt to choose device preference and list locales
12431243
$ smartthings devicepreferences:translations
12441244

1245-
# specify device preference ID and use default locale tag (en)
1245+
# specify device preference ID and list locales
12461246
$ smartthings devicepreferences:translations motionSensitivity
12471247

1248-
# specify device preference ID and locale
1248+
# specify device preference ID and locale to get translated device preference values
12491249
$ smartthings devicepreferences:translations motionSensitivity ko
12501250
```
12511251
@@ -1283,6 +1283,38 @@ EXAMPLE
12831283
12841284
_See code: [src/commands/devicepreferences/translations/create.ts](https://github.com/SmartThingsCommunity/smartthings-cli/blob/v0.0.0-pre.34/packages/cli/src/commands/devicepreferences/translations/create.ts)_
12851285
1286+
## `smartthings devicepreferences:translations:update [PREFERENCEID]`
1287+
1288+
update a device preference translation
1289+
1290+
```
1291+
USAGE
1292+
$ smartthings devicepreferences:translations:update [PREFERENCEID]
1293+
1294+
ARGUMENTS
1295+
PREFERENCEID device preference id or index
1296+
1297+
OPTIONS
1298+
-O, --organization=organization The organization ID to use for this command
1299+
-d, --dry-run produce JSON but don't actually submit
1300+
-h, --help show CLI help
1301+
-i, --input=input specify input file
1302+
-j, --json use JSON format of input and/or output
1303+
-o, --output=output specify output file
1304+
-p, --profile=profile [default: default] configuration profile
1305+
-t, --token=token the auth token to use
1306+
-y, --yaml use YAML format of input and/or output
1307+
--compact use compact table format with no lines between body rows
1308+
--expanded use expanded table format with a line between each body row
1309+
--indent=indent specify indentation for formatting JSON or YAML output
1310+
--language=language ISO language code or "NONE" to not specify a language. Defaults to the OS locale
1311+
1312+
EXAMPLE
1313+
$ smartthings devicepreferences:translations:update -i preferenceTranslation.json
1314+
```
1315+
1316+
_See code: [src/commands/devicepreferences/translations/update.ts](https://github.com/SmartThingsCommunity/smartthings-cli/blob/v0.0.0-pre.34/packages/cli/src/commands/devicepreferences/translations/update.ts)_
1317+
12861318
## `smartthings devicepreferences:update [ID]`
12871319
12881320
update a device preference
@@ -1313,9 +1345,9 @@ ALIASES
13131345
$ smartthings device-preferences:update
13141346

13151347
EXAMPLES
1316-
$ smartthings devicepreferences:update -i dp.json # update a device preference with data from
1348+
$ smartthings devicepreferences:update -i dp.json # update a device preference with data from
13171349
dp.json, select which preference from a list
1318-
$ smartthings devicepreferences:update -i dp.yaml my-preference-id # update device preference my-preference-id with
1350+
$ smartthings devicepreferences:update -i dp.yaml my-preference-id # update device preference my-preference-id with
13191351
data from dp.yaml
13201352
```
13211353
@@ -2433,7 +2465,7 @@ ALIASES
24332465

24342466
EXAMPLES
24352467
smartthings edge:channels:invites # list all invites on all channels you own
2436-
smartthings edge:channels:invites 2 # list details about the second invite show when listed as in the
2468+
smartthings edge:channels:invites 2 # list details about the second invite show when listed as in the
24372469
example above
24382470
smartthings edge:channels:invites -C <channel id> # list all invites on channel with id <channel id>
24392471
smartthings edge:channels:invites <invite id> # list details about the invite with id <invite id>
@@ -2669,9 +2701,9 @@ OPTIONS
26692701

26702702
EXAMPLES
26712703
smartthings edge:drivers:install # use Q&A format to enter required values
2672-
smartthings edge:drivers:install -H <hub-id> # specify the hub on the command line, other
2704+
smartthings edge:drivers:install -H <hub-id> # specify the hub on the command line, other
26732705
fields will be asked for
2674-
smartthings edge:drivers:install -H <hub-id> -C <channel-id> <driver-id> # install a driver from a channel on an
2706+
smartthings edge:drivers:install -H <hub-id> -C <channel-id> <driver-id> # install a driver from a channel on an
26752707
enrolled hub
26762708
```
26772709
@@ -2866,7 +2898,7 @@ OPTIONS
28662898
--all see all commands in CLI
28672899
```
28682900
2869-
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.17/src/commands/help.ts)_
2901+
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.3.1/src/commands/help.ts)_
28702902
28712903
## `smartthings installedapps [ID]`
28722904
@@ -3295,7 +3327,7 @@ EXAMPLE
32953327
$ smartthings plugins
32963328
```
32973329
3298-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.10.1/src/commands/plugins/index.ts)_
3330+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.10.11/src/commands/plugins/index.ts)_
32993331
33003332
## `smartthings plugins:inspect PLUGIN...`
33013333
@@ -3316,7 +3348,7 @@ EXAMPLE
33163348
$ smartthings plugins:inspect myplugin
33173349
```
33183350
3319-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.10.1/src/commands/plugins/inspect.ts)_
3351+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.10.11/src/commands/plugins/inspect.ts)_
33203352
33213353
## `smartthings plugins:install PLUGIN...`
33223354
@@ -3339,20 +3371,20 @@ DESCRIPTION
33393371

33403372
Installation of a user-installed plugin will override a core plugin.
33413373

3342-
e.g. If you have a core plugin that has a 'hello' command, installing a user-installed plugin with a 'hello' command
3343-
will override the core plugin implementation. This is useful if a user needs to update core plugin functionality in
3374+
e.g. If you have a core plugin that has a 'hello' command, installing a user-installed plugin with a 'hello' command
3375+
will override the core plugin implementation. This is useful if a user needs to update core plugin functionality in
33443376
the CLI without the need to patch and update the whole CLI.
33453377

33463378
ALIASES
33473379
$ smartthings plugins:add
33483380

33493381
EXAMPLES
3350-
$ smartthings plugins:install myplugin
3382+
$ smartthings plugins:install myplugin
33513383
$ smartthings plugins:install https://github.com/someuser/someplugin
33523384
$ smartthings plugins:install someuser/someplugin
33533385
```
33543386
3355-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.10.1/src/commands/plugins/install.ts)_
3387+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.10.11/src/commands/plugins/install.ts)_
33563388
33573389
## `smartthings plugins:link PLUGIN`
33583390
@@ -3379,7 +3411,7 @@ EXAMPLE
33793411
$ smartthings plugins:link myplugin
33803412
```
33813413
3382-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.10.1/src/commands/plugins/link.ts)_
3414+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.10.11/src/commands/plugins/link.ts)_
33833415
33843416
## `smartthings plugins:uninstall PLUGIN...`
33853417
@@ -3401,7 +3433,7 @@ ALIASES
34013433
$ smartthings plugins:remove
34023434
```
34033435
3404-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.10.1/src/commands/plugins/uninstall.ts)_
3436+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.10.11/src/commands/plugins/uninstall.ts)_
34053437
34063438
## `smartthings plugins:update`
34073439
@@ -3416,7 +3448,7 @@ OPTIONS
34163448
-v, --verbose
34173449
```
34183450
3419-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.10.1/src/commands/plugins/update.ts)_
3451+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.10.11/src/commands/plugins/update.ts)_
34203452
34213453
## `smartthings presentation PRESENTATIONID [MANUFACTURERNAME]`
34223454

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"@oclif/plugin-not-found": "^1.2.6",
6666
"@oclif/plugin-plugins": "^1.10.11",
6767
"@smartthings/cli-lib": "^0.0.0-pre.34",
68-
"@smartthings/core-sdk": "^2.1.0",
68+
"@smartthings/core-sdk": "^2.1.1",
6969
"@smartthings/plugin-cli-edge": "^1.7.0",
7070
"aws-sdk": "^2.690.0",
7171
"cli-table": "^0.3.11",
Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { APICommand, GetDataFunction, outputItem, SmartThingsCommandInterface, TableCommonOutputProducer } from '@smartthings/cli-lib'
2-
import { DevicePreferencesEndpoint, PreferenceLocalization } from '@smartthings/core-sdk'
1+
import { APICommand, ListDataFunction, ListingOutputConfig, LookupDataFunction, outputListing, SmartThingsCommandInterface } from '@smartthings/cli-lib'
2+
import { DevicePreferencesEndpoint, LocaleReference, PreferenceLocalization } from '@smartthings/core-sdk'
33
import DevicePreferencesTranslationsCommand from '../../../commands/devicepreferences/translations'
44
import { chooseDevicePreference } from '../../../lib/commands/devicepreferences/devicepreferences-util'
55
import { tableFieldDefinitions } from '../../../lib/commands/devicepreferences/translations/translations-util'
@@ -12,28 +12,28 @@ jest.mock('@smartthings/cli-lib', () => {
1212

1313
return {
1414
...originalLib,
15-
outputItem: jest.fn(),
15+
outputListing: jest.fn(),
1616
}
1717
})
1818

1919
describe('DevicePreferencesTranslationsCommand', () => {
2020
const mockChoosePreference = chooseDevicePreference as jest.Mock<Promise<string>, [APICommand, string | undefined]>
21-
const mockOutputItem = outputItem as unknown as
22-
jest.Mock<Promise<PreferenceLocalization>, [
21+
const mockOutputListing = outputListing as unknown as
22+
jest.Mock<Promise<void>, [
2323
SmartThingsCommandInterface,
24-
TableCommonOutputProducer<PreferenceLocalization>,
25-
GetDataFunction<PreferenceLocalization>
24+
ListingOutputConfig<PreferenceLocalization, LocaleReference>,
25+
string | undefined,
26+
ListDataFunction<LocaleReference>,
27+
LookupDataFunction<string, PreferenceLocalization>
2628
]>
2729
const getTranslationsSpy = jest.spyOn(DevicePreferencesEndpoint.prototype, 'getTranslations').mockImplementation()
30+
const listTranslationsSpy = jest.spyOn(DevicePreferencesEndpoint.prototype, 'listTranslations').mockImplementation()
2831

2932
const preferenceId = 'preferenceId'
3033
const localeTag = 'localeTag'
3134

3235
beforeAll(() => {
3336
mockChoosePreference.mockResolvedValue(preferenceId)
34-
mockOutputItem.mockImplementation(async (_command, _config, getFunction) => {
35-
return getFunction()
36-
})
3737
})
3838

3939
afterEach(() => {
@@ -49,32 +49,37 @@ describe('DevicePreferencesTranslationsCommand', () => {
4949
)
5050
})
5151

52-
it('calls outputItem with correct config', async () => {
52+
it('calls outputListing with correct config', async () => {
5353
await expect(DevicePreferencesTranslationsCommand.run([preferenceId, localeTag])).resolves.not.toThrow()
5454

5555
expect(chooseDevicePreference).toBeCalledWith(
5656
expect.any(DevicePreferencesTranslationsCommand),
5757
preferenceId,
5858
)
5959

60-
expect(mockOutputItem).toBeCalledWith(
60+
expect(mockOutputListing).toBeCalledWith(
6161
expect.any(DevicePreferencesTranslationsCommand),
6262
expect.objectContaining({
63+
primaryKeyName: 'tag',
64+
sortKeyName: 'tag',
65+
listTableFieldDefinitions: ['tag'],
6366
tableFieldDefinitions,
6467
}),
68+
localeTag,
69+
expect.any(Function),
6570
expect.any(Function),
6671
)
6772
})
6873

69-
it('calls correct endpoint to get translations', async () => {
74+
it('calls correct endpoints to get translations', async () => {
75+
mockOutputListing.mockImplementationOnce(async (_command, _config, _tag, listFunction, getFunction) => {
76+
await listFunction()
77+
await getFunction(localeTag)
78+
})
79+
7080
await expect(DevicePreferencesTranslationsCommand.run([preferenceId, localeTag])).resolves.not.toThrow()
7181

82+
expect(listTranslationsSpy).toBeCalledWith(preferenceId)
7283
expect(getTranslationsSpy).toBeCalledWith(preferenceId, localeTag)
7384
})
74-
75-
it('uses default locale tag when not specified', async () => {
76-
await expect(DevicePreferencesTranslationsCommand.run([preferenceId])).resolves.not.toThrow()
77-
78-
expect(getTranslationsSpy).toBeCalledWith(preferenceId, 'en')
79-
})
8085
})

0 commit comments

Comments
 (0)