Skip to content

getLoginInfo broken: sso.hivehome.com now uses single-quoted window.HiveSSO* values (JSON decode error at char 19) #181

Open

Description

@domgiles

Summary

HiveApi.getLoginInfo() can no longer parse the config embedded in https://sso.hivehome.com/, so every Home Assistant setup or reload of the Hive integration fails. This is persistent, not transient: sso.hivehome.com returns HTTP 200 from inside the HA container, the Hive mobile app works normally, and repeated reloads fail identically.

Root cause

getLoginInfo turns the first <script> into JSON with string replacements, which assumes the old single-line format (window.HiveSSOPoolId="...",window...):

json_data = json.loads(
    '{"'
    + (html("script:first").text())
    .replace(",", ', "')
    .replace("=", '":')
    .replace("window.", "")
    + "}"
)

The page now uses separate statements, with spaces around = and single-quoted values:

window.HiveSSOPoolId = 'eu-west-1_SamNfoWtf'
window.HiveSSOCognitoClientId = 'jivhemv3fvn8cr32qrggqpcf8'
window.HiveSSOPublicCognitoClientId = '3rl4i0ajrmtdm8sbre54p9dvd9'
window.HiveSSOState = '%%STATE%%'

The first line becomes {"HiveSSOPoolId ": 'eu-west-1..., which is invalid JSON at character 19, exactly the reported Expecting value: line 1 column 20 (char 19). getLoginInfo then logs the error and returns None, so async_init fails with AttributeError: 'NoneType' object has no attribute 'get' on self.data.get("UPID").

Tested fix

Replacing the PyQuery / json.loads block with a regex that accepts either quote style and any spacing fixed it on a live account. The integration loads and all entities return:

import re as _re
json_data = dict(
    _re.findall(r"window\.(\w+)\s*=\s*[\"']([^\"']*)[\"']", data.text)
)

The rest of the function (the UPID / CLIID / REGION mapping and the exception handling) is unchanged, and KeyError is still raised if a key ever goes missing. PyQuery is no longer needed in this function.

It may also be worth raising a typed exception, rather than returning None, when parsing fails, so that callers can tell a parse failure from a configuration problem.

Environment

  • Home Assistant: 2026.10.0 (Container, aarch64, Raspberry Pi 5)
  • Python: 3.14.6
  • pyhive-integration: unknown

Logs

ERROR [apyhiveapi.api.hive_api] Failed to get login info: Expecting value: line 1 column 20 (char 19)
ERROR [apyhiveapi.api.hive_api] API error occurred - returning error response
ERROR [homeassistant.config_entries] Error setting up entry <redacted> for hive
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/hive/__init__.py", line 40, in async_setup_entry
    devices = await hive.session.startSession(hive_config)
  File "/usr/local/lib/python3.14/site-packages/apyhiveapi/session.py", line 853, in startSession
    await self.getDevices("No_ID")
  File "/usr/local/lib/python3.14/site-packages/apyhiveapi/session.py", line 698, in getDevices
    await self.hiveRefreshTokens()
  File "/usr/local/lib/python3.14/site-packages/apyhiveapi/session.py", line 528, in hiveRefreshTokens
    result = await self.auth.refresh_token(
  File "/usr/local/lib/python3.14/site-packages/apyhiveapi/api/hive_auth_async.py", line 612, in refresh_token
    await self.async_init()
  File "/usr/local/lib/python3.14/site-packages/apyhiveapi/api/hive_auth_async.py", line 110, in async_init
    self.__pool_id = self.data.get("UPID")
AttributeError: 'NoneType' object has no attribute 'get'

Reproduce

docker exec homeassistant python3 -c "import requests;t=requests.get('https://sso.hivehome.com/',timeout=10).text;print([l.strip()[:200] for l in t.splitlines() if 'HiveSSO' in l][:5])"

Related: home-assistant/core#182752 (the same setup path, triggered there by a timeout rather than a parse failure).

Activity

  1. domgiles commented on Oct 21, 2026

    @domgiles
    Author

    Issue and suggested fix tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions