
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
switcher-js2
Advanced tools
Fork of @johnathanvidu JS implementation
switcher-js is a native nodejs library for controling Switcher smart home accessories - water heater, sockets, and blinds.
It is a native javascript port of a wonderful python script (can be found here) created as a result of the extensive work which has been done by Aviad Golan (@AviadGolan) and Shai rod (@NightRang3r).
It is a work in progress and there is still a lot of work left to do.
I built it according to my specific needs and my specific device. If any issue arises, please feel free to open an issue and I'll do my best to help.
Current supported devices known to work with switcher-js:
Use npm to install switcher-js.
npm install switcher-js2
const Switcher = require('switcher-js2');
var switcher = new Switcher('device-id', 'device-ip', 'log function', 'listen(boolean)', 'device-type');
To use the auto discover functionallity use:
const Switcher = require('switcher-js2');
var proxy = Switcher.discover('log function', 'identifier(optional)', 'discovery-timeout(optional)');
proxy.on('ready', (switcher) => {
switcher.turn_on(); // switcher is a new initialized instance of Switcher class
});
setTimeout(() => {
proxy.close(); // optional way to close the discovery (if discovery-timeout is not set)
}, 10000);
discover will emit a ready event when auto discovery completed.
identifier (optional) - you can provide the Switcher name, IP or device-id to detect specific device.
discovery-timeout (optional) - set maximum time in seconds to scan for devices.
const Switcher = require('switcher-js2');
var switcher = new Switcher('device-id', 'device-ip', 'log function', 'listen', 'device-type');
// set listen to true if you want to listen for status messages
switcher.on('status', (status) => { // status broadcast message - only works when listen=true
console.log(status)
/* response:
{
power: 1,
remaining_seconds: 591,
default_shutdown_seconds: 5400,
power_consumption: 2447 // in watts
}
*/
});
switcher.on('state', (state) => { // state is the new switcher state
console.log(state) // 1
});
switcher.on('error', (error) => {
});
switcher.turn_on(); // turns switcher on
switcher.turn_on(15); // turns switcher on for 15 minutes
switcher.turn_off(); // turns switcher off
switcher.set_default_shutdown(3600) // set the default auto shutdown to 1 hour (must be between 3600 and 86340)
switcher.status(status => { // get status
console.log(status);
});
switcher.close(); // closes any dangling connections safely
const Switcher = require('switcher-js2');
var runner = new Switcher('device-id', 'device-ip', 'log function', 'listen', 'runner');
// set 'device-type' to 'runner' if you want to control the runner devices
runner.on('status', (status) => { // status broadcast message - only works when listen=true
console.log(status)
/* response:
{
position: 80,
direction: 'STOP'
}
*/
});
runner.on('position', (pos) => { // position is the new switcher position
console.log(pos) // 100
});
switcher.on('error', (error) => {
});
switcher.set_position(80); // Set blinds position to 80%
switcher.stop_runner() // stop the blinds
switcher.close(); // closes any dangling connections safely
Global listen functionality that listens to a single or multiple switcher devices for status messages.
To use the listen functionallity use:
const Switcher = require('switcher-js2');
var proxy = Switcher.listen('log function', 'identifier(optional)');
proxy.on('message', (message) => {
console.log(message)
/* response:
{
device_id: 'e3a845',
device_ip: '10.0.0.1',
name: 'Boiler',
type: 'v4'
state: {
power: 1,
remaining_seconds: 591,
default_shutdown_seconds: 5400,
power_consumption: 2447 // in watts
}
}
*/
});
proxy.close(); // close the listener socket
proxy will emit a message event every time it receives a message from a switcher device.
identifier (optional) - you can provide the Switcher name, IP or device-id to filter specific device messages.
Don't use Discover, Listen and Switcher with (listen=true) at the same time as it will return error since this socket is being used. If you want to listen to multiple devices, use the global listen function to get all statuses, and use the switcher instance without the listen capability.
Pull requests are more than welcome. For major changes, please open an issue first to discuss what you would like to change. Even coding tips and standards are welcome, I have very limited experience with javascript, so there's a lot of things I don't know are cleaner or more standarized in the industry.
FAQs
switcher smart accessories api (fork of @johnathanvidu)
The npm package switcher-js2 receives a total of 53 weekly downloads. As such, switcher-js2 popularity was classified as not popular.
We found that switcher-js2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.