Skip to content

Commit

Permalink
Add access to the token endpoint (#7)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bdraco authored Feb 22, 2021
1 parent 9bb8f3d commit 1f046fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bond_api/bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 12 additions & 0 deletions tests/test_bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 1f046fd

Please sign in to comment.