mirror of
https://github.com/home-assistant/core.git
synced 2026-08-03 20:24:55 +02:00
Add Qube Heat Pump integration (#160409)
Co-authored-by: Norbert Rittel <norbert@rittel.de> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -274,6 +274,7 @@ homeassistant.components.homekit_controller.storage
|
||||
homeassistant.components.homekit_controller.utils
|
||||
homeassistant.components.homewizard.*
|
||||
homeassistant.components.homeworks.*
|
||||
homeassistant.components.hr_energy_qube.*
|
||||
homeassistant.components.http.*
|
||||
homeassistant.components.huawei_lte.*
|
||||
homeassistant.components.humidifier.*
|
||||
|
||||
Generated
+2
@@ -739,6 +739,8 @@ build.json @home-assistant/supervisor
|
||||
/tests/components/homewizard/ @DCSBL
|
||||
/homeassistant/components/honeywell/ @rdfurman @mkmer
|
||||
/tests/components/honeywell/ @rdfurman @mkmer
|
||||
/homeassistant/components/hr_energy_qube/ @MattieGit
|
||||
/tests/components/hr_energy_qube/ @MattieGit
|
||||
/homeassistant/components/html5/ @alexyao2015
|
||||
/tests/components/html5/ @alexyao2015
|
||||
/homeassistant/components/http/ @home-assistant/core
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
"""The Qube Heat Pump integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from python_qube_heatpump import QubeClient
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
|
||||
from .const import PLATFORMS
|
||||
from .coordinator import QubeCoordinator
|
||||
|
||||
|
||||
@dataclass
|
||||
class QubeData:
|
||||
"""Runtime data for Qube Heat Pump."""
|
||||
|
||||
coordinator: QubeCoordinator
|
||||
client: QubeClient
|
||||
sw_version: str | None
|
||||
|
||||
|
||||
type QubeConfigEntry = ConfigEntry[QubeData]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: QubeConfigEntry) -> bool:
|
||||
"""Set up Qube Heat Pump from a config entry."""
|
||||
client = QubeClient(entry.data[CONF_HOST], entry.data[CONF_PORT])
|
||||
|
||||
# Connect and read software version for device info
|
||||
sw_version: str | None = None
|
||||
try:
|
||||
connected = await client.connect()
|
||||
if not connected:
|
||||
await client.close()
|
||||
raise ConfigEntryNotReady(
|
||||
f"Unable to connect to Qube heat pump at {entry.data[CONF_HOST]}"
|
||||
)
|
||||
sw_version = await client.async_get_software_version()
|
||||
except (OSError, TimeoutError) as err:
|
||||
await client.close()
|
||||
raise ConfigEntryNotReady(
|
||||
f"Unable to connect to Qube heat pump at {entry.data[CONF_HOST]}"
|
||||
) from err
|
||||
|
||||
coordinator = QubeCoordinator(hass, client, entry)
|
||||
|
||||
entry.runtime_data = QubeData(
|
||||
coordinator=coordinator,
|
||||
client=client,
|
||||
sw_version=sw_version,
|
||||
)
|
||||
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: QubeConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
||||
await entry.runtime_data.client.close()
|
||||
return unload_ok
|
||||
@@ -0,0 +1,61 @@
|
||||
"""Config flow for Qube Heat Pump integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from python_qube_heatpump import QubeClient
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||
|
||||
from .const import DEFAULT_PORT, DOMAIN
|
||||
|
||||
|
||||
class QubeConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a config flow for Qube Heat Pump."""
|
||||
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle the user step."""
|
||||
errors: dict[str, str] = {}
|
||||
|
||||
if user_input is not None:
|
||||
host = user_input[CONF_HOST]
|
||||
|
||||
self._async_abort_entries_match({CONF_HOST: host})
|
||||
|
||||
# Connect and verify it's a Qube by reading software version
|
||||
client = QubeClient(host, DEFAULT_PORT)
|
||||
try:
|
||||
connected = await client.connect()
|
||||
if not connected:
|
||||
errors["base"] = "cannot_connect"
|
||||
else:
|
||||
version = await client.async_get_software_version()
|
||||
if version is None:
|
||||
errors["base"] = "not_qube_device"
|
||||
except OSError, TimeoutError:
|
||||
errors["base"] = "cannot_connect"
|
||||
finally:
|
||||
await client.close()
|
||||
|
||||
if not errors:
|
||||
return self.async_create_entry(
|
||||
title="Qube heat pump",
|
||||
data={
|
||||
CONF_HOST: host,
|
||||
CONF_PORT: DEFAULT_PORT,
|
||||
},
|
||||
)
|
||||
|
||||
schema = vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_HOST): str,
|
||||
}
|
||||
)
|
||||
return self.async_show_form(step_id="user", data_schema=schema, errors=errors)
|
||||
@@ -0,0 +1,9 @@
|
||||
"""Constants for the Qube Heat Pump integration."""
|
||||
|
||||
from homeassistant.const import Platform
|
||||
|
||||
DOMAIN = "hr_energy_qube"
|
||||
PLATFORMS = (Platform.SENSOR,)
|
||||
|
||||
DEFAULT_PORT = 502
|
||||
DEFAULT_SCAN_INTERVAL = 15
|
||||
@@ -0,0 +1,51 @@
|
||||
"""DataUpdateCoordinator for Qube Heat Pump."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from python_qube_heatpump import QubeClient
|
||||
from python_qube_heatpump.models import QubeState
|
||||
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
from .const import DEFAULT_SCAN_INTERVAL, DOMAIN
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class QubeCoordinator(DataUpdateCoordinator[QubeState]):
|
||||
"""Qube Heat Pump data coordinator."""
|
||||
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, client: QubeClient, entry: ConfigEntry
|
||||
) -> None:
|
||||
"""Initialize the coordinator."""
|
||||
self.client = client
|
||||
super().__init__(
|
||||
hass,
|
||||
_LOGGER,
|
||||
name=DOMAIN,
|
||||
update_interval=timedelta(seconds=DEFAULT_SCAN_INTERVAL),
|
||||
config_entry=entry,
|
||||
)
|
||||
|
||||
async def _async_update_data(self) -> QubeState:
|
||||
"""Fetch data from the device."""
|
||||
try:
|
||||
data = await self.client.get_all_data()
|
||||
except (ConnectionError, TimeoutError, OSError) as exc:
|
||||
raise UpdateFailed(
|
||||
f"Error communicating with Qube heat pump: {exc}"
|
||||
) from exc
|
||||
|
||||
if data is None:
|
||||
raise UpdateFailed("No data received from Qube heat pump")
|
||||
|
||||
return data
|
||||
@@ -0,0 +1,34 @@
|
||||
"""Base entity for Qube Heat Pump."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import QubeCoordinator
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import QubeConfigEntry
|
||||
|
||||
|
||||
class QubeEntity(CoordinatorEntity[QubeCoordinator]):
|
||||
"""Base entity for Qube Heat Pump."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: QubeCoordinator,
|
||||
entry: QubeConfigEntry,
|
||||
) -> None:
|
||||
"""Initialize the base entity."""
|
||||
super().__init__(coordinator)
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, entry.entry_id)},
|
||||
manufacturer="Qube",
|
||||
model="Heat Pump",
|
||||
sw_version=entry.runtime_data.sw_version,
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"domain": "hr_energy_qube",
|
||||
"name": "Qube heat pump",
|
||||
"codeowners": ["@MattieGit"],
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/hr_energy_qube",
|
||||
"integration_type": "hub",
|
||||
"iot_class": "local_polling",
|
||||
"loggers": ["python_qube_heatpump"],
|
||||
"quality_scale": "bronze",
|
||||
"requirements": ["python-qube-heatpump==1.7.0"]
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
rules:
|
||||
# Bronze
|
||||
action-setup:
|
||||
status: exempt
|
||||
comment: Integration does not register custom actions.
|
||||
appropriate-polling: done
|
||||
brands: done
|
||||
common-modules: done
|
||||
config-flow: done
|
||||
config-flow-test-coverage: done
|
||||
dependency-transparency: done
|
||||
docs-actions:
|
||||
status: exempt
|
||||
comment: Integration does not register custom actions.
|
||||
docs-high-level-description: done
|
||||
docs-installation-instructions: done
|
||||
docs-removal-instructions: done
|
||||
entity-event-setup:
|
||||
status: exempt
|
||||
comment: Entities do not subscribe to events.
|
||||
entity-unique-id: done
|
||||
has-entity-name: done
|
||||
runtime-data: done
|
||||
test-before-configure: done
|
||||
test-before-setup: done
|
||||
unique-config-entry: done
|
||||
|
||||
# Silver
|
||||
action-exceptions:
|
||||
status: exempt
|
||||
comment: Integration does not register custom actions.
|
||||
config-entry-unloading: done
|
||||
docs-configuration-parameters:
|
||||
status: exempt
|
||||
comment: No configuration options beyond initial setup.
|
||||
docs-installation-parameters: done
|
||||
entity-unavailable: done
|
||||
integration-owner: done
|
||||
log-when-unavailable: todo
|
||||
parallel-updates: done
|
||||
reauthentication-flow:
|
||||
status: exempt
|
||||
comment: No authentication required for Modbus TCP.
|
||||
test-coverage: done
|
||||
|
||||
# Gold
|
||||
devices: done
|
||||
diagnostics: todo
|
||||
discovery-update-info: todo
|
||||
discovery: todo
|
||||
docs-data-update: todo
|
||||
docs-examples: todo
|
||||
docs-known-limitations: todo
|
||||
docs-supported-devices: todo
|
||||
docs-supported-functions: todo
|
||||
docs-troubleshooting: todo
|
||||
docs-use-cases: todo
|
||||
dynamic-devices:
|
||||
status: exempt
|
||||
comment: Single device per config entry.
|
||||
entity-category: todo
|
||||
entity-device-class: done
|
||||
entity-disabled-by-default: todo
|
||||
entity-translations: done
|
||||
exception-translations: todo
|
||||
icon-translations: todo
|
||||
reconfiguration-flow: todo
|
||||
repair-issues: todo
|
||||
stale-devices:
|
||||
status: exempt
|
||||
comment: Single device per config entry.
|
||||
|
||||
# Platinum
|
||||
async-dependency: done
|
||||
inject-websession:
|
||||
status: exempt
|
||||
comment: Uses Modbus TCP, not HTTP.
|
||||
strict-typing: done
|
||||
@@ -0,0 +1,280 @@
|
||||
"""Sensor platform for Qube Heat Pump."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from python_qube_heatpump.models import QubeState
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
REVOLUTIONS_PER_MINUTE,
|
||||
UnitOfEnergy,
|
||||
UnitOfPower,
|
||||
UnitOfTemperature,
|
||||
UnitOfVolumeFlowRate,
|
||||
)
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from .entity import QubeEntity
|
||||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import QubeConfigEntry
|
||||
from .coordinator import QubeCoordinator
|
||||
|
||||
# Status code to state mapping
|
||||
STATUS_MAP: dict[int, str] = {
|
||||
1: "standby",
|
||||
2: "alarm",
|
||||
6: "keyboard_off",
|
||||
8: "compressor_startup",
|
||||
9: "compressor_shutdown",
|
||||
14: "standby",
|
||||
15: "cooling",
|
||||
16: "heating",
|
||||
17: "start_fail",
|
||||
18: "standby",
|
||||
22: "heating_dhw",
|
||||
}
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
class QubeSensorEntityDescription(SensorEntityDescription):
|
||||
"""Sensor entity description for Qube Heat Pump."""
|
||||
|
||||
value_fn: Callable[[QubeState], StateType]
|
||||
|
||||
|
||||
def _status_value(data: QubeState) -> StateType:
|
||||
"""Return status string from status code."""
|
||||
code = data.status_code
|
||||
if code is None:
|
||||
return None
|
||||
return STATUS_MAP.get(code)
|
||||
|
||||
|
||||
SENSOR_TYPES: tuple[QubeSensorEntityDescription, ...] = (
|
||||
QubeSensorEntityDescription(
|
||||
key="temp_supply",
|
||||
translation_key="temp_supply",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_display_precision=1,
|
||||
value_fn=lambda data: data.temp_supply,
|
||||
),
|
||||
QubeSensorEntityDescription(
|
||||
key="temp_return",
|
||||
translation_key="temp_return",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_display_precision=1,
|
||||
value_fn=lambda data: data.temp_return,
|
||||
),
|
||||
QubeSensorEntityDescription(
|
||||
key="temp_source_in",
|
||||
translation_key="temp_source_in",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_display_precision=1,
|
||||
value_fn=lambda data: data.temp_source_in,
|
||||
),
|
||||
QubeSensorEntityDescription(
|
||||
key="temp_source_out",
|
||||
translation_key="temp_source_out",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_display_precision=1,
|
||||
value_fn=lambda data: data.temp_source_out,
|
||||
),
|
||||
QubeSensorEntityDescription(
|
||||
key="temp_room",
|
||||
translation_key="temp_room",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_display_precision=1,
|
||||
value_fn=lambda data: data.temp_room,
|
||||
),
|
||||
QubeSensorEntityDescription(
|
||||
key="temp_dhw",
|
||||
translation_key="temp_dhw",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_display_precision=1,
|
||||
value_fn=lambda data: data.temp_dhw,
|
||||
),
|
||||
QubeSensorEntityDescription(
|
||||
key="temp_outside",
|
||||
translation_key="temp_outside",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_display_precision=1,
|
||||
value_fn=lambda data: data.temp_outside,
|
||||
),
|
||||
QubeSensorEntityDescription(
|
||||
key="power_thermic",
|
||||
translation_key="power_thermic",
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
native_unit_of_measurement=UnitOfPower.WATT,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_display_precision=0,
|
||||
value_fn=lambda data: data.power_thermic,
|
||||
),
|
||||
QubeSensorEntityDescription(
|
||||
key="power_electric",
|
||||
translation_key="power_electric",
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
native_unit_of_measurement=UnitOfPower.WATT,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_display_precision=0,
|
||||
value_fn=lambda data: data.power_electric,
|
||||
),
|
||||
QubeSensorEntityDescription(
|
||||
key="energy_total_electric",
|
||||
translation_key="energy_total_electric",
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
suggested_display_precision=3,
|
||||
value_fn=lambda data: data.energy_total_electric,
|
||||
),
|
||||
QubeSensorEntityDescription(
|
||||
key="energy_total_thermic",
|
||||
translation_key="energy_total_thermic",
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
suggested_display_precision=3,
|
||||
value_fn=lambda data: data.energy_total_thermic,
|
||||
),
|
||||
QubeSensorEntityDescription(
|
||||
key="cop_calc",
|
||||
translation_key="cop_calc",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_display_precision=1,
|
||||
value_fn=lambda data: data.cop_calc,
|
||||
),
|
||||
QubeSensorEntityDescription(
|
||||
key="compressor_speed",
|
||||
translation_key="compressor_speed",
|
||||
native_unit_of_measurement=REVOLUTIONS_PER_MINUTE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_display_precision=0,
|
||||
value_fn=lambda data: data.compressor_speed,
|
||||
),
|
||||
QubeSensorEntityDescription(
|
||||
key="flow_rate",
|
||||
translation_key="flow_rate",
|
||||
device_class=SensorDeviceClass.VOLUME_FLOW_RATE,
|
||||
native_unit_of_measurement=UnitOfVolumeFlowRate.LITERS_PER_MINUTE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_display_precision=0,
|
||||
value_fn=lambda data: data.flow_rate,
|
||||
),
|
||||
QubeSensorEntityDescription(
|
||||
key="setpoint_room_heat_day",
|
||||
translation_key="setpoint_room_heat_day",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_display_precision=1,
|
||||
value_fn=lambda data: data.setpoint_room_heat_day,
|
||||
),
|
||||
QubeSensorEntityDescription(
|
||||
key="setpoint_room_heat_night",
|
||||
translation_key="setpoint_room_heat_night",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_display_precision=1,
|
||||
value_fn=lambda data: data.setpoint_room_heat_night,
|
||||
),
|
||||
QubeSensorEntityDescription(
|
||||
key="setpoint_room_cool_day",
|
||||
translation_key="setpoint_room_cool_day",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_display_precision=1,
|
||||
value_fn=lambda data: data.setpoint_room_cool_day,
|
||||
),
|
||||
QubeSensorEntityDescription(
|
||||
key="setpoint_room_cool_night",
|
||||
translation_key="setpoint_room_cool_night",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_display_precision=1,
|
||||
value_fn=lambda data: data.setpoint_room_cool_night,
|
||||
),
|
||||
QubeSensorEntityDescription(
|
||||
key="status_heatpump",
|
||||
translation_key="status_heatpump",
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
options=[
|
||||
"standby",
|
||||
"alarm",
|
||||
"keyboard_off",
|
||||
"compressor_startup",
|
||||
"compressor_shutdown",
|
||||
"cooling",
|
||||
"heating",
|
||||
"start_fail",
|
||||
"heating_dhw",
|
||||
],
|
||||
value_fn=_status_value,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: QubeConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Qube sensors."""
|
||||
coordinator = entry.runtime_data.coordinator
|
||||
|
||||
async_add_entities(
|
||||
QubeSensor(coordinator, entry, description) for description in SENSOR_TYPES
|
||||
)
|
||||
|
||||
|
||||
class QubeSensor(QubeEntity, SensorEntity):
|
||||
"""Qube sensor entity."""
|
||||
|
||||
entity_description: QubeSensorEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: QubeCoordinator,
|
||||
entry: QubeConfigEntry,
|
||||
description: QubeSensorEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator, entry)
|
||||
self.entity_description = description
|
||||
self._attr_unique_id = f"{entry.entry_id}-{description.key}"
|
||||
|
||||
@property
|
||||
def native_value(self) -> StateType:
|
||||
"""Return native value."""
|
||||
return self.entity_description.value_fn(self.coordinator.data)
|
||||
@@ -0,0 +1,94 @@
|
||||
{
|
||||
"config": {
|
||||
"abort": {
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
|
||||
},
|
||||
"error": {
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"not_qube_device": "Could not verify this is a Qube heat pump. Check the host address."
|
||||
},
|
||||
"step": {
|
||||
"user": {
|
||||
"data": {
|
||||
"host": "[%key:common::config_flow::data::host%]"
|
||||
},
|
||||
"data_description": {
|
||||
"host": "The IP address or hostname of your Qube heat pump."
|
||||
},
|
||||
"description": "Enter the IP address or hostname of your Qube heat pump."
|
||||
}
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"compressor_speed": {
|
||||
"name": "Compressor speed"
|
||||
},
|
||||
"cop_calc": {
|
||||
"name": "COP"
|
||||
},
|
||||
"energy_total_electric": {
|
||||
"name": "Total electric consumption"
|
||||
},
|
||||
"energy_total_thermic": {
|
||||
"name": "Total thermal yield"
|
||||
},
|
||||
"flow_rate": {
|
||||
"name": "Measured PVT flow"
|
||||
},
|
||||
"power_electric": {
|
||||
"name": "Electric power"
|
||||
},
|
||||
"power_thermic": {
|
||||
"name": "Thermal power"
|
||||
},
|
||||
"setpoint_room_cool_day": {
|
||||
"name": "Room setpoint cooling (day)"
|
||||
},
|
||||
"setpoint_room_cool_night": {
|
||||
"name": "Room setpoint cooling (night)"
|
||||
},
|
||||
"setpoint_room_heat_day": {
|
||||
"name": "Room setpoint heating (day)"
|
||||
},
|
||||
"setpoint_room_heat_night": {
|
||||
"name": "Room setpoint heating (night)"
|
||||
},
|
||||
"status_heatpump": {
|
||||
"name": "Heat pump status",
|
||||
"state": {
|
||||
"alarm": "Alarm",
|
||||
"compressor_shutdown": "Compressor stopping",
|
||||
"compressor_startup": "Compressor startup",
|
||||
"cooling": "[%key:component::climate::entity_component::_::state_attributes::hvac_action::state::cooling%]",
|
||||
"heating": "[%key:component::climate::entity_component::_::state_attributes::hvac_action::state::heating%]",
|
||||
"heating_dhw": "Heating DHW",
|
||||
"keyboard_off": "Keyboard off",
|
||||
"standby": "[%key:common::state::standby%]",
|
||||
"start_fail": "Start failed"
|
||||
}
|
||||
},
|
||||
"temp_dhw": {
|
||||
"name": "DHW temperature"
|
||||
},
|
||||
"temp_outside": {
|
||||
"name": "Outside temperature"
|
||||
},
|
||||
"temp_return": {
|
||||
"name": "Return temperature"
|
||||
},
|
||||
"temp_room": {
|
||||
"name": "Room temperature"
|
||||
},
|
||||
"temp_source_in": {
|
||||
"name": "Source temperature in"
|
||||
},
|
||||
"temp_source_out": {
|
||||
"name": "Source temperature out"
|
||||
},
|
||||
"temp_supply": {
|
||||
"name": "Supply temperature CH"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+1
@@ -305,6 +305,7 @@ FLOWS = {
|
||||
"homewizard",
|
||||
"homeworks",
|
||||
"honeywell",
|
||||
"hr_energy_qube",
|
||||
"html5",
|
||||
"huawei_lte",
|
||||
"hue",
|
||||
|
||||
@@ -2954,6 +2954,12 @@
|
||||
"config_flow": false,
|
||||
"iot_class": "local_polling"
|
||||
},
|
||||
"hr_energy_qube": {
|
||||
"name": "Qube heat pump",
|
||||
"integration_type": "hub",
|
||||
"config_flow": true,
|
||||
"iot_class": "local_polling"
|
||||
},
|
||||
"html5": {
|
||||
"name": "HTML5 Push Notifications",
|
||||
"integration_type": "hub",
|
||||
|
||||
@@ -2496,6 +2496,16 @@ disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.hr_energy_qube.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_subclassing_any = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_decorators = true
|
||||
disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.http.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
|
||||
Generated
+3
@@ -2653,6 +2653,9 @@ python-picnic-api2==1.3.1
|
||||
# homeassistant.components.pooldose
|
||||
python-pooldose==0.8.6
|
||||
|
||||
# homeassistant.components.hr_energy_qube
|
||||
python-qube-heatpump==1.7.0
|
||||
|
||||
# homeassistant.components.rabbitair
|
||||
python-rabbitair==0.0.8
|
||||
|
||||
|
||||
Generated
+3
@@ -2252,6 +2252,9 @@ python-picnic-api2==1.3.1
|
||||
# homeassistant.components.pooldose
|
||||
python-pooldose==0.8.6
|
||||
|
||||
# homeassistant.components.hr_energy_qube
|
||||
python-qube-heatpump==1.7.0
|
||||
|
||||
# homeassistant.components.rabbitair
|
||||
python-rabbitair==0.0.8
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
"""Tests for the Qube Heat Pump integration."""
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def setup_integration(hass: HomeAssistant, config_entry: MockConfigEntry) -> None:
|
||||
"""Set up the Qube Heat Pump integration."""
|
||||
config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
@@ -0,0 +1,79 @@
|
||||
"""Common fixtures for the Qube Heat Pump tests."""
|
||||
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from python_qube_heatpump.models import QubeState
|
||||
|
||||
from homeassistant.components.hr_energy_qube.const import DOMAIN
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_setup_entry() -> Generator[AsyncMock]:
|
||||
"""Override async_setup_entry."""
|
||||
with patch(
|
||||
"homeassistant.components.hr_energy_qube.async_setup_entry", return_value=True
|
||||
) as mock_setup:
|
||||
yield mock_setup
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_qube_client() -> Generator[MagicMock]:
|
||||
"""Mock the QubeClient for both integration and config flow."""
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.hr_energy_qube.QubeClient",
|
||||
autospec=True,
|
||||
) as mock_client_cls,
|
||||
patch(
|
||||
"homeassistant.components.hr_energy_qube.config_flow.QubeClient",
|
||||
new=mock_client_cls,
|
||||
),
|
||||
):
|
||||
client = mock_client_cls.return_value
|
||||
client.host = "1.2.3.4"
|
||||
client.port = 502
|
||||
client.unit = 1
|
||||
client.connect = AsyncMock(return_value=True)
|
||||
client.is_connected = True
|
||||
client.close = AsyncMock(return_value=None)
|
||||
client.async_get_software_version = AsyncMock(return_value="2.15")
|
||||
|
||||
state = QubeState()
|
||||
state.temp_supply = 45.0
|
||||
state.temp_return = 40.0
|
||||
state.temp_outside = 10.0
|
||||
state.temp_source_in = 8.0
|
||||
state.temp_source_out = 12.0
|
||||
state.temp_room = 21.0
|
||||
state.temp_dhw = 50.0
|
||||
state.power_thermic = 5000.0
|
||||
state.power_electric = 1200.0
|
||||
state.energy_total_electric = 123.456
|
||||
state.energy_total_thermic = 500.0
|
||||
state.cop_calc = 4.2
|
||||
state.compressor_speed = 3000.0
|
||||
state.flow_rate = 15.5
|
||||
state.setpoint_room_heat_day = 21.0
|
||||
state.setpoint_room_heat_night = 18.0
|
||||
state.setpoint_room_cool_day = 25.0
|
||||
state.setpoint_room_cool_night = 23.0
|
||||
state.status_code = 1
|
||||
|
||||
client.get_all_data = AsyncMock(return_value=state)
|
||||
yield client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_config_entry() -> MockConfigEntry:
|
||||
"""Mock a config entry."""
|
||||
return MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={CONF_HOST: "1.2.3.4", CONF_PORT: 502},
|
||||
title="Qube heat pump",
|
||||
entry_id="01JQUBEHEATPUMP00000000000",
|
||||
)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,104 @@
|
||||
"""Test the Qube Heat Pump config flow."""
|
||||
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.hr_energy_qube.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_full_flow(
|
||||
hass: HomeAssistant,
|
||||
mock_qube_client: MagicMock,
|
||||
mock_setup_entry: AsyncMock,
|
||||
) -> None:
|
||||
"""Test successful config flow."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_HOST: "qube.local"},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "Qube heat pump"
|
||||
assert result["data"] == {CONF_HOST: "qube.local", CONF_PORT: 502}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("connect_side_effect", "connect_result", "version_result", "error"),
|
||||
[
|
||||
(None, False, "2.15", "cannot_connect"),
|
||||
(OSError, None, "2.15", "cannot_connect"),
|
||||
(None, True, None, "not_qube_device"),
|
||||
],
|
||||
)
|
||||
async def test_flow_errors(
|
||||
hass: HomeAssistant,
|
||||
mock_qube_client: MagicMock,
|
||||
mock_setup_entry: AsyncMock,
|
||||
connect_side_effect: type[Exception] | None,
|
||||
connect_result: bool | None,
|
||||
version_result: str | None,
|
||||
error: str,
|
||||
) -> None:
|
||||
"""Test flow error handling with recovery."""
|
||||
mock_qube_client.connect = AsyncMock(
|
||||
side_effect=connect_side_effect, return_value=connect_result
|
||||
)
|
||||
mock_qube_client.async_get_software_version = AsyncMock(return_value=version_result)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_HOST: "1.2.3.4"},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {"base": error}
|
||||
|
||||
# Reset mocks for successful retry
|
||||
mock_qube_client.connect = AsyncMock(return_value=True)
|
||||
mock_qube_client.async_get_software_version = AsyncMock(return_value="2.15")
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_HOST: "1.2.3.4"},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
|
||||
|
||||
async def test_already_configured(
|
||||
hass: HomeAssistant,
|
||||
mock_qube_client: MagicMock,
|
||||
mock_setup_entry: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test we abort when device is already configured."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_HOST: "1.2.3.4"},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
@@ -0,0 +1,27 @@
|
||||
"""Test the Qube Heat Pump integration init."""
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_setup_and_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mock_qube_client: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test successful setup and unload."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
await hass.config_entries.async_unload(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
|
||||
mock_qube_client.close.assert_called_once()
|
||||
@@ -0,0 +1,85 @@
|
||||
"""Tests for the Qube Heat Pump sensor platform."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.const import STATE_UNAVAILABLE, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_platform
|
||||
|
||||
|
||||
async def test_entities(
|
||||
hass: HomeAssistant,
|
||||
snapshot: SnapshotAssertion,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mock_qube_client: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test all sensor entities via snapshot."""
|
||||
with patch("homeassistant.components.hr_energy_qube.PLATFORMS", [Platform.SENSOR]):
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("side_effect", "return_value"),
|
||||
[
|
||||
(ConnectionError("Connection lost"), None),
|
||||
(None, None),
|
||||
],
|
||||
)
|
||||
async def test_sensor_unavailable_on_coordinator_error(
|
||||
hass: HomeAssistant,
|
||||
mock_qube_client: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
side_effect: Exception | None,
|
||||
return_value: None,
|
||||
) -> None:
|
||||
"""Test sensors become unavailable when coordinator fails."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
# Verify sensors are available after setup
|
||||
states = hass.states.async_all("sensor")
|
||||
assert len(states) > 0
|
||||
assert all(s.state != STATE_UNAVAILABLE for s in states)
|
||||
|
||||
# Make the next fetch fail
|
||||
mock_qube_client.get_all_data = AsyncMock(
|
||||
side_effect=side_effect, return_value=return_value
|
||||
)
|
||||
|
||||
# Skip time to trigger coordinator refresh
|
||||
freezer.tick(timedelta(seconds=31))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# All sensors should be unavailable
|
||||
states = hass.states.async_all("sensor")
|
||||
assert all(s.state == STATE_UNAVAILABLE for s in states)
|
||||
|
||||
|
||||
async def test_sensor_with_none_status_code(
|
||||
hass: HomeAssistant,
|
||||
mock_qube_client: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test status sensor handles None status code."""
|
||||
mock_qube_client.get_all_data.return_value.status_code = None
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
state = hass.states.get("sensor.qube_heat_pump_heat_pump_status")
|
||||
assert state is not None
|
||||
assert state.state == "unknown"
|
||||
Reference in New Issue
Block a user