Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Homebridge v2.0 Breaking Updates #146

Closed
mitch7391 opened this issue Jul 25, 2024 · 60 comments
Closed

[Feature Request] Homebridge v2.0 Breaking Updates #146

mitch7391 opened this issue Jul 25, 2024 · 60 comments
Assignees

Comments

@mitch7391
Copy link
Collaborator

Is your feature request related to a problem? Please describe:
Hey @ztalbot2000 I am not sure if you are aware but the next version of Homebridge (v2.0) comes with breaking changes for a lot of Homebridge plug-ins and it has been put on the developers to get in line and update to match.

For Plug-In Developers

I have tested Cmd4 on the beta version and it will crash Homebridge.

Describe the solution you'd like:
Please have a read of the link above and see what changes are required for Cmd4, this will ultimately affect my plug-in as well.

Describe alternatives you've considered:
All users of Cmd4 will have to remain on Homebridge v1.8.4.

Additional context:
image

@mitch7391
Copy link
Collaborator Author

Tagging @uswong as well to keep in the loop.

@ztalbot2000
Copy link
Owner

Hey Mitch,

Thanks for the heads up. Was your AdvAir impacted too? Would you happen to know if the changes required will be backward compatible?
I know they were mucking about with homebridge-ui but not with homebridge. Thanks for the heads up. I'll have a peek by tomorrow evening sometime.

ttyl,
John

@mitch7391
Copy link
Collaborator Author

Hey John, I think AdvAir will be affected through Cmd4, but I would need to find some time to figure out if AdvAir is affected separately. My testing was as simple as update Homebridge and see which plug-ins threw errors causing a reboot cycle; it is hard to test AdvAir this same way when Cmd4 is already doing it :)

Anyway, glad I gave you a heads up as I know you have a lot of people rely on your plug-in.

@mitch7391
Copy link
Collaborator Author

@ztalbot2000 I spent a bit more time trying to collect some logs for you and find some strange behaviour. It seems the plug-in will fail to initialise altogether, it then removes itself as a child bridge if it is one and then will refuse to load up again until a reboot of Homebridge is attempted. Trying to reboot the child bridge in the plug-ins tab does nothing (I think because it removes itself as a child bridge). This means it does not cause a Homebridge reboot seqeunce but does mean the plug-in fails.

[27/07/2024, 3:57:33 pm] Loaded plugin: [email protected]
[27/07/2024, 3:57:33 pm] ====================
[27/07/2024, 3:57:33 pm] ERROR INITIALIZING PLUGIN homebridge-cmd4:
[27/07/2024, 3:57:33 pm] TypeError: Cannot read properties of undefined (reading 'BOOL')
    at Object.init (/usr/local/lib/node_modules/homebridge-cmd4/lib/CMD4_CHAR_TYPE_ENUMS.js:61:44)
    at Plugin.default [as pluginInitializer] (/usr/local/lib/node_modules/homebridge-cmd4/index.js:41:44)
    at Plugin.initialize (/usr/local/lib/node_modules/homebridge/src/plugin.ts:244:17)
    at PluginManager.initializePlugin (/usr/local/lib/node_modules/homebridge/src/pluginManager.ts:173:20)
    at PluginManager.initializeInstalledPlugins (/usr/local/lib/node_modules/homebridge/src/pluginManager.ts:162:18)
    at Server.start (/usr/local/lib/node_modules/homebridge/src/server.ts:161:5)
[27/07/2024, 3:57:33 pm] ====================
[27/07/2024, 3:57:33 pm] ---

Let me know if you need me to collect more logs, but will suggest with the little spare time on my hands currently that you could spin up a Homebridge instance, install Cmd4, then upgrade Homebridge to the beta and see what happens.

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Jul 27, 2024 via email

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Jul 27, 2024 via email

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Jul 27, 2024 via email

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Jul 28, 2024 via email

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Jul 28, 2024 via email

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Jul 28, 2024 via email

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Jul 28, 2024 via email

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Jul 29, 2024 via email

@mitch7391
Copy link
Collaborator Author

mitch7391 commented Jul 29, 2024

Hey John, I can see you have been busy :) just installed the beta on Homebridge v1.8.4 to start with and have noticed it loads all my accessories but then removes them all; which is pretty annoying as I have to set them all up across Homekit again... Here are the logs just incase.

[29/07/2024, 1:14:46 pm] [Homebridge UI] Running Command: sudo -E -n npm install -g [email protected]
[29/07/2024, 1:16:41 pm] [Cmd4] Restarting child bridge...
[29/07/2024, 1:16:41 pm] Got SIGTERM, shutting down child bridge process...
[29/07/2024, 1:16:48 pm] [Cmd4] Child bridge process ended
[29/07/2024, 1:16:48 pm] [Cmd4] Process Ended. Code: 143, Signal: null
[29/07/2024, 1:16:55 pm] [Cmd4] Restarting Process...
[29/07/2024, 1:16:56 pm] [Cmd4] Launched child bridge with PID 17786
[29/07/2024, 1:16:56 pm] Registering accessory 'homebridge-cmd4.Cmd4'
[29/07/2024, 1:16:57 pm] Registering platform 'homebridge-cmd4.Cmd4'
[29/07/2024, 1:16:57 pm] [Cmd4] Loaded homebridge-cmd4 v8.0.0-beta.3 child bridge successfully
[29/07/2024, 1:16:57 pm] Loaded 16 cached accessories from cachedAccessories.0EF085EB9153.
[29/07/2024, 1:16:57 pm] [Cmd4] Cmd4Platform didFinishLaunching
[29/07/2024, 1:16:57 pm] [Cmd4] Restoring existing accessory from cache: Aircon
[29/07/2024, 1:17:21 pm] [Cmd4] Creating linked accessories for: Aircon
[29/07/2024, 1:17:21 pm] [Cmd4] Restoring existing accessory from cache: Aircon Fan
[29/07/2024, 1:17:21 pm] [Cmd4] Restoring existing accessory from cache: Aircon Timer
[29/07/2024, 1:17:21 pm] [Cmd4] Restoring existing accessory from cache: Living Room Zone
[29/07/2024, 1:17:21 pm] [Cmd4] Restoring existing accessory from cache: Theater Zone
[29/07/2024, 1:17:21 pm] [Cmd4] Restoring existing accessory from cache: Bedroom Zone
[29/07/2024, 1:17:21 pm] [Cmd4] Restoring existing accessory from cache: Craft Room Zone
[29/07/2024, 1:17:21 pm] [Cmd4] Restoring existing accessory from cache: Guest Room Zone
[29/07/2024, 1:17:21 pm] [Cmd4] Restoring existing accessory from cache: Nursery Zone
[29/07/2024, 1:17:21 pm] [Cmd4] Restoring existing accessory from cache: Living Room Temperature
[29/07/2024, 1:17:21 pm] [Cmd4] Restoring existing accessory from cache: Theater Temperature
[29/07/2024, 1:17:21 pm] [Cmd4] Restoring existing accessory from cache: Bedroom Temperature
[29/07/2024, 1:17:21 pm] [Cmd4] Restoring existing accessory from cache: Craft Room Temperature
[29/07/2024, 1:17:21 pm] [Cmd4] Restoring existing accessory from cache: Guest Room Temperature
[29/07/2024, 1:17:21 pm] [Cmd4] Restoring existing accessory from cache: Nursery Temperature
[29/07/2024, 1:17:21 pm] [Cmd4] Restoring existing accessory from cache: PS5
[29/07/2024, 1:17:21 pm] [Cmd4] Adding new platformAccessory: Hisense
[29/07/2024, 1:17:21 pm] [Cmd4] Configuring platformAccessory: Hisense
[29/07/2024, 1:17:21 pm] [Cmd4] Creating accessories for: Hisense
[29/07/2024, 1:17:21 pm] [Cmd4] Creating linked accessories for: Hisense
[29/07/2024, 1:17:21 pm] [Cmd4] Cmd4 is running in Demo Mode for TV
[29/07/2024, 1:17:21 pm] [Cmd4] Cmd4 is running in Demo Mode for HDMI1
[29/07/2024, 1:17:21 pm] [Cmd4] Cmd4 is running in Demo Mode for HDMI2
[29/07/2024, 1:17:21 pm] [Cmd4] Cmd4 is running in Demo Mode for HDMI3
[29/07/2024, 1:17:21 pm] [Cmd4] Cmd4 is running in Demo Mode for HDMI4
[29/07/2024, 1:17:21 pm] [Cmd4] Cmd4 is running in Demo Mode for AV
[29/07/2024, 1:17:21 pm] [Cmd4] Accessory Aircon will be removed.
[29/07/2024, 1:17:21 pm] [Cmd4] Accessory Aircon Fan will be removed.
[29/07/2024, 1:17:40 pm] [Cmd4] Accessory Aircon Timer will be removed.[29/07/2024, 1:18:35 pm] [Cmd4] Accessory Living Room Zone will be removed.
[29/07/2024, 1:18:36 pm] [Cmd4] Accessory Theater Zone will be removed.
[29/07/2024, 1:18:36 pm] [Cmd4] Accessory Bedroom Zone will be removed.
[29/07/2024, 1:18:36 pm] [Cmd4] Accessory Craft Room Zone will be removed.
[29/07/2024, 1:18:36 pm] [Cmd4] Accessory Guest Room Zone will be removed.
[29/07/2024, 1:18:36 pm] [Cmd4] Accessory Nursery Zone will be removed.
[29/07/2024, 1:18:36 pm] [Cmd4] Accessory Living Room Temperature will be removed.
[29/07/2024, 1:18:36 pm] [Cmd4] Accessory Theater Temperature will be removed.
[29/07/2024, 1:18:36 pm] [Cmd4] Accessory Bedroom Temperature will be removed.
[29/07/2024, 1:18:36 pm] [Cmd4] Accessory Craft Room Temperature will be removed.
[29/07/2024, 1:18:36 pm] [Cmd4] Accessory Guest Room Temperature will be removed.
[29/07/2024, 1:18:36 pm] [Cmd4] Accessory Nursery Temperature will be removed.
[29/07/2024, 1:18:36 pm] [Cmd4] Accessory PS5 will be removed.
[29/07/2024, 1:18:36 pm] Homebridge v1.8.4 (HAP v0.12.2) (Cmd4) is running on port 46526.
[29/07/2024, 1:18:36 pm] 

NOTICE TO USERS AND PLUGIN DEVELOPERS
> Homebridge 2.0 is on the way and brings some breaking changes to existing plugins.
> Please visit the following link to learn more about the changes and how to prepare:
> https://github.com/homebridge/homebridge/wiki/Updating-To-Homebridge-v2.0

[29/07/2024, 1:18:36 pm] Parent process did not respond to port allocation request within 5 seconds - assigning random port.
[29/07/2024, 1:18:36 pm] Hisense E7B5 is running on port XXXXX.
[29/07/2024, 1:18:36 pm] Please add [Hisense E7B5] manually in Home app. Setup Code: XXX-XX-XXX
[29/07/2024, 1:19:16 pm] [Cmd4] *** Starting Polling
[29/07/2024, 1:21:19 pm] [Cmd4] *** All characteristics are now being polled

I will try to get and test this on Homebridge v2 soon, just need to make sure I am prepared as it destroys my whole home and have to do a restore afterwards which takes a bit of time.

@mitch7391
Copy link
Collaborator Author

mitch7391 commented Jul 29, 2024

Hey John, looks like Cmd4 v8.0.0-beta.3 is working for me on Homebridge v2 and no more crashing:


[29/07/2024, 2:05:49 pm] [Cmd4] Restarting child bridge...
[29/07/2024, 2:05:49 pm] Got SIGTERM, shutting down child bridge process...
[29/07/2024, 2:05:54 pm] [Cmd4] Child bridge process ended
[29/07/2024, 2:05:54 pm] [Cmd4] Process Ended. Code: 143, Signal: null
[29/07/2024, 2:06:01 pm] [Cmd4] Restarting Process...
[29/07/2024, 2:06:02 pm] [Cmd4] Launched child bridge with PID 20796
[29/07/2024, 2:06:02 pm] Registering accessory 'homebridge-cmd4.Cmd4'
[29/07/2024, 2:06:02 pm] Registering platform 'homebridge-cmd4.Cmd4'
[29/07/2024, 2:06:02 pm] [Cmd4] Loaded homebridge-cmd4 v8.0.0-beta.3 child bridge successfully
[29/07/2024, 2:06:02 pm] Loaded 16 cached accessories from cachedAccessories.0EF085EB9153.
[29/07/2024, 2:06:02 pm] [Cmd4] Cmd4Platform didFinishLaunching
[29/07/2024, 2:06:02 pm] [Cmd4] Restoring existing accessory from cache: Aircon
[29/07/2024, 2:06:05 pm] [Cmd4] Creating linked accessories for: Aircon
[29/07/2024, 2:06:05 pm] [Cmd4] Restoring existing accessory from cache: Aircon Fan
[29/07/2024, 2:06:05 pm] [Cmd4] Restoring existing accessory from cache: Aircon Timer
[29/07/2024, 2:06:05 pm] [Cmd4] Restoring existing accessory from cache: Living Room Zone
[29/07/2024, 2:06:05 pm] [Cmd4] Restoring existing accessory from cache: Theater Zone
[29/07/2024, 2:06:05 pm] [Cmd4] Restoring existing accessory from cache: Bedroom Zone
[29/07/2024, 2:06:05 pm] [Cmd4] Restoring existing accessory from cache: Craft Room Zone
[29/07/2024, 2:06:05 pm] [Cmd4] Restoring existing accessory from cache: Guest Room Zone
[29/07/2024, 2:06:05 pm] [Cmd4] Restoring existing accessory from cache: Nursery Zone
[29/07/2024, 2:06:05 pm] [Cmd4] Restoring existing accessory from cache: Living Room Temperature
[29/07/2024, 2:06:05 pm] [Cmd4] Restoring existing accessory from cache: Theater Temperature
[29/07/2024, 2:06:05 pm] [Cmd4] Restoring existing accessory from cache: Bedroom Temperature
[29/07/2024, 2:06:05 pm] [Cmd4] Restoring existing accessory from cache: Craft Room Temperature
[29/07/2024, 2:06:05 pm] [Cmd4] Restoring existing accessory from cache: Guest Room Temperature
[29/07/2024, 2:06:05 pm] [Cmd4] Restoring existing accessory from cache: Nursery Temperature
[29/07/2024, 2:06:05 pm] [Cmd4] Restoring existing accessory from cache: PS5
[29/07/2024, 2:06:05 pm] [Cmd4] Adding new platformAccessory: Hisense
[29/07/2024, 2:06:05 pm] [Cmd4] Configuring platformAccessory: Hisense
[29/07/2024, 2:06:05 pm] [Cmd4] Creating accessories for: Hisense
[29/07/2024, 2:06:05 pm] [Cmd4] Creating linked accessories for: Hisense
[29/07/2024, 2:06:05 pm] [Cmd4] Cmd4 is running in Demo Mode for TV
[29/07/2024, 2:06:05 pm] [Cmd4] Cmd4 is running in Demo Mode for HDMI1
[29/07/2024, 2:06:05 pm] [Cmd4] Cmd4 is running in Demo Mode for HDMI2
[29/07/2024, 2:06:05 pm] [Cmd4] Cmd4 is running in Demo Mode for HDMI3
[29/07/2024, 2:06:05 pm] [Cmd4] Cmd4 is running in Demo Mode for HDMI4
[29/07/2024, 2:06:05 pm] [Cmd4] Cmd4 is running in Demo Mode for AV
HAP-NodeJS WARNING: The accessory 'My_TelevisionSpeaker' has an invalid 'Name' characteristic ('My_TelevisionSpeaker'). Please use only alphanumeric, space, and apostrophe characters. Ensure it starts and ends with an alphabetic or numeric character, and avoid emojis. This may prevent the accessory from being added in the Home App or cause unresponsiveness.
[29/07/2024, 2:06:05 pm] [Cmd4] Accessory Aircon will be removed.
[29/07/2024, 2:06:05 pm] [Cmd4] Accessory Aircon Fan will be removed.
[29/07/2024, 2:06:05 pm] [Cmd4] Accessory Aircon Timer will be removed.
[29/07/2024, 2:06:05 pm] [Cmd4] Accessory Living Room Zone will be removed.
[29/07/2024, 2:06:05 pm] [Cmd4] Accessory Theater Zone will be removed.
[29/07/2024, 2:06:05 pm] [Cmd4] Accessory Bedroom Zone will be removed.
[29/07/2024, 2:06:05 pm] [Cmd4] Accessory Craft Room Zone will be removed.
[29/07/2024, 2:06:05 pm] [Cmd4] Accessory Guest Room Zone will be removed.
[29/07/2024, 2:06:05 pm] [Cmd4] Accessory Nursery Zone will be removed.
[29/07/2024, 2:06:05 pm] [Cmd4] Accessory Living Room Temperature will be removed.
[29/07/2024, 2:06:05 pm] [Cmd4] Accessory Theater Temperature will be removed.
[29/07/2024, 2:06:05 pm] [Cmd4] Accessory Bedroom Temperature will be removed.
[29/07/2024, 2:06:06 pm] [Cmd4] Accessory Craft Room Temperature will be removed.
[29/07/2024, 2:06:06 pm] [Cmd4] Accessory Guest Room Temperature will be removed.
[29/07/2024, 2:06:06 pm] [Cmd4] Accessory Nursery Temperature will be removed.
[29/07/2024, 2:06:06 pm] [Cmd4] Accessory PS5 will be removed.
[29/07/2024, 2:06:06 pm] Homebridge v1.8.5-beta.4 (HAP v0.12.3-beta.26) (Cmd4) is running on port 46526.
[29/07/2024, 2:06:06 pm] 

NOTICE TO USERS AND PLUGIN DEVELOPERS
> Homebridge 2.0 is on the way and brings some breaking changes to existing plugins.
> Please visit the following link to learn more about the changes and how to prepare:
> https://github.com/homebridge/homebridge/wiki/Updating-To-Homebridge-v2.0

[29/07/2024, 2:06:06 pm] Hisense E7B5 is running on port XXXXX.
[29/07/2024, 2:06:06 pm] Please add [Hisense E7B5] manually in Home app. Setup Code: XXX-XX-XXX
[29/07/2024, 2:06:46 pm] [Cmd4] *** Starting Polling
[29/07/2024, 2:08:49 pm] [Cmd4] *** All characteristics are now being polled

The only thing it complains about is the following:

HAP-NodeJS WARNING: The accessory 'My_TelevisionSpeaker' has an invalid 'Name' characteristic ('My_TelevisionSpeaker'). Please use only alphanumeric, space, and apostrophe characters. Ensure it starts and ends with an alphabetic or numeric character, and avoid emojis. This may prevent the accessory from being added in the Home App or cause unresponsiveness.

Is there an easy way for you to set up all services/charateristics and see which ones complain? As it stands this works perfectly for my AdvAir plug-in, but others might still have warnings like I do for my Hisense TV setup through your plug-in.

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Jul 29, 2024 via email

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Jul 29, 2024 via email

@mitch7391
Copy link
Collaborator Author

Hey John, can’t see a beta 4 in your releases, I have only tested beta 3 and it works, only issue is how it removes all my accessories and re-adds them…

@mitch7391
Copy link
Collaborator Author

As for the My_TelevisionSpeaker, you have to remove the underscore
character "_" in the name.

I can see that in my config now as something have I defined (probably copied from your sample config but never changed myself). Didn’t notice this, sorry haha my brain has turned to mush since having the twins…

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Jul 29, 2024 via email

@mitch7391
Copy link
Collaborator Author

I can’t speak for all your users but I would say your changes fix things for my users :) or at least it does for my setup…

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Jul 29, 2024 via email

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Jul 29, 2024 via email

@mitch7391
Copy link
Collaborator Author

Hey John, will give beta 5 a go tomorrow. It kept failing to update for me today, which I have had happen in the past with other plugins and a physical reboot of my RPi fixed it. I was busy testing some other stuff on my RPi today and did not want to have to reboot it just yet; sorry for the hold up!

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Jul 30, 2024 via email

@mitch7391
Copy link
Collaborator Author

mitch7391 commented Jul 31, 2024

Hey John, just tried the your beta 6 on on Homebridge latest and looks all good. I am about to test on the Homebridge beta but have just now noticed they also have an alpha, which version of theirs should I be testing this on, v1.8.5-beta.5 or v2.0.0-alpha.3?

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Jul 31, 2024 via email

@mitch7391
Copy link
Collaborator Author

mitch7391 commented Jul 31, 2024

Hey John, my plugin homebridge-cmd4-advantageair greatly depends on your plugin still. Any discussions and work with Ung Sing about adopting Cmd4 into AdvAir has not been applied to my plugin, he has adapted it into his own stand alone plugin. Myself and my users will still rely heavily on your good work here :)

@mitch7391
Copy link
Collaborator Author

I also don’t understand which is supposed to be the more updated version of theirs, the alpha or the beta?

@ddong3000
Copy link

hey this ploblem also to me.
after homebridge restart or container restart my accessories was disappear at v8.0.0.
and the childe bridge was set unintentionally.
so i was back to the v7.1.0.
plz check for us.

@uswong
Copy link

uswong commented Aug 7, 2024

Hi John,

As far as I can understand, what the users have been experiencing is due to the fact that the updateReachability (deprecated on Homebridge_v2) was removed on Cmd4 v8.0.0, as such, the accesssory.reachable on line 126 of Cmd5Platform.js becomes undefined when run with Homebridge_v2 or False when run with Homebridge_v1.8.4. In both cases, the restored accessory will all be removed as per code block between lines 126-128.

In place of updateReachability, I experimented with storing the UUID of all processed accessories, which may include all or some of the accessories restored from cache, in a JSON array:

image

then use that JSON array to check which accessories were NOT restored and need to be deleted.

image

I know this seems like a band aid solution and probably a kludge, but it worked! In any case, I just want to share with you what I did in my spare time for your reference.

@uswong
Copy link

uswong commented Aug 7, 2024

My edited version of Cmd4Platform.js can be found here for your reference:
https://github.com/uswong/homebridge-cmd4/blob/master/Cmd4Platform.js

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Aug 8, 2024 via email

@uswong
Copy link

uswong commented Aug 12, 2024

Hey John,

My third attempt to resolve the unintended removal of restored accessories.

Since updateReachability() function and the key reachable are deprecated on Homebridge_v2, we just need to define the key reachable and set it to true for the accessory restored from cache. Just need one addition line of code in Cmd4Platform.js:

Screen Shot 2024-08-12 at 10 55 39 pm

This worked well.

Cheers,
Ung Sing

@uswong
Copy link

uswong commented Aug 13, 2024

The modified Cmd4Platform.js with that one additional line of code can be found in:

https://github.com/uswong/homebridge-cmd4/blob/master/Cmd4Platform.js

@mitch7391, would you please test this out on your system if you have a moment. Thanks.

@mitch7391
Copy link
Collaborator Author

Thanks Ung Sing, will try to take a look tonight or tomorrow night; we have family from Tassie over to see the twins at the moment :)

@mitch7391
Copy link
Collaborator Author

@uswong just gave your fix a go and it works for me. We may just need to check if hardcoding a 'true' is something we should permanently do (is there a time where it needs to read a 'false'?). I will keep the changes in for the time being to monitor and see what John comes back with. Going to re-open this issue seen as it is still an issue.

@mitch7391 mitch7391 reopened this Aug 15, 2024
@uswong
Copy link

uswong commented Aug 15, 2024

Hey @mitch7391, the added line of code existingAccessory.reachable = true in Cmd4Platform.js is just to replace the deprecated updateReachability( ture ) . So, it does not do anything more than before.

existingAccessory.reachable is always false with homebridge v1.8 and always undefined with homebridge v2.0 until we set it to true. If it is not set to true, all restored accessories will be removed. The function updateReachability( true ) was used to set it to true with homebridge v1.8 but that function was deprecated with hombridge v2.0. Therefore we need to set it to true explicitly with homebridge v2.0. And that is what the proposed fix does.

Hope John can have a moment to have a look at this proposed fix soon. It certainly looks like there are quite a few people having this issue.

@mitch7391
Copy link
Collaborator Author

Good point Ung Sing, I had looked over the commit change (the before vs after) but a tired brain did not let that sink in properly! Sounds like a win to me, let’s see what John says when he has a moment.

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Aug 15, 2024 via email

@uswong
Copy link

uswong commented Aug 15, 2024

Hi John,

if you run Cmd4 the third time, you will see the removing accessory message again.... It does not matter you run Cmd4 in Homebridge 1.8 or 2.0, the behavior is the same.

If the accessory is restored from cache, it will always be removed, then the 2nd Cmd4 run will re-create the accessory, then the 3rd run will restore the accessory from cache and immediately will be removed again, and this cycle of Restoring-Removing-Recreating-Restoring-Removing will go on and on....

