Add Config flow to august (#32133)
* Add battery sensors for August devices * Additional tests and cleanup in prep for config flow and device registry * pylint * update name for new style guidelines - https://developers.home-assistant.io/docs/development_guidelines/#use-new-style-string-formatting * Config Flow for august push * Update homeassistant/components/august/__init__.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * Address review items * Update tests Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
900714a3ee
commit
2925e0617c
25 changed files with 1686 additions and 444 deletions
49
tests/components/august/test_gateway.py
Normal file
49
tests/components/august/test_gateway.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
"""The gateway tests for the august platform."""
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from asynctest import mock
|
||||
|
||||
from homeassistant.components.august.const import DOMAIN
|
||||
from homeassistant.components.august.gateway import AugustGateway
|
||||
|
||||
from tests.components.august.mocks import _mock_august_authentication, _mock_get_config
|
||||
|
||||
|
||||
async def test_refresh_access_token(hass):
|
||||
"""Test token refreshes."""
|
||||
await _patched_refresh_access_token(hass, "new_token", 5678)
|
||||
|
||||
|
||||
@mock.patch("homeassistant.components.august.gateway.Authenticator.authenticate")
|
||||
@mock.patch("homeassistant.components.august.gateway.Authenticator.should_refresh")
|
||||
@mock.patch(
|
||||
"homeassistant.components.august.gateway.Authenticator.refresh_access_token"
|
||||
)
|
||||
async def _patched_refresh_access_token(
|
||||
hass,
|
||||
new_token,
|
||||
new_token_expire_time,
|
||||
refresh_access_token_mock,
|
||||
should_refresh_mock,
|
||||
authenticate_mock,
|
||||
):
|
||||
authenticate_mock.side_effect = MagicMock(
|
||||
return_value=_mock_august_authentication("original_token", 1234)
|
||||
)
|
||||
august_gateway = AugustGateway(hass)
|
||||
mocked_config = _mock_get_config()
|
||||
august_gateway.async_setup(mocked_config[DOMAIN])
|
||||
august_gateway.authenticate()
|
||||
|
||||
should_refresh_mock.return_value = False
|
||||
await august_gateway.async_refresh_access_token_if_needed()
|
||||
refresh_access_token_mock.assert_not_called()
|
||||
|
||||
should_refresh_mock.return_value = True
|
||||
refresh_access_token_mock.return_value = _mock_august_authentication(
|
||||
new_token, new_token_expire_time
|
||||
)
|
||||
await august_gateway.async_refresh_access_token_if_needed()
|
||||
refresh_access_token_mock.assert_called()
|
||||
assert august_gateway.access_token == new_token
|
||||
assert august_gateway.authentication.access_token_expires == new_token_expire_time
|
Loading…
Add table
Add a link
Reference in a new issue