Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

home-assistant-js-websocket

Package Overview
Dependencies
Maintainers
2
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

home-assistant-js-websocket - npm Package Compare versions

Comparing version 5.9.0 to 5.10.0

16

dist/auth.js
import { parseQuery } from "./util.js";
import { ERR_HASS_HOST_REQUIRED, ERR_INVALID_AUTH, ERR_INVALID_HTTPS_TO_HTTP } from "./errors.js";
import { ERR_HASS_HOST_REQUIRED, ERR_INVALID_AUTH, ERR_INVALID_HTTPS_TO_HTTP, } from "./errors.js";
export const genClientId = () => `${location.protocol}//${location.host}/`;

@@ -44,3 +44,3 @@ export const genExpires = (expires_in) => {

}
Object.keys(data).forEach(key => {
Object.keys(data).forEach((key) => {
formData.append(key, data[key]);

@@ -51,3 +51,3 @@ });

credentials: "same-origin",
body: formData
body: formData,
});

@@ -69,3 +69,3 @@ if (!resp.ok) {

code,
grant_type: "authorization_code"
grant_type: "authorization_code",
});

@@ -102,3 +102,3 @@ }

grant_type: "refresh_token",
refresh_token: this.data.refresh_token
refresh_token: this.data.refresh_token,
});

@@ -124,3 +124,3 @@ // Access token response does not contain refresh token.

credentials: "same-origin",
body: formData
body: formData,
});

@@ -139,3 +139,3 @@ if (this._saveTokens) {

access_token,
expires_in: 1e11
expires_in: 1e11,
});

@@ -184,3 +184,3 @@ }

hassUrl,
clientId
clientId,
}));

@@ -187,0 +187,0 @@ // Just don't resolve while we navigate to next page

@@ -26,4 +26,4 @@ import { getCollection } from "./collection.js";

}
const subscribeUpdates = (conn, store) => conn.subscribeEvents(ev => processEvent(store, ev), "state_changed");
const subscribeUpdates = (conn, store) => conn.subscribeEvents((ev) => processEvent(store, ev), "state_changed");
export const entitiesColl = (conn) => getCollection(conn, "_ent", fetchEntities, subscribeUpdates);
export const subscribeEntities = (conn, onChange) => entitiesColl(conn).subscribe(onChange);

@@ -39,3 +39,3 @@ (function (global, factory) {

}
function callService(domain, service, serviceData, target) {
function callService$1(domain, service, serviceData, target) {
const message = {

@@ -456,2 +456,28 @@ type: "call_service",

}
// From: https://davidwalsh.name/javascript-debounce-function
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
// eslint-disable-next-line: ban-types
const debounce = (func, wait, immediate = false) => {
let timeout;
// @ts-ignore
return function (...args) {
// @ts-ignore
const context = this;
const later = () => {
timeout = undefined;
if (!immediate) {
func.apply(context, args);
}
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) {
func.apply(context, args);
}
};
};

@@ -499,3 +525,3 @@ const genClientId = () => `${location.protocol}//${location.host}/`;

}
Object.keys(data).forEach(key => {
Object.keys(data).forEach((key) => {
formData.append(key, data[key]);

@@ -506,3 +532,3 @@ });

credentials: "same-origin",
body: formData
body: formData,
});

@@ -524,3 +550,3 @@ if (!resp.ok) {

code,
grant_type: "authorization_code"
grant_type: "authorization_code",
});

@@ -557,3 +583,3 @@ }

grant_type: "refresh_token",
refresh_token: this.data.refresh_token
refresh_token: this.data.refresh_token,
});

@@ -579,3 +605,3 @@ // Access token response does not contain refresh token.

credentials: "same-origin",
body: formData
body: formData,
});

@@ -594,3 +620,3 @@ if (this._saveTokens) {

access_token,
expires_in: 1e11
expires_in: 1e11,
});

@@ -639,3 +665,3 @@ }

hassUrl,
clientId
clientId,
}));

@@ -714,3 +740,3 @@ // Just don't resolve while we navigate to next page

};
}
},
// /**

@@ -785,3 +811,3 @@ // * Remove a previously-registered listener function.

const getUser = (connection) => connection.sendMessagePromise(user());
const callService$1 = (connection, domain, service, serviceData, target) => connection.sendMessagePromise(callService(domain, service, serviceData, target));
const callService = (connection, domain, service, serviceData, target) => connection.sendMessagePromise(callService$1(domain, service, serviceData, target));

