1
0
mirror of https://github.com/home-assistant/core.git synced 2025-07-22 12:47:08 +00:00
Jake Martin 6e024d54f1
Add Monzo integration ()
* Initial monzo implementation

* Tests and fixes

* Extracted api to pypi package

* Add app confirmation step

* Corrected data path for accounts

* Removed useless check

* Improved tests

* Exclude partially tested files from coverage check

* Use has_entity_name naming

* Bumped monzopy to 1.0.10

* Remove commented out code

* Remove reauth from initial PR

* Remove useless code

* Correct comment

* Remove reauth tests

* Remove device triggers from intial PR

* Set attr outside constructor

* Remove f-strings where no longer needed in entity.py

* Rename field to make clearer it's a Callable

* Correct native_unit_of_measurement

* Remove pot transfer service from intial PR

* Remove reauth string

* Remove empty fields in manifest.json

* Freeze SensorEntityDescription and remove Mixin

Also use list comprehensions for producing sensor lists

* Use consts in application_credentials.py

* Revert "Remove useless code"

Apparently this wasn't useless

This reverts commit c6b7109e47202f866c766ea4c16ce3eb0588795b.

* Ruff and pylint style fixes

* Bumped monzopy to 1.1.0

Adds support for joint/business/etc account pots

* Update test snapshot

* Rename AsyncConfigEntryAuth

* Use dataclasses instead of dictionaries

* Move OAuth constants to application_credentials.py

* Remove remaining constants and dependencies for services from this PR

* Remove empty manifest entry

* Fix comment

* Set device entry_type to service

* ACC_SENSORS -> ACCOUNT_SENSORS

* Make value_fn of sensors return StateType

* Rename OAuthMonzoAPI again

* Fix tests

* Patch API instead of integration for unavailable test

* Move pot constant to sensor.py

* Improve type safety in async_get_monzo_api_data()

* Update async_oauth_create_entry() docstring

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-05-07 20:38:58 +02:00

53 lines
1.5 KiB
Python

"""Config flow for Monzo."""
from __future__ import annotations
import logging
from typing import Any
import voluptuous as vol
from homeassistant.config_entries import ConfigFlowResult
from homeassistant.const import CONF_TOKEN
from homeassistant.helpers import config_entry_oauth2_flow
from .const import DOMAIN
class MonzoFlowHandler(
config_entry_oauth2_flow.AbstractOAuth2FlowHandler, domain=DOMAIN
):
"""Handle a config flow."""
DOMAIN = DOMAIN
oauth_data: dict[str, Any]
@property
def logger(self) -> logging.Logger:
"""Return logger."""
return logging.getLogger(__name__)
async def async_step_await_approval_confirmation(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Wait for the user to confirm in-app approval."""
if user_input is not None:
return self.async_create_entry(title=DOMAIN, data={**self.oauth_data})
data_schema = vol.Schema({vol.Required("confirm"): bool})
return self.async_show_form(
step_id="await_approval_confirmation", data_schema=data_schema
)
async def async_oauth_create_entry(self, data: dict[str, Any]) -> ConfigFlowResult:
"""Create an entry for the flow."""
user_id = str(data[CONF_TOKEN]["user_id"])
await self.async_set_unique_id(user_id)
self._abort_if_unique_id_configured()
self.oauth_data = data
return await self.async_step_await_approval_confirmation()