JavaScript websocket client for Home Assistant
OTHER License
Bot releases are visible (Hide)
Published by release-drafter[bot] almost 6 years ago
Now possible to get collection objects, instead of just subscribing to them.
// Will only initialize one collection per connection.
getCollection<State>(
conn: Connection,
key: string,
fetchCollection: (conn: Connection) => Promise<State>,
subscribeUpdates: (
conn: Connection,
store: Store<State>
) => Promise<UnsubscribeFunc>,
): Collection<State>
// Returns object with following type
class Collection<State> {
state: State;
async refresh(): Promise<void>;
subscribe(subscriber: (state: State) => void): UnsubscribeFunc;
}
You can also import the service, config and entities collections:
import { entitiesColl, servicesColl, configColl } from 'home-assistant-js-websocket';
Published by release-drafter[bot] almost 6 years ago
Published by release-drafter[bot] almost 6 years ago
Published by release-drafter[bot] about 6 years ago
Published by release-drafter[bot] about 6 years ago
Published by release-drafter[bot] about 6 years ago
Published by release-drafter[bot] about 6 years ago
3.1.0 was skipped because I accidentally pushed without updating dist files
Published by release-drafter[bot] about 6 years ago
Major rewrite, cleanup and typescriptation of this lib. See release notes of the RCs for the ins and outs.
Published by balloob about 6 years ago
getUser
command exported (#49) @balloobThe following methods have been removed from the connection
object and can now be imported individually: conn.getStates()
, conn.getConfig()
, conn.getServices()
, conn.callService()
.
Replace calls with:
import { getServices } from 'home-assistant-js-websocket';
const services = await getServices(conn);
Published by balloob about 6 years ago
Published by balloob about 6 years ago
Published by release-drafter[bot] about 6 years ago
Published by release-drafter[bot] about 6 years ago
Published by release-drafter[bot] about 6 years ago
The library will now only work with the new OAuth system in Home Assistant. It supports a full OAuth2 authentication flow with any Home Assistant instance out of the box.
The following code is all that is needed to ask the user for their Home Assistant instance url, navigate the user to their instance to authenticate your app, fetch the tokens once returned and connect to the WebSocket API and start logging the entities whenever they change.
import {
getAuth,
createConnection,
subscribeEntities,
ERR_HASS_HOST_REQUIRED
} from "home-assistant-js-websocket";
async function connect() {
let auth;
try {
// If we came back from authentication flow, retrieve tokens and url
auth = await getAuth();
} catch (err) {
if (err === ERR_HASS_HOST_REQUIRED) {
// No host configured, ask user for host and initiate authentication flow
const hassUrl = prompt(
"What host to connect to?",
"http://localhost:8123"
);
auth = await getAuth({ hassUrl });
} else {
alert(`Unknown error: ${err}`);
return;
}
}
const connection = await createConnection({ auth });
subscribeEntities(connection, ent => console.log(ent));
}
connect();
createSocket
connection option. Defined as: (auth, options) => promise<WebSocket>
connection.sendMessagePromise
will now resolve to the result instead of returning the WebSocket API wrapper.
const response = conn.sendMessagePromise({ type: 'ping' });
// < 3.0.0
response.then(message => console.log(message.result))
// 3.0.0
response.then(result => console.log(result))
subscribeConfig
no longer contains the services. To subscribe to services use the new subscribeServices
method.Published by balloob over 6 years ago
Breaking change:
Published by balloob over 6 years ago
(the 1.1.3 release should be ignored due to a package publish fail)
Published by balloob about 7 years ago
splitbyGroups
(@abmantis - #9)Published by balloob over 7 years ago
subscribeConfig
will now process service_removed
events (@pvizeli)Published by balloob over 7 years ago
Fixes a bug that when extracting the entities of a view, we would incorrectly ignore the hidden attribute on group entities.