Trådfri identity shouldn't be hardcoded

0.57.0 adds support for the new tradfri firmware’s identity system. If you lose the identity token, the only way to re-add a trådfri gateway to homeassistant is currently a factory reset, which would lose all paired devices.

Using the psk on the back of the gateway and an identity string, you receive an identity token. You can only request a token for the same client identity once. This is problematic if the token is lost, the gateway changes IP addresses, or more than one home-assistant instance tries to access the trådfri gateway, for example if you’re a developer working on different branches.

If you try to register an identity again, the gateway will respond with ‘4.00 Bad Request’.

Feature request:

.tradfri_psk.conf doesn’t contain the psk (the key on the sticker on the gateway), and should really be named .tradfri_identity.conf. Calling the token inside of it key is confusing; it should really be called identity_token.

We can use any string we want as an identity. They should be generated on demand (uuid?), and saved to .tradfri_identity.conf if an identity token has successfully been retrieved:

{"": {"identity": "some-random-string", "key": "etaoinshrdlu"}}

If there’s no identity/token pair in the config file, or the gateway rejects a token, the user should be asked to enter the psk again in the frontend. .tradfri_identity.conf should only get overwritten if a token has successfully been retrieved.