-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OptionalUnsigned is part of bacpypes3, no need to define it
- Loading branch information
1 parent
4f9445a
commit d4afa81
Showing
1 changed file
with
0 additions
and
45 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 |
---|---|---|
@@ -1,45 +0,0 @@ | ||
from typing import Any as Optional | ||
|
||
from bacpypes3.errors import InvalidTag | ||
from bacpypes3.primitivedata import Tag, TagClass, TagList, TagNumber, Unsigned | ||
|
||
|
||
class OptionalUnsigned(Unsigned): | ||
""" | ||
This is a special case where a vendor will send NULL values for Unsigned | ||
""" | ||
|
||
@classmethod | ||
def decode(cls, tag_list: TagList) -> Optional[Unsigned]: | ||
"""Decode an unsigned element from a tag list.""" | ||
|
||
tag: Optional[Tag] = tag_list.pop() | ||
if not tag: | ||
raise InvalidTag("unsigned application tag expected") | ||
if tag.tag_class == TagClass.application: | ||
if cls._context is not None: | ||
raise InvalidTag(f"unsigned context tag {cls._context} expected") | ||
if tag.tag_number != TagNumber.unsigned: | ||
if tag.tag_number == TagNumber.null: | ||
return None | ||
else: | ||
raise InvalidTag( | ||
f"unsigned application tag expected, got {tag.tag_number}" | ||
) | ||
elif tag.tag_class == TagClass.context: | ||
if cls._context is None: | ||
raise InvalidTag("unsigned application tag expected") | ||
if tag.tag_number != cls._context: | ||
raise InvalidTag("mismatched context") | ||
else: | ||
raise InvalidTag("unexpected opening/closing tag") | ||
if len(tag.tag_data) < 1: | ||
raise InvalidTag("invalid tag length") | ||
|
||
# get the data | ||
value = 0 | ||
for c in tag.tag_data: | ||
value = (value << 8) + c | ||
|
||
# return an instance of this thing | ||
return cls(value) | ||