Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: First implementation of the bridge apiv2 #490

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ __pycache__
# VSCode
/.vscode/launch.json

# IntelliJ
/.idea/
*.iml

# Ruff cache
/.ruff_cache

Expand Down
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
Loading