Skip to content

Commit

Permalink
fix problematic chars
Browse files Browse the repository at this point in the history
  • Loading branch information
Pmant committed Jun 22, 2018
1 parent 8fcacb1 commit f48306f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 27 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -51,6 +51,11 @@ After sending the state will be set to 0 again.

## Changelog

### 0.9.1
please delete all harmony.x objects once
* (Pmant) fix problematic chars


### 0.7.0
* (Pmant) support multiple hubs
* (Pmant) removed hub config from admin
Expand Down
16 changes: 10 additions & 6 deletions harmony.js
Expand Up @@ -15,6 +15,10 @@ var utils = require(__dirname + '/lib/utils'); // Get common adapter utils
var adapter = utils.adapter('harmony');
var hubs = {};
var discover;
const FORBIDDEN_CHARS = /[\]\[*,;'"`<>\\?]/g;
const fixId = function(id) {
return id.replace(FORBIDDEN_CHARS, '_');
}


adapter.on('stateChange', function (id, state) {
Expand Down Expand Up @@ -173,7 +177,7 @@ function discoverStart() {
// Triggered when a new hub was found
if (hub.host_name !== 'undefined' && hub.host_name !== undefined) {
adapter.log.info('discovered ' + hub.host_name);
var hubName = hub.host_name.replace(/[.\s]+/g, '_');
var hubName = fixId(hub.host_name);
initHub(hubName, function () {
//wait 2 seconds for hub before connecting
adapter.log.info('connecting to ' + hub.host_name);
Expand All @@ -187,7 +191,7 @@ function discoverStart() {
// Triggered when a hub disappeared
if (hub.host_name !== 'undefined' && hub.host_name !== undefined) {
adapter.log.warn('lost ' + hub.host_name);
var hubName = hub.host_name.replace(/[.\s]+/g, '_');
var hubName = fixId(hub.host_name.replace);
//stop reconnect timer
if (hubs[hubName]) {
clearTimeout(hubs[hubName].reconnectTimer);
Expand Down Expand Up @@ -442,7 +446,7 @@ function processConfig(hub, hubObj, config) {
}

config.activity.forEach(function (activity) {
var activityLabel = activity.label.replace(/[.\s]+/g, '_');
var activityLabel = fixId(activity.label);
hubs[hub].activities[activity.id] = activityLabel;
hubs[hub].activities_reverse[activityLabel] = activity.id;
if (activity.id == '-1') return;
Expand Down Expand Up @@ -477,7 +481,7 @@ function processConfig(hub, hubObj, config) {
adapter.log.debug('creating devices');
channelName = hub;
config.device.forEach(function (device) {
var deviceLabel = device.label.replace(/[.\s]+/g, '_');
var deviceLabel = fixId(device.label);
var deviceChannelName = channelName + '.' + deviceLabel;
var controlGroup = device.controlGroup;
hubs[hub].devices[device.id] = deviceLabel;
Expand All @@ -499,7 +503,7 @@ function processConfig(hub, hubObj, config) {
controlGroup.function.forEach(function (command) {
command.controlGroup = groupName;
command.deviceId = device.id;
var commandName = command.name.replace(/[.\s]+/g, '_');
var commandName = fixId(command.name);
//create command
adapter.setObject(deviceChannelName + '.' + commandName, {
type: 'state',
Expand Down Expand Up @@ -587,7 +591,7 @@ function setStatusFromActivityID(hub, id, value) {
adapter.log.warn('unknown activityId: ' + id);
return;
}
var channelName = hub + '.activities.' + hubs[hub].activities[id].replace(/[.\s]+/g, '_');
var channelName = fixId(hub + '.activities.' + hubs[hub].activities[id]);
adapter.setState(channelName, {val: value, ack: true});
}

Expand Down
7 changes: 6 additions & 1 deletion io-package.json
@@ -1,7 +1,7 @@
{
"common": {
"name": "harmony",
"version": "0.9.0",
"version": "0.9.1",
"title": "Logitech Harmony Adapter",
"desc": {
"en": "Control your harmony activities from ioBroker",
Expand All @@ -12,6 +12,11 @@
"Pmant <patrickmo@gmx.de>"
],
"news": {
"0.9.1": {
"en": "fix problematic chars",
"de": "Fix für problemantische Zeichen",
"ru": "fix problematic chars"
},
"0.7.1": {
"en": "bug fixes",
"de": "bug fixes",
Expand Down
13 changes: 7 additions & 6 deletions package.json
@@ -1,15 +1,16 @@
{
"name": "iobroker.harmony",
"version": "0.9.0",
"version": "0.9.1",
"description": "Control your harmony activities from ioBroker.",
"author": "Pmant <patrickmo@gmx.de>",
"contributors": [
],
"contributors": [],
"homepage": "https://github.com/pmant/ioBroker.harmony",
"license": "MIT",
"keywords": [
"ioBroker",
"harmony", "hub", "logitech",
"harmony",
"hub",
"logitech",
"home automation"
],
"repository": {
Expand All @@ -18,8 +19,8 @@
},
"dependencies": {
"harmonyhubjs-client": "^1.1.10",
"harmonyhubjs-discover": "^1.0.2",
"semaphore": "~1.0.3"
"harmonyhubjs-discover": "^1.1.1",
"semaphore": "~1.0.3"
},
"devDependencies": {
"grunt": "^0.4.5",
Expand Down
14 changes: 7 additions & 7 deletions tasks/jscs.js
@@ -1,14 +1,14 @@
var srcDir = __dirname + "/../";
var srcDir = __dirname + '/../';

module.exports = {
all: {
src: [
srcDir + "*.js",
srcDir + "lib/*.js",
srcDir + "adapter/example/*.js",
srcDir + "tasks/**/*.js",
srcDir + "www/**/*.js",
'!' + srcDir + "www/lib/**/*.js",
srcDir + '*.js',
srcDir + 'lib/*.js',
srcDir + 'adapter/example/*.js',
srcDir + 'tasks/**/*.js',
srcDir + 'www/**/*.js',
'!' + srcDir + 'www/lib/**/*.js',
'!' + srcDir + 'node_modules/**/*.js',
'!' + srcDir + 'adapter/*/node_modules/**/*.js'
],
Expand Down
14 changes: 7 additions & 7 deletions tasks/jshint.js
@@ -1,16 +1,16 @@
var srcDir = __dirname + "/../";
var srcDir = __dirname + '/../';

module.exports = {
options: {
force: true
},
all: [
srcDir + "*.js",
srcDir + "lib/*.js",
srcDir + "adapter/example/*.js",
srcDir + "tasks/**/*.js",
srcDir + "www/**/*.js",
'!' + srcDir + "www/lib/**/*.js",
srcDir + '*.js',
srcDir + 'lib/*.js',
srcDir + 'adapter/example/*.js',
srcDir + 'tasks/**/*.js',
srcDir + 'www/**/*.js',
'!' + srcDir + 'www/lib/**/*.js',
'!' + srcDir + 'node_modules/**/*.js',
'!' + srcDir + 'adapter/*/node_modules/**/*.js'
]
Expand Down

0 comments on commit f48306f

Please sign in to comment.