-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(robot-server): Robot server command responses (#7170)
* rename models. * Genericize command requests and responses closes #6519
- Loading branch information
amitlissack
authored
Jan 5, 2021
1 parent
85b3d6b
commit 4cab53f
Showing
18 changed files
with
528 additions
and
362 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
31 changes: 11 additions & 20 deletions
31
robot-server/robot_server/service/session/command_execution/command.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,46 @@ | ||
from datetime import datetime | ||
from dataclasses import dataclass, field | ||
from typing import Optional | ||
from typing import Optional, Generic, TypeVar | ||
|
||
from robot_server.service.session.models.command import ( | ||
CommandDataType, CommandStatus, CommandResultType) | ||
from robot_server.service.session.models.command_definitions import \ | ||
CommandDefinitionType | ||
CommandStatus, RequestTypes) | ||
from robot_server.service.session.models.common import ( | ||
IdentifierType, create_identifier) | ||
from opentrons.util.helpers import utc_now | ||
|
||
|
||
@dataclass(frozen=True) | ||
class CommandContent: | ||
name: CommandDefinitionType | ||
data: CommandDataType | ||
|
||
|
||
@dataclass(frozen=True) | ||
class CommandMeta: | ||
identifier: IdentifierType = field(default_factory=create_identifier) | ||
created_at: datetime = field(default_factory=utc_now) | ||
|
||
|
||
ResultTypeT = TypeVar("ResultTypeT") | ||
|
||
|
||
@dataclass(frozen=True) | ||
class CommandResult: | ||
class CommandResult(Generic[ResultTypeT]): | ||
started_at: datetime | ||
completed_at: datetime | ||
status: CommandStatus = CommandStatus.executed | ||
data: Optional[CommandResultType] = None | ||
data: Optional[ResultTypeT] = None | ||
|
||
|
||
@dataclass(frozen=True) | ||
class Command: | ||
content: CommandContent | ||
request: RequestTypes | ||
meta: CommandMeta = field(default_factory=CommandMeta) | ||
|
||
|
||
@dataclass(frozen=True) | ||
class CompletedCommand: | ||
content: CommandContent | ||
request: RequestTypes | ||
meta: CommandMeta | ||
result: CommandResult | ||
|
||
|
||
def create_command(name: CommandDefinitionType, | ||
data: CommandDataType) -> Command: | ||
def create_command(request: RequestTypes) -> Command: | ||
"""Create a command object""" | ||
return Command( | ||
content=CommandContent( | ||
name=name, | ||
data=data | ||
) | ||
request=request | ||
) |
77 changes: 0 additions & 77 deletions
77
robot-server/robot_server/service/session/command_execution/hardware_executor.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.