Supereg / homebridge-http-switch

Powerful http switch for Homebridge: https://github.com/homebridge/homebridge
ISC License
218 stars 36 forks source link

Stateful switch not retrieving status after Homebridge restart #46

Closed gioragen closed 4 years ago

gioragen commented 4 years ago

After restarting homebridge, the stateful http switch doesn't call to get its initial status, it gets status only when the switch is actively changed.

If the switch is on after restarting homebridge I would expect it to be initialized as "on".

I also tried to play with the "statusCache" option but it doesn't seem to fix it.

─ homebridge @ 0.4.52 ─ homebridge-http-switch @ 0.5.27

Configuration

{
            "accessory": "HTTP-SWITCH",
            "name": "Marantz",
            "switchType": "stateful",
            "debug": false,
            "pullInterval": 2000,
            "statusCache": -1,
            "onUrl": {
                "url": "http://10.0.0.6:8080/goform/AppCommand.xml",
                "method": "POST",
                "body": "<?xml version=\"1.0\" encoding=\"utf-8\" ?><tx><cmd id=\"1\">SetPower</cmd><zone>Main</zone><value>ON</value></tx>",
                "headers": {
                    "Content-Type": "application/xml"
                }
            },
            "offUrl": {
                "url": "http://10.0.0.6:8080/goform/AppCommand.xml",
                "method": "POST",
                "body": "<?xml version=\"1.0\" encoding=\"utf-8\" ?><tx><cmd id=\"1\">SetPower</cmd><zone>Main</zone><value>STANDBY</value></tx>",
                "headers": {
                    "Content-Type": "application/xml"
                }
            },
            "statusUrl": {
                "url": "http://10.0.0.6:8080/goform/AppCommand.xml",
                "method": "POST",
                "body": "<?xml version=\"1.0\" encoding=\"utf-8\" ?><tx><cmd id=\"1\">GetAllZonePowerStatus</cmd></tx>",
                "headers": {
                    "Content-Type": "application/xml"
                }
            },
            "statusPattern": ".*ON.*"
        }
Supereg commented 4 years ago

You use a status cache of infinity (-1). Meaning the status is never actually queried (is the equivalent of setting the switch to switchType: "toggle"). The default behavior would be, that the switch queries your http endpoint every time HomeKit queries the state of your switch. This includes also the first call (aka initial status).