Skip to content

Commit

Permalink
feat: first implementation of bridge v2
Browse files Browse the repository at this point in the history
  • Loading branch information
glebiller committed Sep 30, 2023
1 parent 3eb6e7a commit 2d9387a
Show file tree
Hide file tree
Showing 12 changed files with 1,098 additions and 195 deletions.
34 changes: 34 additions & 0 deletions emulated_hue/api.py
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)
259 changes: 122 additions & 137 deletions emulated_hue/apiv1.py

Large diffs are not rendered by default.

Loading

0 comments on commit 2d9387a

Please sign in to comment.