-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for ARC and some refactoring
- Loading branch information
Showing
7 changed files
with
221 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,6 @@ ignore = | |
W503, | ||
E203, | ||
D202, | ||
W504 | ||
W504, | ||
D401 | ||
noqa-require-code = True |
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,42 @@ | ||
"""Module containing the parser for Anthem command.""" | ||
|
||
|
||
class ParsedMessage: | ||
"""Class containing parsed message information.""" | ||
|
||
command: str | ||
value: str | ||
input_number: int | None | ||
|
||
|
||
def parse_message(message: str) -> ParsedMessage: | ||
"""Try to parse a message to a ParsedMessage object.""" | ||
return parse_x40_message(message) | ||
|
||
|
||
def parse_x40_message(message: str) -> ParsedMessage: | ||
"""Try to parse a message for the x40 models.""" | ||
return parse_x40_input_message(message, "ARC") | ||
|
||
|
||
def parse_x40_input_message(message: str, command: str) -> ParsedMessage: | ||
"""Try to parse a message associated to a specific input for the x40 models.""" | ||
if ( | ||
message.startswith("IS") | ||
and command in message | ||
and len(message) >= len(command) + 4 | ||
): | ||
parsed_message = ParsedMessage() | ||
command_position = message.index(command) | ||
parsed_message.command = message[0 : command_position + len(command)] | ||
parsed_message.input_number = int(message[2:command_position]) | ||
parsed_message.value = message[command_position + len(command) :] | ||
return parsed_message | ||
return None | ||
|
||
|
||
def get_x40_input_command(self, input_number: int, command: str) -> str | None: | ||
"""Return a formatted message for a specific input.""" | ||
if input_number > 0: | ||
return f"IS{self.input_number}{command}" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ def readme(): | |
|
||
setup( | ||
name="anthemav", | ||
version="1.4.1", | ||
version="1.4.2", | ||
author="David McNett", | ||
author_email="[email protected]", | ||
url="https://github.com/nugget/python-anthemav", | ||
|
Oops, something went wrong.