hactl 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +3 -1
- package/dist/cli.js +948 -397
- package/package.json +2 -1
package/dist/cli.js
CHANGED
|
@@ -865,7 +865,7 @@ function buildArgumentScanner(parameters, config) {
|
|
|
865
865
|
const parsedFlags = Object.fromEntries(flagEntriesResult.value);
|
|
866
866
|
return { success: true, arguments: [parsedFlags, ...positionalValuesResult.value] };
|
|
867
867
|
},
|
|
868
|
-
proposeCompletions: async ({ partial, completionConfig, text:
|
|
868
|
+
proposeCompletions: async ({ partial, completionConfig, text: text5, context }) => {
|
|
869
869
|
if (activeFlag) {
|
|
870
870
|
return proposeFlagCompletionsForPartialInput(activeFlag[1], context, partial);
|
|
871
871
|
}
|
|
@@ -937,7 +937,7 @@ function buildArgumentScanner(parameters, config) {
|
|
|
937
937
|
completions.push({
|
|
938
938
|
kind: "argument:flag",
|
|
939
939
|
completion: "--",
|
|
940
|
-
brief:
|
|
940
|
+
brief: text5.briefs.argumentEscapeSequence
|
|
941
941
|
});
|
|
942
942
|
}
|
|
943
943
|
let incompleteFlags = Object.entries(flags).filter(
|
|
@@ -1315,7 +1315,7 @@ function help({
|
|
|
1315
1315
|
...config,
|
|
1316
1316
|
global: true,
|
|
1317
1317
|
aliases: alias === false ? [] : [alias],
|
|
1318
|
-
async run(app2, { text:
|
|
1318
|
+
async run(app2, { text: text5, ansiColorByStream, result, additionalFlags }) {
|
|
1319
1319
|
this.process.stdout.write(
|
|
1320
1320
|
result.target.formatHelp({
|
|
1321
1321
|
prefix: result.prefix,
|
|
@@ -1324,7 +1324,7 @@ function help({
|
|
|
1324
1324
|
includeHidden,
|
|
1325
1325
|
config: formatting,
|
|
1326
1326
|
aliases: result.aliases[formatting.caseStyle],
|
|
1327
|
-
text:
|
|
1327
|
+
text: text5,
|
|
1328
1328
|
ansiColor: ansiColorByStream.stdout
|
|
1329
1329
|
})
|
|
1330
1330
|
);
|
|
@@ -1341,7 +1341,7 @@ function version({
|
|
|
1341
1341
|
let versionCheck;
|
|
1342
1342
|
if (info.getLatestVersion) {
|
|
1343
1343
|
const getLatestVersion = info.getLatestVersion;
|
|
1344
|
-
versionCheck = async function({ text:
|
|
1344
|
+
versionCheck = async function({ text: text5, ansiColorByStream }) {
|
|
1345
1345
|
if (checkEnvironmentVariable(this.process, "STRICLI_SKIP_VERSION_CHECK")) {
|
|
1346
1346
|
return;
|
|
1347
1347
|
}
|
|
@@ -1353,7 +1353,7 @@ function version({
|
|
|
1353
1353
|
}
|
|
1354
1354
|
const latestVersion = await getLatestVersion.call(this, currentVersion);
|
|
1355
1355
|
if (latestVersion && currentVersion !== latestVersion) {
|
|
1356
|
-
const warningMessage =
|
|
1356
|
+
const warningMessage = text5.currentVersionIsNotLatest({
|
|
1357
1357
|
currentVersion,
|
|
1358
1358
|
latestVersion,
|
|
1359
1359
|
upgradeCommand: info.upgradeCommand,
|
|
@@ -1487,17 +1487,17 @@ function validateIntegrations(integrations, root2, config) {
|
|
|
1487
1487
|
}
|
|
1488
1488
|
}
|
|
1489
1489
|
}
|
|
1490
|
-
function gatherDefaultIntegrations(config,
|
|
1490
|
+
function gatherDefaultIntegrations(config, text5) {
|
|
1491
1491
|
const integrations = {
|
|
1492
1492
|
help: help({
|
|
1493
|
-
brief:
|
|
1493
|
+
brief: text5.briefs.help,
|
|
1494
1494
|
alias: "h",
|
|
1495
1495
|
defaultForRouteMap: true,
|
|
1496
1496
|
includeHidden: false,
|
|
1497
1497
|
formatting: config.documentation
|
|
1498
1498
|
}),
|
|
1499
1499
|
helpAll: help({
|
|
1500
|
-
brief:
|
|
1500
|
+
brief: text5.briefs.helpAll,
|
|
1501
1501
|
alias: "H",
|
|
1502
1502
|
hidden: !config.documentation.alwaysShowHelpAllFlag,
|
|
1503
1503
|
includeHidden: true,
|
|
@@ -1506,7 +1506,7 @@ function gatherDefaultIntegrations(config, text4) {
|
|
|
1506
1506
|
};
|
|
1507
1507
|
if (config.versionInfo) {
|
|
1508
1508
|
integrations["version"] = version({
|
|
1509
|
-
brief:
|
|
1509
|
+
brief: text5.briefs.version,
|
|
1510
1510
|
info: config.versionInfo,
|
|
1511
1511
|
alias: "v",
|
|
1512
1512
|
hook: "app:start"
|
|
@@ -1516,13 +1516,13 @@ function gatherDefaultIntegrations(config, text4) {
|
|
|
1516
1516
|
}
|
|
1517
1517
|
async function runApplication(app2, rawInputs, context) {
|
|
1518
1518
|
const ansiColorByStream = shouldUseAnsiColorForStreams(context.process, app2.config.documentation);
|
|
1519
|
-
let
|
|
1519
|
+
let text5 = app2.defaultText;
|
|
1520
1520
|
if (context.locale && "loadText" in app2.config.localization) {
|
|
1521
1521
|
const localeText = app2.config.localization.loadText(context.locale);
|
|
1522
1522
|
if (localeText) {
|
|
1523
|
-
|
|
1523
|
+
text5 = localeText;
|
|
1524
1524
|
} else {
|
|
1525
|
-
const warningMessage =
|
|
1525
|
+
const warningMessage = text5.noTextAvailableForLocale({
|
|
1526
1526
|
requestedLocale: context.locale,
|
|
1527
1527
|
defaultLocale: app2.config.localization.defaultLocale,
|
|
1528
1528
|
ansiColor: ansiColorByStream.stderr
|
|
@@ -1535,15 +1535,15 @@ async function runApplication(app2, rawInputs, context) {
|
|
|
1535
1535
|
}
|
|
1536
1536
|
}
|
|
1537
1537
|
const hookStartExitCode = await runHook(app2.integrations, "app:start", context, {
|
|
1538
|
-
text:
|
|
1538
|
+
text: text5,
|
|
1539
1539
|
ansiColorByStream
|
|
1540
1540
|
});
|
|
1541
1541
|
if (typeof hookStartExitCode === "number") {
|
|
1542
1542
|
return hookStartExitCode;
|
|
1543
1543
|
}
|
|
1544
|
-
const exitCode = await scanInputsAndRunTarget(app2, rawInputs, context,
|
|
1544
|
+
const exitCode = await scanInputsAndRunTarget(app2, rawInputs, context, text5, ansiColorByStream);
|
|
1545
1545
|
const hookEndExitCode = await runHook(app2.integrations, "app:end", context, {
|
|
1546
|
-
text:
|
|
1546
|
+
text: text5,
|
|
1547
1547
|
ansiColorByStream,
|
|
1548
1548
|
exitCode
|
|
1549
1549
|
});
|
|
@@ -1552,7 +1552,7 @@ async function runApplication(app2, rawInputs, context) {
|
|
|
1552
1552
|
}
|
|
1553
1553
|
return exitCode;
|
|
1554
1554
|
}
|
|
1555
|
-
async function scanInputsAndRunTarget(app2, rawInputs, context,
|
|
1555
|
+
async function scanInputsAndRunTarget(app2, rawInputs, context, text5, ansiColorByStream) {
|
|
1556
1556
|
const additionalFlags = gatherAdditionalFlagsFromIntegrations(app2.integrations);
|
|
1557
1557
|
const inputs = rawInputs.slice();
|
|
1558
1558
|
const scanner = buildRouteScanner(app2.root, app2.config.scanner, [app2.config.name], additionalFlags);
|
|
@@ -1570,7 +1570,7 @@ async function scanInputsAndRunTarget(app2, rawInputs, context, text4, ansiColor
|
|
|
1570
1570
|
const corrections = filterClosestAlternatives(error.input, routeNames, app2.config.scanner.distanceOptions).map(
|
|
1571
1571
|
(str) => `\`${str}\``
|
|
1572
1572
|
);
|
|
1573
|
-
const errorMessage =
|
|
1573
|
+
const errorMessage = text5.noCommandRegisteredForInput({
|
|
1574
1574
|
input: error.input,
|
|
1575
1575
|
corrections,
|
|
1576
1576
|
ansiColor: ansiColorByStream.stderr
|
|
@@ -1594,13 +1594,13 @@ async function scanInputsAndRunTarget(app2, rawInputs, context, text4, ansiColor
|
|
|
1594
1594
|
}
|
|
1595
1595
|
try {
|
|
1596
1596
|
await activeFlag.run.call(context, app2, {
|
|
1597
|
-
text:
|
|
1597
|
+
text: text5,
|
|
1598
1598
|
ansiColorByStream,
|
|
1599
1599
|
result,
|
|
1600
1600
|
additionalFlags: additionalFlagsForTarget
|
|
1601
1601
|
});
|
|
1602
1602
|
} catch (exc) {
|
|
1603
|
-
const errorMessage =
|
|
1603
|
+
const errorMessage = text5.exceptionWhileRunningIntegrationFlag({
|
|
1604
1604
|
exception: exc,
|
|
1605
1605
|
ansiColor: ansiColorByStream.stderr,
|
|
1606
1606
|
integration: activeFlag.name
|
|
@@ -1620,7 +1620,7 @@ async function scanInputsAndRunTarget(app2, rawInputs, context, text4, ansiColor
|
|
|
1620
1620
|
try {
|
|
1621
1621
|
commandContext = await context.forCommand({ prefix: result.prefix });
|
|
1622
1622
|
} catch (exc) {
|
|
1623
|
-
const errorMessage =
|
|
1623
|
+
const errorMessage = text5.exceptionWhileLoadingCommandContext(exc, ansiColorByStream.stderr);
|
|
1624
1624
|
context.process.stderr.write(
|
|
1625
1625
|
ansiColorByStream.stderr ? `\x1B[1m\x1B[31m${errorMessage}\x1B[39m\x1B[22m` : errorMessage
|
|
1626
1626
|
);
|
|
@@ -1630,7 +1630,7 @@ async function scanInputsAndRunTarget(app2, rawInputs, context, text4, ansiColor
|
|
|
1630
1630
|
commandContext = context;
|
|
1631
1631
|
}
|
|
1632
1632
|
const hookStartExitCode = await runHook(app2.integrations, "command:start", commandContext, {
|
|
1633
|
-
text:
|
|
1633
|
+
text: text5,
|
|
1634
1634
|
ansiColorByStream,
|
|
1635
1635
|
result
|
|
1636
1636
|
});
|
|
@@ -1641,12 +1641,12 @@ async function scanInputsAndRunTarget(app2, rawInputs, context, text4, ansiColor
|
|
|
1641
1641
|
context: commandContext,
|
|
1642
1642
|
inputs: result.unprocessedInputs,
|
|
1643
1643
|
scannerConfig: app2.config.scanner,
|
|
1644
|
-
errorFormatting:
|
|
1644
|
+
errorFormatting: text5,
|
|
1645
1645
|
determineExitCode: app2.config.determineExitCode,
|
|
1646
1646
|
ansiColorByStream
|
|
1647
1647
|
});
|
|
1648
1648
|
const hookEndExitCode = await runHook(app2.integrations, "command:end", commandContext, {
|
|
1649
|
-
text:
|
|
1649
|
+
text: text5,
|
|
1650
1650
|
ansiColorByStream,
|
|
1651
1651
|
result,
|
|
1652
1652
|
exitCode
|
|
@@ -1678,23 +1678,23 @@ function withDefaultFormattingConfiguration(config, scannerCaseStyle) {
|
|
|
1678
1678
|
caseStyle: displayCaseStyle
|
|
1679
1679
|
};
|
|
1680
1680
|
}
|
|
1681
|
-
function wrapRequiredFlag(
|
|
1682
|
-
return `(${
|
|
1681
|
+
function wrapRequiredFlag(text5) {
|
|
1682
|
+
return `(${text5})`;
|
|
1683
1683
|
}
|
|
1684
|
-
function wrapOptionalFlag(
|
|
1685
|
-
return `[${
|
|
1684
|
+
function wrapOptionalFlag(text5) {
|
|
1685
|
+
return `[${text5}]`;
|
|
1686
1686
|
}
|
|
1687
|
-
function wrapVariadicFlag(
|
|
1688
|
-
return `${
|
|
1687
|
+
function wrapVariadicFlag(text5) {
|
|
1688
|
+
return `${text5}...`;
|
|
1689
1689
|
}
|
|
1690
|
-
function wrapRequiredParameter(
|
|
1691
|
-
return `<${
|
|
1690
|
+
function wrapRequiredParameter(text5) {
|
|
1691
|
+
return `<${text5}>`;
|
|
1692
1692
|
}
|
|
1693
|
-
function wrapOptionalParameter(
|
|
1694
|
-
return `[<${
|
|
1693
|
+
function wrapOptionalParameter(text5) {
|
|
1694
|
+
return `[<${text5}>]`;
|
|
1695
1695
|
}
|
|
1696
|
-
function wrapVariadicParameter(
|
|
1697
|
-
return `<${
|
|
1696
|
+
function wrapVariadicParameter(text5) {
|
|
1697
|
+
return `<${text5}>...`;
|
|
1698
1698
|
}
|
|
1699
1699
|
function formatUsageLineForParameters(parameters, args) {
|
|
1700
1700
|
const flagsUsage = Object.entries(parameters.flags ?? {}).filter(([, flag2]) => {
|
|
@@ -1806,11 +1806,11 @@ function buildApplication(root2, appConfig, integrations) {
|
|
|
1806
1806
|
if ("text" in config.localization) {
|
|
1807
1807
|
defaultText = config.localization.text;
|
|
1808
1808
|
} else {
|
|
1809
|
-
const
|
|
1810
|
-
if (!
|
|
1809
|
+
const text5 = config.localization.loadText(config.localization.defaultLocale);
|
|
1810
|
+
if (!text5) {
|
|
1811
1811
|
throw new InternalError(`No text available for the default locale "${config.localization.defaultLocale}"`);
|
|
1812
1812
|
}
|
|
1813
|
-
defaultText =
|
|
1813
|
+
defaultText = text5;
|
|
1814
1814
|
}
|
|
1815
1815
|
if (integrations) {
|
|
1816
1816
|
checkIntegrationsForCollisions(integrations, config.scanner.caseStyle);
|
|
@@ -2077,8 +2077,8 @@ function buildCommand(builderArgs) {
|
|
|
2077
2077
|
const lines = [
|
|
2078
2078
|
...generateCommandHelpLines(builderArgs.parameters, builderArgs.docs, args)
|
|
2079
2079
|
];
|
|
2080
|
-
const
|
|
2081
|
-
return
|
|
2080
|
+
const text5 = lines.join("\n");
|
|
2081
|
+
return text5 + "\n";
|
|
2082
2082
|
},
|
|
2083
2083
|
usesFlag: (flagName, caseStyle) => {
|
|
2084
2084
|
if (caseStyle === "allow-kebab-for-camel") {
|
|
@@ -2203,8 +2203,8 @@ function buildRouteMap({
|
|
|
2203
2203
|
},
|
|
2204
2204
|
formatHelp: (args) => {
|
|
2205
2205
|
const lines = [...generateRouteMapHelpLines(routes, docs, args)];
|
|
2206
|
-
const
|
|
2207
|
-
return
|
|
2206
|
+
const text5 = lines.join("\n");
|
|
2207
|
+
return text5 + "\n";
|
|
2208
2208
|
},
|
|
2209
2209
|
getDefaultCommand: () => {
|
|
2210
2210
|
return defaultCommand;
|
|
@@ -2271,8 +2271,9 @@ async function run(app2, inputs, context) {
|
|
|
2271
2271
|
// package.json
|
|
2272
2272
|
var package_default = {
|
|
2273
2273
|
name: "hactl",
|
|
2274
|
-
version: "0.
|
|
2274
|
+
version: "0.8.0",
|
|
2275
2275
|
description: "Manage Home Assistant instances from the command line",
|
|
2276
|
+
license: "MIT",
|
|
2276
2277
|
repository: {
|
|
2277
2278
|
type: "git",
|
|
2278
2279
|
url: "git+https://github.com/houfio/hactl.git"
|
|
@@ -2371,10 +2372,10 @@ var Issues = true ? true ? (
|
|
|
2371
2372
|
get issues() {
|
|
2372
2373
|
return serializableIssues(this._);
|
|
2373
2374
|
}
|
|
2374
|
-
_e(data, code, expected, message,
|
|
2375
|
+
_e(data, code, expected, message, text5) {
|
|
2375
2376
|
this._.push({ code, path: this._p.slice(), data, expected, message });
|
|
2376
2377
|
if (false)
|
|
2377
|
-
|
|
2378
|
+
text5?.(this._[this._.length - 1]);
|
|
2378
2379
|
return void 0;
|
|
2379
2380
|
}
|
|
2380
2381
|
_k(apply, data, key, ...missing) {
|
|
@@ -2422,10 +2423,10 @@ var Issues = true ? true ? (
|
|
|
2422
2423
|
get issues() {
|
|
2423
2424
|
return serializableIssues(this._);
|
|
2424
2425
|
}
|
|
2425
|
-
_e(data, code, expected, message,
|
|
2426
|
+
_e(data, code, expected, message, text5) {
|
|
2426
2427
|
this._.push({ code, path: this._p.slice(), data, expected, message });
|
|
2427
2428
|
if (false)
|
|
2428
|
-
|
|
2429
|
+
text5?.(this._[this._.length - 1]);
|
|
2429
2430
|
return void 0;
|
|
2430
2431
|
}
|
|
2431
2432
|
_k(apply, data, key, ...missing) {
|
|
@@ -2600,7 +2601,7 @@ var InternalTraversal = class {
|
|
|
2600
2601
|
});
|
|
2601
2602
|
}
|
|
2602
2603
|
/** @internal a validator's failure, as its errors take one */
|
|
2603
|
-
_e(data, code, expected, message,
|
|
2604
|
+
_e(data, code, expected, message, text5) {
|
|
2604
2605
|
const issue = {
|
|
2605
2606
|
code,
|
|
2606
2607
|
path: this.path.slice(),
|
|
@@ -2609,7 +2610,7 @@ var InternalTraversal = class {
|
|
|
2609
2610
|
message
|
|
2610
2611
|
};
|
|
2611
2612
|
if (false)
|
|
2612
|
-
|
|
2613
|
+
text5?.(issue);
|
|
2613
2614
|
this.addError(issue);
|
|
2614
2615
|
return this.failFast;
|
|
2615
2616
|
}
|
|
@@ -2836,8 +2837,8 @@ function sethole1sll4ir138426n() {
|
|
|
2836
2837
|
return true;
|
|
2837
2838
|
}
|
|
2838
2839
|
|
|
2839
|
-
// arktype:~arktype/
|
|
2840
|
-
var [intersectionwidg351n2f7o4Validator,
|
|
2840
|
+
// arktype:~arktype/upswro0hwvfo3-1ocqovb11lm13c
|
|
2841
|
+
var [intersectionwidg351n2f7o4Validator, intersectionegwyf90w1alu2Validator, intersection6w7z2u03slcwpValidator, intersection1lvjdu61ps4xl0Validator, intersection1kfvut30tftkihValidator, intersection1y5nwst153l9s2Validator, intersection1r95ni81xgl88zValidator, intersection8yr2o71ja81ufValidator, intersectionxcm1o1s6e9exValidator, intersection17r4na700khzejValidator, intersection1649hnt0ixrxb1Validator, intersection15ttlhb0m0yhovValidator, intersection10qmong0na8e8rValidator, intersection1nv9uj515bs7itValidator, intersection3rk9um0b729ivValidator, intersection1dmk4z81d1f8mlValidator, intersection1tagcym1fnxkeyValidator, intersection1rp35ue1fi65ccValidator, intersection128bswg1yy3khmValidator, intersection1etdk1h0e9wp9wValidator, intersectionax9iml0n3vs6rValidator, intersection1v7qsxg01pq0unValidator, intersection1vhhd710xh4d2c, intersection1r8kxb1yxb7ek, intersectiongn35sl1ajga14] = (
|
|
2841
2842
|
/* @__NOINLINE__ */
|
|
2842
2843
|
(() => {
|
|
2843
2844
|
const create1sex1811cremth2 = (({ 0: allows, 1: apply }) => {
|
|
@@ -2981,14 +2982,14 @@ var [intersectionwidg351n2f7o4Validator, intersection17r4na700khzejValidator, in
|
|
|
2981
2982
|
}
|
|
2982
2983
|
return false;
|
|
2983
2984
|
}
|
|
2984
|
-
function
|
|
2985
|
+
function intersection15l8ulg0cdy2drAllows(data, ctx) {
|
|
2985
2986
|
for (; ; ) {
|
|
2986
2987
|
if (!Array.isArray(data)) {
|
|
2987
2988
|
break;
|
|
2988
2989
|
}
|
|
2989
2990
|
for (let i = 0; i < data.length; i++) {
|
|
2990
2991
|
if (!/* @__NOINLINE__ */
|
|
2991
|
-
|
|
2992
|
+
intersection1r8kxb1yxb7ekAllows(data[i])) {
|
|
2992
2993
|
return false;
|
|
2993
2994
|
}
|
|
2994
2995
|
}
|
|
@@ -2996,14 +2997,14 @@ var [intersectionwidg351n2f7o4Validator, intersection17r4na700khzejValidator, in
|
|
|
2996
2997
|
}
|
|
2997
2998
|
return false;
|
|
2998
2999
|
}
|
|
2999
|
-
function
|
|
3000
|
+
function intersection6aeab31tdpfdtAllows(data, ctx) {
|
|
3000
3001
|
for (; ; ) {
|
|
3001
3002
|
if (!Array.isArray(data)) {
|
|
3002
3003
|
break;
|
|
3003
3004
|
}
|
|
3004
3005
|
for (let i = 0; i < data.length; i++) {
|
|
3005
3006
|
if (!/* @__NOINLINE__ */
|
|
3006
|
-
|
|
3007
|
+
intersectiong1m2lv14ljv26Allows(data[i])) {
|
|
3007
3008
|
return false;
|
|
3008
3009
|
}
|
|
3009
3010
|
}
|
|
@@ -3395,9 +3396,9 @@ var [intersectionwidg351n2f7o4Validator, intersection17r4na700khzejValidator, in
|
|
|
3395
3396
|
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
3396
3397
|
return data.optional === false || data.optional === true || !failsKey(ctx, data, "optional", "discriminant", "boolean");
|
|
3397
3398
|
}
|
|
3398
|
-
function
|
|
3399
|
+
function intersectione4pcj513cxhmdApply(data, ctx) {
|
|
3399
3400
|
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
3400
|
-
return (typeof data.area_id === "string" || !fails0(ctx, data, "area_id")) && (typeof data.name === "string" || !fails0(ctx, data, "name")) && (!("floor_id" in data) || !ctx._k(union1jkn5x91bzd348Apply, data, "floor_id"));
|
|
3401
|
+
return (typeof data.area_id === "string" || !fails0(ctx, data, "area_id")) && (typeof data.name === "string" || !fails0(ctx, data, "name")) && (!("floor_id" in data) || !ctx._k(union1jkn5x91bzd348Apply, data, "floor_id")) && (!("labels" in data) || !ctx._k(intersection1kfvut30tftkihApply, data, "labels"));
|
|
3401
3402
|
}
|
|
3402
3403
|
function intersection1idvyi512mjtrzApply(data, ctx) {
|
|
3403
3404
|
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
@@ -3415,14 +3416,22 @@ var [intersectionwidg351n2f7o4Validator, intersection17r4na700khzejValidator, in
|
|
|
3415
3416
|
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
3416
3417
|
return (typeof data.entity_id === "string" || !fails0(ctx, data, "entity_id")) && (typeof data.state === "string" || !fails0(ctx, data, "state")) && !ctx._k(intersection1in70h716rkr52Apply, data, "attributes", "an object") && (typeof data.last_changed === "string" || !fails0(ctx, data, "last_changed"));
|
|
3417
3418
|
}
|
|
3418
|
-
function
|
|
3419
|
+
function intersectionadina16r612gApply(data, ctx) {
|
|
3419
3420
|
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
3420
|
-
return (typeof data.
|
|
3421
|
+
return (typeof data.floor_id === "string" || !fails0(ctx, data, "floor_id")) && (typeof data.name === "string" || !fails0(ctx, data, "name")) && (!("level" in data) || !ctx._k(union1cy4v7a1543qpiApply, data, "level")) && (!("aliases" in data) || !ctx._k(intersection1kfvut30tftkihApply, data, "aliases")) && (!("icon" in data) || !ctx._k(union1jkn5x91bzd348Apply, data, "icon"));
|
|
3422
|
+
}
|
|
3423
|
+
function intersectionh0z94150ckodApply(data, ctx) {
|
|
3424
|
+
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
3425
|
+
return (typeof data.id === "string" || !fails0(ctx, data, "id")) && (!("name" in data) || !ctx._k(union1jkn5x91bzd348Apply, data, "name")) && (!("name_by_user" in data) || !ctx._k(union1jkn5x91bzd348Apply, data, "name_by_user")) && (!("manufacturer" in data) || !ctx._k(union1jkn5x91bzd348Apply, data, "manufacturer")) && (!("model" in data) || !ctx._k(union1jkn5x91bzd348Apply, data, "model")) && (!("area_id" in data) || !ctx._k(union1jkn5x91bzd348Apply, data, "area_id")) && (!("labels" in data) || !ctx._k(intersection1kfvut30tftkihApply, data, "labels")) && (!("disabled_by" in data) || !ctx._k(union1jkn5x91bzd348Apply, data, "disabled_by")) && (!("identifiers" in data) || !ctx._k(intersection6aeab31tdpfdtApply, data, "identifiers"));
|
|
3421
3426
|
}
|
|
3422
3427
|
function intersection15cfdd30ejztvcApply(data, ctx) {
|
|
3423
3428
|
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
3424
3429
|
return typeof data.id === "string" || !fails0(ctx, data, "id");
|
|
3425
3430
|
}
|
|
3431
|
+
function intersectioncvon2w1hep5foApply(data, ctx) {
|
|
3432
|
+
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
3433
|
+
return (typeof data.label_id === "string" || !fails0(ctx, data, "label_id")) && (typeof data.name === "string" || !fails0(ctx, data, "name")) && (!("description" in data) || !ctx._k(union1jkn5x91bzd348Apply, data, "description")) && (!("color" in data) || !ctx._k(union1jkn5x91bzd348Apply, data, "color")) && (!("icon" in data) || !ctx._k(union1jkn5x91bzd348Apply, data, "icon"));
|
|
3434
|
+
}
|
|
3426
3435
|
function intersectionpk5ov80e6ufcoApply(data, ctx) {
|
|
3427
3436
|
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
3428
3437
|
return (typeof data.message === "string" || !fails0(ctx, data, "message")) && (!("code" in data) || !(!(typeof data.code === "string") && ctx._k((data2, ctx2) => !ctx2._e(data2, "domain", "a string"), data, "code"))) && (!("translation_key" in data) || !ctx._k(union1jkn5x91bzd348Apply, data, "translation_key"));
|
|
@@ -3627,6 +3636,12 @@ var [intersectionwidg351n2f7o4Validator, intersection17r4na700khzejValidator, in
|
|
|
3627
3636
|
function intersection14a2mca0qafrxyAllows(data, ctx) {
|
|
3628
3637
|
return typeof data === "string" && data.length >= 1;
|
|
3629
3638
|
}
|
|
3639
|
+
function domainppxq4x1g3wemyApply(data, ctx) {
|
|
3640
|
+
return Number.isFinite(data) || !ctx._e(data, "domain", "a number");
|
|
3641
|
+
}
|
|
3642
|
+
function union1cy4v7a1543qpiApply(data, ctx) {
|
|
3643
|
+
return data === null || (typeof data === "number" ? domainppxq4x1g3wemyApply(data, ctx) : !ctx._e(data, "discriminant", "a number or null"));
|
|
3644
|
+
}
|
|
3630
3645
|
function union1jkn5x91bzd348Apply(data, ctx) {
|
|
3631
3646
|
return data === null || (typeof data === "string" ? true : !ctx._e(data, "discriminant", "a string or null"));
|
|
3632
3647
|
}
|
|
@@ -3639,14 +3654,15 @@ var [intersectionwidg351n2f7o4Validator, intersection17r4na700khzejValidator, in
|
|
|
3639
3654
|
function domainwf1rf311hsq3lAllows(data, ctx) {
|
|
3640
3655
|
return typeof data === "string";
|
|
3641
3656
|
}
|
|
3642
|
-
function
|
|
3657
|
+
function intersectione4pcj513cxhmdAllows(data, ctx) {
|
|
3643
3658
|
switch (data) {
|
|
3644
3659
|
case null:
|
|
3645
3660
|
case void 0:
|
|
3646
3661
|
break;
|
|
3647
3662
|
default:
|
|
3648
3663
|
data.area_id;
|
|
3649
|
-
if ((data instanceof Object || Object(data) === data) && (typeof data.area_id === "string" && typeof data.name === "string" && (!("floor_id" in data) || !!(typeof data.floor_id === "string" || data.floor_id === null)))
|
|
3664
|
+
if ((data instanceof Object || Object(data) === data) && (typeof data.area_id === "string" && typeof data.name === "string" && (!("floor_id" in data) || !!(typeof data.floor_id === "string" || data.floor_id === null)) && (!("labels" in data) || !!/* @__NOINLINE__ */
|
|
3665
|
+
intersection1kfvut30tftkihAllows(data.labels)))) {
|
|
3650
3666
|
return true;
|
|
3651
3667
|
}
|
|
3652
3668
|
}
|
|
@@ -3723,14 +3739,15 @@ var [intersectionwidg351n2f7o4Validator, intersection17r4na700khzejValidator, in
|
|
|
3723
3739
|
}
|
|
3724
3740
|
return false;
|
|
3725
3741
|
}
|
|
3726
|
-
function
|
|
3742
|
+
function intersectionh0z94150ckodAllows(data, ctx) {
|
|
3727
3743
|
switch (data) {
|
|
3728
3744
|
case null:
|
|
3729
3745
|
case void 0:
|
|
3730
3746
|
break;
|
|
3731
3747
|
default:
|
|
3732
3748
|
data.id;
|
|
3733
|
-
if ((data instanceof Object || Object(data) === data) && (typeof data.id === "string" && (!("name" in data) || !!(typeof data.name === "string" || data.name === null)) && (!("name_by_user" in data) || !!(typeof data.name_by_user === "string" || data.name_by_user === null)) && (!("manufacturer" in data) || !!(typeof data.manufacturer === "string" || data.manufacturer === null)) && (!("model" in data) || !!(typeof data.model === "string" || data.model === null)) && (!("area_id" in data) || !!(typeof data.area_id === "string" || data.area_id === null)) && (!("disabled_by" in data) || !!(typeof data.disabled_by === "string" || data.disabled_by === null)) && (!("
|
|
3749
|
+
if ((data instanceof Object || Object(data) === data) && (typeof data.id === "string" && (!("name" in data) || !!(typeof data.name === "string" || data.name === null)) && (!("name_by_user" in data) || !!(typeof data.name_by_user === "string" || data.name_by_user === null)) && (!("manufacturer" in data) || !!(typeof data.manufacturer === "string" || data.manufacturer === null)) && (!("model" in data) || !!(typeof data.model === "string" || data.model === null)) && (!("area_id" in data) || !!(typeof data.area_id === "string" || data.area_id === null)) && (!("disabled_by" in data) || !!(typeof data.disabled_by === "string" || data.disabled_by === null)) && (!("labels" in data) || !!/* @__NOINLINE__ */
|
|
3750
|
+
intersection1kfvut30tftkihAllows(data.labels)) && (!("identifiers" in data) || !!/* @__NOINLINE__ */
|
|
3734
3751
|
intersection6aeab31tdpfdtAllows(data.identifiers)))) {
|
|
3735
3752
|
return true;
|
|
3736
3753
|
}
|
|
@@ -3750,6 +3767,33 @@ var [intersectionwidg351n2f7o4Validator, intersection17r4na700khzejValidator, in
|
|
|
3750
3767
|
}
|
|
3751
3768
|
return false;
|
|
3752
3769
|
}
|
|
3770
|
+
function intersectioncvon2w1hep5foAllows(data, ctx) {
|
|
3771
|
+
switch (data) {
|
|
3772
|
+
case null:
|
|
3773
|
+
case void 0:
|
|
3774
|
+
break;
|
|
3775
|
+
default:
|
|
3776
|
+
data.label_id;
|
|
3777
|
+
if ((data instanceof Object || Object(data) === data) && (typeof data.label_id === "string" && typeof data.name === "string" && (!("description" in data) || !!(typeof data.description === "string" || data.description === null)) && (!("color" in data) || !!(typeof data.color === "string" || data.color === null)) && (!("icon" in data) || !!(typeof data.icon === "string" || data.icon === null)))) {
|
|
3778
|
+
return true;
|
|
3779
|
+
}
|
|
3780
|
+
}
|
|
3781
|
+
return false;
|
|
3782
|
+
}
|
|
3783
|
+
function intersectionadina16r612gAllows(data, ctx) {
|
|
3784
|
+
switch (data) {
|
|
3785
|
+
case null:
|
|
3786
|
+
case void 0:
|
|
3787
|
+
break;
|
|
3788
|
+
default:
|
|
3789
|
+
data.level;
|
|
3790
|
+
if ((data instanceof Object || Object(data) === data) && ((!("level" in data) || !!(Number.isFinite(data.level) || data.level === null)) && typeof data.floor_id === "string" && typeof data.name === "string" && (!("icon" in data) || !!(typeof data.icon === "string" || data.icon === null)) && (!("aliases" in data) || !!/* @__NOINLINE__ */
|
|
3791
|
+
intersection1kfvut30tftkihAllows(data.aliases)))) {
|
|
3792
|
+
return true;
|
|
3793
|
+
}
|
|
3794
|
+
}
|
|
3795
|
+
return false;
|
|
3796
|
+
}
|
|
3753
3797
|
function intersectionpk5ov80e6ufcoAllows(data, ctx) {
|
|
3754
3798
|
switch (data) {
|
|
3755
3799
|
case null:
|
|
@@ -3941,22 +3985,6 @@ var [intersectionwidg351n2f7o4Validator, intersection17r4na700khzejValidator, in
|
|
|
3941
3985
|
}, function(data, ctx) {
|
|
3942
3986
|
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
3943
3987
|
return !ctx._k(intersection15cfdd30ejztvcApply, data, "context", "an object");
|
|
3944
|
-
}]), create1sex1811cremth2([function(data, ctx) {
|
|
3945
|
-
switch (data) {
|
|
3946
|
-
case null:
|
|
3947
|
-
case void 0:
|
|
3948
|
-
break;
|
|
3949
|
-
default:
|
|
3950
|
-
data.response;
|
|
3951
|
-
if ((data instanceof Object || Object(data) === data) && ("response" in data && !!/* @__NOINLINE__ */
|
|
3952
|
-
intersectionc5cirx0ys2jaeAllows(data.response))) {
|
|
3953
|
-
return true;
|
|
3954
|
-
}
|
|
3955
|
-
}
|
|
3956
|
-
return false;
|
|
3957
|
-
}, function(data, ctx) {
|
|
3958
|
-
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
3959
|
-
return "response" in data ? !ctx._k(intersectionc5cirx0ys2jaeAllows, data, "response") : !failsKey(ctx, data, "response", "required", "present");
|
|
3960
3988
|
}]), create1sex1811cremth2([function(data, ctx) {
|
|
3961
3989
|
switch (data) {
|
|
3962
3990
|
case null:
|
|
@@ -4031,6 +4059,112 @@ var [intersectionwidg351n2f7o4Validator, intersection17r4na700khzejValidator, in
|
|
|
4031
4059
|
}, function(data, ctx) {
|
|
4032
4060
|
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
4033
4061
|
return !ctx._k(intersectionoku03304znz6aApply, data, "addons", "an array");
|
|
4062
|
+
}]), create1sex1811cremth2([function(data, ctx) {
|
|
4063
|
+
switch (data) {
|
|
4064
|
+
case null:
|
|
4065
|
+
case void 0:
|
|
4066
|
+
break;
|
|
4067
|
+
default:
|
|
4068
|
+
data.result;
|
|
4069
|
+
if ((data instanceof Object || Object(data) === data) && ("result" in data && !!/* @__NOINLINE__ */
|
|
4070
|
+
intersectionc5cirx0ys2jaeAllows(data.result))) {
|
|
4071
|
+
return true;
|
|
4072
|
+
}
|
|
4073
|
+
}
|
|
4074
|
+
return false;
|
|
4075
|
+
}, function(data, ctx) {
|
|
4076
|
+
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
4077
|
+
return "result" in data ? !ctx._k(intersectionc5cirx0ys2jaeAllows, data, "result") : !failsKey(ctx, data, "result", "required", "present");
|
|
4078
|
+
}]), create1sex1811cremth2([function(data, ctx) {
|
|
4079
|
+
switch (data) {
|
|
4080
|
+
case null:
|
|
4081
|
+
case void 0:
|
|
4082
|
+
break;
|
|
4083
|
+
default:
|
|
4084
|
+
data.error;
|
|
4085
|
+
if ((data instanceof Object || Object(data) === data) && (typeof data.error === "string" && typeof data.level === "string")) {
|
|
4086
|
+
return true;
|
|
4087
|
+
}
|
|
4088
|
+
}
|
|
4089
|
+
return false;
|
|
4090
|
+
}, function(data, ctx) {
|
|
4091
|
+
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
4092
|
+
return (typeof data.error === "string" || !fails0(ctx, data, "error")) && (typeof data.level === "string" || !fails0(ctx, data, "level"));
|
|
4093
|
+
}]), create1sex1811cremth2([function(data, ctx) {
|
|
4094
|
+
switch (data) {
|
|
4095
|
+
case null:
|
|
4096
|
+
case void 0:
|
|
4097
|
+
break;
|
|
4098
|
+
default:
|
|
4099
|
+
data.id;
|
|
4100
|
+
if ((data instanceof Object || Object(data) === data) && ((!("id" in data) || !!Number.isFinite(data.id)) && (!("success" in data) || !!(data.success === false || data.success === true)) && typeof data.type === "string" && (!("result" in data) || !!/* @__NOINLINE__ */
|
|
4101
|
+
intersectionc5cirx0ys2jaeAllows(data.result)) && (!("event" in data) || !!/* @__NOINLINE__ */
|
|
4102
|
+
intersectionc5cirx0ys2jaeAllows(data.event)) && (!("error" in data) || !!/* @__NOINLINE__ */
|
|
4103
|
+
intersectionpk5ov80e6ufcoAllows(data.error)))) {
|
|
4104
|
+
return true;
|
|
4105
|
+
}
|
|
4106
|
+
}
|
|
4107
|
+
return false;
|
|
4108
|
+
}, function(data, ctx) {
|
|
4109
|
+
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
4110
|
+
return (typeof data.type === "string" || !fails0(ctx, data, "type")) && (!("id" in data) || !(!Number.isFinite(data.id) && ctx._k((data2, ctx2) => !ctx2._e(data2, "domain", "a number"), data, "id"))) && (!("success" in data) || !ctx._k(union1jlxhky12plhj9Apply, data, "success")) && (!("result" in data) || !ctx._k(intersectionc5cirx0ys2jaeAllows, data, "result")) && (!("event" in data) || !ctx._k(intersectionc5cirx0ys2jaeAllows, data, "event")) && (!("error" in data) || !ctx._k(intersectionpk5ov80e6ufcoApply, data, "error"));
|
|
4111
|
+
}]), create1sex1811cremth2([function(data, ctx) {
|
|
4112
|
+
switch (data) {
|
|
4113
|
+
case null:
|
|
4114
|
+
case void 0:
|
|
4115
|
+
break;
|
|
4116
|
+
default:
|
|
4117
|
+
data.response;
|
|
4118
|
+
if ((data instanceof Object || Object(data) === data) && ("response" in data && !!/* @__NOINLINE__ */
|
|
4119
|
+
intersectionc5cirx0ys2jaeAllows(data.response))) {
|
|
4120
|
+
return true;
|
|
4121
|
+
}
|
|
4122
|
+
}
|
|
4123
|
+
return false;
|
|
4124
|
+
}, function(data, ctx) {
|
|
4125
|
+
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
4126
|
+
return "response" in data ? !ctx._k(intersectionc5cirx0ys2jaeAllows, data, "response") : !failsKey(ctx, data, "response", "required", "present");
|
|
4127
|
+
}]), create1sex1811cremth2([function(data, ctx) {
|
|
4128
|
+
for (; ; ) {
|
|
4129
|
+
if (!(typeof data === "string")) {
|
|
4130
|
+
break;
|
|
4131
|
+
}
|
|
4132
|
+
if (!literal0.test(data)) {
|
|
4133
|
+
break;
|
|
4134
|
+
}
|
|
4135
|
+
if (!/* @__NOINLINE__ */
|
|
4136
|
+
intersection1649hnt0ixrxb1R3(data)) {
|
|
4137
|
+
break;
|
|
4138
|
+
}
|
|
4139
|
+
return true;
|
|
4140
|
+
}
|
|
4141
|
+
return false;
|
|
4142
|
+
}, function(data, ctx) {
|
|
4143
|
+
if (!(typeof data === "string")) {
|
|
4144
|
+
return !ctx._e(data, "domain", "a string");
|
|
4145
|
+
}
|
|
4146
|
+
if (!literal0.test(data)) {
|
|
4147
|
+
return !ctx._e(data, "pattern", "an HTTP or HTTPS URL");
|
|
4148
|
+
}
|
|
4149
|
+
{
|
|
4150
|
+
return !!intersection1649hnt0ixrxb1R3(data, ctx) || !ctx._e(data, "predicate", "an HTTP or HTTPS URL");
|
|
4151
|
+
}
|
|
4152
|
+
}]), create1sex1811cremth2([function(data, ctx) {
|
|
4153
|
+
switch (data) {
|
|
4154
|
+
case null:
|
|
4155
|
+
case void 0:
|
|
4156
|
+
break;
|
|
4157
|
+
default:
|
|
4158
|
+
data.version;
|
|
4159
|
+
if ((data instanceof Object || Object(data) === data) && (typeof data.version === "string" && typeof data.state === "string" && /* @__NOINLINE__ */
|
|
4160
|
+
intersection1kfvut30tftkihAllows(data.components))) {
|
|
4161
|
+
return true;
|
|
4162
|
+
}
|
|
4163
|
+
}
|
|
4164
|
+
return false;
|
|
4165
|
+
}, function(data, ctx) {
|
|
4166
|
+
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
4167
|
+
return (typeof data.version === "string" || !fails0(ctx, data, "version")) && (typeof data.state === "string" || !fails0(ctx, data, "state")) && !ctx._k(intersection1kfvut30tftkihApply, data, "components", "an array");
|
|
4034
4168
|
}]), create1sex1811cremth2([function(data, ctx) {
|
|
4035
4169
|
for (; ; ) {
|
|
4036
4170
|
if (!Array.isArray(data)) {
|
|
@@ -4088,7 +4222,57 @@ var [intersectionwidg351n2f7o4Validator, intersection17r4na700khzejValidator, in
|
|
|
4088
4222
|
}
|
|
4089
4223
|
for (let i = 0; i < data.length; i++) {
|
|
4090
4224
|
if (!/* @__NOINLINE__ */
|
|
4091
|
-
|
|
4225
|
+
intersectionh0z94150ckodAllows(data[i])) {
|
|
4226
|
+
return false;
|
|
4227
|
+
}
|
|
4228
|
+
}
|
|
4229
|
+
return true;
|
|
4230
|
+
}
|
|
4231
|
+
return false;
|
|
4232
|
+
}, function(data, ctx) {
|
|
4233
|
+
if (!Array.isArray(data)) {
|
|
4234
|
+
return !ctx._e(data, "proto", "an array");
|
|
4235
|
+
}
|
|
4236
|
+
for (let i = 0; i < data.length; i++) {
|
|
4237
|
+
if (!/* @__NOINLINE__ */
|
|
4238
|
+
intersectionh0z94150ckodAllows(data[i], ctx) && ctx._k(intersectionh0z94150ckodApply, data, i)) {
|
|
4239
|
+
return false;
|
|
4240
|
+
}
|
|
4241
|
+
}
|
|
4242
|
+
return true;
|
|
4243
|
+
}]), create1sex1811cremth2([function(data, ctx) {
|
|
4244
|
+
for (; ; ) {
|
|
4245
|
+
if (!Array.isArray(data)) {
|
|
4246
|
+
break;
|
|
4247
|
+
}
|
|
4248
|
+
for (let i = 0; i < data.length; i++) {
|
|
4249
|
+
if (!/* @__NOINLINE__ */
|
|
4250
|
+
intersectione4pcj513cxhmdAllows(data[i])) {
|
|
4251
|
+
return false;
|
|
4252
|
+
}
|
|
4253
|
+
}
|
|
4254
|
+
return true;
|
|
4255
|
+
}
|
|
4256
|
+
return false;
|
|
4257
|
+
}, function(data, ctx) {
|
|
4258
|
+
if (!Array.isArray(data)) {
|
|
4259
|
+
return !ctx._e(data, "proto", "an array");
|
|
4260
|
+
}
|
|
4261
|
+
for (let i = 0; i < data.length; i++) {
|
|
4262
|
+
if (!/* @__NOINLINE__ */
|
|
4263
|
+
intersectione4pcj513cxhmdAllows(data[i], ctx) && ctx._k(intersectione4pcj513cxhmdApply, data, i)) {
|
|
4264
|
+
return false;
|
|
4265
|
+
}
|
|
4266
|
+
}
|
|
4267
|
+
return true;
|
|
4268
|
+
}]), create1sex1811cremth2([function(data, ctx) {
|
|
4269
|
+
for (; ; ) {
|
|
4270
|
+
if (!Array.isArray(data)) {
|
|
4271
|
+
break;
|
|
4272
|
+
}
|
|
4273
|
+
for (let i = 0; i < data.length; i++) {
|
|
4274
|
+
if (!/* @__NOINLINE__ */
|
|
4275
|
+
intersectionadina16r612gAllows(data[i])) {
|
|
4092
4276
|
return false;
|
|
4093
4277
|
}
|
|
4094
4278
|
}
|
|
@@ -4101,7 +4285,7 @@ var [intersectionwidg351n2f7o4Validator, intersection17r4na700khzejValidator, in
|
|
|
4101
4285
|
}
|
|
4102
4286
|
for (let i = 0; i < data.length; i++) {
|
|
4103
4287
|
if (!/* @__NOINLINE__ */
|
|
4104
|
-
|
|
4288
|
+
intersectionadina16r612gAllows(data[i], ctx) && ctx._k(intersectionadina16r612gApply, data, i)) {
|
|
4105
4289
|
return false;
|
|
4106
4290
|
}
|
|
4107
4291
|
}
|
|
@@ -4113,7 +4297,7 @@ var [intersectionwidg351n2f7o4Validator, intersection17r4na700khzejValidator, in
|
|
|
4113
4297
|
}
|
|
4114
4298
|
for (let i = 0; i < data.length; i++) {
|
|
4115
4299
|
if (!/* @__NOINLINE__ */
|
|
4116
|
-
|
|
4300
|
+
intersectioncvon2w1hep5foAllows(data[i])) {
|
|
4117
4301
|
return false;
|
|
4118
4302
|
}
|
|
4119
4303
|
}
|
|
@@ -4126,7 +4310,7 @@ var [intersectionwidg351n2f7o4Validator, intersection17r4na700khzejValidator, in
|
|
|
4126
4310
|
}
|
|
4127
4311
|
for (let i = 0; i < data.length; i++) {
|
|
4128
4312
|
if (!/* @__NOINLINE__ */
|
|
4129
|
-
|
|
4313
|
+
intersectioncvon2w1hep5foAllows(data[i], ctx) && ctx._k(intersectioncvon2w1hep5foApply, data, i)) {
|
|
4130
4314
|
return false;
|
|
4131
4315
|
}
|
|
4132
4316
|
}
|
|
@@ -4181,65 +4365,6 @@ var [intersectionwidg351n2f7o4Validator, intersection17r4na700khzejValidator, in
|
|
|
4181
4365
|
}, function(data, ctx) {
|
|
4182
4366
|
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
4183
4367
|
return !ctx._k(intersection1wj0gg91b5c2hlApply, data, "resources", "an object");
|
|
4184
|
-
}]), create1sex1811cremth2([function(data, ctx) {
|
|
4185
|
-
switch (data) {
|
|
4186
|
-
case null:
|
|
4187
|
-
case void 0:
|
|
4188
|
-
break;
|
|
4189
|
-
default:
|
|
4190
|
-
data.id;
|
|
4191
|
-
if ((data instanceof Object || Object(data) === data) && ((!("id" in data) || !!Number.isFinite(data.id)) && (!("success" in data) || !!(data.success === false || data.success === true)) && typeof data.type === "string" && (!("result" in data) || !!/* @__NOINLINE__ */
|
|
4192
|
-
intersectionc5cirx0ys2jaeAllows(data.result)) && (!("event" in data) || !!/* @__NOINLINE__ */
|
|
4193
|
-
intersectionc5cirx0ys2jaeAllows(data.event)) && (!("error" in data) || !!/* @__NOINLINE__ */
|
|
4194
|
-
intersectionpk5ov80e6ufcoAllows(data.error)))) {
|
|
4195
|
-
return true;
|
|
4196
|
-
}
|
|
4197
|
-
}
|
|
4198
|
-
return false;
|
|
4199
|
-
}, function(data, ctx) {
|
|
4200
|
-
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
4201
|
-
return (typeof data.type === "string" || !fails0(ctx, data, "type")) && (!("id" in data) || !(!Number.isFinite(data.id) && ctx._k((data2, ctx2) => !ctx2._e(data2, "domain", "a number"), data, "id"))) && (!("success" in data) || !ctx._k(union1jlxhky12plhj9Apply, data, "success")) && (!("result" in data) || !ctx._k(intersectionc5cirx0ys2jaeAllows, data, "result")) && (!("event" in data) || !ctx._k(intersectionc5cirx0ys2jaeAllows, data, "event")) && (!("error" in data) || !ctx._k(intersectionpk5ov80e6ufcoApply, data, "error"));
|
|
4202
|
-
}]), create1sex1811cremth2([function(data, ctx) {
|
|
4203
|
-
for (; ; ) {
|
|
4204
|
-
if (!(typeof data === "string")) {
|
|
4205
|
-
break;
|
|
4206
|
-
}
|
|
4207
|
-
if (!literal0.test(data)) {
|
|
4208
|
-
break;
|
|
4209
|
-
}
|
|
4210
|
-
if (!/* @__NOINLINE__ */
|
|
4211
|
-
intersection1649hnt0ixrxb1R3(data)) {
|
|
4212
|
-
break;
|
|
4213
|
-
}
|
|
4214
|
-
return true;
|
|
4215
|
-
}
|
|
4216
|
-
return false;
|
|
4217
|
-
}, function(data, ctx) {
|
|
4218
|
-
if (!(typeof data === "string")) {
|
|
4219
|
-
return !ctx._e(data, "domain", "a string");
|
|
4220
|
-
}
|
|
4221
|
-
if (!literal0.test(data)) {
|
|
4222
|
-
return !ctx._e(data, "pattern", "an HTTP or HTTPS URL");
|
|
4223
|
-
}
|
|
4224
|
-
{
|
|
4225
|
-
return !!intersection1649hnt0ixrxb1R3(data, ctx) || !ctx._e(data, "predicate", "an HTTP or HTTPS URL");
|
|
4226
|
-
}
|
|
4227
|
-
}]), create1sex1811cremth2([function(data, ctx) {
|
|
4228
|
-
switch (data) {
|
|
4229
|
-
case null:
|
|
4230
|
-
case void 0:
|
|
4231
|
-
break;
|
|
4232
|
-
default:
|
|
4233
|
-
data.version;
|
|
4234
|
-
if ((data instanceof Object || Object(data) === data) && (typeof data.version === "string" && typeof data.state === "string" && /* @__NOINLINE__ */
|
|
4235
|
-
intersection1kfvut30tftkihAllows(data.components))) {
|
|
4236
|
-
return true;
|
|
4237
|
-
}
|
|
4238
|
-
}
|
|
4239
|
-
return false;
|
|
4240
|
-
}, function(data, ctx) {
|
|
4241
|
-
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
4242
|
-
return (typeof data.version === "string" || !fails0(ctx, data, "version")) && (typeof data.state === "string" || !fails0(ctx, data, "state")) && !ctx._k(intersection1kfvut30tftkihApply, data, "components", "an array");
|
|
4243
4368
|
}]), create1sex1811cremth2([function(data, ctx) {
|
|
4244
4369
|
switch (data) {
|
|
4245
4370
|
case null:
|
|
@@ -4299,7 +4424,7 @@ var create1sfgs3s1wvt6nb = (({ 0: allows, 1: apply }) => {
|
|
|
4299
4424
|
return validator;
|
|
4300
4425
|
});
|
|
4301
4426
|
|
|
4302
|
-
// arktype:~arktype/1kjg1ua1mbgoex-
|
|
4427
|
+
// arktype:~arktype/1kjg1ua1mbgoex-8fih7q1jgrmdt
|
|
4303
4428
|
var created4;
|
|
4304
4429
|
var factory1 = ((p0, p1) => {
|
|
4305
4430
|
checkHeld(p0);
|
|
@@ -4328,7 +4453,7 @@ var errorMeanings = {
|
|
|
4328
4453
|
token_missing: "The active context has no stored token",
|
|
4329
4454
|
keychain_unavailable: "The keychain tool is missing or failed",
|
|
4330
4455
|
unreachable: "The URL does not answer, or redirects",
|
|
4331
|
-
timeout: "A service call
|
|
4456
|
+
timeout: "A service call or template took too long or got no answer",
|
|
4332
4457
|
unauthorized: "Home Assistant rejected the token",
|
|
4333
4458
|
ha_error: "Home Assistant returned an error or an unexpected response",
|
|
4334
4459
|
ssh_not_configured: "The command needs SSH, but the context has no SSH target",
|
|
@@ -4336,7 +4461,7 @@ var errorMeanings = {
|
|
|
4336
4461
|
install_mismatch: "The context's install type does not match what Home Assistant reports",
|
|
4337
4462
|
container_not_running: "The Docker container is not running, or the SSH user cannot run docker",
|
|
4338
4463
|
config_dir_missing: "The config folder has no readable .HA_VERSION",
|
|
4339
|
-
not_found: "
|
|
4464
|
+
not_found: "A named thing does not exist, such as an entity, area, service, app or release",
|
|
4340
4465
|
not_a_binary: "`hactl upgrade` was run from source, not from a release binary",
|
|
4341
4466
|
upgrade_not_writable: "`hactl upgrade` cannot write to the folder the binary is in",
|
|
4342
4467
|
download_failed: "The downloaded binary failed its digest or version check"
|
|
@@ -4619,6 +4744,7 @@ async function resolveActiveContext(environment) {
|
|
|
4619
4744
|
// src/context.ts
|
|
4620
4745
|
import { homedir } from "node:os";
|
|
4621
4746
|
import { isSea } from "node:sea";
|
|
4747
|
+
import { text } from "node:stream/consumers";
|
|
4622
4748
|
|
|
4623
4749
|
// src/run.ts
|
|
4624
4750
|
import { spawn } from "node:child_process";
|
|
@@ -4758,9 +4884,9 @@ function macosKeychain(path, env) {
|
|
|
4758
4884
|
if (!tokenPattern.test(value)) {
|
|
4759
4885
|
throw new UsageError("the token contains characters a Home Assistant token never has");
|
|
4760
4886
|
}
|
|
4761
|
-
const
|
|
4887
|
+
const command5 = `add-generic-password -U -s hactl -a ${context} -w ${value}
|
|
4762
4888
|
`;
|
|
4763
|
-
const result = await runTool(path, ["-i"], env,
|
|
4889
|
+
const result = await runTool(path, ["-i"], env, command5);
|
|
4764
4890
|
if (result.code !== 0 || result.stderr.trim() !== "") {
|
|
4765
4891
|
throw toolFailed("security", "store the token", result);
|
|
4766
4892
|
}
|
|
@@ -4885,23 +5011,34 @@ var keyBegin = new RegExp(`-----BEGIN ${keyLabel}`);
|
|
|
4885
5011
|
var keyEnd = new RegExp(`-----END ${keyLabel}`);
|
|
4886
5012
|
var keyBlock = new RegExp(`-----BEGIN ${keyLabel}[\\s\\S]*?(?:-----END ${keyLabel}|$)`, "g");
|
|
4887
5013
|
var parameter = /([?&#;])([^=&#?;\s"'<>/]+)=([^&#\s"'<>]+)/g;
|
|
4888
|
-
function redactString(input, token) {
|
|
5014
|
+
function redactString(input, token, found) {
|
|
4889
5015
|
const literal = token?.reveal();
|
|
4890
|
-
const
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
5016
|
+
const text5 = literal ? input.replaceAll(literal, hidden) : input;
|
|
5017
|
+
const hide = (secret) => {
|
|
5018
|
+
found?.(secret);
|
|
5019
|
+
return hidden;
|
|
5020
|
+
};
|
|
5021
|
+
const hideAfter = (_, start, secret) => `${start}${hide(secret)}`;
|
|
5022
|
+
return text5.replace(keyBlock, hide).replace(/\b(Bearer[ \t]+)([A-Za-z0-9._~+/=-]+)/gi, hideAfter).replace(/eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*/g, hide).replace(/\bMT:[0-9A-Z.*-]{5,}/g, hide).replace(/(WIFI:(?:(?:\\.|[^\\;\n])*;)*?P:)((?:\\.|[^\\;\n"'])+)/g, hideAfter).replace(
|
|
5023
|
+
/\b([a-z][a-z0-9+.-]*:\/\/)([^/\s?#"'<>]+)@/gi,
|
|
5024
|
+
(_, scheme, userinfo) => {
|
|
5025
|
+
const password = userinfo.slice(userinfo.indexOf(":") + 1);
|
|
5026
|
+
if (password !== userinfo) {
|
|
5027
|
+
found?.(password);
|
|
5028
|
+
}
|
|
5029
|
+
return `${scheme}${hide(userinfo)}@`;
|
|
5030
|
+
}
|
|
5031
|
+
).replace(/(\/api\/(?:webhook|tts_proxy)\/)([A-Za-z0-9_.~%-]+)/g, hideAfter).replace(/(\/bot)(\d+:[A-Za-z0-9_-]+)/g, hideAfter).replace(parameter, (match, separator, name, value) => {
|
|
5032
|
+
const kind = credential(name);
|
|
4896
5033
|
const secret = kind === "one" || kind === "many" && !isCount(value) || parameterNames.test(normalize(name));
|
|
4897
|
-
return secret ? `${separator}${name}=${
|
|
5034
|
+
return secret ? `${separator}${name}=${hide(value)}` : match;
|
|
4898
5035
|
});
|
|
4899
5036
|
}
|
|
4900
5037
|
var assignment = /(?<![A-Za-z0-9_-])([A-Za-z][A-Za-z0-9_-]*)(?:\\*["'])?[ \t]*[:=][ \t]*/g;
|
|
4901
|
-
function closingBracket(
|
|
5038
|
+
function closingBracket(text5, start) {
|
|
4902
5039
|
let depth = 0;
|
|
4903
|
-
for (let index = start; index <
|
|
4904
|
-
const character =
|
|
5040
|
+
for (let index = start; index < text5.length; index++) {
|
|
5041
|
+
const character = text5.charAt(index);
|
|
4905
5042
|
if (character === "[" || character === "{") {
|
|
4906
5043
|
depth++;
|
|
4907
5044
|
} else if (character === "]" || character === "}") {
|
|
@@ -4911,25 +5048,25 @@ function closingBracket(text4, start) {
|
|
|
4911
5048
|
}
|
|
4912
5049
|
}
|
|
4913
5050
|
}
|
|
4914
|
-
return
|
|
5051
|
+
return text5.length;
|
|
4915
5052
|
}
|
|
4916
|
-
function valueRange(
|
|
4917
|
-
const rest =
|
|
5053
|
+
function valueRange(text5, start, name) {
|
|
5054
|
+
const rest = text5.slice(start);
|
|
4918
5055
|
const quoted = /^[bru]?(\\*)(["'])/.exec(rest);
|
|
4919
5056
|
if (quoted !== null) {
|
|
4920
5057
|
const [open, escapes = "", quote = ""] = quoted;
|
|
4921
5058
|
const from = start + open.length;
|
|
4922
5059
|
const close = `${escapes}${quote}`;
|
|
4923
|
-
let to =
|
|
5060
|
+
let to = text5.indexOf(close, from);
|
|
4924
5061
|
if (escapes === "") {
|
|
4925
|
-
while (to > from &&
|
|
4926
|
-
to =
|
|
5062
|
+
while (to > from && text5.charAt(to - 1) === "\\") {
|
|
5063
|
+
to = text5.indexOf(close, to + 1);
|
|
4927
5064
|
}
|
|
4928
5065
|
}
|
|
4929
|
-
return [from, to === -1 ?
|
|
5066
|
+
return [from, to === -1 ? text5.length : to];
|
|
4930
5067
|
}
|
|
4931
5068
|
if (rest.startsWith("{") || rest.startsWith("[")) {
|
|
4932
|
-
return [start, closingBracket(
|
|
5069
|
+
return [start, closingBracket(text5, start)];
|
|
4933
5070
|
}
|
|
4934
5071
|
if (normalize(name) === "authorization") {
|
|
4935
5072
|
const scheme = /^(?:Digest[ \t].*|(?:Basic|Bearer|Token|ApiKey)[ \t]+[^\s,&)\]}]+)/i.exec(rest);
|
|
@@ -4940,24 +5077,28 @@ function valueRange(text4, start, name) {
|
|
|
4940
5077
|
return [start, start + (/^[^\s,&)\]}]*/.exec(rest)?.[0].length ?? 0)];
|
|
4941
5078
|
}
|
|
4942
5079
|
function redactText(input, token) {
|
|
4943
|
-
const
|
|
5080
|
+
const text5 = redactString(input, token);
|
|
4944
5081
|
let result = "";
|
|
4945
5082
|
let done = 0;
|
|
4946
|
-
for (const match of
|
|
5083
|
+
for (const match of text5.matchAll(assignment)) {
|
|
4947
5084
|
const [whole, name = ""] = match;
|
|
4948
5085
|
const kind = credential(name);
|
|
4949
5086
|
if (kind === void 0 || match.index < done) {
|
|
4950
5087
|
continue;
|
|
4951
5088
|
}
|
|
4952
|
-
const [from, to] = valueRange(
|
|
4953
|
-
const value =
|
|
5089
|
+
const [from, to] = valueRange(text5, match.index + whole.length, name);
|
|
5090
|
+
const value = text5.slice(from, to);
|
|
4954
5091
|
if (value === "" || value.startsWith("=") || kind === "many" && isCount(value)) {
|
|
4955
5092
|
continue;
|
|
4956
5093
|
}
|
|
4957
|
-
result += `${
|
|
5094
|
+
result += `${text5.slice(done, from)}${hidden}`;
|
|
4958
5095
|
done = to;
|
|
4959
5096
|
}
|
|
4960
|
-
return result +
|
|
5097
|
+
return result + text5.slice(done);
|
|
5098
|
+
}
|
|
5099
|
+
function secretUnder(key, item) {
|
|
5100
|
+
const kind = entityId.test(key) ? void 0 : credential(key);
|
|
5101
|
+
return kind !== void 0 && item !== null && item !== void 0 && item !== "" && typeof item !== "boolean" && !(kind === "many" && typeof item === "number");
|
|
4961
5102
|
}
|
|
4962
5103
|
function redactData(value, token) {
|
|
4963
5104
|
if (typeof value === "string") {
|
|
@@ -4970,11 +5111,10 @@ function redactData(value, token) {
|
|
|
4970
5111
|
return value;
|
|
4971
5112
|
}
|
|
4972
5113
|
return Object.fromEntries(
|
|
4973
|
-
Object.entries(value).map(([key, item]) =>
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
})
|
|
5114
|
+
Object.entries(value).map(([key, item]) => [
|
|
5115
|
+
redactString(key, token),
|
|
5116
|
+
secretUnder(key, item) ? hidden : redactData(item, token)
|
|
5117
|
+
])
|
|
4978
5118
|
);
|
|
4979
5119
|
}
|
|
4980
5120
|
function redactState(id, state, attributes2) {
|
|
@@ -4997,6 +5137,82 @@ function redactState(id, state, attributes2) {
|
|
|
4997
5137
|
const plural = tails.some((tail) => tail.endsWith("s") && endsInName(tail.slice(0, -1)));
|
|
4998
5138
|
return plural && !isCount(state) ? hidden : state;
|
|
4999
5139
|
}
|
|
5140
|
+
var noValue = /* @__PURE__ */ new Set(["", "unknown", "unavailable"]);
|
|
5141
|
+
function collect(value, whole, found) {
|
|
5142
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
5143
|
+
if (whole) {
|
|
5144
|
+
found(String(value));
|
|
5145
|
+
}
|
|
5146
|
+
if (typeof value === "string") {
|
|
5147
|
+
redactString(value, void 0, found);
|
|
5148
|
+
}
|
|
5149
|
+
} else if (typeof value === "object" && value !== null) {
|
|
5150
|
+
for (const [key, item] of Object.entries(value)) {
|
|
5151
|
+
collect(item, whole || !Array.isArray(value) && secretUnder(key, item), found);
|
|
5152
|
+
}
|
|
5153
|
+
}
|
|
5154
|
+
}
|
|
5155
|
+
function collectSecrets(states) {
|
|
5156
|
+
const secrets = /* @__PURE__ */ new Set();
|
|
5157
|
+
const found = (secret) => {
|
|
5158
|
+
if (!noValue.has(secret)) {
|
|
5159
|
+
secrets.add(secret);
|
|
5160
|
+
}
|
|
5161
|
+
};
|
|
5162
|
+
for (const { entity_id: id, state, attributes: attributes2 } of states) {
|
|
5163
|
+
if (redactState(id, state, attributes2) !== state) {
|
|
5164
|
+
found(state);
|
|
5165
|
+
}
|
|
5166
|
+
collect(state, false, found);
|
|
5167
|
+
collect(attributes2, false, found);
|
|
5168
|
+
}
|
|
5169
|
+
return secrets;
|
|
5170
|
+
}
|
|
5171
|
+
var minInside = 4;
|
|
5172
|
+
function hideIn(text5, secrets) {
|
|
5173
|
+
if (secrets.has(text5)) {
|
|
5174
|
+
return hidden;
|
|
5175
|
+
}
|
|
5176
|
+
const ranges = [];
|
|
5177
|
+
for (const secret of secrets) {
|
|
5178
|
+
if (secret.length >= minInside) {
|
|
5179
|
+
for (let at = text5.indexOf(secret); at !== -1; at = text5.indexOf(secret, at + 1)) {
|
|
5180
|
+
ranges.push([at, at + secret.length]);
|
|
5181
|
+
}
|
|
5182
|
+
}
|
|
5183
|
+
}
|
|
5184
|
+
ranges.sort(([a], [b]) => a - b);
|
|
5185
|
+
let result = "";
|
|
5186
|
+
let end = 0;
|
|
5187
|
+
for (const [from, to] of ranges) {
|
|
5188
|
+
if (from >= end) {
|
|
5189
|
+
result += `${text5.slice(end, from)}${hidden}`;
|
|
5190
|
+
}
|
|
5191
|
+
end = Math.max(end, to);
|
|
5192
|
+
}
|
|
5193
|
+
return result + text5.slice(end);
|
|
5194
|
+
}
|
|
5195
|
+
function hideSecrets(value, secrets) {
|
|
5196
|
+
if (typeof value === "string") {
|
|
5197
|
+
return hideIn(value, secrets);
|
|
5198
|
+
}
|
|
5199
|
+
if (typeof value === "number") {
|
|
5200
|
+
const shown = hideIn(String(value), secrets);
|
|
5201
|
+
return shown === String(value) ? value : shown;
|
|
5202
|
+
}
|
|
5203
|
+
if (Array.isArray(value)) {
|
|
5204
|
+
return value.map((item) => hideSecrets(item, secrets));
|
|
5205
|
+
}
|
|
5206
|
+
if (typeof value !== "object" || value === null) {
|
|
5207
|
+
return value;
|
|
5208
|
+
}
|
|
5209
|
+
return Object.fromEntries(
|
|
5210
|
+
Object.entries(value).map(([key, item]) => [
|
|
5211
|
+
hideIn(key, secrets),
|
|
5212
|
+
hideSecrets(item, secrets)
|
|
5213
|
+
])
|
|
5214
|
+
);
|
|
5215
|
+
}
|
|
5000
5216
|
var keyBody = /^\s*[A-Za-z0-9+/=]+\s*$/;
|
|
5001
5217
|
var fullKeyLine = /^\s*(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[A-Za-z0-9+/]{60,}={0,2}\s*$/;
|
|
5002
5218
|
var maxKeyLines = 200;
|
|
@@ -5042,23 +5258,23 @@ function createLineRedactor(token) {
|
|
|
5042
5258
|
|
|
5043
5259
|
// src/ssh.ts
|
|
5044
5260
|
var sshFailure = 255;
|
|
5045
|
-
function sshArgs(target,
|
|
5046
|
-
return ["-o", "BatchMode=yes", "-o", "ConnectTimeout=10", "--", target,
|
|
5261
|
+
function sshArgs(target, command5) {
|
|
5262
|
+
return ["-o", "BatchMode=yes", "-o", "ConnectTimeout=10", "--", target, command5];
|
|
5047
5263
|
}
|
|
5048
5264
|
function createSshRunner(env) {
|
|
5049
|
-
return async (target,
|
|
5265
|
+
return async (target, command5) => {
|
|
5050
5266
|
const path = await findOnPath("ssh", env);
|
|
5051
5267
|
if (path === void 0) {
|
|
5052
5268
|
throw new SshFailedError("`ssh` was not found on PATH");
|
|
5053
5269
|
}
|
|
5054
|
-
return runTool(path, sshArgs(target,
|
|
5270
|
+
return runTool(path, sshArgs(target, command5), env);
|
|
5055
5271
|
};
|
|
5056
5272
|
}
|
|
5057
5273
|
function shellQuote(value) {
|
|
5058
5274
|
return `'${value.replaceAll("'", `'\\''`)}'`;
|
|
5059
5275
|
}
|
|
5060
|
-
async function runRemote(ssh, target,
|
|
5061
|
-
const result = await ssh(target,
|
|
5276
|
+
async function runRemote(ssh, target, command5) {
|
|
5277
|
+
const result = await ssh(target, command5);
|
|
5062
5278
|
if (result.code !== sshFailure) {
|
|
5063
5279
|
return result;
|
|
5064
5280
|
}
|
|
@@ -5154,6 +5370,7 @@ function buildProcessContext() {
|
|
|
5154
5370
|
homedir: homedir(),
|
|
5155
5371
|
keychain: createKeychain(process.platform, process.env),
|
|
5156
5372
|
readToken: () => readTokenInput(process.stdin, process.stderr),
|
|
5373
|
+
readStdin: () => text(process.stdin),
|
|
5157
5374
|
fetch: globalThis.fetch,
|
|
5158
5375
|
ssh: createSshRunner(process.env),
|
|
5159
5376
|
connect: connectWebSocket,
|
|
@@ -5175,92 +5392,6 @@ function printJson(context, value) {
|
|
|
5175
5392
|
`);
|
|
5176
5393
|
}
|
|
5177
5394
|
|
|
5178
|
-
// src/resources.ts
|
|
5179
|
-
function compact(value) {
|
|
5180
|
-
return Object.fromEntries(
|
|
5181
|
-
Object.entries(value).filter(([, field]) => field !== void 0 && field !== null)
|
|
5182
|
-
);
|
|
5183
|
-
}
|
|
5184
|
-
var byId = (a, b) => a.id.localeCompare(b.id);
|
|
5185
|
-
var text = (value) => value ?? void 0;
|
|
5186
|
-
var flag = (value) => value === void 0 || value === null ? void 0 : true;
|
|
5187
|
-
function toAreas(registry) {
|
|
5188
|
-
return registry.map((area) => compact({ id: area.area_id, name: area.name, floor: text(area.floor_id) })).sort(byId);
|
|
5189
|
-
}
|
|
5190
|
-
function toDevices(registry) {
|
|
5191
|
-
return registry.map(
|
|
5192
|
-
(device) => compact({
|
|
5193
|
-
id: device.id,
|
|
5194
|
-
name: text(device.name_by_user) ?? text(device.name),
|
|
5195
|
-
area: text(device.area_id),
|
|
5196
|
-
manufacturer: text(device.manufacturer),
|
|
5197
|
-
model: text(device.model),
|
|
5198
|
-
integrations: [...new Set((device.identifiers ?? []).map(([domain]) => domain))].sort(),
|
|
5199
|
-
disabled: flag(device.disabled_by)
|
|
5200
|
-
})
|
|
5201
|
-
).sort(byId);
|
|
5202
|
-
}
|
|
5203
|
-
function toEntities(current, registry, devices, options) {
|
|
5204
|
-
const stateOf = new Map(current.map((state) => [state.entity_id, state]));
|
|
5205
|
-
const entryOf = new Map(registry.map((entry) => [entry.entity_id, entry]));
|
|
5206
|
-
const deviceOf = new Map(devices.map((device) => [device.id, device]));
|
|
5207
|
-
const ids = /* @__PURE__ */ new Set([...stateOf.keys(), ...options.all ? entryOf.keys() : []]);
|
|
5208
|
-
return [...ids].map((id) => {
|
|
5209
|
-
const state = stateOf.get(id);
|
|
5210
|
-
const entry = entryOf.get(id);
|
|
5211
|
-
const device = text(entry?.device_id);
|
|
5212
|
-
const friendlyName = state?.attributes["friendly_name"];
|
|
5213
|
-
const owner = device === void 0 ? void 0 : deviceOf.get(device);
|
|
5214
|
-
const ownArea = text(entry?.area_id);
|
|
5215
|
-
const area = ownArea ?? text(owner?.area_id);
|
|
5216
|
-
const areaFrom = area === void 0 ? void 0 : ownArea === void 0 ? "device" : "entity";
|
|
5217
|
-
return compact({
|
|
5218
|
-
id,
|
|
5219
|
-
// The entity's own short name: a device's main entity has none and takes the device's.
|
|
5220
|
-
name: text(entry?.name) ?? text(entry?.original_name) ?? (entry?.has_entity_name === true && owner !== void 0 ? text(owner.name_by_user) ?? text(owner.name) : void 0) ?? (typeof friendlyName === "string" ? friendlyName : void 0),
|
|
5221
|
-
state: state === void 0 ? void 0 : redactState(id, state.state, state.attributes),
|
|
5222
|
-
area,
|
|
5223
|
-
areaFrom,
|
|
5224
|
-
device,
|
|
5225
|
-
integration: entry?.platform,
|
|
5226
|
-
labels: entry?.labels,
|
|
5227
|
-
attributes: state?.attributes,
|
|
5228
|
-
lastChanged: state?.last_changed,
|
|
5229
|
-
hidden: flag(entry?.hidden_by),
|
|
5230
|
-
disabled: flag(entry?.disabled_by)
|
|
5231
|
-
});
|
|
5232
|
-
}).sort(byId);
|
|
5233
|
-
}
|
|
5234
|
-
function toServices(registry, texts = {}) {
|
|
5235
|
-
return Object.entries(registry).flatMap(
|
|
5236
|
-
([domain, entries]) => Object.entries(entries).map(([name, service]) => {
|
|
5237
|
-
const fields = Object.entries(service.fields ?? {}).flatMap(
|
|
5238
|
-
([id, field]) => field.fields === void 0 ? [[id, field]] : Object.entries(field.fields)
|
|
5239
|
-
);
|
|
5240
|
-
const response = service.response === void 0 ? void 0 : service.response.optional ? "optional" : "required";
|
|
5241
|
-
const key = `component.${domain}.services.${name}`;
|
|
5242
|
-
const labelled = (own2, path) => text(own2) || texts[`${key}.${path}`] || void 0;
|
|
5243
|
-
return compact({
|
|
5244
|
-
id: `${domain}.${name}`,
|
|
5245
|
-
name: labelled(service.name, "name"),
|
|
5246
|
-
description: labelled(service.description, "description"),
|
|
5247
|
-
target: service.target === void 0 || service.target === null ? void 0 : true,
|
|
5248
|
-
response,
|
|
5249
|
-
fields: fields.map(
|
|
5250
|
-
([id, field]) => compact({
|
|
5251
|
-
id,
|
|
5252
|
-
name: labelled(field.name, `fields.${id}.name`),
|
|
5253
|
-
description: labelled(field.description, `fields.${id}.description`),
|
|
5254
|
-
required: field.required ?? void 0,
|
|
5255
|
-
example: field.example,
|
|
5256
|
-
selector: field.selector
|
|
5257
|
-
})
|
|
5258
|
-
).sort(byId)
|
|
5259
|
-
});
|
|
5260
|
-
})
|
|
5261
|
-
).sort(byId);
|
|
5262
|
-
}
|
|
5263
|
-
|
|
5264
5395
|
// src/ws.ts
|
|
5265
5396
|
function webSocketUrl(context) {
|
|
5266
5397
|
return `${baseUrl(context).replace(/^http/, "ws")}/api/websocket`;
|
|
@@ -5299,23 +5430,29 @@ function openHa(connect, context, token, timeoutMs2 = 1e4) {
|
|
|
5299
5430
|
};
|
|
5300
5431
|
const unreachable = (reason) => new UnreachableError(`cannot reach ${url2}: ${reason}`);
|
|
5301
5432
|
const notHa2 = () => new HaError(`${url2} did not answer like Home Assistant`);
|
|
5302
|
-
const send = (
|
|
5433
|
+
const send = (command5, parameters, listener) => new Promise((resolve, reject) => {
|
|
5303
5434
|
if (finished) {
|
|
5304
5435
|
reject(lost ?? unreachable("the connection is closed"));
|
|
5305
5436
|
return;
|
|
5306
5437
|
}
|
|
5307
5438
|
const id = nextId++;
|
|
5308
5439
|
const timer = timeout(() => {
|
|
5309
|
-
const reason = `no answer to ${
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5440
|
+
const reason = `no answer to ${command5} within ${timeoutMs2 / 1e3} seconds`;
|
|
5441
|
+
if (command5 === "call_service") {
|
|
5442
|
+
fail(
|
|
5443
|
+
new TimeoutError(
|
|
5444
|
+
`the call was sent, but there was ${reason}`,
|
|
5445
|
+
"It may still be running or have succeeded. Check with `hactl get`."
|
|
5446
|
+
)
|
|
5447
|
+
);
|
|
5448
|
+
} else {
|
|
5449
|
+
fail(
|
|
5450
|
+
command5 === "render_template" ? new TimeoutError(`there was ${reason}`) : unreachable(reason)
|
|
5451
|
+
);
|
|
5452
|
+
}
|
|
5316
5453
|
});
|
|
5317
5454
|
pending.set(id, {
|
|
5318
|
-
command:
|
|
5455
|
+
command: command5,
|
|
5319
5456
|
resolve: (result) => {
|
|
5320
5457
|
clearTimeout(timer);
|
|
5321
5458
|
timers.delete(timer);
|
|
@@ -5326,15 +5463,15 @@ function openHa(connect, context, token, timeoutMs2 = 1e4) {
|
|
|
5326
5463
|
if (listener !== void 0) {
|
|
5327
5464
|
listeners.set(id, listener);
|
|
5328
5465
|
}
|
|
5329
|
-
socket?.send(JSON.stringify({ ...parameters, id, type:
|
|
5466
|
+
socket?.send(JSON.stringify({ ...parameters, id, type: command5 }));
|
|
5330
5467
|
});
|
|
5331
5468
|
const session = {
|
|
5332
|
-
send: (
|
|
5469
|
+
send: (command5, parameters) => send(command5, parameters),
|
|
5333
5470
|
subscribe: async (eventType, listener) => {
|
|
5334
5471
|
await send("subscribe_events", { event_type: eventType }, listener);
|
|
5335
5472
|
},
|
|
5336
|
-
stream: async (
|
|
5337
|
-
await send(
|
|
5473
|
+
stream: async (command5, parameters, listener) => {
|
|
5474
|
+
await send(command5, parameters, listener);
|
|
5338
5475
|
},
|
|
5339
5476
|
lost: () => new Promise((_, reject) => {
|
|
5340
5477
|
if (finished) {
|
|
@@ -5458,11 +5595,11 @@ async function withHa(context, use) {
|
|
|
5458
5595
|
session.close();
|
|
5459
5596
|
}
|
|
5460
5597
|
}
|
|
5461
|
-
var readHa = (context, commands3) => withHa(context, (session) => Promise.all(commands3.map((
|
|
5462
|
-
function parseResult(schema, data,
|
|
5598
|
+
var readHa = (context, commands3) => withHa(context, (session) => Promise.all(commands3.map((command5) => session.send(command5))));
|
|
5599
|
+
function parseResult(schema, data, command5) {
|
|
5463
5600
|
const result = schema(data);
|
|
5464
5601
|
if (result instanceof Issues) {
|
|
5465
|
-
throw new HaError(redactText(`${
|
|
5602
|
+
throw new HaError(redactText(`${command5} returned an unexpected result: ${result.summary}`));
|
|
5466
5603
|
}
|
|
5467
5604
|
return result;
|
|
5468
5605
|
}
|
|
@@ -5485,10 +5622,123 @@ function pick(item, keys) {
|
|
|
5485
5622
|
var idParameter = (brief) => ({ brief, placeholder: "id", parse: String, optional: true });
|
|
5486
5623
|
var filterFlag = (brief, placeholder) => ({ kind: "parsed", parse: String, optional: true, brief, placeholder });
|
|
5487
5624
|
|
|
5488
|
-
// src/
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5625
|
+
// src/resources.ts
|
|
5626
|
+
function compact(value) {
|
|
5627
|
+
return Object.fromEntries(
|
|
5628
|
+
Object.entries(value).filter(([, field]) => field !== void 0 && field !== null)
|
|
5629
|
+
);
|
|
5630
|
+
}
|
|
5631
|
+
var byId = (a, b) => a.id.localeCompare(b.id);
|
|
5632
|
+
var text2 = (value) => value ?? void 0;
|
|
5633
|
+
var flag = (value) => value === void 0 || value === null ? void 0 : true;
|
|
5634
|
+
function toAreas(registry) {
|
|
5635
|
+
return registry.map(
|
|
5636
|
+
(area) => compact({
|
|
5637
|
+
id: area.area_id,
|
|
5638
|
+
name: area.name,
|
|
5639
|
+
floor: text2(area.floor_id),
|
|
5640
|
+
labels: area.labels
|
|
5641
|
+
})
|
|
5642
|
+
).sort(byId);
|
|
5643
|
+
}
|
|
5644
|
+
function toFloors(registry) {
|
|
5645
|
+
return registry.map(
|
|
5646
|
+
(floor) => compact({
|
|
5647
|
+
id: floor.floor_id,
|
|
5648
|
+
name: floor.name,
|
|
5649
|
+
level: floor.level ?? void 0,
|
|
5650
|
+
aliases: floor.aliases,
|
|
5651
|
+
icon: text2(floor.icon)
|
|
5652
|
+
})
|
|
5653
|
+
).sort(byId);
|
|
5654
|
+
}
|
|
5655
|
+
function toLabels(registry) {
|
|
5656
|
+
return registry.map(
|
|
5657
|
+
(label) => compact({
|
|
5658
|
+
id: label.label_id,
|
|
5659
|
+
name: label.name,
|
|
5660
|
+
description: text2(label.description),
|
|
5661
|
+
color: text2(label.color),
|
|
5662
|
+
icon: text2(label.icon)
|
|
5663
|
+
})
|
|
5664
|
+
).sort(byId);
|
|
5665
|
+
}
|
|
5666
|
+
function toDevices(registry) {
|
|
5667
|
+
return registry.map(
|
|
5668
|
+
(device) => compact({
|
|
5669
|
+
id: device.id,
|
|
5670
|
+
name: text2(device.name_by_user) ?? text2(device.name),
|
|
5671
|
+
area: text2(device.area_id),
|
|
5672
|
+
manufacturer: text2(device.manufacturer),
|
|
5673
|
+
model: text2(device.model),
|
|
5674
|
+
integrations: [...new Set((device.identifiers ?? []).map(([domain]) => domain))].sort(),
|
|
5675
|
+
labels: device.labels,
|
|
5676
|
+
disabled: flag(device.disabled_by)
|
|
5677
|
+
})
|
|
5678
|
+
).sort(byId);
|
|
5679
|
+
}
|
|
5680
|
+
function toEntities(current, registry, devices, options) {
|
|
5681
|
+
const stateOf = new Map(current.map((state) => [state.entity_id, state]));
|
|
5682
|
+
const entryOf = new Map(registry.map((entry) => [entry.entity_id, entry]));
|
|
5683
|
+
const deviceOf = new Map(devices.map((device) => [device.id, device]));
|
|
5684
|
+
const ids = /* @__PURE__ */ new Set([...stateOf.keys(), ...options.all ? entryOf.keys() : []]);
|
|
5685
|
+
return [...ids].map((id) => {
|
|
5686
|
+
const state = stateOf.get(id);
|
|
5687
|
+
const entry = entryOf.get(id);
|
|
5688
|
+
const device = text2(entry?.device_id);
|
|
5689
|
+
const friendlyName = state?.attributes["friendly_name"];
|
|
5690
|
+
const owner = device === void 0 ? void 0 : deviceOf.get(device);
|
|
5691
|
+
const ownArea = text2(entry?.area_id);
|
|
5692
|
+
const area = ownArea ?? text2(owner?.area_id);
|
|
5693
|
+
const areaFrom = area === void 0 ? void 0 : ownArea === void 0 ? "device" : "entity";
|
|
5694
|
+
return compact({
|
|
5695
|
+
id,
|
|
5696
|
+
// The entity's own short name: a device's main entity has none and takes the device's.
|
|
5697
|
+
name: text2(entry?.name) ?? text2(entry?.original_name) ?? (entry?.has_entity_name === true && owner !== void 0 ? text2(owner.name_by_user) ?? text2(owner.name) : void 0) ?? (typeof friendlyName === "string" ? friendlyName : void 0),
|
|
5698
|
+
state: state === void 0 ? void 0 : redactState(id, state.state, state.attributes),
|
|
5699
|
+
area,
|
|
5700
|
+
areaFrom,
|
|
5701
|
+
device,
|
|
5702
|
+
integration: entry?.platform,
|
|
5703
|
+
labels: entry?.labels,
|
|
5704
|
+
attributes: state?.attributes,
|
|
5705
|
+
lastChanged: state?.last_changed,
|
|
5706
|
+
hidden: flag(entry?.hidden_by),
|
|
5707
|
+
disabled: flag(entry?.disabled_by)
|
|
5708
|
+
});
|
|
5709
|
+
}).sort(byId);
|
|
5710
|
+
}
|
|
5711
|
+
function toServices(registry, texts = {}) {
|
|
5712
|
+
return Object.entries(registry).flatMap(
|
|
5713
|
+
([domain, entries]) => Object.entries(entries).map(([name, service]) => {
|
|
5714
|
+
const fields = Object.entries(service.fields ?? {}).flatMap(
|
|
5715
|
+
([id, field]) => field.fields === void 0 ? [[id, field]] : Object.entries(field.fields)
|
|
5716
|
+
);
|
|
5717
|
+
const response = service.response === void 0 ? void 0 : service.response.optional ? "optional" : "required";
|
|
5718
|
+
const key = `component.${domain}.services.${name}`;
|
|
5719
|
+
const labelled = (own2, path) => text2(own2) || texts[`${key}.${path}`] || void 0;
|
|
5720
|
+
return compact({
|
|
5721
|
+
id: `${domain}.${name}`,
|
|
5722
|
+
name: labelled(service.name, "name"),
|
|
5723
|
+
description: labelled(service.description, "description"),
|
|
5724
|
+
target: service.target === void 0 || service.target === null ? void 0 : true,
|
|
5725
|
+
response,
|
|
5726
|
+
fields: fields.map(
|
|
5727
|
+
([id, field]) => compact({
|
|
5728
|
+
id,
|
|
5729
|
+
name: labelled(field.name, `fields.${id}.name`),
|
|
5730
|
+
description: labelled(field.description, `fields.${id}.description`),
|
|
5731
|
+
required: field.required ?? void 0,
|
|
5732
|
+
example: field.example,
|
|
5733
|
+
selector: field.selector
|
|
5734
|
+
})
|
|
5735
|
+
).sort(byId)
|
|
5736
|
+
});
|
|
5737
|
+
})
|
|
5738
|
+
).sort(byId);
|
|
5739
|
+
}
|
|
5740
|
+
|
|
5741
|
+
// src/commands/service.ts
|
|
5492
5742
|
function parseServiceId(input) {
|
|
5493
5743
|
const [, domain, service] = /^([a-z0-9_]+)\.([a-z0-9_]+)$/.exec(input) ?? [];
|
|
5494
5744
|
if (domain === void 0 || service === void 0) {
|
|
@@ -5508,22 +5758,20 @@ function parseData(input) {
|
|
|
5508
5758
|
}
|
|
5509
5759
|
return data;
|
|
5510
5760
|
}
|
|
5511
|
-
function parseWait(input) {
|
|
5512
|
-
const seconds = Number(input);
|
|
5513
|
-
if (input.trim() === "" || !Number.isFinite(seconds) || seconds < 0) {
|
|
5514
|
-
throw new UsageError("--wait must be a number of seconds, 0 or more");
|
|
5515
|
-
}
|
|
5516
|
-
return seconds;
|
|
5517
|
-
}
|
|
5518
5761
|
function buildServiceData(flags) {
|
|
5519
5762
|
const entity = flags.entity?.length === 1 && flags.entity[0] === "all" ? "all" : flags.entity;
|
|
5520
|
-
const targets = {
|
|
5763
|
+
const targets = {
|
|
5764
|
+
entity_id: entity,
|
|
5765
|
+
area_id: flags.area,
|
|
5766
|
+
device_id: flags.device,
|
|
5767
|
+
floor_id: flags.floor,
|
|
5768
|
+
label_id: flags.label
|
|
5769
|
+
};
|
|
5521
5770
|
return {
|
|
5522
5771
|
...flags.data,
|
|
5523
5772
|
...Object.fromEntries(Object.entries(targets).filter(([, ids]) => ids !== void 0))
|
|
5524
5773
|
};
|
|
5525
5774
|
}
|
|
5526
|
-
var strings = (value) => [value].flat().filter((item) => typeof item === "string");
|
|
5527
5775
|
async function checkTargets(session, flags) {
|
|
5528
5776
|
const check2 = (kind, wanted, known) => {
|
|
5529
5777
|
const missing = wanted.find((id) => !known.includes(id));
|
|
@@ -5531,7 +5779,7 @@ async function checkTargets(session, flags) {
|
|
|
5531
5779
|
throw new NotFoundError(`${kind} "${missing}" does not exist`);
|
|
5532
5780
|
}
|
|
5533
5781
|
};
|
|
5534
|
-
const list = async (schema,
|
|
5782
|
+
const list = async (schema, command5) => parseResult(schema, await session.send(command5), command5);
|
|
5535
5783
|
const entities = (flags.entity ?? []).filter((id) => id !== "all" && id !== "none");
|
|
5536
5784
|
if (entities.length > 0) {
|
|
5537
5785
|
const current = (await list(intersection10qmong0na8e8rValidator, "get_states")).map((state) => state.entity_id);
|
|
@@ -5541,7 +5789,7 @@ async function checkTargets(session, flags) {
|
|
|
5541
5789
|
}
|
|
5542
5790
|
}
|
|
5543
5791
|
if (flags.area !== void 0) {
|
|
5544
|
-
const areas = await list(
|
|
5792
|
+
const areas = await list(intersection1dmk4z81d1f8mlValidator, "config/area_registry/list");
|
|
5545
5793
|
check2(
|
|
5546
5794
|
"area",
|
|
5547
5795
|
flags.area,
|
|
@@ -5549,14 +5797,104 @@ async function checkTargets(session, flags) {
|
|
|
5549
5797
|
);
|
|
5550
5798
|
}
|
|
5551
5799
|
if (flags.device !== void 0) {
|
|
5552
|
-
const devices = await list(
|
|
5800
|
+
const devices = await list(intersection3rk9um0b729ivValidator, "config/device_registry/list");
|
|
5553
5801
|
check2(
|
|
5554
5802
|
"device",
|
|
5555
5803
|
flags.device,
|
|
5556
5804
|
devices.map((device) => device.id)
|
|
5557
5805
|
);
|
|
5558
5806
|
}
|
|
5807
|
+
if (flags.floor !== void 0) {
|
|
5808
|
+
const floors = await list(intersection1tagcym1fnxkeyValidator, "config/floor_registry/list");
|
|
5809
|
+
check2(
|
|
5810
|
+
"floor",
|
|
5811
|
+
flags.floor,
|
|
5812
|
+
floors.map((floor) => floor.floor_id)
|
|
5813
|
+
);
|
|
5814
|
+
}
|
|
5815
|
+
if (flags.label !== void 0) {
|
|
5816
|
+
const labels = await list(intersection1rp35ue1fi65ccValidator, "config/label_registry/list");
|
|
5817
|
+
check2(
|
|
5818
|
+
"label",
|
|
5819
|
+
flags.label,
|
|
5820
|
+
labels.map((label) => label.label_id)
|
|
5821
|
+
);
|
|
5822
|
+
}
|
|
5823
|
+
}
|
|
5824
|
+
async function callForResponse(session, { domain, service }, data) {
|
|
5825
|
+
const reply = await session.send("call_service", {
|
|
5826
|
+
domain,
|
|
5827
|
+
service,
|
|
5828
|
+
service_data: data,
|
|
5829
|
+
return_response: true
|
|
5830
|
+
});
|
|
5831
|
+
return parseResult(intersection17r4na700khzejValidator, reply, "call_service").response;
|
|
5832
|
+
}
|
|
5833
|
+
async function responseSupport(session, { domain, service }) {
|
|
5834
|
+
const all = parseResult(intersection128bswg1yy3khmValidator, await session.send("get_services"), "get_services");
|
|
5835
|
+
const inDomain = Object.hasOwn(all, domain) ? all[domain] : void 0;
|
|
5836
|
+
if (inDomain === void 0 || !Object.hasOwn(inDomain, service)) {
|
|
5837
|
+
return void 0;
|
|
5838
|
+
}
|
|
5839
|
+
const response = inDomain[service]?.response;
|
|
5840
|
+
if (response === void 0) {
|
|
5841
|
+
return "none";
|
|
5842
|
+
}
|
|
5843
|
+
return response.optional ? "optional" : "required";
|
|
5844
|
+
}
|
|
5845
|
+
function explain({ domain, service }, error) {
|
|
5846
|
+
if (!(error instanceof HaCommandError)) {
|
|
5847
|
+
return error;
|
|
5848
|
+
}
|
|
5849
|
+
const id = `${domain}.${service}`;
|
|
5850
|
+
if (error.translationKey === "service_not_found") {
|
|
5851
|
+
return new NotFoundError(`service "${id}" does not exist`);
|
|
5852
|
+
}
|
|
5853
|
+
if (error.haCode === "invalid_format") {
|
|
5854
|
+
return new HaError(error.message, `See \`hactl get services ${id}\` for its fields.`);
|
|
5855
|
+
}
|
|
5856
|
+
return error;
|
|
5559
5857
|
}
|
|
5858
|
+
var targetFlag = (kind) => ({
|
|
5859
|
+
kind: "parsed",
|
|
5860
|
+
parse: String,
|
|
5861
|
+
variadic: true,
|
|
5862
|
+
optional: true,
|
|
5863
|
+
brief: `Target ${kind} id, as \`hactl get\` prints it; repeatable`,
|
|
5864
|
+
placeholder: "id"
|
|
5865
|
+
});
|
|
5866
|
+
var serviceFlags = {
|
|
5867
|
+
entity: targetFlag("entity"),
|
|
5868
|
+
area: targetFlag("area"),
|
|
5869
|
+
device: targetFlag("device"),
|
|
5870
|
+
floor: targetFlag("floor"),
|
|
5871
|
+
label: targetFlag("label"),
|
|
5872
|
+
data: {
|
|
5873
|
+
kind: "parsed",
|
|
5874
|
+
parse: parseData,
|
|
5875
|
+
optional: true,
|
|
5876
|
+
brief: "The service's other fields, as a JSON object",
|
|
5877
|
+
placeholder: "json"
|
|
5878
|
+
}
|
|
5879
|
+
};
|
|
5880
|
+
var serviceParameter = {
|
|
5881
|
+
brief: "Service id, e.g. light.turn_on",
|
|
5882
|
+
placeholder: "service",
|
|
5883
|
+
parse: parseServiceId
|
|
5884
|
+
};
|
|
5885
|
+
|
|
5886
|
+
// src/commands/call.ts
|
|
5887
|
+
var defaultWaitSeconds = 2;
|
|
5888
|
+
var maxDelayMs = 2 ** 31 - 1;
|
|
5889
|
+
var targetKeys = ["entity_id", "area_id", "device_id", "floor_id", "label_id"];
|
|
5890
|
+
function parseWait(input) {
|
|
5891
|
+
const seconds = Number(input);
|
|
5892
|
+
if (input.trim() === "" || !Number.isFinite(seconds) || seconds < 0) {
|
|
5893
|
+
throw new UsageError("--wait must be a number of seconds, 0 or more");
|
|
5894
|
+
}
|
|
5895
|
+
return seconds;
|
|
5896
|
+
}
|
|
5897
|
+
var strings = (value) => [value].flat().filter((item) => typeof item === "string");
|
|
5560
5898
|
function changedAttributes(before, after) {
|
|
5561
5899
|
return Object.fromEntries(
|
|
5562
5900
|
[.../* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)])].filter((key) => !isDeepStrictEqual(before[key], after[key])).map((key) => [key, after[key] ?? null])
|
|
@@ -5623,39 +5961,6 @@ async function callAndWatch(session, { domain, service }, data, seconds) {
|
|
|
5623
5961
|
return Object.keys(attributes2).length === 0 ? summary : Object.assign(summary, { attributes: attributes2 });
|
|
5624
5962
|
}).sort((a, b) => a.id.localeCompare(b.id));
|
|
5625
5963
|
}
|
|
5626
|
-
async function callForResponse(session, { domain, service }, data) {
|
|
5627
|
-
const reply = await session.send("call_service", {
|
|
5628
|
-
domain,
|
|
5629
|
-
service,
|
|
5630
|
-
service_data: data,
|
|
5631
|
-
return_response: true
|
|
5632
|
-
});
|
|
5633
|
-
return parseResult(intersection17r4na700khzejValidator, reply, "call_service").response;
|
|
5634
|
-
}
|
|
5635
|
-
function explain({ domain, service }, error) {
|
|
5636
|
-
if (!(error instanceof HaCommandError)) {
|
|
5637
|
-
return error;
|
|
5638
|
-
}
|
|
5639
|
-
const id = `${domain}.${service}`;
|
|
5640
|
-
if (error.translationKey === "service_not_found") {
|
|
5641
|
-
return new NotFoundError(`service "${id}" does not exist`);
|
|
5642
|
-
}
|
|
5643
|
-
if (error.translationKey === "service_lacks_response_request") {
|
|
5644
|
-
return new HaError(error.message, "Add `--response`.");
|
|
5645
|
-
}
|
|
5646
|
-
if (error.haCode === "invalid_format") {
|
|
5647
|
-
return new HaError(error.message, `See \`hactl get services ${id}\` for its fields.`);
|
|
5648
|
-
}
|
|
5649
|
-
return error;
|
|
5650
|
-
}
|
|
5651
|
-
var targetFlag = (kind) => ({
|
|
5652
|
-
kind: "parsed",
|
|
5653
|
-
parse: String,
|
|
5654
|
-
variadic: true,
|
|
5655
|
-
optional: true,
|
|
5656
|
-
brief: `Target ${kind} id, as \`hactl get\` prints it; repeatable`,
|
|
5657
|
-
placeholder: "id"
|
|
5658
|
-
});
|
|
5659
5964
|
var callCommand = buildCommand({
|
|
5660
5965
|
docs: {
|
|
5661
5966
|
brief: "Call a service and print the states it changed",
|
|
@@ -5663,12 +5968,12 @@ var callCommand = buildCommand({
|
|
|
5663
5968
|
|
|
5664
5969
|
Calls <domain>.<service> on the active context. It never asks for confirmation.
|
|
5665
5970
|
List services with \`hactl get services\`, and a service's fields with
|
|
5666
|
-
\`hactl get services <id>\`.
|
|
5971
|
+
\`hactl get services <id>\`. A service whose "response" is "required" only returns data: run
|
|
5972
|
+
it with \`hactl query\`, as call refuses it.
|
|
5667
5973
|
|
|
5668
|
-
Targets: --entity, --area and --
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
checked: Home Assistant ignores unknown ones. A lone --entity all targets every entity of
|
|
5974
|
+
Targets: --entity, --area, --device, --floor and --label are repeatable and replace the same
|
|
5975
|
+
key in --data. A target flag naming something that does not exist fails with not_found and
|
|
5976
|
+
nothing is called. Ids in --data are not checked: Home Assistant ignores unknown ones. A lone --entity all targets every entity of
|
|
5672
5977
|
the service's domain: \`light.turn_off --entity all\` turns off every light. The
|
|
5673
5978
|
homeassistant.turn_on, turn_off and toggle services reject all.
|
|
5674
5979
|
|
|
@@ -5680,8 +5985,8 @@ A change counts when Home Assistant attributes it to this call or it is on a tar
|
|
|
5680
5985
|
entity, including members of targeted groups and scenes. Home Assistant attributes for
|
|
5681
5986
|
5 seconds after commanding a device, so slower changes of untargeted devices are missed.
|
|
5682
5987
|
|
|
5683
|
-
With --response, the service
|
|
5684
|
-
It cannot be combined with --wait. Credentials in either output and in error messages are
|
|
5988
|
+
With --response, the response data of a service whose "response" is "optional", such as a
|
|
5989
|
+
script, is printed instead, without waiting. It cannot be combined with --wait. Credentials in either output and in error messages are
|
|
5685
5990
|
printed as REDACTED; a secret without a recognizable name or shape cannot be caught.
|
|
5686
5991
|
|
|
5687
5992
|
Home Assistant answers a call when the service is done. After 10 seconds without an answer
|
|
@@ -5691,20 +5996,11 @@ returns at once.
|
|
|
5691
5996
|
|
|
5692
5997
|
hactl call light.turn_on --area kitchen --data '{"brightness_pct": 50}'
|
|
5693
5998
|
hactl call cover.open_cover --entity cover.garage --wait 30
|
|
5694
|
-
hactl call
|
|
5999
|
+
hactl call script.report --response`
|
|
5695
6000
|
},
|
|
5696
6001
|
parameters: {
|
|
5697
6002
|
flags: {
|
|
5698
|
-
|
|
5699
|
-
area: targetFlag("area"),
|
|
5700
|
-
device: targetFlag("device"),
|
|
5701
|
-
data: {
|
|
5702
|
-
kind: "parsed",
|
|
5703
|
-
parse: parseData,
|
|
5704
|
-
optional: true,
|
|
5705
|
-
brief: "The service's other fields, as a JSON object",
|
|
5706
|
-
placeholder: "json"
|
|
5707
|
-
},
|
|
6003
|
+
...serviceFlags,
|
|
5708
6004
|
response: {
|
|
5709
6005
|
kind: "boolean",
|
|
5710
6006
|
optional: true,
|
|
@@ -5720,9 +6016,7 @@ returns at once.
|
|
|
5720
6016
|
},
|
|
5721
6017
|
positional: {
|
|
5722
6018
|
kind: "tuple",
|
|
5723
|
-
parameters: [
|
|
5724
|
-
{ brief: "Service id, e.g. light.turn_on", placeholder: "service", parse: parseServiceId }
|
|
5725
|
-
]
|
|
6019
|
+
parameters: [serviceParameter]
|
|
5726
6020
|
}
|
|
5727
6021
|
},
|
|
5728
6022
|
async func(flags, service) {
|
|
@@ -5733,6 +6027,10 @@ returns at once.
|
|
|
5733
6027
|
const data = buildServiceData(flags);
|
|
5734
6028
|
const session = await openHa(this.connect, context, token);
|
|
5735
6029
|
try {
|
|
6030
|
+
if (await responseSupport(session, service) === "required") {
|
|
6031
|
+
const id = `${service.domain}.${service.service}`;
|
|
6032
|
+
throw new UsageError(`"${id}" only returns data`, `Run it with \`hactl query ${id}\`.`);
|
|
6033
|
+
}
|
|
5736
6034
|
await checkTargets(session, flags);
|
|
5737
6035
|
const output = flags.response === true ? await callForResponse(session, service, data) : await callAndWatch(session, service, data, flags.wait ?? defaultWaitSeconds);
|
|
5738
6036
|
printJson(this, redactData(output, token));
|
|
@@ -5840,7 +6138,7 @@ Prints an array of contexts, in the shape \`hactl ctx --help\` describes.`
|
|
|
5840
6138
|
});
|
|
5841
6139
|
|
|
5842
6140
|
// src/commands/ctx/set.ts
|
|
5843
|
-
var
|
|
6141
|
+
var text3 = (brief, placeholder) => ({ kind: "parsed", parse: String, optional: true, brief, placeholder });
|
|
5844
6142
|
function buildInstall(name, flags, existing) {
|
|
5845
6143
|
const kind = flags.install ?? existing?.install.type;
|
|
5846
6144
|
if (kind === "haos" || kind === void 0) {
|
|
@@ -5870,10 +6168,10 @@ Prints the context. Store its token next with \`hactl ctx token-set <name>\`.
|
|
|
5870
6168
|
},
|
|
5871
6169
|
parameters: {
|
|
5872
6170
|
flags: {
|
|
5873
|
-
url:
|
|
6171
|
+
url: text3("Home Assistant base URL", "url"),
|
|
5874
6172
|
install: { kind: "enum", values: ["haos", "docker"], optional: true, brief: "Install type" },
|
|
5875
|
-
container:
|
|
5876
|
-
ssh:
|
|
6173
|
+
container: text3("Home Assistant container name (docker only, required there)", "name"),
|
|
6174
|
+
ssh: text3("SSH target, user@host (without it, the context has no SSH access)", "target"),
|
|
5877
6175
|
noSsh: { kind: "boolean", optional: true, brief: "Remove the SSH target" }
|
|
5878
6176
|
},
|
|
5879
6177
|
positional: {
|
|
@@ -6192,7 +6490,8 @@ var areasCommand = buildCommand({
|
|
|
6192
6490
|
brief: "List areas, or show one",
|
|
6193
6491
|
fullDescription: `List areas, or show one
|
|
6194
6492
|
|
|
6195
|
-
Fields: "id", "name", "floor".
|
|
6493
|
+
Fields: "id", "name", "floor". An id adds "labels".
|
|
6494
|
+
Credentials are printed as REDACTED; a secret without a recognizable name or shape cannot be
|
|
6196
6495
|
caught.`
|
|
6197
6496
|
},
|
|
6198
6497
|
parameters: { positional: { kind: "tuple", parameters: [idParameter("Area id")] } },
|
|
@@ -6203,10 +6502,10 @@ caught.`
|
|
|
6203
6502
|
} = await readHa(this, [command]);
|
|
6204
6503
|
printItems(
|
|
6205
6504
|
this,
|
|
6206
|
-
toAreas(parseResult(
|
|
6505
|
+
toAreas(parseResult(intersection1dmk4z81d1f8mlValidator, registry, command)),
|
|
6207
6506
|
id,
|
|
6208
6507
|
"area",
|
|
6209
|
-
(area) => area,
|
|
6508
|
+
(area) => pick(area, ["id", "name", "floor"]),
|
|
6210
6509
|
token
|
|
6211
6510
|
);
|
|
6212
6511
|
}
|
|
@@ -6220,7 +6519,7 @@ var devicesCommand = buildCommand({
|
|
|
6220
6519
|
fullDescription: `List devices, or show one
|
|
6221
6520
|
|
|
6222
6521
|
Fields: "id", "name", "area", "manufacturer", "model", "integrations". An id adds
|
|
6223
|
-
"disabled". An unknown --area is not_found.
|
|
6522
|
+
"labels" and "disabled". An unknown --area is not_found.
|
|
6224
6523
|
Credentials are printed as REDACTED; a secret without a recognizable name or shape cannot be
|
|
6225
6524
|
caught.
|
|
6226
6525
|
|
|
@@ -6236,9 +6535,9 @@ caught.
|
|
|
6236
6535
|
token
|
|
6237
6536
|
} = await readHa(this, commands);
|
|
6238
6537
|
if (flags.area !== void 0) {
|
|
6239
|
-
findById(toAreas(parseResult(
|
|
6538
|
+
findById(toAreas(parseResult(intersection1dmk4z81d1f8mlValidator, areas, commands[1])), flags.area, "area");
|
|
6240
6539
|
}
|
|
6241
|
-
const devices = toDevices(parseResult(
|
|
6540
|
+
const devices = toDevices(parseResult(intersection3rk9um0b729ivValidator, registry, commands[0])).filter(
|
|
6242
6541
|
(device) => flags.area === void 0 || device.area === flags.area
|
|
6243
6542
|
);
|
|
6244
6543
|
printItems(
|
|
@@ -6257,7 +6556,9 @@ var commands2 = [
|
|
|
6257
6556
|
"get_states",
|
|
6258
6557
|
"config/entity_registry/list",
|
|
6259
6558
|
"config/device_registry/list",
|
|
6260
|
-
"config/area_registry/list"
|
|
6559
|
+
"config/area_registry/list",
|
|
6560
|
+
"config/floor_registry/list",
|
|
6561
|
+
"config/label_registry/list"
|
|
6261
6562
|
];
|
|
6262
6563
|
var entitiesCommand = buildCommand({
|
|
6263
6564
|
docs: {
|
|
@@ -6265,8 +6566,12 @@ var entitiesCommand = buildCommand({
|
|
|
6265
6566
|
fullDescription: `List entities with a state, or show one
|
|
6266
6567
|
|
|
6267
6568
|
Lists entities that have a state, hidden ones included. --all adds disabled entities, which
|
|
6268
|
-
have "disabled": true and no "state". Filters combine. An unknown --area
|
|
6269
|
-
not_found; a domain without entities gives [].
|
|
6569
|
+
have "disabled": true and no "state". Filters combine. An unknown --area, --device, --floor
|
|
6570
|
+
or --label is not_found; a domain without entities gives [].
|
|
6571
|
+
|
|
6572
|
+
--floor keeps entities whose "area" is on that floor. --label keeps entities that carry the
|
|
6573
|
+
label themselves, not through their device or area. A \`hactl call\` targeting a floor or
|
|
6574
|
+
label can therefore reach other entities than these filters list.
|
|
6270
6575
|
|
|
6271
6576
|
Fields: "id", "name", "state", "area", "areaFrom", "device", "integration", "disabled".
|
|
6272
6577
|
An id adds "labels", "attributes", "lastChanged" and "hidden". Credentials anywhere in the
|
|
@@ -6282,6 +6587,8 @@ without a recognizable name or shape cannot be caught.
|
|
|
6282
6587
|
domain: filterFlag("Only entities in this domain, e.g. light", "domain"),
|
|
6283
6588
|
area: filterFlag("Only entities in this area", "id"),
|
|
6284
6589
|
device: filterFlag("Only entities of this device", "id"),
|
|
6590
|
+
floor: filterFlag("Only entities in an area on this floor", "id"),
|
|
6591
|
+
label: filterFlag("Only entities with this label", "id"),
|
|
6285
6592
|
all: { kind: "boolean", optional: true, brief: "Also list disabled entities" }
|
|
6286
6593
|
},
|
|
6287
6594
|
positional: { kind: "tuple", parameters: [idParameter("Entity id")] }
|
|
@@ -6290,14 +6597,22 @@ without a recognizable name or shape cannot be caught.
|
|
|
6290
6597
|
const { value: results, token } = await readHa(this, commands2);
|
|
6291
6598
|
const current = parseResult(intersection10qmong0na8e8rValidator, results[0], commands2[0]);
|
|
6292
6599
|
const registry = parseResult(intersection1nv9uj515bs7itValidator, results[1], commands2[1]);
|
|
6293
|
-
const devices = parseResult(
|
|
6294
|
-
const
|
|
6600
|
+
const devices = parseResult(intersection3rk9um0b729ivValidator, results[2], commands2[2]);
|
|
6601
|
+
const areas = toAreas(parseResult(intersection1dmk4z81d1f8mlValidator, results[3], commands2[3]));
|
|
6602
|
+
const { area, device, floor, label } = flags;
|
|
6295
6603
|
if (area !== void 0) {
|
|
6296
|
-
findById(
|
|
6604
|
+
findById(areas, area, "area");
|
|
6297
6605
|
}
|
|
6298
6606
|
if (device !== void 0) {
|
|
6299
6607
|
findById(toDevices(devices), device, "device");
|
|
6300
6608
|
}
|
|
6609
|
+
if (floor !== void 0) {
|
|
6610
|
+
findById(toFloors(parseResult(intersection1tagcym1fnxkeyValidator, results[4], commands2[4])), floor, "floor");
|
|
6611
|
+
}
|
|
6612
|
+
if (label !== void 0) {
|
|
6613
|
+
findById(toLabels(parseResult(intersection1rp35ue1fi65ccValidator, results[5], commands2[5])), label, "label");
|
|
6614
|
+
}
|
|
6615
|
+
const onFloor = new Set(areas.filter((item) => item.floor === floor).map((item) => item.id));
|
|
6301
6616
|
const entities = toEntities(
|
|
6302
6617
|
current,
|
|
6303
6618
|
registry,
|
|
@@ -6305,7 +6620,7 @@ without a recognizable name or shape cannot be caught.
|
|
|
6305
6620
|
// A single id is found whether or not it is disabled.
|
|
6306
6621
|
{ all: flags.all === true || id !== void 0 }
|
|
6307
6622
|
).filter(
|
|
6308
|
-
(entity) => (flags.domain === void 0 || entity.id.startsWith(`${flags.domain}.`)) && (
|
|
6623
|
+
(entity) => (flags.domain === void 0 || entity.id.startsWith(`${flags.domain}.`)) && (area === void 0 || entity.area === area) && (device === void 0 || entity.device === device) && (floor === void 0 || entity.area !== void 0 && onFloor.has(entity.area)) && (label === void 0 || entity.labels?.includes(label) === true)
|
|
6309
6624
|
);
|
|
6310
6625
|
printItems(
|
|
6311
6626
|
this,
|
|
@@ -6327,8 +6642,64 @@ without a recognizable name or shape cannot be caught.
|
|
|
6327
6642
|
}
|
|
6328
6643
|
});
|
|
6329
6644
|
|
|
6645
|
+
// src/commands/get/floors.ts
|
|
6646
|
+
var command2 = "config/floor_registry/list";
|
|
6647
|
+
var floorsCommand = buildCommand({
|
|
6648
|
+
docs: {
|
|
6649
|
+
brief: "List floors, or show one",
|
|
6650
|
+
fullDescription: `List floors, or show one
|
|
6651
|
+
|
|
6652
|
+
Fields: "id", "name", "level". An id adds "aliases" and "icon".
|
|
6653
|
+
Credentials are printed as REDACTED; a secret without a recognizable name or shape cannot be
|
|
6654
|
+
caught.`
|
|
6655
|
+
},
|
|
6656
|
+
parameters: { positional: { kind: "tuple", parameters: [idParameter("Floor id")] } },
|
|
6657
|
+
async func(_flags, id) {
|
|
6658
|
+
const {
|
|
6659
|
+
value: [registry],
|
|
6660
|
+
token
|
|
6661
|
+
} = await readHa(this, [command2]);
|
|
6662
|
+
printItems(
|
|
6663
|
+
this,
|
|
6664
|
+
toFloors(parseResult(intersection1tagcym1fnxkeyValidator, registry, command2)),
|
|
6665
|
+
id,
|
|
6666
|
+
"floor",
|
|
6667
|
+
(floor) => pick(floor, ["id", "name", "level"]),
|
|
6668
|
+
token
|
|
6669
|
+
);
|
|
6670
|
+
}
|
|
6671
|
+
});
|
|
6672
|
+
|
|
6673
|
+
// src/commands/get/labels.ts
|
|
6674
|
+
var command3 = "config/label_registry/list";
|
|
6675
|
+
var labelsCommand = buildCommand({
|
|
6676
|
+
docs: {
|
|
6677
|
+
brief: "List labels, or show one",
|
|
6678
|
+
fullDescription: `List labels, or show one
|
|
6679
|
+
|
|
6680
|
+
Fields: "id", "name", "description". An id adds "color" and "icon".
|
|
6681
|
+
Credentials are printed as REDACTED; a secret without a recognizable name or shape cannot be
|
|
6682
|
+
caught.`
|
|
6683
|
+
},
|
|
6684
|
+
parameters: { positional: { kind: "tuple", parameters: [idParameter("Label id")] } },
|
|
6685
|
+
async func(_flags, id) {
|
|
6686
|
+
const {
|
|
6687
|
+
value: [registry],
|
|
6688
|
+
token
|
|
6689
|
+
} = await readHa(this, [command3]);
|
|
6690
|
+
printItems(
|
|
6691
|
+
this,
|
|
6692
|
+
toLabels(parseResult(intersection1rp35ue1fi65ccValidator, registry, command3)),
|
|
6693
|
+
id,
|
|
6694
|
+
"label",
|
|
6695
|
+
(label) => pick(label, ["id", "name", "description"]),
|
|
6696
|
+
token
|
|
6697
|
+
);
|
|
6698
|
+
}
|
|
6699
|
+
});
|
|
6700
|
+
|
|
6330
6701
|
// src/commands/get/services.ts
|
|
6331
|
-
var
|
|
6702
|
+
var command4 = "get_services";
|
|
6332
6703
|
var translationCommand = "frontend/get_translations";
|
|
6333
6704
|
async function serviceTexts(session) {
|
|
6334
6705
|
try {
|
|
@@ -6351,7 +6722,8 @@ The id is <domain>.<service>, as \`hactl call\` takes it. A list has "id", "name
|
|
|
6351
6722
|
|
|
6352
6723
|
An id adds:
|
|
6353
6724
|
"target" true when the service takes --entity, --area or --device
|
|
6354
|
-
"response"
|
|
6725
|
+
"response" when it returns data: required (use \`hactl query\`) or optional
|
|
6726
|
+
(\`hactl call --response\`)
|
|
6355
6727
|
"fields" the keys --data takes: "id", "name", "description", "required", "example"
|
|
6356
6728
|
and "selector" (the type and limits of the value)
|
|
6357
6729
|
|
|
@@ -6371,9 +6743,9 @@ caught.
|
|
|
6371
6743
|
token
|
|
6372
6744
|
} = await withHa(
|
|
6373
6745
|
this,
|
|
6374
|
-
async (session) => [await session.send(
|
|
6746
|
+
async (session) => [await session.send(command4), await serviceTexts(session)]
|
|
6375
6747
|
);
|
|
6376
|
-
const all = toServices(parseResult(intersection128bswg1yy3khmValidator, result,
|
|
6748
|
+
const all = toServices(parseResult(intersection128bswg1yy3khmValidator, result, command4), texts);
|
|
6377
6749
|
if (id !== void 0 && all.some((service) => service.id.startsWith(`${id}.`))) {
|
|
6378
6750
|
throw new NotFoundError(
|
|
6379
6751
|
`service "${id}" does not exist`,
|
|
@@ -6395,25 +6767,25 @@ caught.
|
|
|
6395
6767
|
});
|
|
6396
6768
|
|
|
6397
6769
|
// src/commands/get/index.ts
|
|
6398
|
-
var getRoutes = buildRouteMap(
|
|
6399
|
-
{
|
|
6400
|
-
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6770
|
+
var getRoutes = buildRouteMap({
|
|
6771
|
+
routes: {
|
|
6772
|
+
entities: entitiesCommand,
|
|
6773
|
+
devices: devicesCommand,
|
|
6774
|
+
areas: areasCommand,
|
|
6775
|
+
floors: floorsCommand,
|
|
6776
|
+
labels: labelsCommand,
|
|
6777
|
+
services: servicesCommand
|
|
6778
|
+
},
|
|
6779
|
+
docs: {
|
|
6780
|
+
brief: "Read entities, devices, areas, floors, labels and services from Home Assistant",
|
|
6781
|
+
fullDescription: `Read entities, devices, areas, floors, labels and services from Home Assistant
|
|
6409
6782
|
|
|
6410
6783
|
Reads from the active context over the WebSocket API; SSH is not needed.
|
|
6411
6784
|
Without an id a command prints an array sorted by "id". With an id it prints that one item
|
|
6412
|
-
in full. Items refer to each other by id, so an "area"
|
|
6413
|
-
another command
|
|
6414
|
-
}
|
|
6785
|
+
in full. Items refer to each other by id, so an "area", "device", "floor" or "labels" value
|
|
6786
|
+
can be passed to another command. Zones are entities: \`get entities --domain zone\`.`
|
|
6415
6787
|
}
|
|
6416
|
-
);
|
|
6788
|
+
});
|
|
6417
6789
|
|
|
6418
6790
|
// src/commands/logs.ts
|
|
6419
6791
|
var sourceLines = 100;
|
|
@@ -6659,6 +7031,179 @@ without a recognizable name or shape is printed.
|
|
|
6659
7031
|
}
|
|
6660
7032
|
});
|
|
6661
7033
|
|
|
7034
|
+
// src/commands/query.ts
|
|
7035
|
+
var queryCommand = buildCommand({
|
|
7036
|
+
docs: {
|
|
7037
|
+
brief: "Run a service that only returns data, and print it",
|
|
7038
|
+
fullDescription: `Run a service that only returns data, and print it
|
|
7039
|
+
|
|
7040
|
+
Calls <domain>.<service> on the active context and prints its response data as JSON. It only
|
|
7041
|
+
runs services that Home Assistant says require a response, such as forecasts, calendar
|
|
7042
|
+
events, to-do items and statistics: \`hactl get services <id>\` shows "response": "required".
|
|
7043
|
+
Any other service is refused with usage_error and nothing is called: use \`hactl call\`, also
|
|
7044
|
+
for scripts. query relies on the integration's own claim that such a service changes nothing.
|
|
7045
|
+
|
|
7046
|
+
Targets: --entity, --area, --device, --floor and --label are repeatable and replace the same
|
|
7047
|
+
key in --data, which holds the service's other fields. A target flag naming something that
|
|
7048
|
+
does not exist fails with not_found and nothing is called. Ids in --data are not checked.
|
|
7049
|
+
\`hactl get services <id>\` lists the fields.
|
|
7050
|
+
|
|
7051
|
+
The response can hold private data. Credentials in it and in error messages are printed as
|
|
7052
|
+
REDACTED; a secret without a recognizable name or shape cannot be caught.
|
|
7053
|
+
|
|
7054
|
+
After 10 seconds without an answer the command fails with timeout.
|
|
7055
|
+
|
|
7056
|
+
hactl query weather.get_forecasts --entity weather.home --data '{"type": "daily"}'
|
|
7057
|
+
hactl query todo.get_items --entity todo.shopping
|
|
7058
|
+
hactl query calendar.get_events --entity calendar.home --data '{"duration": {"days": 7}}'`
|
|
7059
|
+
},
|
|
7060
|
+
parameters: {
|
|
7061
|
+
flags: serviceFlags,
|
|
7062
|
+
positional: { kind: "tuple", parameters: [serviceParameter] }
|
|
7063
|
+
},
|
|
7064
|
+
async func(flags, service) {
|
|
7065
|
+
const { context, token } = await resolveActiveContext(this);
|
|
7066
|
+
const data = buildServiceData(flags);
|
|
7067
|
+
const id = `${service.domain}.${service.service}`;
|
|
7068
|
+
const session = await openHa(this.connect, context, token);
|
|
7069
|
+
try {
|
|
7070
|
+
const support = await responseSupport(session, service);
|
|
7071
|
+
if (support === void 0) {
|
|
7072
|
+
throw new NotFoundError(`service "${id}" does not exist`);
|
|
7073
|
+
}
|
|
7074
|
+
if (support !== "required") {
|
|
7075
|
+
throw new UsageError(
|
|
7076
|
+
`"${id}" can change the instance, so query does not run it`,
|
|
7077
|
+
`Run it with \`hactl call ${id}\`.`
|
|
7078
|
+
);
|
|
7079
|
+
}
|
|
7080
|
+
await checkTargets(session, flags);
|
|
7081
|
+
printJson(this, redactData(await callForResponse(session, service, data), token));
|
|
7082
|
+
} catch (error) {
|
|
7083
|
+
throw explain(service, error);
|
|
7084
|
+
} finally {
|
|
7085
|
+
session.close();
|
|
7086
|
+
}
|
|
7087
|
+
}
|
|
7088
|
+
});
|
|
7089
|
+
|
|
7090
|
+
// src/commands/template.ts
|
|
7091
|
+
var renderSeconds = 5;
|
|
7092
|
+
var answerMs = 1e4;
|
|
7093
|
+
async function render(session, template) {
|
|
7094
|
+
const warnings = /* @__PURE__ */ new Set();
|
|
7095
|
+
let done = () => void 0;
|
|
7096
|
+
let failed = () => void 0;
|
|
7097
|
+
const outcome = new Promise((resolve, reject) => {
|
|
7098
|
+
done = resolve;
|
|
7099
|
+
failed = reject;
|
|
7100
|
+
});
|
|
7101
|
+
outcome.catch(() => void 0);
|
|
7102
|
+
await session.stream(
|
|
7103
|
+
"render_template",
|
|
7104
|
+
{ template, timeout: renderSeconds, report_errors: true },
|
|
7105
|
+
(event) => {
|
|
7106
|
+
const success = intersection1r95ni81xgl88zValidator(event);
|
|
7107
|
+
if (!(success instanceof Issues)) {
|
|
7108
|
+
done({ result: success.result, warnings: [...warnings] });
|
|
7109
|
+
return;
|
|
7110
|
+
}
|
|
7111
|
+
const problem = intersection8yr2o71ja81ufValidator(event);
|
|
7112
|
+
if (problem instanceof Issues) {
|
|
7113
|
+
failed(new HaError("render_template sent an unexpected event"));
|
|
7114
|
+
} else if (problem.level === "WARNING") {
|
|
7115
|
+
warnings.add(problem.error);
|
|
7116
|
+
} else {
|
|
7117
|
+
failed(new HaError(problem.error));
|
|
7118
|
+
}
|
|
7119
|
+
}
|
|
7120
|
+
);
|
|
7121
|
+
return Promise.race([
|
|
7122
|
+
outcome,
|
|
7123
|
+
session.wait(answerMs).then(() => {
|
|
7124
|
+
throw new TimeoutError("render_template sent no result");
|
|
7125
|
+
})
|
|
7126
|
+
]);
|
|
7127
|
+
}
|
|
7128
|
+
function explain3(error, secrets) {
|
|
7129
|
+
const clean = (message) => redactText(String(hideSecrets(message, secrets)));
|
|
7130
|
+
if (error instanceof HaCommandError && error.message.includes("Exceeded maximum execution time")) {
|
|
7131
|
+
return new TimeoutError(`the template did not finish within ${renderSeconds} seconds`);
|
|
7132
|
+
}
|
|
7133
|
+
return error instanceof HaError ? new HaError(clean(error.message), error.hint) : error;
|
|
7134
|
+
}
|
|
7135
|
+
var templateCommand = buildCommand({
|
|
7136
|
+
docs: {
|
|
7137
|
+
brief: "Render a Jinja template on Home Assistant",
|
|
7138
|
+
fullDescription: `Render a Jinja template on Home Assistant
|
|
7139
|
+
|
|
7140
|
+
Renders <template> on the active context, to try it before putting it in the configuration.
|
|
7141
|
+
With - the template is read from standard input. A template cannot call services, so nothing
|
|
7142
|
+
on the instance changes, and no admin token is needed.
|
|
7143
|
+
|
|
7144
|
+
Output: text is printed as it is, nothing when empty. Anything else Home Assistant makes of
|
|
7145
|
+
the result, such as a number, boolean, list or object, is printed as JSON.
|
|
7146
|
+
|
|
7147
|
+
Warnings, such as an undefined variable, go to standard error as \`warning: <message>\` and do
|
|
7148
|
+
not change the exit code. A template that cannot be rendered fails with ha_error. Variables
|
|
7149
|
+
that an automation or script would supply, such as trigger, are not defined here: stand in
|
|
7150
|
+
for them with {% set %}.
|
|
7151
|
+
|
|
7152
|
+
Home Assistant stops rendering after ${renderSeconds} seconds, which fails with timeout. An expensive
|
|
7153
|
+
template slows Home Assistant down while it runs.
|
|
7154
|
+
|
|
7155
|
+
Values that hactl hides elsewhere, such as password states and camera tokens, are printed as
|
|
7156
|
+
REDACTED wherever they appear, even inside other words. This guards against accidents, not
|
|
7157
|
+
intent: a template that cuts up or encodes a secret gets past it, and a secret without a
|
|
7158
|
+
recognizable name or shape cannot be caught.
|
|
7159
|
+
|
|
7160
|
+
hactl template "{{ states('sensor.outside_temperature') }}"
|
|
7161
|
+
hactl template "{{ states.light | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list }}"
|
|
7162
|
+
hactl template - < sensor.jinja
|
|
7163
|
+
hactl template "{% set trigger = {'to_state': {'state': 'on'}} %}{{ trigger.to_state.state }}"`
|
|
7164
|
+
},
|
|
7165
|
+
parameters: {
|
|
7166
|
+
positional: {
|
|
7167
|
+
kind: "tuple",
|
|
7168
|
+
parameters: [
|
|
7169
|
+
{ brief: "The template, or - for standard input", placeholder: "template", parse: String }
|
|
7170
|
+
]
|
|
7171
|
+
}
|
|
7172
|
+
},
|
|
7173
|
+
async func(_flags, argument) {
|
|
7174
|
+
const template = argument === "-" ? await this.readStdin() : argument;
|
|
7175
|
+
if (template.trim() === "") {
|
|
7176
|
+
throw new UsageError("the template is empty");
|
|
7177
|
+
}
|
|
7178
|
+
const { context, token } = await resolveActiveContext(this);
|
|
7179
|
+
const session = await openHa(this.connect, context, token);
|
|
7180
|
+
let secrets = /* @__PURE__ */ new Set();
|
|
7181
|
+
try {
|
|
7182
|
+
secrets = collectSecrets(
|
|
7183
|
+
parseResult(intersection10qmong0na8e8rValidator, await session.send("get_states"), "get_states")
|
|
7184
|
+
);
|
|
7185
|
+
const { result, warnings } = await render(session, template);
|
|
7186
|
+
for (const warning of warnings) {
|
|
7187
|
+
const text5 = redactText(String(hideSecrets(warning, secrets)), token);
|
|
7188
|
+
this.process.stderr.write(`warning: ${text5}
|
|
7189
|
+
`);
|
|
7190
|
+
}
|
|
7191
|
+
const safe = hideSecrets(result, secrets);
|
|
7192
|
+
if (typeof safe !== "string") {
|
|
7193
|
+
printJson(this, redactData(safe, token));
|
|
7194
|
+
} else if (safe !== "") {
|
|
7195
|
+
const text5 = redactText(safe, token);
|
|
7196
|
+
this.process.stdout.write(text5.endsWith("\n") ? text5 : `${text5}
|
|
7197
|
+
`);
|
|
7198
|
+
}
|
|
7199
|
+
} catch (error) {
|
|
7200
|
+
throw explain3(error, secrets);
|
|
7201
|
+
} finally {
|
|
7202
|
+
session.close();
|
|
7203
|
+
}
|
|
7204
|
+
}
|
|
7205
|
+
});
|
|
7206
|
+
|
|
6662
7207
|
// src/upgrade.ts
|
|
6663
7208
|
import { createHash, randomBytes as randomBytes2 } from "node:crypto";
|
|
6664
7209
|
import { access as access2, chmod, constants as constants2, rename as rename2, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
@@ -6806,7 +7351,7 @@ function formatFailure(exc) {
|
|
|
6806
7351
|
return `internal_error: ${message}
|
|
6807
7352
|
hint: Report it at https://github.com/houfio/hactl/issues.`;
|
|
6808
7353
|
}
|
|
6809
|
-
var
|
|
7354
|
+
var text4 = {
|
|
6810
7355
|
...text_en,
|
|
6811
7356
|
exceptionWhileParsingArguments(exc, ansiColor) {
|
|
6812
7357
|
if (exc instanceof ArgumentParseError && exc.exception instanceof HactlError) {
|
|
@@ -6826,7 +7371,9 @@ var root = buildRouteMap({
|
|
|
6826
7371
|
routes: {
|
|
6827
7372
|
ctx: ctxRoutes,
|
|
6828
7373
|
get: getRoutes,
|
|
7374
|
+
query: queryCommand,
|
|
6829
7375
|
call: callCommand,
|
|
7376
|
+
template: templateCommand,
|
|
6830
7377
|
logs: logsCommand,
|
|
6831
7378
|
upgrade: upgradeCommand
|
|
6832
7379
|
},
|
|
@@ -6841,11 +7388,15 @@ Set one up first (details in \`hactl ctx --help\`):
|
|
|
6841
7388
|
hactl ctx token-set home
|
|
6842
7389
|
hactl ctx use home
|
|
6843
7390
|
|
|
6844
|
-
Then read with \`hactl get\`, act with \`hactl call\` and see what happened with
|
|
7391
|
+
Then read with \`hactl get\` and \`hactl query\`, act with \`hactl call\` and see what happened with
|
|
7392
|
+
\`hactl logs\`. Try Jinja with \`hactl template\`.
|
|
7393
|
+
|
|
7394
|
+
\`get\`, \`logs\`, \`query\` and \`template\` only read. \`call\` is the only command that can change the instance.
|
|
7395
|
+
\`ctx\` and \`upgrade\` change only this machine.
|
|
6845
7396
|
Every command and group has its own \`--help\` with its behavior, output and examples.
|
|
6846
7397
|
|
|
6847
|
-
Output is JSON on standard output, except that \`hactl logs\` prints plain text
|
|
6848
|
-
a value are left out.
|
|
7398
|
+
Output is JSON on standard output, except that \`hactl logs\` prints plain text and \`hactl
|
|
7399
|
+
template\` prints a text result as it is. Fields without a value are left out.
|
|
6849
7400
|
|
|
6850
7401
|
A failure prints nothing on standard output, except that a lost \`hactl logs --follow\` fails
|
|
6851
7402
|
after the lines it already printed. Standard error starts with a stable code and
|
|
@@ -6859,7 +7410,7 @@ ${Object.entries(errorMeanings).map(([code, meaning]) => ` ${code.padEnd(23)}${
|
|
|
6859
7410
|
var app = buildApplication(root, {
|
|
6860
7411
|
name: "hactl",
|
|
6861
7412
|
scanner: { caseStyle: "allow-kebab-for-camel" },
|
|
6862
|
-
localization: { text:
|
|
7413
|
+
localization: { text: text4 },
|
|
6863
7414
|
versionInfo: { currentVersion: package_default.version },
|
|
6864
7415
|
determineExitCode: (exc) => exc instanceof UsageError ? ExitCode.InvalidArgument : ExitCode.CommandRunError
|
|
6865
7416
|
});
|