Skip to content

Gestalt Endpoint does not require a token #48

@StillTravelling

Description

@StillTravelling

I currently use my own flow to send realtime frames to my Twinkly devices . I have just got into the world of Home Assistant, however In Home Assistant just the discovery process flow for Twinkly devices on the network is causing my authentication tokens to become invalid. It took a number of hours to figure out what was going on, initially I had to capture the network traffic in Wireshark to figure out something else was making requests.

ttls/ttls/client.py

Lines 336 to 337 in a56530f

async def get_details(self) -> Any:
return self._valid_response(await self._get("gestalt"))

 async def get_details(self) -> Any:
        return self._valid_response(await self._get("gestalt"))

During the discovery process in Home Assistant it makes a call to this endpoint, but in my testing, it is not required to pass the X-Auth-Token to get the response. Is it possible to make an exception for gestalt endpoint so the below does not "ensure" the token?

ttls/ttls/client.py

Lines 240 to 266 in a56530f

async def _get(self, endpoint: str, **kwargs) -> Any:
await self.get_api_version()
await self.ensure_token()
_LOGGER.debug("GET endpoint %s", endpoint)
headers = kwargs.pop("headers", self._headers)
retry_num = kwargs.pop("retry_num", 0)
try:
async with self._get_session().get(
f"{self.base}/{endpoint}",
headers=headers,
timeout=self._timeout,
raise_for_status=True,
**kwargs,
) as r:
_LOGGER.debug("GET response %d", r.status)
return await r.json()
except ClientResponseError as e:
if e.status == HTTPUnauthorized.status_code:
return await self._handle_authorized(
self._get,
endpoint,
exception=e,
retry_num=retry_num,
**kwargs,
)
else:
raise e

async def _get(self, endpoint: str, **kwargs) -> Any:
        await self.get_api_version()
        await self.ensure_token()

For now I have had to add the twinkly devices into Home Assistant, but simply disable them. I think this has solved my issue with the tokens getting invalidated, but wondered if it might be best to change the above in case there are others in similar situations who were scratching their heads for a few hours trying to figure out what was going on. I also think it's probably best practice that there should only be authentication once the user has added the twinkly devices into Home Assistant as the current discovery process may also interfere with Twinkly's own application. For example, a user has just bought a twinkly device, setting it up in the Twinkly App (and maybe unaware there's a Twinkly integration in Home Assistant), but gets knocked off line due to the Home Assistant discovery process while trying to map the lights.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions