Skip to content

Commit

Permalink
Fix support for SIREN1
Browse files Browse the repository at this point in the history
  • Loading branch information
ptz0n committed Jan 25, 2017
1 parent 6bc2c92 commit a92dee2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
This is a plugin for [homebridge](https://github.com/nfarina/homebridge). It's a
working implementation for several Verisure devices:

- [x] __VOICEBOX1__ - Temperature
- [x] __SMOKE2__ - Temperature
- [x] __SIREN1__ - Temperature
- [x] __SMARTPLUG__ - State, on, off
- [x] __SMOKE2__ - Temperature
- [x] __VOICEBOX1__ - Temperature

## Installation

Expand Down
34 changes: 26 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ const PLATFORM_NAME = 'verisure';
const MANUFACTURER = 'Verisure';

const DEVICE_TYPES = {
'VOICEBOX1': 'Directenhet',
'SIREN1': 'Siren',
'SMARTPLUG': 'Smart plug',
'SMOKE2': 'Rökdetektor',
'SMARTPLUG': 'Smart plug'
'VOICEBOX1': 'Directenhet'
}

let VERISURE_TOKEN = null;
let VERISURE_INSTALLATION = null;
let VERISURE_CALLS = {};
let VERISURE_DEVICE_NAMES = []


const getVerisureInstallation = function(config, callback) {
Expand Down Expand Up @@ -47,6 +49,17 @@ const getOverview = function(callback) {
});
}

const getUniqueName = function(name) {
if(VERISURE_DEVICE_NAMES.includes(name)) {
const match = name.match(/(.+) #(\d+)/) || [null, name, 1]
return getUniqueName(`${match[1]} #${parseInt(match[2])+1}`);
}
else {
VERISURE_DEVICE_NAMES.push(name)
return name;
}
}


module.exports = function(homebridge) {
Accessory = homebridge.platformAccessory;
Expand All @@ -66,13 +79,14 @@ const VerisurePlatform = function(log, config, api) {

this.accessories = function(callback) {
getVerisureInstallation(config, function(err) {
if(err) return log(err);
if(err) return log.error(err);

verisure.overview(VERISURE_TOKEN, VERISURE_INSTALLATION, function(err, overview) {
if(err) return log(err);
if(err) return log.error(err);
var devices = overview.climateValues.map(function(device) {
const deviceName = DEVICE_TYPES[device.deviceType] || device.deviceType
return new VerisureAccessory(log, {
name: `${DEVICE_TYPES[device.deviceType] || device.deviceType} (${device.deviceArea})`,
name: getUniqueName(`${deviceName} (${device.deviceArea})`),
model: device.deviceType,
serialNumber: device.deviceLabel,
value: 0
Expand All @@ -81,7 +95,7 @@ const VerisurePlatform = function(log, config, api) {

devices = devices.concat(overview.smartPlugs.map(function(device) {
return new VerisureAccessory(log, {
name: `${DEVICE_TYPES.SMARTPLUG} (${device.area})`,
name: getUniqueName(`${DEVICE_TYPES.SMARTPLUG} (${device.area})`),
model: 'SMARTPLUG',
serialNumber: device.deviceLabel,
value: device.currentState == 'ON' ? 1 : 0
Expand Down Expand Up @@ -164,7 +178,7 @@ VerisureAccessory.prototype = {

var service = null;

if(this.model == 'SMARTPLUG') {
if(['SMARTPLUG'].includes(this.model)) {
service = new Service.Switch(this.name);
service
.getCharacteristic(Characteristic.On)
Expand All @@ -173,13 +187,17 @@ VerisureAccessory.prototype = {
.value = this.value;
}

if(['VOICEBOX1', 'SMOKE2'].includes(this.model)) {
if(['SIREN1', 'SMOKE2', 'VOICEBOX1'].includes(this.model)) {
service = new Service.TemperatureSensor(this.name);
service
.getCharacteristic(Characteristic.CurrentTemperature)
.on('get', this._getCurrentTemperature.bind(this));
}

if(!service) {
this.log.error(`Device ${this.model} is not yet supported`);
}

return [accessoryInformation, service]
}
}

0 comments on commit a92dee2

Please sign in to comment.