# chains-amqp

> This package is an abstract class for Chains NodeJS-devices.

Latest version **1.0.2** (published 2014-08-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install chains-amqp
pnpm add chains-amqp
yarn add chains-amqp
bun add chains-amqp
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2014-08-28 |
| First published | 2014-08-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ole-Kenneth Rangnes |
| Maintainers | olekenneth |
| Keywords | chains, homeautomation, home, automation, rabbitmq, amqp, advanced, message, queing |

## Links

- npm: https://www.npmjs.com/package/chains-amqp
- Repository: https://github.com/olekenneth/chains-amqp
- Issues: https://github.com/olekenneth/chains-amqp/issues
- npm.io page: https://npm.io/package/chains-amqp

## Dependencies (2)

- [amqp](https://npm.io/package/amqp.md) 0.2.0
- [lodash](https://npm.io/package/lodash.md) *

## Recent versions

- 1.0.2 (latest) — 2014-08-28
- 1.0.1 — 2014-08-22
- 1.0.0 — 2014-08-05

## README

Chains AMQP
===========

## SUMMARY

This package is an abstract class for Chains NodeJS-devices. It requires `node-amqp`. The class connects to RabbitMQ and emits events based on actions being trigged in Chains. It also handles heart beats.

## INSTALLING

    npm install chains-amqp

Or put this in your `package.json`

```javascript
"dependencies": {
    "chains-amqp": "*"
}
```

## USAGE

If you are going to create a new Chains-device. You can do it like this:

### Example one

```javascript
var amqp = require('chains-amqp').connect({deviceName: 'xcomfort'});

amqp.on('on', function(deviceId, actionId) {
    var light = lights.findWhere({serial: deviceId});
    
    if (light) {
        light.set('isOn', true);
    
        amqp.sendResponse('on', actionId);
    }
});
```
### Example two

```javascript
var amqp = require('chains-amqp').connect({deviceName: 'xcomfort'});

amqp.on('describe', function(deviceId, actionId) {
    var events = [
        [ 'xcomfort-on', {
            'key': ['str', null, 'Event trigger'],
            'value': ['int', null, 'Light ID']
            }, 'Action to turn on a single device. Needs value to be a ID of a device']
        ];
    
    var actions = [
        [ 'action_on', {
            'key': ['str', null, 'device Id'],
            'value': ['int', null, 'Light ID']
            }, 'Action to turn on a single device. Needs value to be a ID of a device'],

        [ 'action_off', {
            'key': ['str', null, 'device Id'],
            'value': ['int', null, 'Light ID']
            }, 'Action to turn on a single device. Needs value to be a ID of a device']
    ];
    
    amqp.sendResponse('describe', actionId, {
        'info': 'Controll XComfort-devices. Lights etc',
        'actions': actions,
        'events': events
    });
});
```

## LICENSE

MIT, see the LICENSE file

---
_Source: https://npm.io/package/chains-amqp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
