diff --git a/ChannelServices/HomeKitGenericService.js b/ChannelServices/HomeKitGenericService.js index 7b0b4f3..0bd9c33 100644 --- a/ChannelServices/HomeKitGenericService.js +++ b/ChannelServices/HomeKitGenericService.js @@ -34,8 +34,6 @@ class HomeKitGenericService { this.serial = parts[2] this.channelnumber = parts[3] this.deviceaddress = this.intf + '.' + this.serial - } else { - this.log.warn('Unable to parse device address %s so nothing will work for %s', address, name) } this.platform = platform @@ -644,11 +642,10 @@ class HomeKitGenericService { this.log.debug('[Generic] datapoint %s', tp.dpName) this.log.debug('[Generic] remoteGetValue Intf:%s, Adre:%s, ChI:%s, Dp:%s', tp.intf, tp.serial, tp.channelId, tp.dpName) - if (tp.intf === 'Var') { + if (tp.intf === 'Variable') { // This is a variable so get the value - let script = "WriteLine(dom.GetObject(ID_SYSTEM_VARIABLES).Get('" + tp.serial + "').State());" - this.command('sendregacommand', '', script, function (result) { - // do not cache this + this.log.debug('[Generic] its a variable %s', tp.serial) + this.ccuManager.getVariable(tp.serial, function (result) { if (callback) { self.log.debug('[Generic] run callback on variable %s with %s', tp.serial, result) callback(result) @@ -1008,7 +1005,11 @@ class HomeKitGenericService { let chidx = parts[1] let dpn = parts[2] this.log.debug('[Generic] match C.D Format |I:%s|A:%s|C:%s|D:%s', this.intf, this.serial, chidx, dpn) - return new HomeMaticAddress(this.intf, this.serial, chidx, dpn) + if (this.intf === 'Variable') { + return new HomeMaticAddress(this.intf, this.address, chidx, dpn) + } else { + return new HomeMaticAddress(this.intf, this.serial, chidx, dpn) + } } } } else { diff --git a/ChannelServices/HomeMaticHomeKitVariableService.js b/ChannelServices/HomeMaticHomeKitVariableService.js index 72bdb20..cf72479 100644 --- a/ChannelServices/HomeMaticHomeKitVariableService.js +++ b/ChannelServices/HomeMaticHomeKitVariableService.js @@ -14,7 +14,8 @@ class HomeMaticHomeKitVariableService extends HomeKitGenericService { .on('get', function (callback) { self.remoteGetValue('1.STATE', function (value) { - if (callback) callback(null, value) + self.log.debug('VAR result is %s', value) + if (callback) callback(null, self.isTrue(value)) }) }) diff --git a/ChannelServices/HomeMaticHomeKitWeatherStationServiceIP.js b/ChannelServices/HomeMaticHomeKitWeatherStationServiceIP.js index 976bed7..e55f79f 100644 --- a/ChannelServices/HomeMaticHomeKitWeatherStationServiceIP.js +++ b/ChannelServices/HomeMaticHomeKitWeatherStationServiceIP.js @@ -1,133 +1,12 @@ 'use strict' const HomeKitGenericService = require('./HomeKitGenericService.js').HomeKitGenericService -const util = require('util') +const WeatherStationTypes = require('./WeatherStationTypes.js') +let weatherTypes class HomeMaticHomeKitWeatherStationServiceIP extends HomeKitGenericService { propagateServices (homebridge, Service, Characteristic) { - var uuid = homebridge.homebridge.hap.uuid - Characteristic.IsRainingCharacteristic = function () { - var charUUID = uuid.generate('HomeMatic:customchar:IsRainingCharacteristic') - Characteristic.call(this, 'Regen', charUUID) - this.setProps({ - format: Characteristic.Formats.BOOL, - perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY] - }) - this.value = this.getDefaultValue() - } - util.inherits(Characteristic.IsRainingCharacteristic, Characteristic) - - Service.IsRainingService = function (displayName, subtype) { - var servUUID = uuid.generate('HomeMatic:customchar:IsRainingService') - Service.call(this, displayName, servUUID, subtype) - this.addCharacteristic(Characteristic.IsRainingCharacteristic) - } - - util.inherits(Service.IsRainingService, Service) - - Characteristic.RainCountCharacteristic = function () { - var charUUID = uuid.generate('HomeMatic:customchar:RainCountCharacteristic') - Characteristic.call(this, 'Regenmenge', charUUID) - this.setProps({ - format: Characteristic.Formats.FLOAT, - unit: 'mm', - minStep: 0.1, - perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY] - }) - this.value = this.getDefaultValue() - } - util.inherits(Characteristic.RainCountCharacteristic, Characteristic) - - Service.RainCountService = function (displayName, subtype) { - var servUUID = uuid.generate('HomeMatic:customchar:RainCountService') - Service.call(this, displayName, servUUID, subtype) - this.addCharacteristic(Characteristic.RainCountCharacteristic) - } - - util.inherits(Service.RainCountService, Service) - - Characteristic.WindSpeedCharacteristic = function () { - var charUUID = uuid.generate('HomeMatic:customchar:WindSpeedCharacteristic') - Characteristic.call(this, 'Wind Geschwindigkeit', charUUID) - this.setProps({ - format: Characteristic.Formats.FLOAT, - unit: 'km/h', - minStep: 0.1, - perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY] - }) - this.value = this.getDefaultValue() - } - util.inherits(Characteristic.WindSpeedCharacteristic, Characteristic) - - Service.WindSpeedService = function (displayName, subtype) { - var servUUID = uuid.generate('HomeMatic:customchar:WindSpeedService') - Service.call(this, displayName, servUUID, subtype) - this.addCharacteristic(Characteristic.WindSpeedCharacteristic) - } - - util.inherits(Service.WindSpeedService, Service) - - Characteristic.WindDirectionCharacteristic = function () { - var charUUID = uuid.generate('HomeMatic:customchar:WindDirectionCharacteristic') - Characteristic.call(this, 'Wind Richtung', charUUID) - this.setProps({ - format: Characteristic.Formats.INTEGER, - unit: 'Grad', - perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY] - }) - this.value = this.getDefaultValue() - } - util.inherits(Characteristic.WindDirectionCharacteristic, Characteristic) - - Service.WindDirectionService = function (displayName, subtype) { - var servUUID = uuid.generate('HomeMatic:customchar:WindDirectionService') - Service.call(this, displayName, servUUID, subtype) - this.addCharacteristic(Characteristic.WindDirectionCharacteristic) - } - - util.inherits(Service.WindDirectionService, Service) - - Characteristic.WindRangeCharacteristic = function () { - var charUUID = uuid.generate('HomeMatic:customchar:WindRangeCharacteristic') - Characteristic.call(this, 'Wind Schwankungsbreite', charUUID) - this.setProps({ - format: Characteristic.Formats.INTEGER, - unit: 'Grad', - perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY] - }) - this.value = this.getDefaultValue() - } - util.inherits(Characteristic.WindRangeCharacteristic, Characteristic) - - this.log.debug('[WSIP] generate WindRangeService') - Service.WindRangeService = function (displayName, subtype) { - var servUUID = uuid.generate('HomeMatic:customchar:WindRangeService') - Service.call(this, displayName, servUUID, subtype) - this.addCharacteristic(Characteristic.WindRangeCharacteristic) - } - - util.inherits(Service.WindRangeService, Service) - - Characteristic.SunshineCharacteristic = function () { - var charUUID = uuid.generate('HomeMatic:customchar:SunshineCharacteristic') - Characteristic.call(this, 'Sonnenscheindauer', charUUID) - this.setProps({ - format: Characteristic.Formats.FLOAT, - unit: 'Minuten', - perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY] - }) - this.value = this.getDefaultValue() - } - util.inherits(Characteristic.SunshineCharacteristic, Characteristic) - - this.log.debug('[WSIP] generate SunshineService') - Service.SunshineService = function (displayName, subtype) { - var servUUID = uuid.generate('HomeMatic:customchar:SunshineService') - Service.call(this, displayName, servUUID, subtype) - this.addCharacteristic(Characteristic.SunshineCharacteristic) - } - - util.inherits(Service.SunshineService, Service) + weatherTypes = new WeatherStationTypes(homebridge) } createDeviceService (Service, Characteristic) { @@ -174,21 +53,19 @@ class HomeMaticHomeKitWeatherStationServiceIP extends HomeKitGenericService { this.currentBrightnessCharacteristic.eventEnabled = true - var sunshineduration = this.getService(Service.SunshineService) - - this.characteristicSunshine = sunshineduration.getCharacteristic(Characteristic.SunshineCharacteristic) + let sunshine = this.getService(weatherTypes.Service.SunshineWeatherService) + this.characteristicSunshine = sunshine.getCharacteristic(weatherTypes.Characteristic.SunshineCharacteristic) .on('get', function (callback) { this.query('SUNSHINEDURATION', function (value) { if (callback) callback(null, value) }) }.bind(this)) - this.characteristicSunshine.eventEnabled = true if (this.deviceType === 'HmIP-SWO-B') { - var windspeed = this.getService(Service.WindSpeedService) + var windspeed = this.getService(weatherTypes.Service.WindSpeedWeatherService) - this.characteristicWindSpeed = windspeed.getCharacteristic(Characteristic.WindSpeedCharacteristic) + this.characteristicWindSpeed = windspeed.getCharacteristic(weatherTypes.Characteristic.WindSpeedCharacteristic) .on('get', function (callback) { this.query('WIND_SPEED', function (value) { if (callback) callback(null, value) @@ -200,9 +77,9 @@ class HomeMaticHomeKitWeatherStationServiceIP extends HomeKitGenericService { // HmIP-SWO-PL - HmIP-SWO-B + RainSensor RainCountService if ((this.deviceType === 'HmIP-SWO-PL') || (this.deviceType === 'HmIP-SWO-PR')) { - var raining = this.getService(Service.IsRainingService) + var rainService = this.getService(weatherTypes.Service.RainService) - this.characteristicIsRaining = raining.getCharacteristic(Characteristic.IsRainingCharacteristic) + this.characteristicIsRaining = rainService.getCharacteristic(weatherTypes.Characteristic.IsRainingCharacteristic) .on('get', function (callback) { self.query('RAINING', function (value) { if (callback) callback(null, value) @@ -211,9 +88,7 @@ class HomeMaticHomeKitWeatherStationServiceIP extends HomeKitGenericService { this.characteristicIsRaining.eventEnabled = true - var raincount = this.getService(Service.RainCountService) - - this.characteristicRainCount = raincount.getCharacteristic(Characteristic.RainCountCharacteristic) + this.characteristicRainCount = rainService.getCharacteristic(weatherTypes.Characteristic.RainCountCharacteristic) .on('get', function (callback) { this.query('RAIN_COUNTER', function (value) { if (callback) callback(null, value) @@ -225,9 +100,9 @@ class HomeMaticHomeKitWeatherStationServiceIP extends HomeKitGenericService { // HmIP-SWO-PR - HmIP-SWO-PL + WindDirectionService + WindRangeService if (this.deviceType === 'HmIP-SWO-PR') { - var winddirection = this.getService(Service.WindDirectionService) + var windService = this.getService(weatherTypes.Service.WindService) - this.characteristicWindDirection = winddirection.getCharacteristic(Characteristic.WindDirectionCharacteristic) + this.characteristicWindDirection = windService.getCharacteristic(Characteristic.WindDirectionCharacteristic) .on('get', function (callback) { this.query('WIND_DIR', function (value) { if (callback) callback(null, value) @@ -236,9 +111,7 @@ class HomeMaticHomeKitWeatherStationServiceIP extends HomeKitGenericService { this.characteristicWindDirection.eventEnabled = true - var windrange = this.getService(Service.WindRangeService) - - this.characteristicWindRange = windrange.getCharacteristic(Characteristic.WindRangeCharacteristic) + this.characteristicWindRange = windService.getCharacteristic(Characteristic.WindRangeCharacteristic) .on('get', function (callback) { this.query('WIND_DIR_RANGE', function (value) { if (callback) callback(null, value) @@ -274,15 +147,25 @@ class HomeMaticHomeKitWeatherStationServiceIP extends HomeKitGenericService { }) } + if (this.characteristicSunshine) { + this.platform.registeraddressForEventProcessingAtAccessory(this.buildHomeMaticAddress('SUNSHINEDURATION'), this, function (newValue) { + self.characteristicSunshine.updateValue(parseFloat(newValue)) + }) + } + if (this.characteristicIsRaining) { this.platform.registeraddressForEventProcessingAtAccessory(this.buildHomeMaticAddress('RAINING'), this, function (newValue) { self.characteristicRain.updateValue(self.isTrue(newValue) ? 1 : 0) }) } - this.platform.registeraddressForEventProcessingAtAccessory(this.buildHomeMaticAddress('WINDSPEED'), this, function (newValue) { - self.characteristicWindspeed.updateValue(parseFloat(newValue), null) - }) + if (this.characteristicWindspeed) { + this.platform.registeraddressForEventProcessingAtAccessory(this.buildHomeMaticAddress('WINDSPEED'), this, function (newValue) { + if (self.characteristicWindspeed) { + self.characteristicWindspeed.updateValue(parseFloat(newValue), null) + } + }) + } if (this.characteristicWindDirection) { this.platform.registeraddressForEventProcessingAtAccessory(this.buildHomeMaticAddress('WIND_DIR'), this, function (newValue) { diff --git a/ChannelServices/WeatherStationTypes.js b/ChannelServices/WeatherStationTypes.js new file mode 100644 index 0000000..c6a29e5 --- /dev/null +++ b/ChannelServices/WeatherStationTypes.js @@ -0,0 +1,68 @@ +'use strict' + +const CustomHomeKitTypes = require('./CustomHomeKitTypes.js') + +let hap + +module.exports = class WeatherStationTypes extends CustomHomeKitTypes { + constructor (homebridge) { + super(homebridge) + hap = homebridge.homebridge.hap + var uuid = hap.uuid + + this.createCharacteristic('IsRainingCharacteristic', uuid.generate('HomeMatic:customchar:IsRainingCharacteristic'), { + format: hap.Characteristic.Formats.BOOL, + perms: [hap.Characteristic.Perms.READ, hap.Characteristic.Perms.NOTIFY] + }, 'is Raining') + + this.createCharacteristic('RainCountCharacteristic', uuid.generate('HomeMatic:customchar:RainCountCharacteristic'), { + format: hap.Characteristic.Formats.FLOAT, + unit: 'mm', + minStep: 0.1, + perms: [hap.Characteristic.Perms.READ, hap.Characteristic.Perms.NOTIFY] + }, 'Rain Count') + + this.createCharacteristic('WindSpeedCharacteristic', uuid.generate('HomeMatic:customchar:WindSpeedCharacteristic'), { + format: hap.Characteristic.Formats.FLOAT, + unit: 'km/h', + minStep: 0.1, + perms: [hap.Characteristic.Perms.READ, hap.Characteristic.Perms.NOTIFY] + }, 'Wind speed') + + this.createCharacteristic('WindDirectionCharacteristic', uuid.generate('HomeMatic:customchar:WindDirectionCharacteristic'), { + format: hap.Characteristic.Formats.INTEGER, + unit: 'degree', + perms: [hap.Characteristic.Perms.READ, hap.Characteristic.Perms.NOTIFY] + }, 'Wind direction') + + this.createCharacteristic('WindRangeCharacteristic', uuid.generate('HomeMatic:customchar:WindRangeCharacteristic'), { + format: hap.Characteristic.Formats.INTEGER, + unit: 'degree', + perms: [hap.Characteristic.Perms.READ, hap.Characteristic.Perms.NOTIFY] + }, 'Wind range') + + this.createCharacteristic('SunshineCharacteristic', uuid.generate('HomeMatic:customchar:SunshineCharacteristic'), { + format: hap.Characteristic.Formats.FLOAT, + unit: 'minutes', + perms: [hap.Characteristic.Perms.READ, hap.Characteristic.Perms.NOTIFY] + }, 'Sunshine') + + this.createService('SunshineWeatherService', uuid.generate('HomeMatic:customchar:SimpleSunshineWeatherServiceWeatherService'), [ + this.Characteristic.SunshineCharacteristic + ]) + + this.createService('WindSpeedWeatherService', uuid.generate('HomeMatic:customchar:WindSpeedWeatherService'), [ + this.Characteristic.WindSpeedCharacteristic + ]) + + this.createService('RainService', uuid.generate('HomeMatic:customchar:RainService'), [ + this.Characteristic.IsRainingCharacteristic, + this.Characteristic.RainCountCharacteristic + ]) + + this.createService('WindService', uuid.generate('HomeMatic:customchar:WindService'), [ + this.Characteristic.WindDirectionCharacteristic, + this.Characteristic.WindRangeCharacteristic + ]) + } +} diff --git a/HomeMaticCCU.js b/HomeMaticCCU.js index 4a271cb..6ded39a 100644 --- a/HomeMaticCCU.js +++ b/HomeMaticCCU.js @@ -95,6 +95,11 @@ class HomeMaticCCU { rega.setVariable(varName, varValue, callback) } + getVariable (varName, callback) { + let rega = this.createRegaRequest() + rega.getVariable(varName, callback) + } + runScript (script, callback) { let rega = this.createRegaRequest() rega.script(script, callback) diff --git a/PluginConfigurationService/index.js b/PluginConfigurationService/index.js index 5f72fff..b23c238 100644 --- a/PluginConfigurationService/index.js +++ b/PluginConfigurationService/index.js @@ -35,7 +35,9 @@ class PluginConfigurationService { } shutdown () { - this.server.close() + if (this.server) { + this.server.close() + } } prepareAccessories (serverList) { diff --git a/package.json b/package.json index 6f4471c..d27fac3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homebridge-homematic", - "version": "0.1.224", + "version": "0.1.229", "description": "Homematic plugin for homebridge: https://github.com/nfarina/homebridge", "license": "ISC", "keywords": [