Example #1
0
EvohomePlatform.prototype.periodicUpdate = function(session,myAccessories) {

    if(!this.updating && this.myAccessories){
        this.updating = true;
        
        evohome.login(this.username, this.password, this.appId).then(function(session) {
        
            session.getLocations().then(function(locations){
                                    
                for(var i=0; i<this.myAccessories.length; ++i) {
                    var device = locations[0].devices[this.myAccessories[i].deviceId];

                    if(device) {
                        // Check if temp has changed
                        var oldCurrentTemp = this.myAccessories[i].device.thermostat.indoorTemperature;
                        var newCurrentTemp = device.thermostat.indoorTemperature;
                                        
                        var service = this.myAccessories[i].thermostatService;
                                        
                        if(oldCurrentTemp!=newCurrentTemp && service) {
                            this.log("Updating: " + device.name + " currentTempChange from: " + oldCurrentTemp + "to: " + newCurrentTemp);
                            var charCT = service.getCharacteristic(Characteristic.CurrentTemperature);
                            if(charCT) charCT.setValue(newCurrentTemp);
                            else this.log("No Characteristic.CurrentTemperature found " + service);
                        }
                                        
                        var oldTargetTemp = this.myAccessories[i].device.thermostat.changeableValues.heatSetpoint['value'];     
                        var newTargetTemp = device.thermostat.changeableValues.heatSetpoint['value'];
                                        
                        if(oldTargetTemp!=newTargetTemp && service) {
                            this.log("Updating: " + device.name + " targetTempChange from: " + oldTargetTemp + "to: " + newTargetTemp);
                            var charTT = service.getCharacteristic(Characteristic.TargetTemperature);
                            if(charTT) charCT.setValue(newTargetTemp);
                            else this.log("No Characteristic.TargetTemperature found " + service);
                        }
                        
                        this.myAccessories[i].device = device;
                    }
                }
            }.bind(this)).fail(function(err){
                this.log('Evohome Failed:', err);
            });
        }.bind(this)).fail(function(err){
            this.log('Evohome Failed:', err);
        });
        
        this.updating = false;
    }
}
Example #2
0
	accessories: function(callback) {
		this.log("Logging into Evohome...");

		var that = this;
		// create the myAccessories array
		this.myAccessories = [];

		evohome.login(that.username, that.password, that.appId).then(function(session) {
			this.log("Logged into Evohome!");

			session.getLocations().then(function(locations){
				this.log('You have', locations.length, 'location(s). Only the first one will be used!');
				this.log('You have', locations[0].devices.length, 'device(s).')

				// iterate through the devices
				for (var deviceId in locations[0].devices) {
					// print name of the device
					this.log(deviceId + ": " + locations[0].devices[deviceId].name + " (" + locations[0].devices[deviceId].thermostat.indoorTemperature + "°)");
					
					// store device in var
					var device = locations[0].devices[deviceId];
					// store name of device
					var name = locations[0].devices[deviceId].name + " Thermostat";
					// create accessory
					var accessory = new EvohomeThermostatAccessory(that.log, name, device, deviceId);
					// store accessory in myAccessories
					this.myAccessories.push(accessory);
				}

				callback(this.myAccessories);
                                        
                setInterval(that.periodicUpdate.bind(this), this.cache_timeout * 1000);

			}.bind(this)).fail(function(err){
				that.log('Evohome Failed:', err);
			});


		}.bind(this)).fail(function(err) {
			// tell me if login did not work!
			that.log("Error during Login:", err);
		});
	}