diff --git a/drivers/mi-robot/device.js b/drivers/mi-robot/device.js index 4b6ecfb..89c9d23 100644 --- a/drivers/mi-robot/device.js +++ b/drivers/mi-robot/device.js @@ -28,7 +28,6 @@ class MiRobotDevice extends Homey.Device { if (error) { callback(error, false); } else { - this._device.state.onoff = value; this.setCapabilityValue('onoff', value); callback(null, value); } @@ -39,20 +38,16 @@ class MiRobotDevice extends Homey.Device { switch (value) { case "cleaning": var vacuum_state = 'start'; - this._device.state.state = 'cleaning'; break; case "spot_cleaning": var vacuum_state = 'spotclean'; - this._device.state.state = 'spot_cleaning'; break; case "stopped": var vacuum_state = 'stop'; - this._device.state.state = 'stopped'; break; case "docked": case "charging": var vacuum_state = 'charge'; - this._device.state.state = 'charging'; break; default: this.log("Not a valid vacuumcleaner_state"); @@ -77,43 +72,39 @@ class MiRobotDevice extends Homey.Device { this.pollingInterval = setInterval(() => { util.getVacuumCleaner(this.getSetting('address'), this.getSetting('token')) .then(result => { - if (this._device.state.onoff != result.onoff) { - this._device.state.onoff = result.onoff; + if (this.getCapabilityValue('onoff') != result.onoff) { this.setCapabilityValue('onoff', result.onoff); } - if (this._device.state.battery != result.battery) { - this._device.state.battery = result.battery; + if (this.getCapabilityValue('measure_battery') != result.battery) { this.setCapabilityValue('measure_battery', result.battery); } + var vacuumcleanerState = this.getCapabilityValue('vacuumcleaner_state'); + switch (result.state) { case 'cleaning': case 'returning': - if (this._device.state.state != 'cleaning') { - this._device.state.state = 'cleaning'; + if (vacuumcleanerState != 'cleaning') { this.setCapabilityValue('vacuumcleaner_state', 'cleaning'); } break; case 'spot-cleaning': - if (this._device.state.state != 'spot_cleaning') { - this._device.state.state = 'spot_cleaning'; + if (vacuumcleanerState != 'spot_cleaning') { this.setCapabilityValue('vacuumcleaner_state', 'spot_cleaning'); } break; case 'charging': - if (this._device.state.state != 'charging') { - this._device.state.state = 'charging'; + if (vacuumcleanerState != 'charging') { this.setCapabilityValue('vacuumcleaner_state', 'charging'); } break; case 'paused': - if (this._device.state.state != 'stopped') { - this._device.state.state = 'stopped'; + if (vacuumcleanerState != 'stopped') { this.setCapabilityValue('vacuumcleaner_state', 'stopped'); } break; default: - this._device.state.state = 'stopped'; + vacuumcleanerState = 'stopped'; this.setCapabilityValue('vacuumcleaner_state', 'stopped'); } diff --git a/node_modules/appdirectory/.npmignore b/node_modules/appdirectory/.npmignore new file mode 100644 index 0000000..d577dd4 --- /dev/null +++ b/node_modules/appdirectory/.npmignore @@ -0,0 +1,3 @@ +coverage +node_modules +.coveralls.yml \ No newline at end of file diff --git a/node_modules/appdirectory/.travis.yml b/node_modules/appdirectory/.travis.yml new file mode 100644 index 0000000..dcfe368 --- /dev/null +++ b/node_modules/appdirectory/.travis.yml @@ -0,0 +1,9 @@ +language: node_js +node_js: + - "0.11" + - "0.10" + - "0.8" + +before_script: 'npm install -g istanbul && npm install -g mocha' +script: 'make test-cov' +after_success: 'make coveralls' \ No newline at end of file diff --git a/node_modules/appdirectory/LICENSE.md b/node_modules/appdirectory/LICENSE.md new file mode 100644 index 0000000..644fa5e --- /dev/null +++ b/node_modules/appdirectory/LICENSE.md @@ -0,0 +1,19 @@ +Copyright (c) 2014 Johz jonathan.frere@gmail.com + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/node_modules/appdirectory/Makefile b/node_modules/appdirectory/Makefile new file mode 100644 index 0000000..4a6acf1 --- /dev/null +++ b/node_modules/appdirectory/Makefile @@ -0,0 +1,10 @@ +test: + ./node_modules/mocha/bin/mocha --reporter spec + +test-cov: + istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R dot + +coveralls: + cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage + +.PHONY: test \ No newline at end of file diff --git a/node_modules/appdirectory/README.md b/node_modules/appdirectory/README.md new file mode 100644 index 0000000..9f07d69 --- /dev/null +++ b/node_modules/appdirectory/README.md @@ -0,0 +1,51 @@ +[![Build Status](https://travis-ci.org/MrJohz/appdirectory.png?branch=master)](https://travis-ci.org/MrJohz/appdirectory) +[![Coverage Status](https://coveralls.io/repos/MrJohz/appdirectory/badge.png)](https://coveralls.io/r/MrJohz/appdirectory) + +# AppDirectory + +AppDirectory is a port of Python's [appdirs][] module. It can be used as a small cross-platform tool to find the correct directory for an application to use for persistence. It isn't perfect, but it might be useful. + +### Usage +AppDirectory offers one export: the `AppDirectory` constructor: + +``` +var AppDirectory = require('appdirectory') +var dirs = new AppDirectory('mycoolappname') +``` + +`AppDirectory` can be instantiated either with a single string (the application's name) or an object containing more information about the application. + +``` +var dirs = new AppDirectory({ + appName: "mycoolapp", // the app's name, kinda self-explanatory + appAuthor: "Superman", // The author's name, or (more likely) the name of the company/organisation producing this software. +   // Only used on Windows, if omitted will default to appName. + appVersion: "v6000", // The version, will be appended to certain dirs to allow for distinction between versions. + // If it isn't present, no version parameter will appear in the paths + useRoaming: true, // Should AppDirectory use Window's roaming directories? (Defaults to false) + platform: "darwin" // You should almost never need to use this, it will be automatically determined +}) +``` + +Now to get some actual paths. + +``` +dirs.userData() // e.g. /home/awesomeuser/Library/Application Support/mycoolapp on Macs +dirs.userConfig() // e.g. /home/awesomeuser/.config/mycoolapp on linux etc. +dirs.userCache() // e.g. C:\Users\awesomeuser\AppData\Local\mycoolapp\mycoolapp\Cache on Windows 7 (and Vista, I believe) +dirs.userLogs() // e.g. /home/awesomeuser/.cache/mycoolapp/log +``` + +That's pretty much all there is to it. + + +### Todo +- Fix site* functions +- Test all user* functions + +### Known Limitations +> Note: All this limitations have been fixed by virtue of removing the site* functions. The aim is to add them back in, at which point they will still exist, as one's a design decision, and the other's unfixable as far as I can tell. However, at this point, there are no known limitations to AppDirectory! (Feel free to tell me about new limitations by filing an issue.) +- ~~On Windows Vista, the site-config and site-data directories are hidden system directories, which may cause issues. I don't have a copy of Vista to hand to play around with how well this works, though, so YMMV.~~ +- ~~On unix-likes (including those with XDG-compliance), requesting the site-config and site-data directories will return just one directory, even in cases where the XDG* variables contain more than one individual path. (Specifically, it will be the first path AppDirectory finds.)~~ + +[appdirs]: \ No newline at end of file diff --git a/node_modules/appdirectory/lib/appdirectory.js b/node_modules/appdirectory/lib/appdirectory.js new file mode 100644 index 0000000..142a87e --- /dev/null +++ b/node_modules/appdirectory/lib/appdirectory.js @@ -0,0 +1,200 @@ +var path = require('path') +var helpers = require('./helpers') + +var userData = function(roaming, platform) { + var dataPath + , platform = platform || process.platform + if (platform === "darwin") { + dataPath = path.join(process.env.HOME, 'Library', 'Application Support', '{0}') + } else if (platform === "win32") { + var sysVariable + if (roaming) { + sysVariable = "APPDATA" + } else { + sysVariable = "LOCALAPPDATA" // Note, on WinXP, LOCALAPPDATA doesn't exist, catch this later + } + dataPath = path.join(process.env[sysVariable] || process.env.APPDATA /*catch for XP*/, '{1}', '{0}') + } else { + if (process.env.XDG_DATA_HOME) { + dataPath = path.join(process.env.XDG_DATA_HOME, '{0}') + } else { + dataPath = path.join(process.env.HOME, ".local", "share", "{0}") + } + } + return dataPath +} + +/*var siteData = function(platform) { + var dataPath + , platform = platform || process.platform + + if (platform === "darwin") { + dataPath = path.join("/Library", "Application Support", "{0}") + } else if (platform === "win32") { + dataPath = path.join(process.env.PROGRAMDATA, "{1}", "{0}") + } else { + if (process.env.XDG_DATA_DIRS) { + dataPath = process.env.XDG_DATA_DIRS.split((path.delimiter || ':'))[0] + } else { + dataPath = path.join("/usr", "local", "share") + } + + dataPath = path.join(dataPath, "{0}") + } + return dataPath +}*/ + +var userConfig = function(roaming, platform) { + var dataPath + , platform = platform || process.platform + + if (platform === "darwin" || platform === "win32") { + dataPath = userData(roaming, platform) + } else { + if (process.env.XDG_CONFIG_HOME) { + dataPath = path.join(process.env.XDG_CONFIG_HOME, "{0}") + } else { + dataPath = path.join(process.env.HOME, ".config", "{0}") + } + } + + return dataPath +} + +/*var siteConfig = function(platform) { + var dataPath + , platform = platform || process.platform + + if (platform === "darwin" || platform === "win32") { + dataPath = siteData(platform) + } else { + if (process.env.XDG_CONFIG_HOME) { + dataPath = process.env.XDG_CONFIG_HOME.split((path.delimiter || ':'))[0] + } else { + dataPath = path.join("/etc", "xdg") + } + + dataPath = path.join(dataPath, "{0}") + } + return dataPath +}*/ + +var userCache = function(platform) { + var dataPath + , platform = platform || process.platform + + if (platform === "win32") { + dataPath = path.join(process.env.LOCALAPPDATA || process.env.APPDATA, '{1}', '{0}', 'Cache') + } else if (platform === "darwin") { + dataPath = path.join(process.env.HOME, 'Library', 'Caches', '{0}') + } else { + if (process.env.XDG_CACHE_HOME) { + dataPath = path.join(process.env.XDG_CACHE_HOME, '{0}') + } else { + dataPath = path.join(process.env.HOME, '.cache', '{0}') + } + } + return dataPath +} + +var userLogs = function(platform) { + var dataPath + , platform = platform || process.platform + + if (platform === "win32") { + dataPath = path.join(userData(false, platform), 'Logs') + } else if (platform === "darwin") { + dataPath = path.join(process.env.HOME, 'Library', 'Logs', '{0}') + } else { + dataPath = path.join(userCache(platform), 'log') + } + return dataPath +} + +function AppDirectory(options) { + if (helpers.instanceOf(options, String)) { + options = {appName: options} + } + + // substitution order: + // {0} - appName + // {1} - appAuthor + + this.appName = options.appName + this.appAuthor = options.appAuthor || options.appName + this.appVersion = options.appVersion || null + this._useRoaming = options.useRoaming || false + this._platform = options.platform || null + + this._setTemplates() +} + +AppDirectory.prototype = { + _setTemplates: function() { + this._userDataTemplate = userData(this._useRoaming, this._platform) + /*this._siteDataTemplate = siteData(this._platform)*/ + this._userConfigTemplate = userConfig(this._useRoaming, this._platform) + /*this._siteConfigTempalte = siteConfig(this._platform)*/ + this._userCacheTemplate = userCache(this._platform) + this._userLogsTemplate = userLogs(this._platform) + }, + get useRoaming() { + return this._useRoaming + }, + set useRoaming(bool) { + this._useRoaming = bool + this._setTemplates() + }, + get platform() { + return this._platform + }, + set platform(str) { + this._platform = str + this._setTemplates() + }, + userData: function() { + var dataPath = this._userDataTemplate + if (this.appVersion !== null) { + var dataPath = path.join(dataPath, this.appVersion) + } + return helpers.formatStr(dataPath, this.appName, this.appAuthor) + }, + siteData: function() { + var dataPath = this._siteDataTemplate + if (this.appVersion !== null) { + var dataPath = path.join(dataPath, this.appVersion) + } + return helpers.formatStr(dataPath, this.appName, this.appAuthor) + }, + userConfig: function() { + var dataPath = this._userConfigTemplate + if (this.appVersion !== null) { + var dataPath = path.join(dataPath, this.appVersion) + } + return helpers.formatStr(dataPath, this.appName, this.appAuthor) + }, + siteConfig: function() { + var dataPath = this._siteConfigTemplate + if (this.appVersion !== null) { + var dataPath = path.join(dataPath, this.appVersion) + } + return helpers.formatStr(dataPath, this.appName, this.appAuthor) + }, + userCache: function() { + var dataPath = this._userCacheTemplate + if (this.appVersion !== null) { + var dataPath = path.join(dataPath, this.appVersion) + } + return helpers.formatStr(dataPath, this.appName, this.appAuthor) + }, + userLogs: function() { + var dataPath = this._userLogsTemplate + if (this.appVersion !== null) { + var dataPath = path.join(dataPath, this.appVersion) + } + return helpers.formatStr(dataPath, this.appName, this.appAuthor) + } + +} + +module.exports = AppDirectory diff --git a/node_modules/appdirectory/lib/helpers.js b/node_modules/appdirectory/lib/helpers.js new file mode 100644 index 0000000..c46008a --- /dev/null +++ b/node_modules/appdirectory/lib/helpers.js @@ -0,0 +1,46 @@ +/* This module contains helpers for appdirectory + * + * instanceOf(object, constructor) + * - determines if an object is an instance of + * a constructor + * - ignores distinction between objects and + * literals - converts all literals into + * their object counterparts + * - returns a boolean + */ + +var instanceOf = function(object, constructor) { + // If object is a string/array/number literal, + // turn it into a 'real' object + if (typeof object != "object") { + object = new object.constructor(object) + } + + // Iterate up the object's prototype chain + while (object != null) { + if (object == constructor.prototype) { + // We've found the correct prototype! + return true + } + + // Next prototype up + object = Object.getPrototypeOf(object) + } + + // Nothing found. + return false +} + +var formatStr = function(format) { + // This function has been stolen liberally from + // http://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format + var args = Array.prototype.slice.call(arguments, 1) + return format.replace(/{(\d+)}/g, function(match, number) { + return typeof args[number] != 'undefined' + ? args[number] + : match + }) +} + +module.exports.instanceOf = instanceOf +module.exports.formatStr= formatStr \ No newline at end of file diff --git a/node_modules/appdirectory/package.json b/node_modules/appdirectory/package.json new file mode 100644 index 0000000..fa2a895 --- /dev/null +++ b/node_modules/appdirectory/package.json @@ -0,0 +1,61 @@ +{ + "_args": [ + [ + "appdirectory@0.1.0", + "D:\\Solide Webservices\\Github\\SDK2\\com.xiaomi-miio" + ] + ], + "_from": "appdirectory@0.1.0", + "_id": "appdirectory@0.1.0", + "_inBundle": false, + "_integrity": "sha1-62yBYyDnsqsW9e2ZfyjYIF31Y3U=", + "_location": "/appdirectory", + "_phantomChildren": {}, + "_requested": { + "type": "version", + "registry": true, + "raw": "appdirectory@0.1.0", + "name": "appdirectory", + "escapedName": "appdirectory", + "rawSpec": "0.1.0", + "saveSpec": null, + "fetchSpec": "0.1.0" + }, + "_requiredBy": [ + "/miio" + ], + "_resolved": "https://registry.npmjs.org/appdirectory/-/appdirectory-0.1.0.tgz", + "_spec": "0.1.0", + "_where": "D:\\Solide Webservices\\Github\\SDK2\\com.xiaomi-miio", + "author": { + "name": "Johz" + }, + "bugs": { + "url": "https://github.com/MrJohz/appdirectory/issues" + }, + "description": "A cross-platform utility to find the best directory to put data and config files.", + "devDependencies": { + "coveralls": "~2.8.0", + "mocha": "~1.17.1", + "should": "~3.1.3" + }, + "homepage": "https://github.com/MrJohz/appdirectory#readme", + "keywords": [ + "cross-platform", + "utility", + "appdata", + "config", + "directory" + ], + "license": "MIT", + "main": "lib/appdirectory.js", + "name": "appdirectory", + "repository": { + "type": "git", + "url": "git+ssh://git@github.com/MrJohz/appdirectory.git" + }, + "scripts": { + "test": "make test" + }, + "version": "0.1.0" +} diff --git a/node_modules/appdirectory/test/tests.js b/node_modules/appdirectory/test/tests.js new file mode 100644 index 0000000..f879f4f --- /dev/null +++ b/node_modules/appdirectory/test/tests.js @@ -0,0 +1,301 @@ +var should = require('should') +var path = require('path') // *always* use the correct pathseps! + +var helpers = require('../lib/helpers') +var AppDirectory = require('../lib/appdirectory') + +var oldEnv = {} + +function monkeyPatchEnvironment(xdg) { + oldEnv.HOME = process.env.HOME + process.env.HOME = path.join("/home", "awesomeuser") + + oldEnv.APPDATA = process.env.APPDATA + process.env.APPDATA = path.join("C:", "Users", "awesomeuser", "AppData", "Roaming") + oldEnv.LOCALAPPDATA = process.env.LOCALAPPDATA + process.env.LOCALAPPDATA = path.join("C:", "Users", "awesomeuser", "AppData", "Local") + oldEnv.PROGRAMDATA = process.env.PROGRAMDATA + process.env.PROGRAMDATA = path.join("C:", "ProgramData") + + + if (xdg) { + oldEnv.XDG_DATA_HOME = process.env.XDG_DATA_HOME + process.env.XDG_DATA_HOME = path.join("/home", "awesomeuser", "xdg", "share") // I don't know what an XDG_DATA_HOME directory should look like... + oldEnv.XDG_DATA_DIRS = process.env.XDG_DATA_DIRS + xdgDataDirs = path.join("/usr", "xdg", "share") + (path.delimiter || ':') + path.join("/usr", "local", "xdg", "share") + process.env.XDG_DATA_DIRS = xdgDataDirs // I also don't know what an XDG_DATA_DIRS directory should look like... + oldEnv.XDG_CONFIG_HOME = process.env.XDG_CONFIG_HOME + process.env.XDG_CONFIG_HOME = path.join("/home", "awesomeuser", "xdg", ".config") + } else { + oldEnv.XDG_DATA_HOME = process.env.XDG_DATA_HOME + process.env.XDG_DATA_HOME = '' + oldEnv.XDG_DATA_DIRS = process.env.XDG_DATA_DIRS + process.env.XDG_DATA_DIRS = '' + oldEnv.XDG_CONFIG_HOME = process.env.XDG_CONFIG_HOME + process.env.XDG_CONFIG_HOME = '' + } +} + +function unPatchEnvironment() { + process.env.HOME = oldEnv.HOME + process.env.APPDATA = oldEnv.APPDATA + process.env.LOCALAPPDATA = oldEnv.LOCALAPPDATA + process.env.XDG_DATA_HOME = oldEnv.XDG_DATA_HOME + process.env.XDG_CONFIG_HOME = oldEnv.XDG_CONFIG_HOME +} + +describe('helpers.js', function() { + describe('instanceOf', function() { + it('should correctly work out if an object is a subtype of a prototype', function() { + + helpers.instanceOf('sampleString', String).should.be.true + helpers.instanceOf(new String(), String).should.be.true + + helpers.instanceOf({}, Object).should.be.true + helpers.instanceOf(new Object(), Object).should.be.true + helpers.instanceOf('string', Object).should.be.true // Potentially confusing behaviour + + helpers.instanceOf([], Array).should.be.true + helpers.instanceOf(new Array(), Array).should.be.true + + helpers.instanceOf('', Array).should.be.false + helpers.instanceOf({'hello': 'goodbye'}, String).should.be.false + + }) + }) + + describe('formatStr', function() { + it('should format strings correctly', function() { + + helpers.formatStr('{0} is dead, but {1} is alive! {0} {2}', 'ASP', 'ASP.NET').should.equal('ASP is dead, but ASP.NET is alive! ASP {2}') + helpers.formatStr('{1} string does not have an index 0', 'uncalled', 'This').should.equal('This string does not have an index 0') + + }) + }) +}) + +describe('appdirectory.js', function() { + describe('AppDirectory', function() { + it('should handle instantiation options object', function() { + monkeyPatchEnvironment() // needed to ensure *APPDATA vars are present + var ad = new AppDirectory({ + appName: "myapp", + appAuthor: "Johz", + appVersion: "0.1.1", + useRoaming: true, + platform: "win32" + }) + + ad.should.containEql({appName: 'myapp'}) + ad.should.containEql({appAuthor: 'Johz'}) + ad.should.containEql({appVersion: '0.1.1'}) + ad.should.containEql({useRoaming: true}) + ad.should.containEql({_platform: "win32"}) + + ad.platform.should.equal("win32") // test getters here as well + + unPatchEnvironment() + }) + + it('should handle default instantiations', function() { + var ad = new AppDirectory({ + appName: "myapp", + }) + + ad.should.containEql({appName: 'myapp'}) + ad.should.containEql({appAuthor: 'myapp'}) + ad.should.containEql({appVersion: null}) + ad.should.containEql({useRoaming: false}) + ad.should.containEql({_platform: null}) + }) + + it('should handle instatiation with string', function() { + var ad = new AppDirectory("myapp") + + ad.should.containEql({appName: 'myapp'}) + ad.should.containEql({appAuthor: 'myapp'}) + ad.should.containEql({appVersion: null}) + ad.should.containEql({useRoaming: false}) + ad.should.containEql({_platform: null}) + }) + + describe("#userData", function() { + it('should return the correct format string', function() { + + monkeyPatchEnvironment(false) // get the correct system vars in place + + var ad = new AppDirectory({ + appName: "myapp", + appAuthor: "Johz", + appVersion: "0.1.1", + useRoaming: true, + platform: "win32" + }) + + ad.userData().should.equal(path.join("C:", "Users", "awesomeuser", "AppData", "Roaming", "Johz", "myapp", "0.1.1")) + + ad = new AppDirectory({ + appName: "myapp", + useRoaming: false, + platform: "win32" + }) + + ad.userData().should.equal(path.join("C:", "Users", "awesomeuser", "AppData", "Local", "myapp", "myapp")) + + ad = new AppDirectory({ + appName: "myapp", + platform: "darwin" + }) + + ad.userData().should.equal(path.join("/home", "awesomeuser", "Library", "Application Support", "myapp")) + + ad = new AppDirectory({ + appName: "myapp", + platform: "linux" + }) + + ad.userData().should.equal(path.join("/home", "awesomeuser", ".local", "share", "myapp")) + + unPatchEnvironment() + monkeyPatchEnvironment(true) // set XDG variables + + ad = new AppDirectory({ + appName: "myapp", + platform: "linux" + }) + + ad.userData().should.equal(path.join("/home", "awesomeuser", "xdg", "share", "myapp")) + + unPatchEnvironment() // return everything to how it was in case something weird's happening afterwards + + }) + + it('should be modifiable using getters and setters', function() { + monkeyPatchEnvironment(false) + + ad = new AppDirectory({ + appName: "myapp", + platform: "win32" + }) + + ad.userData().should.equal(path.join("C:", "Users", "awesomeuser", "AppData", "Local", "myapp", "myapp")) + + ad.useRoaming = true + + ad.userData().should.equal(path.join("C:", "Users", "awesomeuser", "AppData", "Roaming", "myapp", "myapp")) + + ad.platform = "linux" + + ad.platform.should.equal("linux") + + ad.userData().should.equal(path.join("/home", "awesomeuser", ".local", "share", "myapp")) + + unPatchEnvironment() + }) + }) + + describe('#siteData', function() { + it('should return the correct paths on different OSs'/*, function() { + + monkeyPatchEnvironment(false) // get the correct system vars in place + + var ad = new AppDirectory({ + appName: "myapp", + appAuthor: "Johz", + appVersion: "0.1.1", + useRoaming: true, + platform: "win32" + }) + + ad.siteData().should.equal(path.join("C:", "ProgramData", "Johz", "myapp", "0.1.1")) + + ad = new AppDirectory({ + appName: "myapp", + useRoaming: false, + platform: "win32" + }) + + ad.siteData().should.equal(path.join("C:", "ProgramData", "myapp", "myapp")) + + ad = new AppDirectory({ + appName: "myapp", + platform: "darwin" + }) + + ad.siteData().should.equal(path.join("/Library", "Application Support", "myapp")) + + ad = new AppDirectory({ + appName: "myapp", + platform: "linux" + }) + + ad.siteData().should.equal(path.join("/usr", "local", "share", "myapp")) + + unPatchEnvironment() + monkeyPatchEnvironment(true) // set XDG variables + + ad = new AppDirectory({ + appName: "myapp", + platform: "linux" + }) + + ad.siteData().should.equal(path.join("/usr", "xdg", "share", "myapp")) + + unPatchEnvironment() // return everything to how it was in case something weird's happening afterwards + + }*/) + }) + + describe('#userConfig', function() { + it('should return the correct paths on different OSs', function() { + + monkeyPatchEnvironment(false) // get the correct system vars in place + + var ad = new AppDirectory({ + appName: "myapp", + appAuthor: "Johz", + appVersion: "0.1.1", + useRoaming: true, + platform: "win32" + }) + + ad.userConfig().should.equal(path.join("C:", "Users", "awesomeuser", "AppData", "Roaming", "Johz", "myapp", "0.1.1")) + + ad = new AppDirectory({ + appName: "myapp", + useRoaming: false, + platform: "win32" + }) + + ad.userConfig().should.equal(path.join("C:", "Users", "awesomeuser", "AppData", "Local", "myapp", "myapp")) + + ad = new AppDirectory({ + appName: "myapp", + platform: "darwin" + }) + + ad.userConfig().should.equal(path.join("/home", "awesomeuser", "Library", "Application Support", "myapp")) + + ad = new AppDirectory({ + appName: "myapp", + platform: "linux" + }) + + ad.userConfig().should.equal(path.join("/home", "awesomeuser", ".config", "myapp")) + + unPatchEnvironment() + monkeyPatchEnvironment(true) // set XDG variables + + ad = new AppDirectory({ + appName: "myapp", + platform: "linux" + }) + + ad.userConfig().should.equal(path.join("/home", "awesomeuser", "xdg", ".config", "myapp")) + + unPatchEnvironment() // return everything to how it was in case something weird's happening afterwards + + }) + }) + }) +}) \ No newline at end of file diff --git a/node_modules/miio/.gitignore b/node_modules/miio/.gitignore deleted file mode 100644 index 93f1361..0000000 --- a/node_modules/miio/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -npm-debug.log diff --git a/node_modules/miio/.npmignore b/node_modules/miio/.npmignore deleted file mode 100644 index 93f1361..0000000 --- a/node_modules/miio/.npmignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -npm-debug.log diff --git a/node_modules/miio/cli/index.js b/node_modules/miio/cli/index.js index d119862..c2df2cd 100644 --- a/node_modules/miio/cli/index.js +++ b/node_modules/miio/cli/index.js @@ -120,11 +120,9 @@ if(args.discover) { .then(() => { return device.management.info(); }) - .then(info => { - if(info.ap && info.ap.ssid === String(ssid)) { - warn(reg.id, 'at', reg.address, 'is already configured to use this network'); - hasConfigured = true; - return; + .then(deviceInfo => { + if(deviceInfo.ap && deviceInfo.ap.ssid === String(ssid)) { + info(reg.id, 'at', reg.address, 'is already configured to use this network'); } return device.management.updateWireless({ diff --git a/node_modules/miio/lib/management.js b/node_modules/miio/lib/management.js index 2336a5d..82ca80a 100644 --- a/node_modules/miio/lib/management.js +++ b/node_modules/miio/lib/management.js @@ -34,7 +34,7 @@ class DeviceManagement { return this.device.call('miIO.config_router', options) .then(result => { - if(result !== 0) { + if(result !== 0 && result !== 'OK' && result !== 'ok') { throw new Error('Failed updating wireless'); } return true; diff --git a/node_modules/miio/package.json b/node_modules/miio/package.json index 72d1548..2c406c1 100644 --- a/node_modules/miio/package.json +++ b/node_modules/miio/package.json @@ -1,36 +1,69 @@ { - "name": "miio", - "version": "0.13.0", - "license": "MIT", - "description": "Control Mi Home devices, such as Mi Robot Vacuums, Mi Air Purifiers, Mi Smart Home Gateway (Aqara) and more", - "repository": "aholstenson/miio", - "main": "lib/index.js", - "keywords": [ - "xiaomi", - "mi", - "miio", - "aqara", - "yeelight", - "mijia" + "_from": "miio@0.14.0", + "_id": "miio@0.14.0", + "_inBundle": false, + "_integrity": "sha512-+gdRI92L/+DU0UoXH9S8vm5XY4NyjK0LZHr0WINLSuE9AtKcRdLHPZ12cwLosMlnNWx3tnm08GmC02SgtTIdJQ==", + "_location": "/miio", + "_phantomChildren": {}, + "_requested": { + "type": "version", + "registry": true, + "raw": "miio@0.14.0", + "name": "miio", + "escapedName": "miio", + "rawSpec": "0.14.0", + "saveSpec": null, + "fetchSpec": "0.14.0" + }, + "_requiredBy": [ + "#USER", + "/" ], + "_resolved": "https://registry.npmjs.org/miio/-/miio-0.14.0.tgz", + "_shasum": "4919234f0f98a26365a78d0a65885397eb0ea5a2", + "_spec": "miio@0.14.0", + "_where": "D:\\Solide Webservices\\Github\\SDK2\\com.xiaomi-miio", "bin": { "miio": "./cli/index.js" }, - "scripts": { - "prepublish": "node_modules/.bin/eslint .", - "test": "node_modules/.bin/eslint ." - }, - "engines": { - "node": ">=6.0.0" + "bugs": { + "url": "https://github.com/aholstenson/miio/issues" }, + "bundleDependencies": false, "dependencies": { "chalk": "^1.1.3", "debug": "^2.6.3", "minimist": "^1.2.0", "mkdirp": "^0.5.1" }, + "deprecated": false, + "description": "Control Mi Home devices, such as Mi Robot Vacuums, Mi Air Purifiers, Mi Smart Home Gateway (Aqara) and more", "devDependencies": { "eslint": "^3.11.1", "eslint-plugin-node": "^3.0.5" - } + }, + "engines": { + "node": ">=6.0.0" + }, + "homepage": "https://github.com/aholstenson/miio#readme", + "keywords": [ + "xiaomi", + "mi", + "miio", + "aqara", + "yeelight", + "mijia" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "miio", + "repository": { + "type": "git", + "url": "git+https://github.com/aholstenson/miio.git" + }, + "scripts": { + "prepublish": "eslint .", + "test": "eslint ." + }, + "version": "0.14.0" } diff --git a/package-lock.json b/package-lock.json index faa7b95..6c911b6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "com.xiaomi-miio", - "version": "2.1.2", + "version": "2.3.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -53,9 +53,9 @@ } }, "miio": { - "version": "0.13.0", - "resolved": "https://registry.npmjs.org/miio/-/miio-0.13.0.tgz", - "integrity": "sha1-h8S0Fltsyl1UviKaFzYbudxbqGs=", + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/miio/-/miio-0.14.0.tgz", + "integrity": "sha512-+gdRI92L/+DU0UoXH9S8vm5XY4NyjK0LZHr0WINLSuE9AtKcRdLHPZ12cwLosMlnNWx3tnm08GmC02SgtTIdJQ==", "requires": { "appdirectory": "0.1.0", "chalk": "1.1.3", diff --git a/package.json b/package.json index de5d6fa..8756711 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Xiaomi Mi Home", "main": "app.js", "dependencies": { - "miio": "^0.13.0", + "miio": "^0.14.0", "tinycolor2": "^1.4.1" }, "devDependencies": {},