Skip to content

Commit

Permalink
fix potential memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnowack committed Nov 18, 2016
1 parent b6de927 commit 59f2d6f
Showing 1 changed file with 35 additions and 34 deletions.
69 changes: 35 additions & 34 deletions src/thermostat.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,40 @@ export default function createThermostat({ Service, Characteristic }) {
this.temperatureDisplayUnits = Characteristic.TemperatureDisplayUnits.CELSIUS

this.thermostatService = new Service.Thermostat(this.name)
this.informationService = new Service.AccessoryInformation()

this.informationService
.setCharacteristic(Characteristic.Manufacturer, 'eq-3')
.setCharacteristic(Characteristic.Model, 'CC-RT-BLE')

this.thermostatService
.getCharacteristic(Characteristic.CurrentHeatingCoolingState)
.on('get', this.execAfterConnect.bind(this, this.getCurrentHeatingCoolingState.bind(this)))

this.thermostatService
.getCharacteristic(Characteristic.TargetHeatingCoolingState)
.on('get', this.execAfterConnect.bind(this, this.getTargetHeatingCoolingState.bind(this)))
.on('set', this.execAfterConnect.bind(this, this.setTargetHeatingCoolingState.bind(this)))

this.thermostatService
.getCharacteristic(Characteristic.CurrentTemperature)
.on('get', this.execAfterConnect.bind(this, this.getTargetTemperature.bind(this)))

this.thermostatService
.getCharacteristic(Characteristic.TargetTemperature)
.on('get', this.execAfterConnect.bind(this, this.getTargetTemperature.bind(this)))
.on('set', this.execAfterConnect.bind(this, this.setTargetTemperature.bind(this)))

this.thermostatService
.getCharacteristic(Characteristic.TemperatureDisplayUnits)
.on('get', this.execAfterConnect.bind(this, this.getTemperatureDisplayUnits.bind(this)))
.on('set', this.execAfterConnect.bind(this, this.setTemperatureDisplayUnits.bind(this)))

this.thermostatService
.getCharacteristic(Characteristic.HeatingThresholdTemperature)
.on('get', this.execAfterConnect.bind(this, this.getTargetTemperature.bind(this)))


this.discovered = this.discover()
this.discovered.catch((err) => { throw err })
}
Expand Down Expand Up @@ -173,40 +207,7 @@ export default function createThermostat({ Service, Characteristic }) {
}

getServices() {
const informationService = new Service.AccessoryInformation()

informationService
.setCharacteristic(Characteristic.Manufacturer, 'eq-3')
.setCharacteristic(Characteristic.Model, 'CC-RT-BLE')

this.thermostatService
.getCharacteristic(Characteristic.CurrentHeatingCoolingState)
.on('get', this.execAfterConnect.bind(this, this.getCurrentHeatingCoolingState.bind(this)))

this.thermostatService
.getCharacteristic(Characteristic.TargetHeatingCoolingState)
.on('get', this.execAfterConnect.bind(this, this.getTargetHeatingCoolingState.bind(this)))
.on('set', this.execAfterConnect.bind(this, this.setTargetHeatingCoolingState.bind(this)))

this.thermostatService
.getCharacteristic(Characteristic.CurrentTemperature)
.on('get', this.execAfterConnect.bind(this, this.getTargetTemperature.bind(this)))

this.thermostatService
.getCharacteristic(Characteristic.TargetTemperature)
.on('get', this.execAfterConnect.bind(this, this.getTargetTemperature.bind(this)))
.on('set', this.execAfterConnect.bind(this, this.setTargetTemperature.bind(this)))

this.thermostatService
.getCharacteristic(Characteristic.TemperatureDisplayUnits)
.on('get', this.execAfterConnect.bind(this, this.getTemperatureDisplayUnits.bind(this)))
.on('set', this.execAfterConnect.bind(this, this.setTemperatureDisplayUnits.bind(this)))

this.thermostatService
.getCharacteristic(Characteristic.HeatingThresholdTemperature)
.on('get', this.execAfterConnect.bind(this, this.getTargetTemperature.bind(this)))

return [informationService, this.thermostatService]
return [this.informationService, this.thermostatService]
}
}
}

0 comments on commit 59f2d6f

Please sign in to comment.