neilpatel121 / homebridge-skyq-tvremote

Apache License 2.0
10 stars 3 forks source link

Power state is not maintained when box is controlled using remote #19

Closed benfysh closed 3 years ago

benfysh commented 3 years ago

Describe The Bug:

If you control a Sky Q box from the Home app and then using the remote then the power state in the app will get out of sync. This is reset if Homebridge is restarted.

To Reproduce:

  1. Switch on the box using the Home app
  2. Power state is Home app is shown as on
  3. Logs state [21/04/2021, 12:49:24] [skyq-tvremote] [Sky Q Mini] Get Active: ACTIVE
  4. System information endpoint shows "activeStandby" : false,
  5. Switch off the box using the remote
  6. Power state is Home app remains as on
  7. Logs state [21/04/2021, 12:55:31] [skyq-tvremote] [Sky Q Mini] Get Active: ACTIVE
  8. System information endpoint shows "activeStandby" : true,

You either have to power on the box using the remote or restart homebridge to reset the state otherwise when you switch it off in the home app it will actually switch on.

Note: If you switch the device on using the remote then the power state will remain as off in the Home until reset also.

Expected Behaviour:

The home app reflects the actual power state of the box as opposed to what was last triggered

Logs: N/A

Plugin Config:

        {
            "devices": [
                {
                    "name": "Sky Q",
                    "ipAddress": "192.168.6.223"
                },
                {
                    "name": "Sky Q Mini",
                    "ipAddress": "192.168.6.224"
                },
                {
                    "name": "Sky Q Mini 2",
                    "ipAddress": "192.168.6.225"
                }
            ],
            "platform": "skyq-tvremote"
        }

Screenshots: N/A

Environment:

SmolSoftBoi commented 3 years ago

Fixed, could you test 1.2.0-beta.2 please?

benfysh commented 3 years ago

getting this error:

[24/04/2021, 16:29:23] [skyq-tvremote] [Sky Q Mini 2] Perhaps looking at this error will help you figure out why
[24/04/2021, 16:29:23] [skyq-tvremote] TypeError: boxCheck.getPowerState is not a function
    at /usr/local/lib/node_modules/homebridge-skyq-tvremote/src/platform.ts:291:16
    at new Promise (<anonymous>)
    at SkyTVPlugin.getActive (/usr/local/lib/node_modules/homebridge-skyq-tvremote/src/platform.ts:290:12)
    at Active.<anonymous> (/usr/local/lib/node_modules/homebridge-skyq-tvremote/src/platform.ts:167:14)
    at Active.emit (events.js:315:20)
    at /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:1508:14
    at new Promise (<anonymous>)
    at Active.<anonymous> (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:1506:12)
    at step (/usr/local/lib/node_modules/homebridge/node_modules/tslib/tslib.js:143:27)
    at Object.next (/usr/local/lib/node_modules/homebridge/node_modules/tslib/tslib.js:124:57)
    at /usr/local/lib/node_modules/homebridge/node_modules/tslib/tslib.js:117:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/usr/local/lib/node_modules/homebridge/node_modules/tslib/tslib.js:113:16)
    at Active.Characteristic.handleGetRequest (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Characteristic.js:656:24)
    at Active.<anonymous> (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:2103:22)
    at step (/usr/local/lib/node_modules/homebridge/node_modules/tslib/tslib.js:143:27)
    at Object.next (/usr/local/lib/node_modules/homebridge/node_modules/tslib/tslib.js:124:57)
    at /usr/local/lib/node_modules/homebridge/node_modules/tslib/tslib.js:117:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/usr/local/lib/node_modules/homebridge/node_modules/tslib/tslib.js:113:16)
    at Active.Characteristic.toHAP (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/dist/lib/Characteristic.js:1293:24)
    at _loop_1 (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Service.ts:601:24)
SmolSoftBoi commented 3 years ago

Could you test 1.2.0-beta.3 please?

benfysh commented 3 years ago

No errors now and state is updating now. However only if you close and reopen the home app or lock and unlock your phone.

The logs may need tidying up a bit also as there is now an entry for 'Standby' and 'Active' for each box:

[24/04/2021, 22:21:03] [skyq-tvremote] [Sky Q Mini 2] The sky box is in standby
[24/04/2021, 22:21:03] [skyq-tvremote] [Sky Q Mini 2] Get Active: INACTIVE
[24/04/2021, 22:21:03] [skyq-tvremote] [Sky Q] The sky box is in standby
[24/04/2021, 22:21:03] [skyq-tvremote] [Sky Q] Get Active: INACTIVE
[24/04/2021, 22:21:03] [skyq-tvremote] [Sky Q Mini] Sky box is on
[24/04/2021, 22:21:03] [skyq-tvremote] [Sky Q Mini] Get Active: ACTIVE

