From 1f046fd593515232f0d57dc218d38eb6dba9d35f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 22 Feb 2021 03:05:16 -1000 Subject: [PATCH] Add access to the token endpoint (#7) If the fan or bridge has the power reset, the token is accessible for 10 minutes before the endpoint is locked. We can allow home assistant to setup the device without the user having to use the app to find the token by resetting the power to it. --- bond_api/bond.py | 4 ++++ tests/test_bond.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/bond_api/bond.py b/bond_api/bond.py index a103efe..74a868b 100644 --- a/bond_api/bond.py +++ b/bond_api/bond.py @@ -37,6 +37,10 @@ async def version(self) -> dict: """Return the version of hub/bridge reported by API.""" return await self.__get("/v2/sys/version") + async def token(self) -> dict: + """Return the token after power rest or proof of ownership event.""" + return await self.__get("/v2/token") + async def bridge(self) -> dict: """Return the name and location of the bridge.""" return await self.__get("/v2/bridge") diff --git a/tests/test_bond.py b/tests/test_bond.py index 0b9c2d5..99bc499 100644 --- a/tests/test_bond.py +++ b/tests/test_bond.py @@ -52,6 +52,18 @@ async def test_bridge(bond: Bond): assert actual == {"name": "name", "location": "location"} +@pytest.mark.asyncio +async def test_token(bond: Bond): + """Tests token API.""" + with aioresponses() as response: + response.get( + "http://test-host/v2/token", + payload={"locked": 0,"token": "8f514567acaf9869"} + ) + actual = await bond.token() + assert actual == {"locked": 0,"token": "8f514567acaf9869"} + + @pytest.mark.asyncio async def test_devices(bond: Bond): """Tests API to get a list of device IDs."""