-
Notifications
You must be signed in to change notification settings - Fork 6
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
16 changed files
with
287 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import sanic | ||
from interactor.commander.devices import Devices | ||
from interactor.commander.selector import Selector | ||
from interactor.commander.store import Command, store | ||
from photons_web_server import commander | ||
|
||
|
||
@store.command | ||
class DiscoveryCommands(Command): | ||
@classmethod | ||
def add_routes(kls, routes: commander.RouteTransformer) -> None: | ||
routes.http(kls.discover, "/v1/discover/serials/<selector>", methods=["GET"]) | ||
routes.http( | ||
kls.discover, "/v1/discover/serials", methods=["GET"], name="v1_discover_serials_all" | ||
) | ||
|
||
async def discover( | ||
self, | ||
progress: commander.Progress, | ||
request: commander.Request, | ||
selector: Selector, | ||
/, | ||
) -> commander.Response | None: | ||
devices = self.create(Devices, {"selector": selector}) | ||
return sanic.json(await devices.serials()) |
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,6 @@ | ||
import os | ||
|
||
for filename in os.listdir(os.path.dirname(__file__)): | ||
if not filename.startswith("_") and filename.endswith(".py"): | ||
name = filename[:-3] | ||
__import__(f"interactor.commander.commands.{name}") |
File renamed without changes.
15 changes: 13 additions & 2 deletions
15
...tor/interactor/commander/commands/base.py → ...or/interactor/commander/commands2/base.py
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,31 @@ | ||
import attrs | ||
import strcs | ||
from interactor.commander.store import creator | ||
from photons_app.registers import ReferenceResolverRegister | ||
from photons_app.special import SpecialReference | ||
|
||
|
||
@attrs.define | ||
class Selector: | ||
raw: str | ||
selector: SpecialReference | ||
|
||
|
||
@creator(Selector) | ||
def create_selector( | ||
val: object, /, reference_resolver_register: ReferenceResolverRegister | ||
) -> strcs.ConvertResponse[Selector]: | ||
if val is strcs.NotSpecified: | ||
val = "_" | ||
if isinstance(val, str): | ||
return {"raw": val, "selector": reference_resolver_register.reference_object(val)} | ||
return None | ||
|
||
|
||
@creator(SpecialReference) | ||
def create_special_reference( | ||
val: object, /, reference_resolver_register: ReferenceResolverRegister | ||
) -> strcs.ConvertResponse[SpecialReference]: | ||
if isinstance(val, Selector): | ||
return val.selector | ||
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
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
Oops, something went wrong.