-
-
Notifications
You must be signed in to change notification settings - Fork 37.6k
Add new Aqvify integration #172936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,110
−0
Merged
Add new Aqvify integration #172936
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
46c3e26
Initial upload - WIP
astrandb 8d0f84d
Test coverage for config_flow
astrandb bab8f8f
Visit quality scale
astrandb 82be2db
Remove commented code
astrandb d453d9a
Follow advice from Copilot
astrandb 9dc6a0a
Follow advice from Copilot
astrandb e56de7d
Add tests for second config entry
astrandb 6a61670
Adjust wordings
astrandb 4e2f87f
Add some tests
astrandb 2ca90ab
Follow advice from Copilot
astrandb 61bbcce
Address review comments
astrandb 9984a9f
Add account_id to entity unique_id
astrandb b4c495b
Change entity icons
astrandb 53436e2
Address Copilot comments
astrandb 8d1e85e
Add tests for sensor platform
astrandb 16c80ef
Improve tests
astrandb 96dd458
Bump pyaqvify dependency
astrandb 642790f
Adapt to new pyaqvify interface
astrandb dbe4f02
Fixup
astrandb 85e4b59
Set strict typing
astrandb cf01514
Cleanup test_config_flow
astrandb ccf25b7
Address review comments
astrandb 633908a
A few more comments fixed
astrandb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| """The Aqvify integration.""" | ||
|
|
||
| import logging | ||
|
|
||
| from pyaqvify import AqvifyAPI, AqvifyAuthException | ||
|
|
||
| from homeassistant.const import CONF_API_KEY, Platform | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady | ||
| from homeassistant.helpers.aiohttp_client import async_get_clientsession | ||
|
|
||
| from .coordinator import AqvifyConfigEntry, AqvifyCoordinator | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
| PLATFORMS: list[Platform] = [Platform.SENSOR] | ||
|
|
||
|
|
||
| async def async_setup_entry(hass: HomeAssistant, entry: AqvifyConfigEntry) -> bool: | ||
| """Set up Aqvify from a config entry.""" | ||
|
|
||
| _api = AqvifyAPI(entry.data[CONF_API_KEY], websession=async_get_clientsession(hass)) | ||
| try: | ||
| await _api.async_get_account_id() | ||
| except AqvifyAuthException as err: | ||
| raise ConfigEntryAuthFailed(f"Invalid Aqvify API key: {err}") from err | ||
| except Exception as err: | ||
| raise ConfigEntryNotReady(f"Failed to connect to Aqvify API: {err}") from err | ||
|
|
||
| coordinator = AqvifyCoordinator(hass, entry) | ||
|
|
||
| await coordinator.async_config_entry_first_refresh() | ||
| entry.runtime_data = coordinator | ||
|
|
||
| await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| async def async_unload_entry(hass: HomeAssistant, entry: AqvifyConfigEntry) -> bool: | ||
| """Unload Aqvify config entry.""" | ||
| return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| """Config flow for the Aqvify integration.""" | ||
|
|
||
| import logging | ||
| from typing import Any | ||
|
|
||
| from aiohttp import ClientResponseError | ||
| from pyaqvify import AqvifyAPI, AqvifyAuthException | ||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.config_entries import ConfigFlow, ConfigFlowResult | ||
| from homeassistant.const import CONF_API_KEY | ||
| from homeassistant.helpers.aiohttp_client import async_get_clientsession | ||
|
|
||
| from .const import DOMAIN | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| STEP_USER_DATA_SCHEMA = vol.Schema( | ||
| { | ||
| vol.Required(CONF_API_KEY): str, | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| class AqvifyConfigFlow(ConfigFlow, domain=DOMAIN): | ||
| """Handle a config flow for Aqvify.""" | ||
|
|
||
| VERSION = 1 | ||
|
|
||
| async def async_step_user( | ||
| self, user_input: dict[str, Any] | None = None | ||
| ) -> ConfigFlowResult: | ||
| """Handle the initial step.""" | ||
| errors: dict[str, str] = {} | ||
| if user_input is not None: | ||
| hub = AqvifyAPI( | ||
| user_input[CONF_API_KEY], | ||
| websession=async_get_clientsession(self.hass), | ||
| ) | ||
| try: | ||
| account_data = await hub.async_get_account_id() | ||
| except AqvifyAuthException: | ||
| errors["base"] = "invalid_auth" | ||
| except ClientResponseError: | ||
| errors["base"] = "cannot_connect" | ||
| except Exception: | ||
| _LOGGER.exception("Unexpected exception") | ||
| errors["base"] = "unknown" | ||
| else: | ||
| await self.async_set_unique_id(account_data.account_id) | ||
| self._abort_if_unique_id_configured() | ||
| return self.async_create_entry(title="Aqvify", data=user_input) | ||
|
|
||
| return self.async_show_form( | ||
| step_id="user", | ||
| data_schema=STEP_USER_DATA_SCHEMA, | ||
| errors=errors, | ||
| description_placeholders={ | ||
| "aqvify_url": "https://app.aqvify.com/User", | ||
| }, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| """Constants for the Aqvify integration.""" | ||
|
|
||
| DOMAIN = "aqvify" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| """Coordinator for Aqvify integration.""" | ||
|
|
||
| from dataclasses import dataclass | ||
| from datetime import timedelta | ||
| import logging | ||
|
|
||
| from aiohttp import ClientResponseError | ||
| from pyaqvify import AqvifyAPI, AqvifyDeviceData, AqvifyDevices | ||
|
|
||
| from homeassistant.config_entries import ConfigEntry | ||
| from homeassistant.const import CONF_API_KEY | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers.aiohttp_client import async_get_clientsession | ||
| from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed | ||
|
|
||
| from .const import DOMAIN | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| UPDATE_INTERVAL = timedelta(seconds=60) | ||
|
astrandb marked this conversation as resolved.
|
||
|
|
||
| type AqvifyConfigEntry = ConfigEntry[AqvifyCoordinator] | ||
|
|
||
|
|
||
| @dataclass | ||
| class AqvifyCoordinatorData: | ||
| """Data class for storing coordinator data.""" | ||
|
|
||
| devices: AqvifyDevices | ||
| device_data: dict[str, AqvifyDeviceData] | ||
|
|
||
|
|
||
| class AqvifyCoordinator(DataUpdateCoordinator[AqvifyCoordinatorData]): | ||
| """Data update coordinator for Aqvify devices.""" | ||
|
|
||
| config_entry: AqvifyConfigEntry | ||
|
|
||
| def __init__(self, hass: HomeAssistant, entry: AqvifyConfigEntry) -> None: | ||
| """Initialize the Aqvify data update coordinator.""" | ||
| super().__init__( | ||
| hass, | ||
| logger=_LOGGER, | ||
| name=DOMAIN, | ||
| update_interval=UPDATE_INTERVAL, | ||
| config_entry=entry, | ||
| ) | ||
|
|
||
| self.api_client = AqvifyAPI( | ||
| entry.data[CONF_API_KEY], websession=async_get_clientsession(hass) | ||
| ) | ||
|
|
||
| async def _async_update_data(self) -> AqvifyCoordinatorData: | ||
| """Fetch device state.""" | ||
| try: | ||
| devices = await self.api_client.async_get_devices() | ||
| except ClientResponseError as err: | ||
| raise UpdateFailed(f"Error communicating with Aqvify API: {err}") from err | ||
| except TimeoutError as err: | ||
| raise UpdateFailed(f"Timeout communicating with Aqvify API: {err}") from err | ||
|
|
||
| device_data = {} | ||
| for device in devices.devices.values(): | ||
| try: | ||
| device_key = str(device.device_key) | ||
| device_data[ | ||
| device_key | ||
| ] = await self.api_client.async_get_device_latest_data(device_key) | ||
|
astrandb marked this conversation as resolved.
|
||
| except ClientResponseError as err: | ||
| raise UpdateFailed( | ||
| f"Error communicating with Aqvify API: {err}" | ||
| ) from err | ||
| except TimeoutError as err: | ||
| raise UpdateFailed( | ||
| f"Timeout communicating with Aqvify API: {err}" | ||
| ) from err | ||
|
Comment on lines
+73
to
+87
|
||
|
|
||
| return AqvifyCoordinatorData( | ||
| devices=devices, | ||
| device_data=device_data, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| """Defines a base Aqvify entity.""" | ||
|
|
||
| from homeassistant.helpers.device_registry import DeviceInfo | ||
| from homeassistant.helpers.entity import EntityDescription | ||
| from homeassistant.helpers.update_coordinator import CoordinatorEntity | ||
|
|
||
| from .const import DOMAIN | ||
| from .coordinator import AqvifyCoordinator | ||
|
|
||
|
|
||
| class AqvifyBaseEntity(CoordinatorEntity[AqvifyCoordinator]): | ||
| """Defines a base Aqvify entity.""" | ||
|
|
||
| _attr_has_entity_name = True | ||
|
|
||
| def __init__( | ||
| self, | ||
| coordinator: AqvifyCoordinator, | ||
| description: EntityDescription, | ||
| device_key: str, | ||
| ) -> None: | ||
| """Initialize the Aqvify entity.""" | ||
| super().__init__(coordinator) | ||
|
|
||
| account_id = self.coordinator.config_entry.unique_id | ||
| self.device_key = device_key | ||
| self._attr_device_info = DeviceInfo( | ||
| identifiers={(DOMAIN, f"{account_id}_{device_key}")}, | ||
| name=coordinator.data.devices.devices[device_key].name, | ||
|
astrandb marked this conversation as resolved.
|
||
| manufacturer="Aqvify", | ||
| configuration_url="https://app.aqvify.com", | ||
| serial_number=device_key, | ||
| ) | ||
| self._attr_unique_id = f"{account_id}_{device_key}_{description.key}" | ||
| self.entity_description = description | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "entity": { | ||
| "sensor": { | ||
| "meter_value": { | ||
| "default": "mdi:waves-arrow-up" | ||
| }, | ||
| "water_level": { | ||
| "default": "mdi:waves" | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "domain": "aqvify", | ||
| "name": "Aqvify", | ||
| "codeowners": ["@astrandb"], | ||
| "config_flow": true, | ||
| "documentation": "https://www.home-assistant.io/integrations/aqvify", | ||
| "integration_type": "hub", | ||
| "iot_class": "cloud_polling", | ||
| "loggers": ["pyaqvify"], | ||
| "quality_scale": "bronze", | ||
| "requirements": ["pyaqvify==0.0.8"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| rules: | ||
| # Bronze | ||
| action-setup: | ||
| status: exempt | ||
| comment: | | ||
| No actions in this integration. | ||
| appropriate-polling: done | ||
| brands: done | ||
| common-modules: done | ||
| config-flow-test-coverage: done | ||
| config-flow: done | ||
| dependency-transparency: done | ||
| docs-actions: | ||
| status: exempt | ||
| comment: | | ||
| The integration does not provide any actions. | ||
| docs-high-level-description: done | ||
| docs-installation-instructions: done | ||
| docs-removal-instructions: done | ||
| entity-event-setup: | ||
| status: exempt | ||
| comment: | | ||
| Entities of this integration do not explicitly 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: todo | ||
| config-entry-unloading: done | ||
| docs-configuration-parameters: todo | ||
| docs-installation-parameters: todo | ||
| entity-unavailable: todo | ||
| integration-owner: todo | ||
| log-when-unavailable: todo | ||
| parallel-updates: done | ||
| reauthentication-flow: todo | ||
| test-coverage: todo | ||
|
|
||
| # Gold | ||
| devices: todo | ||
| 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: todo | ||
| entity-category: todo | ||
| entity-device-class: todo | ||
| entity-disabled-by-default: todo | ||
| entity-translations: todo | ||
| exception-translations: todo | ||
| icon-translations: done | ||
| reconfiguration-flow: todo | ||
| repair-issues: todo | ||
| stale-devices: todo | ||
|
|
||
| # Platinum | ||
| async-dependency: todo | ||
| inject-websession: todo | ||
| strict-typing: todo | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.