
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
homeassistant-ws
Advanced tools
Minimalist client library for Homeassistant's Websocket API. Works in node, and also in the browser.
Using npm
:
$ npm i --save homeassistant-ws
Import it in your project:
import hass from 'homeassistant-ws'
async function main () {
// Assuming hass running in `localhost`, under the default `8321` port:
const client = await hass({
token: 'my-secret-token'
})
}
Tokens are available from your profile page under the Homeassistant UI. For documentation on the authentication API, see the official HA documentation.
The following properties (shown with their defaults) can be passed to the constructor. All are optional.
hass({
protocol: 'ws',
host: 'localhost',
port: 8123,
path: '/api/websocket',
// Must be set if HA expects authentication:
token: null,
// Used to serialize outgoing messages:
messageSerializer: outgoingMessage => JSON.stringify(outgoingMessage),
// Used to parse incoming messages. Receives the entire Websocket message object:
messageParser: incomingMessage => JSON.parse(incomingMessage.data),
// Should return a WebSocket instance
ws (opts) {
return new WebSocket(`${opts.protocol}://${opts.host}:${opts.port}${opts.path}`)
}
})
The following example includes all available methods. For more details on available Homeassistant event types, states, etc. see the official Websocket API
import hass from 'hass'
async function main () {
// Establishes a connection, and authenticates if necessary:
const client = await hass({ token: 'my-token' })
// Get a list of all available states, panels or services:
await client.getStates()
await client.getServices()
await client.getPanels()
// Get hass configuration:
await client.getConfig()
// Get a Buffer containing the current thumbnail for the given media player
await client.getMediaPlayerThumbnail('media_player.my_player')
// { content_type: 'image/jpeg', content: Buffer<...>}
// Get a Buffer containing a thumbnail for the given camera
await client.getCameraThumbnail('camera.front_yard')
// { content_type: 'image/jpeg', content: Buffer<...>}
// Call a service, by its domain and name. The third argument is optional.
await client.callService('lights', 'turn_on', { entity_id: 'light.my_light' })
// Register event handlers. Return a promise since we need to call the HA API to
// subscribe to events the first time.
await client.onAnyEvent((event) => console.log(event))
await client.onStateChanged((event) => console.log(event))
await client.onEvent('event_name', (event) => console.log(event))
// Tell HA to stop sending events of the following type:
await client.unsubscribeFromEvent('event_name')
}
FAQs
Client for Homeassistant's websocket API
The npm package homeassistant-ws receives a total of 27 weekly downloads. As such, homeassistant-ws popularity was classified as not popular.
We found that homeassistant-ws demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.