Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -28,10 +28,14 @@ _LOGGER = logging.getLogger(__name__)
|
||||
class CloudClient(Interface):
|
||||
"""Interface class for Home Assistant Cloud."""
|
||||
|
||||
def __init__(self, hass: HomeAssistantType, prefs: CloudPreferences,
|
||||
websession: aiohttp.ClientSession,
|
||||
alexa_user_config: Dict[str, Any],
|
||||
google_user_config: Dict[str, Any]):
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistantType,
|
||||
prefs: CloudPreferences,
|
||||
websession: aiohttp.ClientSession,
|
||||
alexa_user_config: Dict[str, Any],
|
||||
google_user_config: Dict[str, Any],
|
||||
):
|
||||
"""Initialize client interface to Cloud."""
|
||||
self._hass = hass
|
||||
self._prefs = prefs
|
||||
@@ -83,7 +87,8 @@ class CloudClient(Interface):
|
||||
if self._alexa_config is None:
|
||||
assert self.cloud is not None
|
||||
self._alexa_config = alexa_config.AlexaConfig(
|
||||
self._hass, self.alexa_user_config, self._prefs, self.cloud)
|
||||
self._hass, self.alexa_user_config, self._prefs, self.cloud
|
||||
)
|
||||
|
||||
return self._alexa_config
|
||||
|
||||
@@ -93,7 +98,8 @@ class CloudClient(Interface):
|
||||
if not self._google_config:
|
||||
assert self.cloud is not None
|
||||
self._google_config = google_config.CloudGoogleConfig(
|
||||
self.google_user_config, self._prefs, self.cloud)
|
||||
self.google_user_config, self._prefs, self.cloud
|
||||
)
|
||||
|
||||
return self._google_config
|
||||
|
||||
@@ -101,8 +107,7 @@ class CloudClient(Interface):
|
||||
"""Initialize the client."""
|
||||
self.cloud = cloud
|
||||
|
||||
if (not self.alexa_config.should_report_state or
|
||||
not self.cloud.is_logged_in):
|
||||
if not self.alexa_config.should_report_state or not self.cloud.is_logged_in:
|
||||
return
|
||||
|
||||
try:
|
||||
@@ -127,16 +132,13 @@ class CloudClient(Interface):
|
||||
if identifier.startswith("remote_"):
|
||||
async_dispatcher_send(self._hass, DISPATCHER_REMOTE_UPDATE, data)
|
||||
|
||||
async def async_alexa_message(
|
||||
self, payload: Dict[Any, Any]) -> Dict[Any, Any]:
|
||||
async def async_alexa_message(self, payload: Dict[Any, Any]) -> Dict[Any, Any]:
|
||||
"""Process cloud alexa message to client."""
|
||||
return await alexa_sh.async_handle_message(
|
||||
self._hass, self.alexa_config, payload,
|
||||
enabled=self._prefs.alexa_enabled
|
||||
self._hass, self.alexa_config, payload, enabled=self._prefs.alexa_enabled
|
||||
)
|
||||
|
||||
async def async_google_message(
|
||||
self, payload: Dict[Any, Any]) -> Dict[Any, Any]:
|
||||
async def async_google_message(self, payload: Dict[Any, Any]) -> Dict[Any, Any]:
|
||||
"""Process cloud google message to client."""
|
||||
if not self._prefs.google_enabled:
|
||||
return ga.turned_off_response(payload)
|
||||
@@ -145,44 +147,39 @@ class CloudClient(Interface):
|
||||
self._hass, self.google_config, self.prefs.cloud_user, payload
|
||||
)
|
||||
|
||||
async def async_webhook_message(
|
||||
self, payload: Dict[Any, Any]) -> Dict[Any, Any]:
|
||||
async def async_webhook_message(self, payload: Dict[Any, Any]) -> Dict[Any, Any]:
|
||||
"""Process cloud webhook message to client."""
|
||||
cloudhook_id = payload['cloudhook_id']
|
||||
cloudhook_id = payload["cloudhook_id"]
|
||||
|
||||
found = None
|
||||
for cloudhook in self._prefs.cloudhooks.values():
|
||||
if cloudhook['cloudhook_id'] == cloudhook_id:
|
||||
if cloudhook["cloudhook_id"] == cloudhook_id:
|
||||
found = cloudhook
|
||||
break
|
||||
|
||||
if found is None:
|
||||
return {
|
||||
'status': 200
|
||||
}
|
||||
return {"status": 200}
|
||||
|
||||
request = MockRequest(
|
||||
content=payload['body'].encode('utf-8'),
|
||||
headers=payload['headers'],
|
||||
method=payload['method'],
|
||||
query_string=payload['query'],
|
||||
content=payload["body"].encode("utf-8"),
|
||||
headers=payload["headers"],
|
||||
method=payload["method"],
|
||||
query_string=payload["query"],
|
||||
)
|
||||
|
||||
response = await self._hass.components.webhook.async_handle_webhook(
|
||||
found['webhook_id'], request)
|
||||
found["webhook_id"], request
|
||||
)
|
||||
|
||||
response_dict = utils.aiohttp_serialize_response(response)
|
||||
body = response_dict.get('body')
|
||||
body = response_dict.get("body")
|
||||
|
||||
return {
|
||||
'body': body,
|
||||
'status': response_dict['status'],
|
||||
'headers': {
|
||||
'Content-Type': response.content_type
|
||||
}
|
||||
"body": body,
|
||||
"status": response_dict["status"],
|
||||
"headers": {"Content-Type": response.content_type},
|
||||
}
|
||||
|
||||
async def async_cloudhooks_update(
|
||||
self, data: Dict[str, Dict[str, str]]) -> None:
|
||||
async def async_cloudhooks_update(self, data: Dict[str, Dict[str, str]]) -> None:
|
||||
"""Update local list of cloudhooks."""
|
||||
await self._prefs.async_update(cloudhooks=data)
|
||||
Reference in new issue
Block a user