ztalbot2000 / homebridge-cmd4

CMD4 Plugin for Homebridge - Supports ~All Accessory Types & now all Characteristics too
Apache License 2.0
145 stars 14 forks source link

[Bug] Cmd4_Mode: "Always" is caching #102

Closed tomasvitek closed 3 years ago

tomasvitek commented 3 years ago

After updating to v3.4.0 my cmd4 setup has broken. All devices seem to be cached and both Set or Get never reach the device.

Describe The Bug:

Before this version, I had my cmd4 set to "restartRecover": false and "fetch": "Always", and for each item I had it set to "polling": true. When updating to v3.4.0, I have replaced the "fetch" setting in the cmd4 platform settings with Cmd4_Mode: "Always" and added Cmd4_Mode: "Always" to every device.

Whenever I changed a switch's state in Home app, the Homebridge UI logs would show

And when looking as logs for the script that is meant to run, it was not run.

To try to debug it, I deleted accessories and persist (and readded everything homebridge related, incl. automations). To be honest it is quite a pain. (Unrelated suggestion to this bug -- is there maybe some way to store the cmd4 cache separately, so that one doesn't have to hose their whole homebridge setup to debug cmd4?). But it did not work anyway.

I have reverted back to v 3.3.2 and it works again, so will just wait with an update until this is fixed.

To Reproduce:

See below for a config.json snippet. If the problem is in my config, then I apologise. But the docs are a bit confusing, so wasn't exactly certain how to update the config other than what I did.

Expected Behaviour: No caching. Ever. The device (the script) is pinged whenever a Set or Get is performed.

Paste of Logs:

Mar 26 16:39:45 Kryten homebridge.sh[864]: [3/26/2021, 4:39:45 PM] [Cmd4] Setting (Cached) update_tv On true

Cmd4 Config:

{
            "platform": "Cmd4",
            "name": "Cmd4",
            "outputConstants": false,
            "restartRecover": false,
            "Cmd4_Mode": "Always",
            "accessories": [
                {
                    "type": "Switch",
                    "displayName": "update_tv",
                    "name": "Update TV",
                    "on": false,
                    "polling": true,
                    "Cmd4_Mode": "Always",
                    "stateChangeResponseTime": 1,
                    "state_cmd_prefix": "/homebridge/forward.sh",
                    "state_cmd": "/data/.setup/homebridge/accessories/switch.sh"
                }
            ]
}

Environment:

If there is anything else I can do to help to debug, let me know.

Thank you! 🙂

ztalbot2000 commented 3 years ago

Hi,

That is really weird. I will check into it for sure. The change was not really anything more than adding to an "if" clause the new FullyPolled and a variable name change for "cached". There should have been no affect to Always.

If you play with Homebridge-config-UI-x, it allows you to delete specific cached accessory information. Homebridge, does the caching, not me. I just tell it what to cache.

ttyl, John

On Fri, Mar 26, 2021 at 12:21 PM Tomáš Vítek @.***> wrote:

After updating to v3.4.0 my cmd4 setup has broken. All devices seem to be cached and both Set or Get never reach the device.

Describe The Bug:

Before this version, I had my cmd4 set to "restartRecover": false and "fetch": "Always", and for each item I had it set to "polling": true. When updating to v3.4.0, I have replaced the "fetch" setting in the cmd4 platform settings with Cmd4_Mode: "Always" and added Cmd4_Mode: "Always" to every device.

Whenever I changed a switch's state in Home app, the Homebridge UI logs would show

  • Setting (Cached) DEVICE On true

And when looking as logs for the script that is meant to run, it was not run.

To try to debug it, I deleted accessories and persist (and readded everything homebridge related, incl. automations). To be honest it is quite a pain. (Unrelated suggestion to this bug -- is there maybe some way to store the cmd4 cache separately, so that one doesn't have to hose their whole homebridge setup to debug cmd4?). But it did not work anyway.

I have reverted back to v 3.3.2 and it works again, so will just wait with an update until this is fixed.

To Reproduce:

See below for a config.json snippet. If the problem is in my config, then I apologise. But the docs are a bit confusing, so wasn't exactly certain how to update the config other than what I did.

Expected Behaviour: No caching. Ever. The device (the script) is pinged whenever a Set or Get is performed.

Paste of Logs:

Mar 26 16:39:45 Kryten homebridge.sh[864]: [3/26/2021, 4:39:45 PM] [Cmd4] Setting (Cached) update_tv On true

Cmd4 Config:

{

        "platform": "Cmd4",

        "name": "Cmd4",

        "outputConstants": false,

        "restartRecover": false,

        "Cmd4_Mode": "Always",

        "accessories": [

            {

                "type": "Switch",

                "displayName": "update_tv",

                "name": "Update TV",

                "on": false,

                "polling": true,

                "Cmd4_Mode": "Always",

                "stateChangeResponseTime": 1,

                "state_cmd_prefix": "/homebridge/forward.sh",

                "state_cmd": "/data/.setup/homebridge/accessories/switch.sh"

            }

        ]

}

Environment:

  • Node.js Version: v14.16.0
  • NPM Version: 6.14.11
  • Homebridge Version: 1.3.4
  • homebridge-cmd4 Version: v3.4.0
  • Operating System: Debian
  • Process Supervisor: Docker

If there is anything else I can do to help to debug, let me know.

Thank you! 🙂

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/102, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX3K6GQLREJOT4J5AQ3TFSYCLANCNFSM4Z3WC3PQ .

tomasvitek commented 3 years ago

Hi!

Thanks for the reply. I am not sure what is happening either. Maybe my config is wrong?

I see, thank you for the info that it is possible to delete specific cache from Homebridge-config-UI-X. Very good to know. Sorry if my initial bug report seemed a bi too harsh, I was just frustrated that I had to redo my automations and Home setup. 😀

ztalbot2000 commented 3 years ago

Hi,

So I first looked through the code. For "Always" it is really only parsed for an option and as the default is never checked again. I therefore did not see anything wrong. I then created an accessory like the specs you said and ran a test. I found that Get was to the device, but my Set was to cached as you indicated. Something is funny. I am looking further into the issue.

ttfn, John

On Fri, Mar 26, 2021 at 12:59 PM Tomáš Vítek @.***> wrote:

Hi!

Thanks for the reply. I am not sure what is happening either. Maybe my config is wrong?

I see, thank you for the info that it is possible to delete specific cache from Homebridge-config-UI-X. Very good to know. Sorry if my initial bug report seemed a bi too harsh, I was just frustrated that I had to redo my automations and Home setup. 😀

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/102#issuecomment-808372655, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX6JEFLUWWN5GL52OGTTFS4OZANCNFSM4Z3WC3PQ .

tomasvitek commented 3 years ago

Thank you for looking into it! 👍🏻

ztalbot2000 commented 3 years ago

Hi, Fixed with update b7ff2f68 and Cmd4 v3.4.1 is the result. The if statement got a little long. As noted "Always" was not even in the condition, but the condition missed the new comparator, making the statement truthful for setCachedValue.

Sorry for that. We at least both learned something ;-)

tomasvitek commented 3 years ago

Not at all! Thank you for the fix and for fixing it so quickly! I really appreciate it. Anywhere I can tip you for a coffee maybe? 🙂 Have a nice weekend!

btw Just tested it and all work as expected now! 👍🏻