meg768 / homebridge-ikea-tradfri-gateway

homebridge-ikea-tradfri-gateway
GNU General Public License v3.0
73 stars 24 forks source link

Cannot read property 'name' of null #47

Open Aubermean opened 4 years ago

Aubermean commented 4 years ago

I cannot initialize this plugin. Here is the output and my config file - any ideas anyone? I'm using macos 10.15. Thanks!

% homebridge
[11/28/2019, 1:48:20 PM] Loaded config.json with 0 accessories and 1 platforms.
[11/28/2019, 1:48:20 PM] ---
[11/28/2019, 1:48:20 PM] Loaded plugin: homebridge-ikea-tradfri-gateway
[11/28/2019, 1:48:20 PM] Registering platform 'homebridge-ikea-gateway.Ikea Trådfri Gateway'
[11/28/2019, 1:48:20 PM] ---
[11/28/2019, 1:48:20 PM] Loaded plugin: homebridge-tradfri-plugin
[11/28/2019, 1:48:20 PM] Registering platform 'homebridge-tradfri.IkeaTradfri'
[11/28/2019, 1:48:20 PM] ---
[11/28/2019, 1:48:20 PM] Loading 1 platforms...
[11/28/2019, 1:48:20 PM] [Ikea Trådfri Gateway] Initializing Ikea Trådfri Gateway platform...
[11/28/2019, 1:48:20 PM] [Ikea Trådfri Gateway] didFinishLaunching
[11/28/2019, 1:48:20 PM] [Ikea Trådfri Gateway] Discovering gateway...
TypeError: Cannot read property 'name' of null
    at Ikea.discoverGateway.then (/usr/local/lib/node_modules/homebridge-ikea-tradfri-gateway/src/gateway.js:35:64)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    "bridge": {
        "name": "Trådfri",
        "username": "MAC_ADDRESS_REMOVED",
        "port": 51826,
        "pin": "123-45-678"
    },

    "description": "This is an example configuration file",

    "platforms": [
        {
            "platform": "Ikea Trådfri Gateway",
            "name": "Ikea Trådfri Gateway",
            "securityCode" : "blahblahblah",
            "expose": ["blinds"]
        }
    ]
}
meg768 commented 4 years ago

It seems like the "auto-ip-address-detect-feature" of the gateway failed. Try specifying the IP address manually. Modified the code to respond with an appropriate message.

    getHostName() {
        return new Promise((resolve, reject) => {

            if (this.config.host != undefined)
                resolve(this.config.host);
            else {
                this.log('Discovering gateway...');

                Ikea.discoverGateway().then((discovery) => {
                    if (discovery && discovery.name) {
                        this.log('Discovered host "%s"', discovery.name);
                        resolve(discovery.name);
                    }
                    else {
                        reject(new Error('Cannot discover gateway address. Sorry, you have to enter the IP address yourself in ~/.homebridge/config.json.'));    
                    }

                })
                .catch((error) => {
                    reject(error);
                })
            }
        });        
    }
meg768 commented 4 years ago

New version on npmjs now. 1.2.29...