Also an entry for 'BBC One Yorks' has appeared in the accessory so now it wont turn on and off with one tap and you need to tap on the tile and then the power button.

IMG_5E8A929E03C9-1

SmolSoftBoi commented 3 years ago

No errors now and state is updating now. However only if you close and reopen the home app or lock and unlock your phone.

To fix this, the power state is now automatically updated every 10 seconds.

The logs may need tidying up a bit also as there is now an entry for 'Standby' and 'Active' for each box:

Tidied up. 🧹

Also an entry for 'BBC One Yorks' has appeared in the accessory so now it wont turn on and off with one tap and you need to tap on the tile and then the power button.

This is related to #20 and is currently being tested. What iOS version are you using?

Could you test 1.2.0-beta.4?

benfysh commented 3 years ago

Great thanks now working as expected, and updates within 10 seconds. It may be worth updating the logs less frequently or only when the state changes as now its quite noisy :)

iOS version is 14.4.2

initially 'BBC One Yorks' was showing as an input on my boxes but doesn't seem to do anything. However I could then toggle on and off with one tap.

However after restarting homebridge it reverted to having the previous state shown in the comment above and the following is shown in the logs on startup. Killing and opening the home app seemed to revert it to showing as an input so not sure if it is related to the plugin or the home app …

(node:594) UnhandledPromiseRejectionWarning: Error: Cannot add a Service with the same UUID '000000D9-0000-1000-8000-0026BB765291' as another Service in this Accessory without also defining a unique 'subtype' property.
    at Accessory.addService (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:445:17)
    at PlatformAccessory.addService (/usr/local/lib/node_modules/homebridge/src/platformAccessory.ts:93:41)
    at /usr/local/lib/node_modules/homebridge-skyq-tvremote/src/platform.ts:152:42
    at Array.forEach (<anonymous>)
    at /usr/local/lib/node_modules/homebridge-skyq-tvremote/src/platform.ts:136:23
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:594) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:594) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:594) UnhandledPromiseRejectionWarning: Error: Cannot add a Service with the same UUID '000000D9-0000-1000-8000-0026BB765291' as another Service in this Accessory without also defining a unique 'subtype' property.
    at Accessory.addService (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:445:17)
    at PlatformAccessory.addService (/usr/local/lib/node_modules/homebridge/src/platformAccessory.ts:93:41)
    at /usr/local/lib/node_modules/homebridge-skyq-tvremote/src/platform.ts:152:42
    at Array.forEach (<anonymous>)
    at /usr/local/lib/node_modules/homebridge-skyq-tvremote/src/platform.ts:136:23
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:594) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:594) UnhandledPromiseRejectionWarning: Error: Cannot add a Service with the same UUID '000000D9-0000-1000-8000-0026BB765291' as another Service in this Accessory without also defining a unique 'subtype' property.
    at Accessory.addService (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Accessory.ts:445:17)
    at PlatformAccessory.addService (/usr/local/lib/node_modules/homebridge/src/platformAccessory.ts:93:41)
    at /usr/local/lib/node_modules/homebridge-skyq-tvremote/src/platform.ts:152:42
    at Array.forEach (<anonymous>)
    at /usr/local/lib/node_modules/homebridge-skyq-tvremote/src/platform.ts:136:23
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:594) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
SmolSoftBoi commented 3 years ago

Great thanks now working as expected, and updates within 10 seconds. It may be worth updating the logs less frequently or only when the state changes as now its quite noisy :)

We're not tracking the power state internally anymore, but only logging the update if debugging.

Could you test 1.2.0-beta.5 please?

benfysh commented 3 years ago

The logging is a lot less chatty now thanks.

The issue with the inputs not appearing after a restart and requiring the home app to be killed and reopened persists. There is also an error thrown if you select the input:

[25/04/2021, 12:20:22] [skyq-tvremote] [Sky Q Mini] Set Input: 101
[25/04/2021, 12:20:22] [homebridge-skyq-tvremote] This plugin threw an error from the characteristic 'Active Identifier': Unhandled error thrown inside write handler for characteristic: input.split is not a function or its return value is not iterable. See https://git.io/JtMGR for more info.
SmolSoftBoi commented 3 years ago

I'm moving the remaining issue to #20 and closing this issue.

SmolSoftBoi commented 3 years ago

Leaving open so I can close this when released.