Skip to content

Commit

Permalink
fixes for weather station and variables
Browse files Browse the repository at this point in the history
  • Loading branch information
thkl committed Apr 19, 2020
1 parent 7f923db commit e1f872d
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 153 deletions.
15 changes: 8 additions & 7 deletions ChannelServices/HomeKitGenericService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion ChannelServices/HomeMaticHomeKitVariableService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
})

Expand Down
169 changes: 26 additions & 143 deletions ChannelServices/HomeMaticHomeKitWeatherStationServiceIP.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
68 changes: 68 additions & 0 deletions ChannelServices/WeatherStationTypes.js
Original file line number Diff line number Diff line change
@@ -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
])
}
}
5 changes: 5 additions & 0 deletions HomeMaticCCU.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion PluginConfigurationService/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class PluginConfigurationService {
}

shutdown () {
this.server.close()
if (this.server) {
this.server.close()
}
}

prepareAccessories (serverList) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down

0 comments on commit e1f872d

Please sign in to comment.