-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: first implementation of bridge v2
- Loading branch information
Showing
12 changed files
with
1,098 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import logging | ||
|
||
from aiohttp import web | ||
from emulated_hue.controllers import Controller | ||
from emulated_hue.utils import send_error_response | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class HueApiEndpoints: | ||
"""Base class for Hue API endpoints.""" | ||
|
||
def __init__(self, ctl: Controller): | ||
"""Initialize the v1 api.""" | ||
self.ctl = ctl | ||
|
||
async def async_unknown_request(self, request: web.Request): | ||
"""Handle unknown requests (catch-all).""" | ||
request_data = await request.text() | ||
if request_data: | ||
LOGGER.warning("Invalid/unknown request: %s --> %s", request, request_data) | ||
else: | ||
LOGGER.warning("Invalid/unknown request: %s", request) | ||
if request.method == "GET": | ||
address = request.path.lstrip("/").split("/") | ||
# Ensure a resource is requested | ||
if len(address) > 2: | ||
username = address[1] | ||
if not await self.ctl.config_instance.async_get_user(username): | ||
return send_error_response(request.path, "unauthorized user", 1) | ||
return send_error_response( | ||
request.path, "method, GET, not available for resource, {path}", 4 | ||
) | ||
return send_error_response(request.path, "unknown request", 404) |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.