homebridge-gpio-electic-rim-lock 1.0.3 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ name: Publish to NPM
2
+
3
+ on:
4
+ workflow_dispatch:
5
+
6
+ jobs:
7
+ build:
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - name: Checkout
12
+ uses: actions/checkout@v2
13
+
14
+ - name: Setup Node
15
+ uses: actions/setup-node@v2
16
+ with:
17
+ node-version: '18'
18
+ registry-url: 'https://registry.npmjs.org'
19
+
20
+ - name: Install dependencies
21
+ run: npm install --ignore-scripts
22
+
23
+ - name: Publish package
24
+ run: npm publish
25
+ env:
26
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/README.md CHANGED
@@ -1,51 +1,53 @@
1
1
  # homebridge-gpio-electic-rim-lock
2
- Homebridge plugin to open electric rim locks via Raspberry Pi GPIO pins
2
+ Homebridge plugin to open electric rim locks via Raspberry Pi GPIO pins.
3
3
 
4
- # Circuit
4
+ ## Circuit
5
5
 
6
6
  This plugin assumes that you are using a Raspberry Pi to directly control your electric rim locks. Electric rim locks usually have a switch on the wall that you can push to open the door. On my model, this is just a very simple switch that completes a 12vac circuit. The button must be pressed for about a second before the door will open. In order for this to be an effective electric rim locks opener, you need a relay that will perform the duty of the button.
7
7
 
