-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
90 additions
and
32 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
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
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 |
---|---|---|
|
@@ -5,3 +5,5 @@ | |
"Chrome/129.0.0.0 " | ||
"Safari/537.36" | ||
) | ||
|
||
BATTERY_HEADER = "X-Inkplate-Battery-Voltage" |
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
This file was deleted.
Oops, something went wrong.
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
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
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,28 @@ | ||
from typing import cast | ||
|
||
from starlette.requests import Request | ||
|
||
from inkplate_dashboard.chrome import ChromiumInstance | ||
from inkplate_dashboard.config import DisplayConfiguration | ||
from inkplate_dashboard.constants import BATTERY_HEADER | ||
|
||
|
||
def get_chromium(request: Request) -> ChromiumInstance: | ||
return cast(ChromiumInstance, request.state.chromium) | ||
|
||
|
||
def get_display(request: Request) -> DisplayConfiguration: | ||
return cast(DisplayConfiguration, request.app.state.display) | ||
|
||
|
||
def get_voltage(request: Request) -> float | None: | ||
voltage = request.headers.get(BATTERY_HEADER) | ||
if voltage is None: | ||
return None | ||
if not voltage.endswith("V"): | ||
return None | ||
|
||
try: | ||
return float(voltage[:-1]) | ||
except ValueError: | ||
return None |
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