@@ -796,7 +822,7 @@ function processComponentLoaded(state, event) {

const fetchConfig = (conn) => getConfig(conn);
const subscribeUpdates = (conn, store) => Promise.all([
const subscribeUpdates$2 = (conn, store) => Promise.all([
conn.subscribeEvents(store.action(processComponentLoaded), "component_loaded"),
conn.subscribeEvents(() => fetchConfig(conn).then((config) => store.setState(config, true)), "core_config_updated"),
]).then((unsubs) => () => unsubs.forEach((unsub) => unsub()));
const configColl = (conn) => getCollection(conn, "_cnf", fetchConfig, subscribeUpdates);
const configColl = (conn) => getCollection(conn, "_cnf", fetchConfig, subscribeUpdates$2);
const subscribeConfig = (conn, onChange) => configColl(conn).subscribe(onChange);

@@ -809,10 +835,13 @@ const STATE_NOT_RUNNING = "NOT_RUNNING";

function processServiceRegistered(state, event) {
function processServiceRegistered(conn, store, event) {
var _a;
const state = store.state;
if (state === undefined)
return null;
return;
const { domain, service } = event.data;
const domainInfo = Object.assign({}, state[domain], {
[service]: { description: "", fields: {} },
});
return { [domain]: domainInfo };
if (!((_a = state.domain) === null || _a === void 0 ? void 0 : _a.service)) {
const domainInfo = Object.assign(Object.assign({}, state[domain]), { [service]: { description: "", fields: {} } });
store.setState({ [domain]: domainInfo });
}
debouncedFetchServices(conn, store);
}

@@ -833,5 +862,6 @@ function processServiceRemoved(state, event) {

}
const debouncedFetchServices = debounce((conn, store) => fetchServices(conn).then((services) => store.setState(services, true)), 5000);
const fetchServices = (conn) => getServices(conn);
const subscribeUpdates$1 = (conn, store) => Promise.all([
conn.subscribeEvents(store.action(processServiceRegistered), "service_registered"),
conn.subscribeEvents((ev) => processServiceRegistered(conn, store, ev), "service_registered"),
conn.subscribeEvents(store.action(processServiceRemoved), "service_removed"),

@@ -865,4 +895,4 @@ ]).then((unsubs) => () => unsubs.forEach((fn) => fn()));

}
const subscribeUpdates$2 = (conn, store) => conn.subscribeEvents(ev => processEvent(store, ev), "state_changed");
const entitiesColl = (conn) => getCollection(conn, "_ent", fetchEntities, subscribeUpdates$2);
const subscribeUpdates = (conn, store) => conn.subscribeEvents((ev) => processEvent(store, ev), "state_changed");
const entitiesColl = (conn) => getCollection(conn, "_ent", fetchEntities, subscribeUpdates);
const subscribeEntities = (conn, onChange) => entitiesColl(conn).subscribe(onChange);

@@ -893,3 +923,3 @@

exports.STATE_STOPPING = STATE_STOPPING;
exports.callService = callService$1;
exports.callService = callService;
exports.configColl = configColl;

@@ -896,0 +926,0 @@ exports.createCollection = createCollection;

import { getCollection } from "./collection.js";
import { getServices } from "./commands.js";
function processServiceRegistered(state, event) {
import { debounce } from "./util.js";
function processServiceRegistered(conn, store, event) {
var _a;
const state = store.state;
if (state === undefined)
return null;
return;
const { domain, service } = event.data;
const domainInfo = Object.assign({}, state[domain], {
[service]: { description: "", fields: {} },
});
return { [domain]: domainInfo };
if (!((_a = state.domain) === null || _a === void 0 ? void 0 : _a.service)) {
const domainInfo = Object.assign(Object.assign({}, state[domain]), { [service]: { description: "", fields: {} } });
store.setState({ [domain]: domainInfo });
}
debouncedFetchServices(conn, store);
}

@@ -26,5 +30,6 @@ function processServiceRemoved(state, event) {

}
const debouncedFetchServices = debounce((conn, store) => fetchServices(conn).then((services) => store.setState(services, true)), 5000);
const fetchServices = (conn) => getServices(conn);
const subscribeUpdates = (conn, store) => Promise.all([
conn.subscribeEvents(store.action(processServiceRegistered), "service_registered"),
conn.subscribeEvents((ev) => processServiceRegistered(conn, store, ev), "service_registered"),
conn.subscribeEvents(store.action(processServiceRemoved), "service_removed"),

@@ -31,0 +36,0 @@ ]).then((unsubs) => () => unsubs.forEach((fn) => fn()));

@@ -69,3 +69,3 @@ export const createStore = (state) => {

};
}
},
// /**

@@ -72,0 +72,0 @@ // * Remove a previously-registered listener function.

export declare function parseQuery<T>(queryString: string): T;
export declare const debounce: <T extends (...args: any[]) => unknown>(func: T, wait: number, immediate?: boolean) => T;

@@ -12,1 +12,27 @@ export function parseQuery(queryString) {

}
// From: https://davidwalsh.name/javascript-debounce-function
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
// eslint-disable-next-line: ban-types
export const debounce = (func, wait, immediate = false) => {
let timeout;
// @ts-ignore
return function (...args) {
// @ts-ignore
const context = this;
const later = () => {
timeout = undefined;
if (!immediate) {
func.apply(context, args);
}
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) {
func.apply(context, args);
}
};
};

@@ -5,3 +5,3 @@ {

"sideEffects": false,
"version": "5.9.0",
"version": "5.10.0",
"description": "Home Assistant websocket client",

@@ -29,3 +29,4 @@ "source": "lib/index.ts",

"build": "tsc && rollup -c",
"test": "tsc && mocha",
"test": "tsc && prettier --check . && mocha",
"format": "prettier --write .",
"prepublishOnly": "rm -rf dist && yarn build && npm test"

@@ -40,3 +41,3 @@ },

"husky": "^4.2.5",
"lint-staged": "^10.2.10",
"lint-staged": "^11.0.0",
"mocha": "^8.0.1",

@@ -43,0 +44,0 @@ "prettier": "^2.0.5",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc