My extension will work for a while but then it needs to be re-enabled in the Roon setttings / Extensions to get it working again. I cannot explain why.
I do discovery and authorization a little differently:
discover = RoonDiscovery(None)
server = discover.first()
discover.stop()
apis = [RoonApi(app, None, server[0], server[1], False)]
auth_api = []
print("\nWaiting for authorization - in Roon, click Settings -> Extensions -> Enable\n", flush=True)
while len(auth_api) == 0:
auth_api = [api for api in apis if api.token is not None]
time.sleep(10)
api = auth_api[0]
for api in apis:
api.stop()
print("\nRoonCoreIP =", api.host)
print("RoonCorePort =", api._port)
# save the token for next time
with open(tokenfile, "w") as f:
f.write(str(api.token))
This attempts to locate all Roon cores but I only grab the first. You are also only getting the first but supplying a core id to disover. Is this because you have multiple cores or wish to support a deployment with multiple cores? Also, I am saving the returned token for future use and this token gets refreshed and saved on subsequent access. Anyway, this is how I am doing it.
I found that some roon clients - esp on Mac - respond to the server discovery packet - even though they are not cores.
So my discovery code gets all the clients that respond, asks all for authorisation, and notes which one gets authorised.
It then stores both the core id and the token, and then subsequent connect requests specify the core id, so they don’t get confused by the other responses.
Of course this also works if you do have multiple cores.