8
- ![Schematic](https://github.com/roberto-montanari/homebridge-gpio-electic-rim-lock/blob/master/images/circuit.png?raw=true)
8
+ ![Schematic](https://github.com/roberto-montanari/homebridge-gpio-electic-rim-lock/blob/master/images/schematic.png?raw=true)
9
9
 
10
- # Installation
10
+ ## Installation
11
11
 
12
- Install this plugin using:
12
+ ### Via Homebridge UI (Recommended)
13
+
14
+ 1. Open the Homebridge UI
15
+ 2. Navigate to Plugins
16
+ 3. Search for "homebridge-gpio-electic-rim-lock"
17
+ 4. Click Install
18
+
19
+ ### Via npm
13
20
  ```
14
- sudo npm install -g --unsafe-perm homebridge-gpio-electic-rim-lock
21
+ sudo npm install -g homebridge-gpio-electic-rim-lock --unsafe-perm
15
22
  ```
23
+ Restart Homebridge after installing.
16
24
 
25
+ ## Configuration
17
26
 
18
- # Configuration
27
+ ### Via Homebridge UI
19
28
 
20
- You will need to add the following accessory configuration to the Homebridge [config.json](https://github.com/nfarina/homebridge/blob/master/config-sample.json)
29
+ The plugin provides a full configuration UI. Navigate to Plugins → Settings for Homebridge Gpio Electic Rim Lock.
21
30
 
22
- Configuration sample:
31
+ ### Manual Configuration
23
32
 
33
+ Add the following accessory configuration to the Homebridge [config.json](https://github.com/nfarina/homebridge/blob/master/config-sample.json):
24
34
  ```JSON
25
- {
26
- "bridge": {
27
- "name": "Raspberry Pi 2",
28
- "username": "CC:22:3D:E3:CE:32",
29
- "port": 51826,
30
- "pin": "031-45-154"
31
- },
32
35
 
36
+ {
33
37
  "accessories": [
34
38
  {
35
- "accessory": "Tiro",
36
- "name": "Door",
37
- "pin": 12,
38
- "duration": 4000
39
+ "accessory": "Tiro",
40
+ "name": "Door",
41
+ "pin": 12,
42
+ "duration": 500
39
43
  }
40
- ],
41
-
42
- "platforms": []
44
+ ]
43
45
  }
44
46
 
45
47
  ```
46
48
 
47
49
  Fields:
48
50
 
49
- * name - Can be anything (required)
50
- * pin - The physical GPIO pin number that controls the relay (required)
51
- * duratin - Number of milliseconds to trigger the relay. Defaults to 1000 millseconds (1 second) if not specified
51
+ * name - The door name visible in HomeKit, can be anything (required).
52
+ * pin - The physical GPIO pin number that controls the relay (required).
53
+ * duratin - Number of milliseconds to trigger the relay. Defaults to 500 millseconds (0,5 second) if not specified.
@@ -0,0 +1,44 @@
1
+ {
2
+ "pluginAlias": "Tiro",config.schema.json
3
+ "pluginType": "accessory",
4
+ "singular": false,
5
+
6
+ "headerDisplay": "Homebridge plugin to open electric rim locks via Raspberry Pi GPIO pins.",
7
+ "footerDisplay": "For documentation, see the [plugin homepage](https://github.com/roberto-montanari/homebridge-gpio-electic-rim-lock) on GitHub.",
8
+
9
+ "schema": {
10
+ "type": "object",
11
+ "required": [
12
+ "name",
13
+ "pin",
14
+ "duration"
15
+ ],
16
+ "properties": {
17
+
18
+ "name": {
19
+ "title": "Door name",
20
+ "type": "string",
21
+ "description": "Door name visible in HomeKit",
22
+ "minLength": 1
23
+ },
24
+
25
+ "pin": {
26
+ "title": "GPIO pin number",
27
+ "type": "integer",
28
+ "description": "The physical GPIO pin number that controls the relay",
29
+ "enum": [
30
+ 11, 12, 13, 15
31
+ ]
32
+ },
33
+
34
+ "duration": {
35
+ "title": "Pulse duration (ms)",
36
+ "type": "integer",
37
+ "description": "Number of milliseconds to trigger the relay",
38
+ "default": 500,
39
+ "minimum": 500,
40
+ "maximum": 2000
41
+ }
42
+ }
43
+ }
44
+ }
Binary file
package/index.js CHANGED
@@ -5,42 +5,54 @@ var rpio = require('rpio');
5
5
  module.exports = function(homebridge) {
6
6
  Service = homebridge.hap.Service;
7
7
  Characteristic = homebridge.hap.Characteristic;
8
-
9
- homebridge.registerAccessory('homebridge-gpio-electic-rim-lock', 'Tiro', ElecticRimLockAccessory);
8
+
9
+ homebridge.registerAccessory('homebridge-gpio-electic-rim-lock', 'Tiro', ElecticRimLockAccessory);
10
+ }
11
+
12
+ function getSerial(){
13
+ var fs = require('fs');
14
+ var content = fs.readFileSync('/proc/cpuinfo', 'utf8').split("\n");
15
+ var serial = content[content.length-2].split(":");
16
+ return serial[1].slice(9);
10
17
  }
11
18
 
12
19
  function ElecticRimLockAccessory(log, config) {
13
- this.log = log;
14
- this.name = config['name'];
15
- this.pin = config['pin'];
16
- this.duration = config['duration'];
20
+ this.log = log;
21
+ this.name = config['name'];
22
+ this.pin = config['pin'];
23
+ this.duration = config['duration'];
24
+ this.version = require('./package.json').version;
17
25
  this.lastLockTargetState = 1;
18
26
 
19
- if (!this.pin) throw new Error("You must provide a config value for pin.");
20
- if (this.duration == null || this.duration % 1 != 0) this.duration = 1000;
27
+ if (!this.pin) throw new Error("You must provide a config value for pin.");
28
+ if (this.duration == null || this.duration % 1 != 0) this.duration = 500;
29
+ this.log("Tiro GPIO version: " + this.version);
30
+ this.log("Switch pin: " + this.pin);
31
+ this.log("Active time: " + this.duration + " ms");
21
32
  }
22
33
 
23
34
  ElecticRimLockAccessory.prototype = {
24
35
 
25
36
  getServices: function() {
26
37
  let informationService = new Service.AccessoryInformation();
27
- informationService
28
- .setCharacteristic(Characteristic.Manufacturer, "Muntaner's Technology")
38
+ informationService
39
+ .setCharacteristic(Characteristic.Manufacturer, "Roberto Montanari")
29
40
  .setCharacteristic(Characteristic.Model, "Tiro GPIO")
30
- .setCharacteristic(Characteristic.SerialNumber, "000-000-0"+this.pin);
41
+ .setCharacteristic(Characteristic.SerialNumber, getSerial() + this.pin)
42
+ .setCharacteristic(Characteristic.FirmwareRevision, this.version);
31
43
 
32
44
  let lockMechanismService = new Service.LockMechanism(this.name);
33
45
  lockMechanismService
34
- .getCharacteristic(Characteristic.LockCurrentState)
35
- .on('get', this.getLockCurrentState.bind(this));
46
+ .getCharacteristic(Characteristic.LockCurrentState)
47
+ .on('get', this.getLockCurrentState.bind(this));
36
48
  lockMechanismService
37
- .getCharacteristic(Characteristic.LockTargetState)
38
- .on('get', this.getLockTargetState.bind(this))
39
- .on('set', this.setLockTargetState.bind(this));
49
+ .getCharacteristic(Characteristic.LockTargetState)
50
+ .on('get', this.getLockTargetState.bind(this))
51
+ .on('set', this.setLockTargetState.bind(this));
40
52
 
41
53
  this.informationService = informationService;
42
- this.lockMechanismService = lockMechanismService;
43
-
54
+ this.lockMechanismService = lockMechanismService;
55
+
44
56
  return [informationService, lockMechanismService];
45
57
  },
46
58
 
@@ -61,7 +73,7 @@ ElecticRimLockAccessory.prototype = {
61
73
  setLockTargetState: function(state, callback) {
62
74
  if (state == 0) {
63
75
  this.writePin(1);
64
- this.log("Wait " + this.duration + " ms");
76
+ this.log("Wait for " + this.duration + " ms");
65
77
  var self = this;
66
78
  setTimeout(function(){self.writePin(0)}, this.duration);
67
79
  this.log("Set state to open");
@@ -69,15 +81,15 @@ ElecticRimLockAccessory.prototype = {
69
81
  callback(null);
70
82
  } else {
71
83
  this.writePin(0);
72
- this.log("Set state to close");
84
+ this.log("Set state to closed");
73
85
  this.lastLockTargetState = 1;
74
86
  callback(null);
75
87
  }
76
88
  },
77
89
 
78
- writePin: function(val) {
79
- this.log("Turning " + (val == 0 ? "off" : "on") + " pin #" + this.pin);
80
- rpio.open(this.pin, rpio.OUTPUT);
81
- rpio.write(this.pin, val == 0 ? rpio.LOW : rpio.HIGH);
90
+ writePin: function(val) {
91
+ this.log("Turning " + (val == 0 ? "off" : "on") + " pin " + this.pin);
92
+ rpio.open(this.pin, rpio.OUTPUT);
93
+ rpio.write(this.pin, val);
82
94
  }
83
95
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-gpio-electic-rim-lock",
3
- "version": "1.0.3",
3
+ "version": "2.0.1",
4
4
  "description": "Homebridge plugin to open electric rim locks via Raspberry Pi GPIO pins",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -23,7 +23,7 @@
23
23
  "homepage": "https://github.com/roberto-montanari/homebridge-gpio-electic-rim-lock#readme",
24
24
  "engines": {
25
25
  "node": ">=0.12.0",
26
- "homebridge": ">=0.2.0"
26
+ "homebridge": ">=0.2.0 || ^2.0.0"
27
27
  },
28
28
  "dependencies": {
29
29
  "rpio": ">=0.9.12"
Binary file