Skip to content

Plugin should refresh access tokens after expiry

Expected Behavior

The plugin continues to display current energy usage after the initial JWT token (returned by Glowmarkt during setup) expires.

Current Behavior

After the initial JWT token expires (approximately 7 days after setup), the plugin fails to update the current energy usage and logs the following to HomeAssistant.

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/config/custom_components/hildebrandglow/sensor.py", line 15, in async_setup_entry
    resources = await glow.retrieve_resources()
  File "/config/custom_components/hildebrandglow/glow.py", line 43, in retrieve_resources
    raise InvalidAuth
custom_components.hildebrandglow.glow.InvalidAuth

Possible Solution

The plugin should detect an expired JWT token (either through direct inspection of the token or by analysing the replies from Glowmarkt) and request a new one using the credentials stored in the config entry.

Steps to Reproduce

  1. Set up the plugin
  2. Verify energy readings are being picked up
  3. Wait approximately 7 days
  4. Energy readings are no longer updated by the plugin