Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions custom_components/hive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@

from aiohttp.web_exceptions import HTTPException
from apyhiveapi import Auth, Hive
from apyhiveapi.helper.hive_exceptions import HiveReauthRequired
from apyhiveapi.helper.hive_exceptions import (
HiveConnectionError,
HiveReauthRequired,
HiveUnknownConfiguration,
)

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_SCAN_INTERVAL
Expand Down Expand Up @@ -43,7 +47,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: HiveConfigEntry) -> bool
except HTTPException as error:
_LOGGER.error("Could not connect to the internet: %s", error)
raise ConfigEntryNotReady from error
except HiveReauthRequired as err:
except HiveConnectionError as error:
_LOGGER.error("Could not fetch devices from Hive: %s", error)
raise ConfigEntryNotReady from error
except (HiveReauthRequired, HiveUnknownConfiguration) as err:
raise ConfigEntryAuthFailed from err

device_registry = dr.async_get(hass)
Expand Down Expand Up @@ -89,13 +96,13 @@ async def async_remove_config_entry_device(
return True


def refresh_system[_HiveEntityT: HiveEntity, **_P](
func: Callable[Concatenate[_HiveEntityT, _P], Awaitable[Any]],
) -> Callable[Concatenate[_HiveEntityT, _P], Coroutine[Any, Any, None]]:
def refresh_system[HiveEntityT: HiveEntity, **P](
func: Callable[Concatenate[HiveEntityT, P], Awaitable[Any]],
) -> Callable[Concatenate[HiveEntityT, P], Coroutine[Any, Any, None]]:
"""Force update all entities after state change."""

@wraps(func)
async def wrapper(self: _HiveEntityT, *args: _P.args, **kwargs: _P.kwargs) -> None:
async def wrapper(self: HiveEntityT, *args: P.args, **kwargs: P.kwargs) -> None:
await func(self, *args, **kwargs)
async_dispatcher_send(self.hass, DOMAIN)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/hive/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from homeassistant.components.hive.binary_sensor import *
from homeassistant.components.hive.binary_sensor import *
2 changes: 1 addition & 1 deletion custom_components/hive/climate.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from homeassistant.components.hive.climate import *
from homeassistant.components.hive.climate import *
25 changes: 19 additions & 6 deletions custom_components/hive/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from collections.abc import Mapping
import copy
import logging
from typing import Any

from apyhiveapi import Auth
Expand All @@ -23,7 +24,6 @@
)
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
from homeassistant.core import callback
import logging

