luisiam / homebridge-cmdswitch2

CMD Plugin for HomeBridge (API 2.0): https://github.com/nfarina/homebridge
Apache License 2.0
176 stars 29 forks source link

absence of state_cmd cause error #31

Closed casouri closed 6 years ago

casouri commented 6 years ago

Observed

Error:

child_process.js:380
    throw new TypeError('"file" argument must be a non-empty string');
    ^

TypeError: "file" argument must be a non-empty string
    at normalizeSpawnArguments (child_process.js:380:11)
    at exports.spawn (child_process.js:485:38)
    at Object.exports.execFile (child_process.js:208:15)
    at exports.exec (child_process.js:138:18)
    at cmdSwitchPlatform.getState (/Users/yuan/p/hm/node_modules/homebridge-cmdswitch2/index.js:153:3)
    at cmdSwitchPlatform.getPowerState (/Users/yuan/p/hm/node_modules/homebridge-cmdswitch2/index.js:198:10)
    at emitThree (events.js:135:13)
    at Characteristic.On.emit (events.js:216:7)
    at Characteristic.On.Characteristic.getValue (/Users/yuan/p/hm/node_modules/hap-nodejs/lib/Characteristic.js:142:10)
    at cmdSwitchPlatform.getInitState (/Users/yuan/p/hm/node_modules/homebridge-cmdswitch2/index.js:141:8)

config.json:

    "bridge": {
        "name": "Homebridge",
        "username": "CC:22:3D:E3:CE:30",
        "port": 51115,
        "pin": "199-81-210"
    },
    "description": "smart home control center",
    "accessories": [],
    "platforms": [
        {
            "platform": "cmdSwitch2",
            "name": "CMD Switch",
            "switches": [
                {
                    "name": "Lamp",
                    "on_cmd": "say on",
                    "off_cmd": "say off"
                }
            ]
        }
    ]
}

what fix it

adding state_cmd fixes it

{
    "bridge": {
        "name": "Homebridge",
        "username": "CC:22:3D:E3:CE:30",
        "port": 51115,
        "pin": "199-81-210"
    },
    "description": "smart home control center",
    "accessories": [],
    "platforms": [
        {
            "platform": "cmdSwitch2",
            "name": "CMD Switch",
            "switches": [
                {
                    "name": "Lamp",
                    "on_cmd": "say on",
                    "state_cmd": "echo off",
                    "off_cmd": "say off"
                }
            ]
        }
    ]
}

Problem

is state_cmd required? It is not marked required on readme.

sieren commented 6 years ago

Could reproduce this here. The fix you provided does not really solve it as it would always return "on" as the state.

I've put in a PR with a fix proposal.

casouri commented 6 years ago

Yeah, I just filled something in there for experimental purpose. state_cmd is suppose to return either true or false.

casouri commented 6 years ago

Since there is a PR I will close this.