Skip to content

Commit

Permalink
Merge pull request #123 from NabuCasa/dev
Browse files Browse the repository at this point in the history
0.31
  • Loading branch information
balloob authored Jan 6, 2020
2 parents 326d29e + a7fe5eb commit 7cf0509
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 16 deletions.
3 changes: 0 additions & 3 deletions hass_nabucasa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def __init__(
region=None,
relayer=None,
google_actions_report_state_url=None,
google_actions_sync_url=None,
subscription_info_url=None,
cloudhook_create_url=None,
remote_api_url=None,
Expand Down Expand Up @@ -69,7 +68,6 @@ def __init__(
self.region = region
self.relayer = relayer
self.google_actions_report_state_url = google_actions_report_state_url
self.google_actions_sync_url = google_actions_sync_url
self.subscription_info_url = subscription_info_url
self.cloudhook_create_url = cloudhook_create_url
self.remote_api_url = remote_api_url
Expand All @@ -87,7 +85,6 @@ def __init__(
self.region = info["region"]
self.relayer = info["relayer"]
self.google_actions_report_state_url = info["google_actions_report_state_url"]
self.google_actions_sync_url = info["google_actions_sync_url"]
self.subscription_info_url = info["subscription_info_url"]
self.cloudhook_create_url = info["cloudhook_create_url"]
self.remote_api_url = info["remote_api_url"]
Expand Down
14 changes: 13 additions & 1 deletion hass_nabucasa/cloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,27 @@ async def async_remote_challenge_cleanup(cloud, txt: str):


@_check_token
@_log_response
async def async_alexa_access_token(cloud):
"""Create a cloudhook."""
"""Request Alexa access token."""
return await cloud.websession.post(
cloud.alexa_access_token_url, headers={AUTHORIZATION: cloud.id_token}
)


@_check_token
@_log_response
async def async_voice_connection_details(cloud):
"""Return connection details for voice service."""
url = f"{cloud.voice_api_url}/connection_details"
return await cloud.websession.get(url, headers={AUTHORIZATION: cloud.id_token})


@_check_token
@_log_response
async def async_google_actions_request_sync(cloud):
"""Request a Google Actions sync request."""
return await cloud.websession.post(
f"{cloud.google_actions_report_state_url}/request_sync",
headers={AUTHORIZATION: f"Bearer {cloud.id_token}"},
)
6 changes: 1 addition & 5 deletions hass_nabucasa/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
"user_pool_id": "us-east-1_87ll5WOP8",
"region": "us-east-1",
"relayer": "wss://cloud.nabucasa.com/websocket",
"google_actions_report_state_url": "wss://remotestate.nabucasa.com/v1",
"google_actions_sync_url": (
"https://24ab3v80xd.execute-api.us-east-1."
"amazonaws.com/prod/smart_home_sync"
),
"google_actions_report_state_url": "https://remotestate.nabucasa.com",
"subscription_info_url": (
"https://stripe-api.nabucasa.com/payments/" "subscription_info"
),
Expand Down
3 changes: 2 additions & 1 deletion hass_nabucasa/google_report_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def package_name(self) -> str:
@property
def ws_server_url(self) -> str:
"""Server to connect to."""
return self.cloud.google_actions_report_state_url
# https -> wss, http -> ws
return f"ws{self.cloud.google_actions_report_state_url[4:]}/v1"

async def async_send_message(self, msg):
"""Send a message."""
Expand Down
2 changes: 1 addition & 1 deletion requirements_tests.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
flake8==3.7.9
pylint==2.4.4
pytest==5.2.2
pytest==5.3.2
pytest-timeout==1.3.3
pytest-aiohttp==0.3.0
black==19.10b0
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup

VERSION = "0.30"
VERSION = "0.31"

setup(
name="hass-nabucasa",
Expand Down Expand Up @@ -30,7 +30,7 @@
install_requires=[
"warrant==0.6.1",
"snitun==0.20",
"acme==0.39.0",
"acme==0.40.1",
"cryptography>=2.5",
"attrs>=18.2.0",
"pytz",
Expand Down
18 changes: 17 additions & 1 deletion tests/test_google_report_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,29 @@ async def create_grs(loop, ws_server, server_msg_handler) -> GoogleReportState:
mock_cloud = Mock(
run_task=loop.create_task,
subscription_expired=False,
google_actions_report_state_url="mock-report-state-url",
google_actions_report_state_url="https://mock-report-state-url.com",
auth=Mock(async_check_token=Mock(side_effect=mock_coro)),
websession=Mock(ws_connect=Mock(return_value=mock_coro(client))),
)
return GoogleReportState(mock_cloud)


async def test_ws_server_url():
"""Test generating ws server url."""
assert (
GoogleReportState(
Mock(google_actions_report_state_url="https://example.com")
).ws_server_url
== "wss://example.com/v1"
)
assert (
GoogleReportState(
Mock(google_actions_report_state_url="http://example.com")
).ws_server_url
== "ws://example.com/v1"
)


async def test_send_messages(loop, ws_server):
"""Test that we connect if we are not connected."""
server_msgs = []
Expand Down
2 changes: 0 additions & 2 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def test_constructor_loads_info_from_constant(cloud_client):
"user_pool_id": "test-user_pool_id",
"region": "test-region",
"relayer": "test-relayer",
"google_actions_sync_url": "test-google_actions_sync_url",
"subscription_info_url": "test-subscription-info-url",
"cloudhook_create_url": "test-cloudhook_create_url",
"remote_api_url": "test-remote_api_url",
Expand All @@ -38,7 +37,6 @@ def test_constructor_loads_info_from_constant(cloud_client):
assert cl.user_pool_id == "test-user_pool_id"
assert cl.region == "test-region"
assert cl.relayer == "test-relayer"
assert cl.google_actions_sync_url == "test-google_actions_sync_url"
assert cl.subscription_info_url == "test-subscription-info-url"
assert cl.cloudhook_create_url == "test-cloudhook_create_url"
assert cl.remote_api_url == "test-remote_api_url"
Expand Down

0 comments on commit 7cf0509

Please sign in to comment.