hass-taste-test 0.2.0 → 0.2.2
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/lib/index.d.ts +4 -0
- package/lib/index.js +15 -3
- package/lib/integrations/playwright.d.ts +1 -0
- package/lib/integrations/playwright.js +3 -0
- package/lib/socket.js +1 -0
- package/lib/types.d.ts +1 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export declare class HomeAssistant<E> {
|
|
|
25
25
|
private accessToken;
|
|
26
26
|
private options;
|
|
27
27
|
private dashboards;
|
|
28
|
+
private entitiesCollection;
|
|
28
29
|
ws: hass.Connection;
|
|
29
30
|
private constructor();
|
|
30
31
|
private path_confFile;
|
|
@@ -77,9 +78,11 @@ export declare class HomeAssistant<E> {
|
|
|
77
78
|
cards: HassCard<E>[];
|
|
78
79
|
parent: HomeAssistant<E>;
|
|
79
80
|
path: string;
|
|
81
|
+
page: BrowserPage<E>;
|
|
80
82
|
link(): Promise<string>;
|
|
81
83
|
openInBrowser(): Promise<void>;
|
|
82
84
|
}>;
|
|
85
|
+
states(): Promise<hass.HassEntities>;
|
|
83
86
|
/** Clean up connections and stop the HomeAssistant server */
|
|
84
87
|
close(): Promise<void>;
|
|
85
88
|
HassDashboard: {
|
|
@@ -87,6 +90,7 @@ export declare class HomeAssistant<E> {
|
|
|
87
90
|
cards: HassCard<E>[];
|
|
88
91
|
parent: HomeAssistant<E>;
|
|
89
92
|
path: string;
|
|
93
|
+
page: BrowserPage<E>;
|
|
90
94
|
link(): Promise<string>;
|
|
91
95
|
openInBrowser(): Promise<void>;
|
|
92
96
|
};
|
package/lib/index.js
CHANGED
|
@@ -36,6 +36,7 @@ const net = __importStar(require("net"));
|
|
|
36
36
|
const hass = __importStar(require("home-assistant-js-websocket"));
|
|
37
37
|
const socket_1 = require("./socket");
|
|
38
38
|
const proper_lockfile_1 = __importDefault(require("proper-lockfile"));
|
|
39
|
+
const home_assistant_js_websocket_1 = require("home-assistant-js-websocket");
|
|
39
40
|
var playwright_1 = require("./integrations/playwright");
|
|
40
41
|
Object.defineProperty(exports, "PlaywrightBrowser", { enumerable: true, get: function () { return playwright_1.PlaywrightBrowser; } });
|
|
41
42
|
/** Sleeps for 100 ms */
|
|
@@ -55,6 +56,7 @@ class HomeAssistant {
|
|
|
55
56
|
accessToken;
|
|
56
57
|
options;
|
|
57
58
|
dashboards = 0;
|
|
59
|
+
entitiesCollection;
|
|
58
60
|
ws;
|
|
59
61
|
constructor(options) {
|
|
60
62
|
this.venvDir = (0, path_1.join)((0, os_1.tmpdir)(), 'hasstest-venv');
|
|
@@ -184,7 +186,7 @@ class HomeAssistant {
|
|
|
184
186
|
const installed = await this.hassVersion();
|
|
185
187
|
if (!installed || installed !== this.cache.latestHass) {
|
|
186
188
|
await exec(this.path_pip(), ['install', '--upgrade', 'wheel']);
|
|
187
|
-
await exec(this.path_pip(), ['install', '--upgrade', 'homeassistant']);
|
|
189
|
+
await exec(this.path_pip(), ['install', '--upgrade', 'mutagen', 'homeassistant']);
|
|
188
190
|
}
|
|
189
191
|
}
|
|
190
192
|
async readCache() {
|
|
@@ -319,6 +321,8 @@ class HomeAssistant {
|
|
|
319
321
|
auth,
|
|
320
322
|
createSocket: async () => (0, socket_1.createSocket)(auth, false),
|
|
321
323
|
});
|
|
324
|
+
console.log('VERSION IS', this.ws.haVersion);
|
|
325
|
+
this.entitiesCollection = (0, home_assistant_js_websocket_1.entitiesColl)(this.ws);
|
|
322
326
|
}
|
|
323
327
|
async addIntegration(name) {
|
|
324
328
|
const response = await this.post('/api/config/config_entries/flow', {
|
|
@@ -352,8 +356,8 @@ class HomeAssistant {
|
|
|
352
356
|
mode: 'storage',
|
|
353
357
|
require_admin: false,
|
|
354
358
|
show_in_sidebar: true,
|
|
355
|
-
title: `Dashboard ${id}`,
|
|
356
359
|
...options,
|
|
360
|
+
title: options?.title || `Dashboard ${id}`,
|
|
357
361
|
};
|
|
358
362
|
await this.ws.sendMessagePromise(args);
|
|
359
363
|
return args.url_path;
|
|
@@ -376,12 +380,18 @@ class HomeAssistant {
|
|
|
376
380
|
async Dashboard(config, options) {
|
|
377
381
|
if (!this.options.browser)
|
|
378
382
|
throw new Error('Cannot launch a dashboard without a browser integration. Make sure to specify options.integration');
|
|
379
|
-
const dashboard = await this.createDashboard();
|
|
383
|
+
const dashboard = await this.createDashboard({ title: options?.title });
|
|
380
384
|
await this.setDashboardView(dashboard, config);
|
|
381
385
|
const code = await this.fetchLoginCode();
|
|
382
386
|
const page = await this.options.browser.open(this.customDashboard(dashboard, code), options || {});
|
|
383
387
|
return new this.HassDashboard(this, dashboard, config, page);
|
|
384
388
|
}
|
|
389
|
+
async states() {
|
|
390
|
+
console.log(this.entitiesCollection.state);
|
|
391
|
+
// this.entitiesCollection = entitiesColl(this.ws);
|
|
392
|
+
// await this.entitiesCollection.refresh();
|
|
393
|
+
return this.entitiesCollection.state;
|
|
394
|
+
}
|
|
385
395
|
/** Clean up connections and stop the HomeAssistant server */
|
|
386
396
|
async close() {
|
|
387
397
|
if (this.options.browser)
|
|
@@ -398,10 +408,12 @@ class HomeAssistant {
|
|
|
398
408
|
HassDashboard = class {
|
|
399
409
|
parent;
|
|
400
410
|
path;
|
|
411
|
+
page;
|
|
401
412
|
cards = [];
|
|
402
413
|
constructor(parent, path, config, page) {
|
|
403
414
|
this.parent = parent;
|
|
404
415
|
this.path = path;
|
|
416
|
+
this.page = page;
|
|
405
417
|
for (let i = 0; i < config.length; i++) {
|
|
406
418
|
this.cards.push(new HassCard(i, page));
|
|
407
419
|
}
|
|
@@ -20,4 +20,5 @@ export declare class PlaywrightPage implements BrowserPage<PlaywrightElement> {
|
|
|
20
20
|
screenshot(element: PlaywrightElement): Promise<Buffer>;
|
|
21
21
|
find(element: PlaywrightElement, selector: string): Promise<ElementHandle<SVGElement | HTMLElement> | null>;
|
|
22
22
|
textContent(element: PlaywrightElement): Promise<string>;
|
|
23
|
+
get playwright(): Page;
|
|
23
24
|
}
|
package/lib/socket.js
CHANGED
|
@@ -88,6 +88,7 @@ function createSocket(auth, ignoreCertificates) {
|
|
|
88
88
|
socket.removeEventListener('message', handleMessage);
|
|
89
89
|
socket.removeEventListener('close', closeMessage);
|
|
90
90
|
socket.removeEventListener('error', errorMessage);
|
|
91
|
+
socket.haVersion = message.ha_version;
|
|
91
92
|
promResolve(socket);
|
|
92
93
|
break;
|
|
93
94
|
default:
|
package/lib/types.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export interface DiffOptions {
|
|
|
23
23
|
}
|
|
24
24
|
export type DashboardOptions = Partial<{
|
|
25
25
|
colorScheme: 'light' | 'dark' | 'no-preference';
|
|
26
|
+
title: string;
|
|
26
27
|
}>;
|
|
27
28
|
export interface BrowserIntegration<E> {
|
|
28
29
|
open(url: string, options: DashboardOptions): Promise<BrowserPage<E>>;
|