Home Assistant Unofficial Reference
2024.12.1
api.py
Go to the documentation of this file.
1
"""API for Neato Botvac bound to Home Assistant OAuth."""
2
3
from
__future__
import
annotations
4
5
from
asyncio
import
run_coroutine_threadsafe
6
from
typing
import
Any
7
8
import
pybotvac
9
10
from
homeassistant
import
config_entries, core
11
from
homeassistant.components.application_credentials
import
AuthImplementation
12
from
homeassistant.helpers
import
config_entry_oauth2_flow
13
14
15
class
ConfigEntryAuth
(pybotvac.OAuthSession):
# type: ignore[misc]
16
"""Provide Neato Botvac authentication tied to an OAuth2 based config entry."""
17
18
def
__init__
(
19
self,
20
hass: core.HomeAssistant,
21
config_entry:
config_entries.ConfigEntry
,
22
implementation: config_entry_oauth2_flow.AbstractOAuth2Implementation,
23
) ->
None
:
24
"""Initialize Neato Botvac Auth."""
25
self.
hass
hass = hass
26
self.
session
session = config_entry_oauth2_flow.OAuth2Session(
27
hass, config_entry, implementation
28
)
29
super().
__init__
(self.
session
session.token, vendor=pybotvac.Neato())
30
31
def
refresh_tokens
(self) -> str:
32
"""Refresh and return new Neato Botvac tokens."""
33
run_coroutine_threadsafe(
34
self.
session
session.async_ensure_token_valid(), self.
hass
hass.loop
35
).result()
36
37
return
self.
session
session.token[
"access_token"
]
# type: ignore[no-any-return]
38
39
40
class
NeatoImplementation
(
AuthImplementation
):
41
"""Neato implementation of LocalOAuth2Implementation.
42
43
We need this class because we have to add client_secret
44
and scope to the authorization request.
45
"""
46
47
@property
48
def
extra_authorize_data
(self) -> dict[str, Any]:
49
"""Extra data that needs to be appended to the authorize url."""
50
return
{
"client_secret"
: self.client_secret}
51
52
async
def
async_generate_authorize_url
(self, flow_id: str) -> str:
53
"""Generate a url for the user to authorize.
54
55
We must make sure that the plus signs are not encoded.
56
"""
57
url = await super().
async_generate_authorize_url
(flow_id)
58
return
f
"{url}&scope=public_profile+control_robots+maps"
homeassistant.components.application_credentials.AuthImplementation
Definition:
__init__.py:189
homeassistant.components.neato.api.ConfigEntryAuth
Definition:
api.py:15
homeassistant.components.neato.api.ConfigEntryAuth.__init__
None __init__(self, core.HomeAssistant hass, config_entries.ConfigEntry config_entry, config_entry_oauth2_flow.AbstractOAuth2Implementation implementation)
Definition:
api.py:23
homeassistant.components.neato.api.ConfigEntryAuth.hass
hass
Definition:
api.py:25
homeassistant.components.neato.api.ConfigEntryAuth.refresh_tokens
str refresh_tokens(self)
Definition:
api.py:31
homeassistant.components.neato.api.ConfigEntryAuth.session
session
Definition:
api.py:26
homeassistant.components.neato.api.NeatoImplementation
Definition:
api.py:40
homeassistant.components.neato.api.NeatoImplementation.async_generate_authorize_url
str async_generate_authorize_url(self, str flow_id)
Definition:
api.py:52
homeassistant.components.neato.api.NeatoImplementation.extra_authorize_data
dict[str, Any] extra_authorize_data(self)
Definition:
api.py:48
homeassistant.config_entries.ConfigEntry
Definition:
config_entries.py:316
homeassistant.components.application_credentials
Definition:
__init__.py:1
homeassistant.helpers
Definition:
__init__.py:1
core
homeassistant
components
neato
api.py
Generated by
1.9.1