This behavior persists because the key reachable is either false (with homebrige 1.8) or undefined (with homebridge 2.0). One way to break this behavior is to set the key reachable to true if the accessory is restored from cache. And this can be achieved by inserting a line of code after line 474 in Cmd4Platform.js:
existingAccessory.reachable = true;

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Aug 15, 2024 via email

@uswong
Copy link

uswong commented Aug 15, 2024 via email

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Aug 15, 2024 via email

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Aug 15, 2024 via email

@uswong
Copy link

uswong commented Aug 16, 2024

...they did deprecate it but if their template does not handle accessories being restored properly, then all plugins will have this issue and they have a problem.

Hey John,

Their latest homebridge template does not include any logic for the removable of existing accessory from cache, it is up to the plugin developer to code the logic.

Your existing logic in Cmd4Platform.js is if ( ! accessory.reachable ) then remove the existing accessory from cache. By default reachable is false or undefined. As such, we have to define reachable and set it to true if that accessory is restored from cache and we do not want it to be removed.

My proposed fix is to add a line of code existingAccessory.reachable = true; after line 474 in Cmd4Platform.js.

It works beautifully. Please test it out for yourself.

You can find my modified version of Cmd4Platform.js here:
https://github.com/uswong/homebridge-cmd4/blob/master/Cmd4Platform.js)

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Aug 16, 2024 via email

@uswong
Copy link

uswong commented Aug 16, 2024

Hi John,

Apparently, there is already an issue raised requesting a template on how to remove accessory from cache but homebridge hasn't replied for 2.5 months: homebridge/homebridge-plugin-template#73

In any case, I think it is worthwhile to have a temporary solution for now for your many Cmd4 users.

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Aug 16, 2024 via email

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Aug 16, 2024 via email

@ztalbot2000
Copy link
Owner

Closed with homebridge-cmd4 v8.0.1
It was no longer necessary to remove old cached accessories that are not in your config.json as they never get re-allocated. Unfortunately this made it look like current accessories were added and removed.

ttyl,
John Talbot

@mitch7391
Copy link
Collaborator Author

mitch7391 commented Aug 17, 2024

Hey John, been a hectic few days for us with the twins and family staying; just catching up now…

Their latest homebridge template does not include any logic for the removable of existing accessory from cache, it is up to the plugin developer to code the logic.

Ung Sing is completely right here, this is an area of your platform.ts file (if you are using the Homebridge template) where the developer needs to handle the discovery, adding and removing of existing accessories; at the developer’s discretion they can choose to do absolutely nothing here but at the cost of the functionality.

In your latest version the platform does not remove accessories from the cache and therefore leaves them there as accessories in HomeKit showing ‘no response’, you are then placing it on the user to go to Homebridge settings and individually remove these no longer required accessories using the ‘remove single cached accessory’ option.

I do believe if you do not know of a better solution than what Ung Sing has presented, I do think we should go ahead with his proposed solution; as it does work as your plugin used to do before the Homebridge v2 change requirements.

@mitch7391
Copy link
Collaborator Author

@ztalbot2000 just checking in on you and to let you know this is still an issue...

@mitch7391
Copy link
Collaborator Author

Hey @ztalbot2000 just checking in again :)

@ztalbot2000
Copy link
Owner

ztalbot2000 commented Oct 18, 2024 via email

@mitch7391
Copy link
Collaborator Author

Hey John, this is not an issue Homebridge are going to fix... Have a look here at the Homebridge Template Plugin platform.ts file Line 34 onward. It is on the plugin developer to create the accessory discovery, adding and removing of accessories; Homebridge itself is only going to handle the caching of these accessories after the fact.

All of my plugin users and all Cmd4 users will be experiencing the issue I described above if they are trialing the Homebridge v2 beta or once Homebridge release it properly:

In your latest version the platform does not remove accessories from the cache and therefore leaves them there as accessories in HomeKit showing ‘no response’, you are then placing it on the user to go to Homebridge settings and individually remove these no longer required accessories using the ‘remove single cached accessory’ option.

I have had to manually apply Ung Sing's fix way back when he suggested it and avoid updating any further so I do not blow it away. This will be a ticking time bomb for when Homebridge roll out the update and I can guarantee I will have users submit an issue for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants