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 🙏

© 2024 – Pkg Stats / Ryan Hefner

homebridge-mvc

v0.1.3

Published

MVC Plugin for Homebridge

Downloads

5

Readme

homebridge-mvc

NPM version

Homebridge-mvc is a Plugin for Homebridge. This Example-plugin is based on MVC (Model-View-Controller) pattern.

Have a look at homebridge-mqtt for a practical implementation.

Installation

If you are new to homebridge, please follow the instructions in homebridge for the homebridge server installation.

Install homebridge-mvc:

sudo npm install -g homebridge-mvc

Configuration

Add the platform in config.json in your home directory inside .homebridge.

{
  "platform": "mvc",
  "name": "mvc"
}

API

  • addAccessory()
  • addService()
  • removeAccessory()
  • removeService()
  • setValue()
  • getAccessories()
  • updateReachability()
  • setAccessoryInformation()
  • get()
  • set()
  • identify()

Howto examples

  1. Define your homebridge platform in index.js:
var platform_name = "myPlatform";

Note: remeber to change config.json for your platform.

  1. Modify the functions for your plugin in model.js

add accessory

accessory = {"name": "flex_lamp", "service_name": "light", "service": "Switch"};
result = addAccessory(accessory);

add service

Note: an accessory with the same name must be added before.

accessory = {"name": "multi_sensor", "service_name": "Humidity", "service": "HumiditySensor"};
result = addService(accessory);

remove accessory

accessory = {"name": "flex_lamp"};
result = removeAccessory(accessory);

remove service

accessory = {"name": "multi_sensor", "service_name": "Humidity"};
result = removeService(accessory);

get accessory/accessories

The purpose of this function is to retrieve accessory definitions.

accessory = {"name": "outdoor_temp"};
result = getAccessories(accessory);
accessory = {"name": "*"};
result = getAccessories(accessory);

set value

accessory = {"name": "flex_lamp", "service_name": "light", "characteristic": "On", "value": true};
result = setValue(accessory);

update reachability


accessory = {"name": "flex_lamp", "reachable": true};
or
accessory = {"name": "flex_lamp", "reachable": false};
result = updateReachability(accessory);

set accessory information

accessory = {"name": "flex_lamp", "manufacturer": "espressif", "model": "esp8266-12", "serialnumber": "4711"};
result = setAccessoryInformation(accessory);

get (from homebridge)

Model.prototype.get = function(name, service_name, characteristic) {...}

set (from homebridge)

Model.prototype.set = function(name, service_name, characteristic, value, callback) {...}

identify (from homebridge)

Model.prototype.identify = function (name, manufacturer, model, serialnumber) {...}

define characterstic

The required characteristics are added with the default properties. If you need to change the default, define the characteristic-name with the properties. e.g.:

accessory = 
  {
    "name": "living_temp",
    "service": "TemperatureSensor",
    "CurrentTemperature": {"minValue": -20, "maxValue": 60, "minStep": 1}
  };
result = addAccessory(accessory);

To add an optional charachteristic define the characteristic-name with "default" or with the properties. e.g.:

accessory = 
  {
    "name": "living_lamp",
    "service": "Lightbulb",
    "Brightness": "default"
  };
result = addAccessory(accessory);
accessory =
  {
    "name": "bathroom_blind",
    "service": "WindowCovering",
    "CurrentPosition": {"minStep": 5},
    "TargetPosition": {"minStep": 5},
    "CurrentHorizontalTiltAngle": {"minValue": 0, "minStep": 5},
    "TargetHorizontalTiltAngle": {"minValue": 0, "minStep": 5}
  };
result = addAccessory(accessory);

HomeKitTypes.js describes all the predifined Services, Characteristcs, format and properties for the value e.g.:

/**
 * Service "Contact Sensor"
 */

Service.ContactSensor = function(displayName, subtype) {
  Service.call(this, displayName, '00000080-0000-1000-8000-0026BB765291', subtype);

  // Required Characteristics
  this.addCharacteristic(Characteristic.ContactSensorState);

  // Optional Characteristics
  this.addOptionalCharacteristic(Characteristic.StatusActive);
  this.addOptionalCharacteristic(Characteristic.StatusFault);
  this.addOptionalCharacteristic(Characteristic.StatusTampered);
  this.addOptionalCharacteristic(Characteristic.StatusLowBattery);
  this.addOptionalCharacteristic(Characteristic.Name);
};

/**
 * Characteristic "Contact Sensor State"
 */

Characteristic.ContactSensorState = function() {
  Characteristic.call(this, 'Contact Sensor State', '0000006A-0000-1000-8000-0026BB765291');
  this.setProps({
    format: Characteristic.Formats.UINT8,
    perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
  });
  this.value = this.getDefaultValue();
};

inherits(Characteristic.ContactSensorState, Characteristic);

Characteristic.ContactSensorState.UUID = '0000006A-0000-1000-8000-0026BB765291';

// The value property of ContactSensorState must be one of the following:
Characteristic.ContactSensorState.CONTACT_DETECTED = 0;
Characteristic.ContactSensorState.CONTACT_NOT_DETECTED = 1;

Derived from this:

service = ContactSensor
characteristic = ContactSensorState
format = UINT8
property = 0 or 1