-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup internal resources for requests and responses (#80)
Update the rainbird request/response objects to be in the same format, so that we can later encode/decode them using the same functions.
- Loading branch information
1 parent
13bb8b4
commit d5fab2e
Showing
9 changed files
with
132 additions
and
110 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
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,10 +1,41 @@ | ||
"""Resources related to rainbird devices.""" | ||
|
||
from typing import Any | ||
|
||
import yaml | ||
from pkg_resources import resource_stream | ||
|
||
# parameters in number of nibbles (based on string representations of SIP bytes), total lengths in number of SIP bytes | ||
RAINBIRD_COMMANDS = yaml.load( | ||
COMMAND = "command" | ||
TYPE = "type" | ||
LENGTH = "length" | ||
RESPONSE = "response" | ||
# Fields in the command template that should not be encoded | ||
RESERVED_FIELDS = [COMMAND, TYPE, LENGTH, RESPONSE] | ||
|
||
SIP_COMMANDS = yaml.load( | ||
resource_stream("pyrainbird.resources", "sipcommands.yaml"), Loader=yaml.FullLoader | ||
) | ||
RAINBIRD_MODELS = yaml.load( | ||
resource_stream("pyrainbird.resources", "models.yaml"), Loader=yaml.FullLoader | ||
) | ||
|
||
|
||
def build_id_map(commands: dict[str, Any]) -> dict[str, Any]: | ||
"""Build an ID based map for the specified command struct.""" | ||
return { | ||
content[COMMAND]: { | ||
**content, | ||
TYPE: key, | ||
} | ||
for key, content in commands.items() | ||
} | ||
|
||
|
||
CONTROLLER_COMMANDS = "ControllerCommands" | ||
CONTROLLER_RESPONSES = "ControllerResponses" | ||
|
||
RAINBIRD_COMMANDS = {**SIP_COMMANDS[CONTROLLER_COMMANDS]} | ||
RAINBIRD_RESPONSES = {**SIP_COMMANDS[CONTROLLER_RESPONSES]} | ||
|
||
RAINBIRD_COMMANDS_BY_ID = build_id_map(SIP_COMMANDS[CONTROLLER_COMMANDS]) | ||
RAINBIRD_RESPONSES_BY_ID = build_id_map(SIP_COMMANDS[CONTROLLER_RESPONSES]) |
Oops, something went wrong.