Compare commits

...
Author SHA1 Message Date
Bram Kragten 756a456c01 add test scanner 2024-04-08 14:09:04 +02:00
Bram Kragten cfdbaac5d6 Update external barcode scanning API 2024-04-08 14:04:03 +02:00
renovate[bot] 0d3e730c9c Update dependency magic-string to v0.30.9 (#20465)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-08 09:33:26 +02:00
renovate[bot] c7a87d02b2 Update dependency @types/leaflet to v1.9.9 (#20452) 2024-04-07 20:37:42 +02:00
Bram Kragten dd082c204b Remove unused type (#20429) 2024-04-05 12:22:47 +02:00
renovate[bot] c4af3d1579 Update typescript-eslint monorepo to v7.5.0 (#20426)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-05 11:36:28 +02:00
7 changed files with 215 additions and 126 deletions
+4 -4
View File
@@ -175,7 +175,7 @@
"@types/glob": "8.1.0",
"@types/html-minifier-terser": "7.0.2",
"@types/js-yaml": "4.0.9",
"@types/leaflet": "1.9.8",
"@types/leaflet": "1.9.9",
"@types/leaflet-draw": "1.0.11",
"@types/luxon": "3.4.2",
"@types/mocha": "10.0.6",
@@ -185,8 +185,8 @@
"@types/tar": "6.1.11",
"@types/ua-parser-js": "0.7.39",
"@types/webspeechapi": "0.0.29",
"@typescript-eslint/eslint-plugin": "7.4.0",
"@typescript-eslint/parser": "7.4.0",
"@typescript-eslint/eslint-plugin": "7.5.0",
"@typescript-eslint/parser": "7.5.0",
"@web/dev-server": "0.1.38",
"@web/dev-server-rollup": "0.4.1",
"babel-loader": "9.1.3",
@@ -220,7 +220,7 @@
"lint-staged": "15.2.2",
"lit-analyzer": "2.0.3",
"lodash.template": "4.5.0",
"magic-string": "0.30.8",
"magic-string": "0.30.9",
"map-stream": "0.0.7",
"mocha": "10.3.0",
"object-hash": "3.0.0",
+42 -1
View File
@@ -9,7 +9,19 @@ import { fireEvent } from "../common/dom/fire_event";
import { mainWindow } from "../common/dom/get_main_window";
import { showAutomationEditor } from "../data/automation";
import { HomeAssistantMain } from "../layouts/home-assistant-main";
import type { EMIncomingMessageCommands } from "./external_messaging";
import type {
EMIncomingMessageBarCodeScanAborted,
EMIncomingMessageBarCodeScanResult,
EMIncomingMessageCommands,
} from "./external_messaging";
const barCodeListeners = new Set<
(
msg:
| EMIncomingMessageBarCodeScanResult
| EMIncomingMessageBarCodeScanAborted
) => boolean
>();
export const attachExternalToApp = (hassMainEl: HomeAssistantMain) => {
window.addEventListener("haptic", (ev) =>
@@ -24,6 +36,19 @@ export const attachExternalToApp = (hassMainEl: HomeAssistantMain) => {
);
};
export const addExternalBarCodeListener = (
listener: (
msg:
| EMIncomingMessageBarCodeScanResult
| EMIncomingMessageBarCodeScanAborted
) => boolean
) => {
barCodeListeners.add(listener);
return () => {
barCodeListeners.delete(listener);
};
};
const handleExternalMessage = (
hassMainEl: HomeAssistantMain,
msg: EMIncomingMessageCommands
@@ -88,6 +113,22 @@ const handleExternalMessage = (
success: true,
result: null,
});
} else if (msg.command === "bar_code/scan_result") {
barCodeListeners.forEach((listener) => listener(msg));
bus.fireMessage({
id: msg.id,
type: "result",
success: true,
result: null,
});
} else if (msg.command === "bar_code/aborted") {
barCodeListeners.forEach((listener) => listener(msg));
bus.fireMessage({
id: msg.id,
type: "result",
success: true,
result: null,
});
} else {
return false;
}
+8 -4
View File
@@ -37,9 +37,11 @@ interface EMOutgoingMessageConfigGet extends EMMessage {
interface EMOutgoingMessageBarCodeScan extends EMMessage {
type: "bar_code/scan";
title: string;
description: string;
alternative_option_label?: string;
payload: {
title: string;
description: string;
alternative_option_label?: string;
};
}
interface EMOutgoingMessageBarCodeClose extends EMMessage {
@@ -48,7 +50,9 @@ interface EMOutgoingMessageBarCodeClose extends EMMessage {
interface EMOutgoingMessageBarCodeNotify extends EMMessage {
type: "bar_code/notify";
message: string;
payload: {
message: string;
};
}
interface EMOutgoingMessageMatterCommission extends EMMessage {
+98
View File
@@ -0,0 +1,98 @@
import "@material/mwc-ripple";
import { LitElement, html } from "lit";
import { customElement, state } from "lit/decorators";
import "../../../components/ha-card";
import { HomeAssistant } from "../../../types";
import { addExternalBarCodeListener } from "../../../external_app/external_app_entrypoint";
@customElement("test-scanner-card")
export class TestScannerCard extends LitElement {
public hass!: HomeAssistant;
@state() private _result: string[] = [];
private _removeListener?: () => void;
public getCardSize(): number {
return 4;
}
public setConfig(_config): void {}
protected render() {
if (!this.hass.auth.external?.config.hasBarCodeScanner) {
return html`
<ha-card>
<div class="card-content">
Barcode scanner not available, use a mobile app that has barcode
scanning support.
</div>
</ha-card>
`;
}
return html`
<ha-card>
<div class="card-content"><pre>${this._result.join("\r\n")}</pre></div>
<div class="card-actions">
<mwc-button @click=${this._openScanner}>Open scanner</mwc-button>
</div>
</ha-card>
`;
}
private _openScanner() {
this._removeListener = addExternalBarCodeListener((msg) => {
if (msg.command === "bar_code/scan_result") {
this._result = [
...this._result,
`Result: ${JSON.stringify(msg.payload)}`,
];
if (msg.payload.format !== "qr_code") {
this._notifyScanner(
`Wrong barcode scanned! ${msg.payload.format}: ${msg.payload.rawValue}, we need a QR code.`
);
} else {
this._closeScanner();
}
} else if (msg.command === "bar_code/aborted") {
this._removeListener!();
this._result = [
...this._result,
`Aborted: ${JSON.stringify(msg.payload)}`,
];
}
return true;
});
this.hass.auth.external!.fireMessage({
type: "bar_code/scan",
payload: {
title: "Scan test barcode",
description: "Scan a barcode to test the scanner.",
alternative_option_label: "Click to manually enter the test barcode",
},
});
}
private _closeScanner() {
this._removeListener!();
this.hass.auth.external!.fireMessage({
type: "bar_code/close",
});
}
private _notifyScanner(message: string) {
this.hass.auth.external!.fireMessage({
type: "bar_code/notify",
payload: {
message,
},
});
}
}
declare global {
interface HTMLElementTagNameMap {
"test-scanner-card": TestScannerCard;
}
}
-55
View File
@@ -487,61 +487,6 @@ export interface WeatherForecastCardConfig extends LovelaceCardConfig {
double_tap_action?: ActionConfig;
}
export interface EnergyFlowCardConfig extends LovelaceCardConfig {
type: string;
name?: string;
show_header_toggle?: boolean;
show_warning?: boolean;
show_error?: boolean;
test_gui?: boolean;
show_w_not_kw?: any;
hide_inactive_lines?: boolean;
threshold_in_k?: number;
energy_flow_diagramm?: boolean;
energy_flow_diagramm_lines_factor?: number;
change_house_bubble_color_with_flow?: boolean;
grid_icon?: string;
generation_icon?: string;
house_icon?: string;
battery_icon?: string;
appliance1_icon?: string;
appliance2_icon?: string;
icon_entities?: Map<string, string>;
line_entities?: Map<string, string>;
house_entity?: string;
battery_entity?: string;
generation_entity?: string;
grid_entity?: string;
grid_to_house_entity?: string;
grid_to_battery_entity?: string;
generation_to_grid_entity?: string;
generation_to_battery_entity?: string;
generation_to_house_entity?: string;
battery_to_house_entity?: string;
battery_to_grid_entity?: string;
grid_extra_entity?: string;
generation_extra_entity?: string;
house_extra_entity?: string;
battery_extra_entity?: string;
appliance1_consumption_entity?: string;
appliance1_extra_entity?: string;
appliance2_consumption_entity?: string;
appliance2_extra_entity?: string;
tap_action?: ActionConfig;
hold_action?: ActionConfig;
double_tap_action?: ActionConfig;
}
export interface TileCardConfig extends LovelaceCardConfig {
entity: string;
name?: string;
+1
View File
@@ -76,6 +76,7 @@ import { showSaveDialog } from "./editor/show-save-config-dialog";
import { isLegacyStrategyConfig } from "./strategies/legacy-strategy";
import { LocalizeKeys } from "../../common/translations/localize";
import { getLovelaceStrategy } from "./strategies/get-strategy";
import "./cards/test-scanner";
@customElement("hui-root")
class HUIRoot extends LitElement {
+62 -62
View File
@@ -4264,12 +4264,12 @@ __metadata:
languageName: node
linkType: hard
"@types/leaflet@npm:*, @types/leaflet@npm:1.9.8":
version: 1.9.8
resolution: "@types/leaflet@npm:1.9.8"
"@types/leaflet@npm:*, @types/leaflet@npm:1.9.9":
version: 1.9.9
resolution: "@types/leaflet@npm:1.9.9"
dependencies:
"@types/geojson": "npm:*"
checksum: 10/c0c68ae0d1ccbed60e08ad82670df48f8bb6f19e3abaf84a9cd0a6cbc6d6efdd46852ee7be56744dfa7f3d8665adb56bb06ab02d09f979d3367c941a1fd90f2f
checksum: 10/7f1de85f4fa16f6feb3b19f80a8b9db092710e1b8695950a4c7d35b32e1b0bb4bdcd0f179d6c2e0aee49d1c725ab6c7a25ea48c5ea53bd15eb0a02296d4d87d0
languageName: node
linkType: hard
@@ -4543,15 +4543,15 @@ __metadata:
languageName: node
linkType: hard
"@typescript-eslint/eslint-plugin@npm:7.4.0":
version: 7.4.0
resolution: "@typescript-eslint/eslint-plugin@npm:7.4.0"
"@typescript-eslint/eslint-plugin@npm:7.5.0":
version: 7.5.0
resolution: "@typescript-eslint/eslint-plugin@npm:7.5.0"
dependencies:
"@eslint-community/regexpp": "npm:^4.5.1"
"@typescript-eslint/scope-manager": "npm:7.4.0"
"@typescript-eslint/type-utils": "npm:7.4.0"
"@typescript-eslint/utils": "npm:7.4.0"
"@typescript-eslint/visitor-keys": "npm:7.4.0"
"@typescript-eslint/scope-manager": "npm:7.5.0"
"@typescript-eslint/type-utils": "npm:7.5.0"
"@typescript-eslint/utils": "npm:7.5.0"
"@typescript-eslint/visitor-keys": "npm:7.5.0"
debug: "npm:^4.3.4"
graphemer: "npm:^1.4.0"
ignore: "npm:^5.2.4"
@@ -4564,44 +4564,44 @@ __metadata:
peerDependenciesMeta:
typescript:
optional: true
checksum: 10/9bd8852c7e4e9608c3fded94f7c60506cc7d2b6d8a8c1cad6d48969a7363751b20282874e55ccdf180635cf204cb10b3e1e5c3d1cff34d4fcd07762be3fc138e
checksum: 10/5469900a0c2f485dcae10fc8509e2e1d981538d4c90a13330672fbd10cb7b9bb6d55445d6edea876e2c1719f1f0e25f6af0eb2d413e0c458a8930a371481b9e6
languageName: node
linkType: hard
"@typescript-eslint/parser@npm:7.4.0":
version: 7.4.0
resolution: "@typescript-eslint/parser@npm:7.4.0"
"@typescript-eslint/parser@npm:7.5.0":
version: 7.5.0
resolution: "@typescript-eslint/parser@npm:7.5.0"
dependencies:
"@typescript-eslint/scope-manager": "npm:7.4.0"
"@typescript-eslint/types": "npm:7.4.0"
"@typescript-eslint/typescript-estree": "npm:7.4.0"
"@typescript-eslint/visitor-keys": "npm:7.4.0"
"@typescript-eslint/scope-manager": "npm:7.5.0"
"@typescript-eslint/types": "npm:7.5.0"
"@typescript-eslint/typescript-estree": "npm:7.5.0"
"@typescript-eslint/visitor-keys": "npm:7.5.0"
debug: "npm:^4.3.4"
peerDependencies:
eslint: ^8.56.0
peerDependenciesMeta:
typescript:
optional: true
checksum: 10/142a9e1187d305ed43b4fef659c36fa4e28359467198c986f0955c70b4067c9799f4c85d9881fbf099c55dfb265e30666e28b3ef290520e242b45ca7cb8e4ca9
checksum: 10/a5414fb2fbd78bf7337125f4a3040318bdffa996a94e27b4f791d51535d5d9286c3e0ae43652b251c48549bbfece0e3a33553b30ed986af6b4f715d76361d6bb
languageName: node
linkType: hard
"@typescript-eslint/scope-manager@npm:7.4.0":
version: 7.4.0
resolution: "@typescript-eslint/scope-manager@npm:7.4.0"
"@typescript-eslint/scope-manager@npm:7.5.0":
version: 7.5.0
resolution: "@typescript-eslint/scope-manager@npm:7.5.0"
dependencies:
"@typescript-eslint/types": "npm:7.4.0"
"@typescript-eslint/visitor-keys": "npm:7.4.0"
checksum: 10/8cf9292444f9731017a707cac34bef5ae0eb33b5cd42ed07fcd046e981d97889d9201d48e02f470f2315123f53771435e10b1dc81642af28a11df5352a8e8be2
"@typescript-eslint/types": "npm:7.5.0"
"@typescript-eslint/visitor-keys": "npm:7.5.0"
checksum: 10/9446c07290a7f7f539a0bdaaf2fb97ae57095a01cd0baad9ecac532da88e7d0d207e5180131c0608542aee2fd1270caf700a2788fa460ffc6e65e966baf34135
languageName: node
linkType: hard
"@typescript-eslint/type-utils@npm:7.4.0":
version: 7.4.0
resolution: "@typescript-eslint/type-utils@npm:7.4.0"
"@typescript-eslint/type-utils@npm:7.5.0":
version: 7.5.0
resolution: "@typescript-eslint/type-utils@npm:7.5.0"
dependencies:
"@typescript-eslint/typescript-estree": "npm:7.4.0"
"@typescript-eslint/utils": "npm:7.4.0"
"@typescript-eslint/typescript-estree": "npm:7.5.0"
"@typescript-eslint/utils": "npm:7.5.0"
debug: "npm:^4.3.4"
ts-api-utils: "npm:^1.0.1"
peerDependencies:
@@ -4609,23 +4609,23 @@ __metadata:
peerDependenciesMeta:
typescript:
optional: true
checksum: 10/a8bd0929d8237679b2b8a7817f070a4b9658ee976882fba8ff37e4a70dd33f87793e1b157771104111fe8054eaa8ad437a010b6aa465072fbdb932647125db2d
checksum: 10/257730553760fa943538db9648a11f4253efb722ab3394cd325bd775ee0c9d93af84c62540dee9377d4a669eb1cd801faed5e1bcb673d1606c9225eee82b420a
languageName: node
linkType: hard
"@typescript-eslint/types@npm:7.4.0":
version: 7.4.0
resolution: "@typescript-eslint/types@npm:7.4.0"
checksum: 10/2782c5bf65cd3dfa9cd32bc3023676bbca22144987c3f6c6b67fd96c73d4a60b85a57458c49fd11b9971ac6531824bb3ae0664491e7a6de25d80c523c9be92b7
"@typescript-eslint/types@npm:7.5.0":
version: 7.5.0
resolution: "@typescript-eslint/types@npm:7.5.0"
checksum: 10/12eac46d0dfbbeb1db7d0658b841d554d38365420f42b699dea531e0c475b77d6fd838ac4046b7672e53d9bb76a021eaf6198cf3210fe1ecf1056ea44b6699a9
languageName: node
linkType: hard
"@typescript-eslint/typescript-estree@npm:7.4.0":
version: 7.4.0
resolution: "@typescript-eslint/typescript-estree@npm:7.4.0"
"@typescript-eslint/typescript-estree@npm:7.5.0":
version: 7.5.0
resolution: "@typescript-eslint/typescript-estree@npm:7.5.0"
dependencies:
"@typescript-eslint/types": "npm:7.4.0"
"@typescript-eslint/visitor-keys": "npm:7.4.0"
"@typescript-eslint/types": "npm:7.5.0"
"@typescript-eslint/visitor-keys": "npm:7.5.0"
debug: "npm:^4.3.4"
globby: "npm:^11.1.0"
is-glob: "npm:^4.0.3"
@@ -4635,34 +4635,34 @@ __metadata:
peerDependenciesMeta:
typescript:
optional: true
checksum: 10/162ec9d7582f45588342e1be36fdb60e41f50bbdfbc3035c91b517ff5d45244f776921c88d88e543e1c7d0f1e6ada5474a8316b78f1b0e6d2233b101bc45b166
checksum: 10/7487293a9ab9459b133322e695435b4540ffcad89f2bea917c3389676d68283297a663c77d6bda298144d3581361733ae4af632213fa7ef48be67e9aa792b4cc
languageName: node
linkType: hard
"@typescript-eslint/utils@npm:7.4.0":
version: 7.4.0
resolution: "@typescript-eslint/utils@npm:7.4.0"
"@typescript-eslint/utils@npm:7.5.0":
version: 7.5.0
resolution: "@typescript-eslint/utils@npm:7.5.0"
dependencies:
"@eslint-community/eslint-utils": "npm:^4.4.0"
"@types/json-schema": "npm:^7.0.12"
"@types/semver": "npm:^7.5.0"
"@typescript-eslint/scope-manager": "npm:7.4.0"
"@typescript-eslint/types": "npm:7.4.0"
"@typescript-eslint/typescript-estree": "npm:7.4.0"
"@typescript-eslint/scope-manager": "npm:7.5.0"
"@typescript-eslint/types": "npm:7.5.0"
"@typescript-eslint/typescript-estree": "npm:7.5.0"
semver: "npm:^7.5.4"
peerDependencies:
eslint: ^8.56.0
checksum: 10/ffed27e770c486cd000ff892d9049b0afe8b9d6318452a5355b78a37436cbb414bceacae413a2ac813f3e584684825d5e0baa2e6376b7ad6013a108ac91bc19d
checksum: 10/a0b2f206a1c35dd77b292d1cd385443f42d00ccf8a5151811fe6bdd6b5f3a450372bf99b8757c307988d14d99587424c59ed59e78cf56c17b43c9c3fd8932871
languageName: node
linkType: hard
"@typescript-eslint/visitor-keys@npm:7.4.0":
version: 7.4.0
resolution: "@typescript-eslint/visitor-keys@npm:7.4.0"
"@typescript-eslint/visitor-keys@npm:7.5.0":
version: 7.5.0
resolution: "@typescript-eslint/visitor-keys@npm:7.5.0"
dependencies:
"@typescript-eslint/types": "npm:7.4.0"
"@typescript-eslint/types": "npm:7.5.0"
eslint-visitor-keys: "npm:^3.4.1"
checksum: 10/70dc99f2ad116c6e2d9e55af249e4453e06bba2ceea515adef2d2e86e97e557865bb1b1d467667462443eb0d624baba36f7442fd1082f3874339bbc381c26e93
checksum: 10/ba83113110b13bc65120ea3d1e21e1dcea6010b0a1a3d07da2fd274bb0feb552a92276b6052e659d2fe40178938b17368ede64752c4937f41685c53bdf9d2634
languageName: node
linkType: hard
@@ -9678,7 +9678,7 @@ __metadata:
"@types/glob": "npm:8.1.0"
"@types/html-minifier-terser": "npm:7.0.2"
"@types/js-yaml": "npm:4.0.9"
"@types/leaflet": "npm:1.9.8"
"@types/leaflet": "npm:1.9.9"
"@types/leaflet-draw": "npm:1.0.11"
"@types/luxon": "npm:3.4.2"
"@types/mocha": "npm:10.0.6"
@@ -9688,8 +9688,8 @@ __metadata:
"@types/tar": "npm:6.1.11"
"@types/ua-parser-js": "npm:0.7.39"
"@types/webspeechapi": "npm:0.0.29"
"@typescript-eslint/eslint-plugin": "npm:7.4.0"
"@typescript-eslint/parser": "npm:7.4.0"
"@typescript-eslint/eslint-plugin": "npm:7.5.0"
"@typescript-eslint/parser": "npm:7.5.0"
"@vaadin/combo-box": "npm:24.3.10"
"@vaadin/vaadin-themable-mixin": "npm:24.3.10"
"@vibrant/color": "npm:3.2.1-alpha.1"
@@ -9753,7 +9753,7 @@ __metadata:
lit-analyzer: "npm:2.0.3"
lodash.template: "npm:4.5.0"
luxon: "npm:3.4.4"
magic-string: "npm:0.30.8"
magic-string: "npm:0.30.9"
map-stream: "npm:0.0.7"
marked: "npm:12.0.1"
memoize-one: "npm:6.0.0"
@@ -11679,12 +11679,12 @@ __metadata:
languageName: node
linkType: hard
"magic-string@npm:0.30.8, magic-string@npm:^0.30.3":
version: 0.30.8
resolution: "magic-string@npm:0.30.8"
"magic-string@npm:0.30.9, magic-string@npm:^0.30.3":
version: 0.30.9
resolution: "magic-string@npm:0.30.9"
dependencies:
"@jridgewell/sourcemap-codec": "npm:^1.4.15"
checksum: 10/72ab63817af600e92c19dc8489c1aa4a9599da00cfd59b2319709bd48fb0cf533fdf354bf140ac86e598dbd63e6b2cc83647fe8448f864a3eb6061c62c94e784
checksum: 10/a49b7f848e36914c2794e443d4da6579abebb3e57a5e98b1603958f4672d1435dc15261f70c2793e9b6d6c891191c83b9608322b48d0d76a9be32e73e039cc8a
languageName: node
linkType: hard