NorthernMan54 / homebridge-alexa

Expose your homebridge controlled devices to Amazon Alexa.
https://www.homebridge.ca
459 stars 68 forks source link

Debug mode fails to open alexaDiscovery.json #620

Open dazzlee42 opened 7 months ago

dazzlee42 commented 7 months ago

Analysis

Hi, Just updated to v0.6.9 and I have debug turned on for the plugin. Restarted homebridge and after a few seconds it restarts. I managed to disable the plugin and check the logs. Seems it is now trying to save out to alexaDiscovery.json when in debug mode and failing.

Expected Behavior

Don't crash ;-) Save the file to a known location.

Steps To Reproduce

Enable debug, restart.

Logs

[19/04/2024, 12:36:25] Homebridge v1.7.0 (HAP v0.11.1) (Homebridge) is running on port 51826.
[19/04/2024, 12:36:25] [BraviaPlatform] Loaded cookie file from /home/dkeverne/.homebridge/plugin-persist/homebridge-bravia/sonycookie_Lounge TV
2024-04-19T11:36:26.360Z alexaLocal connect mqtts://alexa.homebridge.ca:8883/ command/dazzlee69/#
2024-04-19T11:36:26.811Z hapNodeJSClient HAP Device discovered Homebridge CAD8 [ '127.0.0.1', '::1' ]
[19/04/2024, 12:36:28] [Homebridge UI] Homebridge UI v4.56.1 is listening on :: port 8080
[19/04/2024, 12:36:30] [homebridge-sonoff] This plugin slows down Homebridge. The read handler for the characteristic 'On' was slow to respond! See https://homebridge.io/w/JtMGR for more info.
2024-04-19T11:36:30.232Z hapNodeJSClient Homebridge instance discovered Homebridge CAD8 @ http://127.0.0.1:51826 with 34 accessories
dkeverne : TTY=pts/0 ; PWD=/home/dkeverne/.homebridge ; USER=root ; COMMAND=/usr/bin/journalctl -o cat -n 500 -f -u homebridge
pam_unix(sudo:session): session opened for user root(uid=0) by (uid=1000)
2024-04-19T11:36:45.613Z hapNodeJSClient Ready
2024-04-19T11:36:45.614Z alexaActions alexaDiscovery
[19/04/2024, 12:36:45] [Alexa] alexaDiscovery - returned 32 devices
[19/04/2024, 12:36:45] Error: EACCES: permission denied, open 'alexaDiscovery.json'
    at Object.openSync (node:fs:596:3)
    at Object.writeFileSync (node:fs:2322:35)
    at Object.<anonymous> (/usr/lib/node_modules/homebridge-alexa/lib/alexaActions.js:141:10)
    at HAPNodeJSClient.HAPaccessories (/usr/lib/node_modules/homebridge-alexa/node_modules/hap-node-client/HAPNodeJSClient.js:245:3)
    at Object.alexaDiscovery (/usr/lib/node_modules/homebridge-alexa/lib/alexaActions.js:92:14)
    at HAPNodeJSClient.<anonymous> (/usr/lib/node_modules/homebridge-alexa/lib/alexaActions.js:36:20)
    at HAPNodeJSClient.emit (node:events:517:28)
    at HAPNodeJSClient.<anonymous> (/usr/lib/node_modules/homebridge-alexa/node_modules/hap-node-client/HAPNodeJSClient.js:119:10)
    at Timeout._onTimeout (/usr/lib/node_modules/homebridge-alexa/node_modules/hap-node-client/HAPNodeJSClient.js:199:7)
    at listOnTimeout (node:internal/timers:569:17)
    at processTimers (node:internal/timers:512:7)
[19/04/2024, 12:36:45] Got SIGTERM, shutting down Homebridge...
homebridge.service: Main process exited, code=exited, status=143/n/a
homebridge.service: Failed with result 'exit-code'.

Configuration

{
    "bridge": {
        "name": "Homebridge",
        "username": "CC:22:3D:E3:CE:30",
        "port": 51826,
        "pin": "031-45-155",
        "advertiser": "ciao"
    },
    "description": "Homebridge on ananke",
    "ports": {
        "start": 52100,
        "end": 52250,
        "comment": "This section is used to control the range of ports that separate accessory (like camera or television) should be bind to."
    },
    "platforms": [
        {
            "name": "Config",
            "port": 8080,
            "auth": "none",
            "theme": "teal",
            "restart": "sudo -n systemctl restart homebridge",
            "sudo": true,
            "log": {
                "method": "systemd",
                "service": "homebridge"
            },
            "platform": "config"
        },
        {
            "name": "Alexa",
            "username": "dazzlee69",
            "password": "L3tm3Br1dge",
            "pin": "031-45-155",
            "debug": false,
            "refresh": 900,
            "keepalive": 5,
            "CloudTransport": "mqtts",
            "deviceListHandling": "none",
            "platform": "Alexa"
        },

... <other platforms removed> ...

}

Environment

Process Supervisor

hb-service

Additional Context

No response

dazzlee42 commented 7 months ago

Note, turning off debug, bypasses the code trying to open the file, so I'm back and working. Not sure what debug was giving me, would be good to get this working with debug and have the json files to review. Thanks

NorthernMan54 commented 7 months ago

That option is saving a copy of your configuration that was shared with Amazon alexa to aid in debugging a users setup. The file is written to the current directory from which homebridge was installed, and assumes that the directory is writable. Do you need debug enabled for something ?

dazzlee42 commented 7 months ago

Hi, not specifically, but I normally run with debug on, just in case. Was this changed, as it was not crashing before. Shouldn't it save to the config directory, where all the other plugins save to? Cheers