npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

homebridge-fakeswitchfs

v1.2.2

Published

Simulated switch plugin for Homebridge: https://github.com/nfarina/homebridge

Downloads

20

Readme

Simulated switch plugin for Homebridge

Turn on or off a simulated switch

Created for testing homebridge

Installing

To install the plugin, head over to the machine with Homebridge set up and run

sudo npm install -g homebridge-sonytvpower
Configuration

To make Homebridge aware of the new plugin, you will have to add it to your configuration usually found in .homebridge/config.json. Somewhere inside that file you should see a key named accessories. You can just add this:

"accessories": [
    {
      "accessory": "FakeSwitch",
      "name": "Test Switch",
    } 
]

Accessory should always be FakeSwitch. You can change the name whatever you want. YOU NEED TO MAKE A .TXT FILE CALLED thenameyouentered_conf.txt WITH THE NUMBER 0 IN IT IN YOUR USER'S .homebridge/persist FOLDER!!!!!!!!!!! NOTE: The "state file" will be stored in the .homebridge/ folder. The filename is "name_conf.txt".

What it does?

WARNING: The text below containes description to beginners who want to write plugins for Homebridge. Professional programmers, GO AWAY! I import the fs(filesystem) package to write/read files:

var fs = require("fs");

I create variables for homebridge stuff:

var Service, Characteristic, HomebridgeAPI;

A function here for homebridge:

module.exports = function(homebridge){

Setting the Service variable to the HAP Service "module". Service tells the program I want a switch, or a lightbulb, or a door opener, etc.

    Service = homebridge.hap.Service;

Setting the Characteristic variable: Characteristic tells the Service what is the proper function to call if the user presses a button.

    Characteristic = homebridge.hap.Characteristic;

Setting the HomebridgeAPI variable: This is REALLY important. With this, we can tell Homebridge what accessory's plugin we are(more on that later).

    HomebridgeAPI = homebridge;

Registering our plugin into Homebridge: 1st argument: Module original name ("homebridge-xy") 2nd argument: Module name ("xy") 3rd argument: Module function name ("Xy")

    HomebridgeAPI.registerAccessory("homebridge-fakeswitch", "FakeSwitch", FakeSwitch);

Close this function:

}

Create our Module function. The name should be the name you entered into registerAccessory.

function FakeSwitch(log, config){

Creating our own logger function that Homebridge gave to us.

    this.log = log;

Getting the "name" entry from the config file:

    this.name = config.name;

Defining our file path for fs:

    this.filePath = HomebridgeAPI.user.persistPath() + "/" + this.name + "_conf.txt";

Defining what service is our device use: In this case, it's a switch.

    this._service = new Service.Switch(this.name);

"Telling" our functions via Characteristic: Get is for getting the state of the device. Set is for setting the state of the device.

    this._service.getCharacteristic(Characteristic.On)
        .on('get', this._get.bind(this))
        .on('set', this._set.bind(this));

Close this function:

}

Create a getServices function in our prototype for Homebridge to(guess for what) get our services:

FakeSwitch.prototype.getServices = function(){

Return the _service variable from our module:

    return [this._service];

Close this function:

}

Create a _set function in our prototype: We said go to here when setting device states to Homebridge earlier.

FakeSwitch.prototype._set = function (state, callback){

We are going to write a file: Path: this.filePath(we defined this earlier) Content: state(this is a variable we get from Homebridge when it calls this function)+''(this is used for converting int to string) Encoding: UTF-8(I don't know why) Callback: Our function which throws an error if it exists, or executes the callback function

    fs.writeFile(this.filePath, state + '', "utf8", function(err){ if (err) throw err; callback(null); });

Close this function:

}

Create a _get function in our prototype: We said go to here when getting device states to Homebridge earlier.

FakeSwitch.prototype._get = function(callback){

We are going to read a file: Path: this.filePath(we defined this earlier) Callback: Our function which throws an error if it exists, or executes the callback function

    fs.readFile(this.filePath, function(err, data){ if (err) throw err; callback(null, parseInt(data) ); });

Close this function:

}