from . import HiveConfigEntry
from .const import (
Expand Down Expand Up @@ -52,7 +52,10 @@ def _walk(node: Any) -> Any:
result: dict[str, Any] = {}
for key, value in node.items():
key_lower = key.lower()
if any(part in key_lower for part in ("password", "token", "secret", "code", "session")):
if any(
part in key_lower
for part in ("password", "token", "secret", "code", "session")
):
result[key] = _mask(value)
else:
result[key] = _walk(value)
Expand Down Expand Up @@ -128,18 +131,28 @@ async def async_step_user(
auth_result = self.tokens.get("AuthenticationResult", {})
new_device = auth_result.get("NewDeviceMetadata") or {}
access_token = auth_result.get("AccessToken")
if new_device.get("DeviceGroupKey") and new_device.get("DeviceKey") and access_token:
if (
new_device.get("DeviceGroupKey")
and new_device.get("DeviceKey")
and access_token
):
# If Hive returned fresh device metadata directly from login, register it now
# so fallback device auth works when refresh tokens expire.
self.hive_auth.access_token = access_token
self.hive_auth.device_group_key = new_device["DeviceGroupKey"]
self.hive_auth.device_key = new_device["DeviceKey"]
try:
await self.hive_auth.device_registration(self.device_name)
self.data["device_data"] = await self.hive_auth.get_device_data()
_LOGGER.debug("Stored Hive device_data from login NewDeviceMetadata.")
self.data[
"device_data"
] = await self.hive_auth.get_device_data()
_LOGGER.debug(
"Stored Hive device_data from login NewDeviceMetadata."
)
except HiveApiError:
_LOGGER.warning("Hive device registration failed after login; continuing without device_data.")
_LOGGER.warning(
"Hive device registration failed after login; continuing without device_data."
)

try:
return await self.async_setup_hive_entry()
Expand Down
1 change: 1 addition & 0 deletions custom_components/hive/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Constants for Hive."""

from homeassistant.const import Platform

ATTR_MODE = "mode"
Expand Down
4 changes: 2 additions & 2 deletions custom_components/hive/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/Pyhass/Hive-Custom-Component/issues",
"loggers": ["apyhiveapi"],
"requirements": ["pyhive-integration==1.0.10"],
"version": "2026.10.1b2"
"requirements": ["pyhive-integration==2.0.0b5"],
"version": "2026.11.0b1"
}
4 changes: 2 additions & 2 deletions custom_components/hive/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from datetime import timedelta
from typing import Any

from apyhiveapi import Hive

from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
Expand All @@ -23,13 +25,11 @@

from . import HiveConfigEntry
from .entity import HiveEntity
from apyhiveapi import Hive

PARALLEL_UPDATES = 0
SCAN_INTERVAL = timedelta(seconds=15)



@dataclass(frozen=True)
class HiveSensorEntityDescription(SensorEntityDescription):
"""Describes Hive sensor entity."""
Expand Down
166 changes: 114 additions & 52 deletions custom_components/hive/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,62 +1,124 @@
{
"config": {
"abort": {
"already_configured": "Account is already configured",
"reauth_successful": "Re-authentication was successful",
"unknown_entry": "Unable to find existing entry."
"step": {
"user": {
"title": "Hive login",
"description": "Enter your Hive login information.",
"data": {
"username": "Username",
"password": "Password",
"disable_2fa_debug": "Disable 2FA (debug)",
"scan_interval": "Scan interval (seconds)"
}
},
"error": {
"invalid_code": "Failed to sign into Hive. Your two-factor authentication code was incorrect.",
"invalid_password": "Failed to sign into Hive. Incorrect password please try again.",
"invalid_username": "Failed to sign into Hive. Your email address is not recognised.",
"twofa_bypassed_debug": "2FA step was intentionally bypassed for debug. Check Home Assistant logs for Hive auth responses.",
"no_internet_available": "An internet connection is required to connect to Hive.",
"unknown": "Unexpected error"
"2fa": {
"title": "Hive two-factor authentication",
"description": "Enter your Hive authentication code.\n\nPlease enter code 0000 to request another code.",
"data": {
"2fa": "Two-factor code"
}
},
"step": {
"2fa": {
"data": {
"2fa": "Two-factor code"
},
"description": "Enter your Hive authentication code. \n \n Please enter code 0000 to request another code.",
"title": "Hive Two-factor Authentication."
},
"configuration": {
"data": {
"device_name": "Device Name"
},
"description": "Enter your Hive configuration ",
"title": "Hive Configuration."
},
"reauth": {
"data": {
"password": "Password",
"username": "Username"
},
"description": "Re-enter your Hive login information.",
"title": "Hive Login"
},
"user": {
"data": {
"password": "Password",
"disable_2fa_debug": "Disable 2FA (debug)",
"scan_interval": "Scan Interval (seconds)",
"username": "Username"
},
"description": "Enter your Hive login information.",
"title": "Hive Login"
}
"configuration": {
"title": "Hive configuration",
"description": "Enter your Hive configuration.",
"data": {
"device_name": "Device name"
}
},
"reauth": {
"title": "Hive login",
"description": "Re-enter your Hive login information.",
"data": {
"username": "Username",
"password": "Password"
}
}
},
"error": {
"invalid_username": "Failed to sign in to Hive. Your email address is not recognized.",
"invalid_password": "Failed to sign in to Hive. Incorrect password, please try again.",
"invalid_code": "Failed to sign in to Hive. Your two-factor authentication code was incorrect.",
"twofa_bypassed_debug": "2FA step was intentionally bypassed for debug. Check Home Assistant logs for Hive auth responses.",
"no_internet_available": "An Internet connection is required to connect to Hive.",
"unknown": "Unexpected error"
},
"abort": {
"already_configured": "Account is already configured",
"unknown_entry": "Unable to find existing entry.",
"reauth_successful": "Re-authentication was successful"
}
},
"options": {
"step": {
"user": {
"data": {
"scan_interval": "Scan Interval (seconds)"
},
"description": "Update the scan interval to poll for data more often.",
"title": "Options for Hive"
}
"step": {
"user": {
"title": "Options for Hive",
"description": "Update the scan interval to poll for data more often.",
"data": {
"scan_interval": "Scan interval (seconds)"
}
}
}
},
"services": {
"boost_heating_on": {
"name": "Boost heating on",
"description": "Sets the boost mode ON, defining the period of time and the desired target temperature for the boost.",
"fields": {
"time_period": {
"name": "Time period",
"description": "The time period for the boost."
},
"temperature": {
"name": "Temperature",
"description": "The target temperature for the boost period."
}
}
},
"boost_heating_off": {
"name": "Boost heating off",
"description": "Sets the boost mode OFF.",
"fields": {
"entity_id": {
"name": "Entity ID",
"description": "The entity ID to turn boost off."
}
}
},
"boost_hot_water": {
"name": "Boost hotwater",
"description": "Sets the boost mode ON or OFF, defining the period of time for the boost.",
"fields": {
"entity_id": {
"name": "Entity ID",
"description": "The entity ID to boost."
},
"time_period": {
"name": "Time period",
"description": "The time period for the boost."
},
"on_off": {
"name": "Mode",
"description": "Set the boost function on or off."
}
}
}
},
"entity": {
"sensor": {
"heating": {
"state": {
"manual": "Manual",
"off": "Off",
"schedule": "Schedule"
}
},
"hot_water": {
"state": {
"on": "On",
"off": "Off",
"schedule": "Schedule"
}
}
}
}
}
Loading