Skip to content

Commit

Permalink
prepare v0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
stankudrow authored and Stanley Kudrow committed Nov 8, 2024
1 parent 0ee2da9 commit 8173100
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 85 deletions.
20 changes: 1 addition & 19 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions pymbus/telegrams/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,3 @@ def fields(self) -> list[TelegramField]:

def as_bytes(self) -> bytes:
return bytes(field.byte for field in self.fields)


class TelegramBlock(TelegramContainer):
"""Base Telegram Block class."""
2 changes: 2 additions & 0 deletions pymbus/telegrams/blocks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from pymbus.telegrams.blocks.data_info import DataInformationBlock
from pymbus.telegrams.blocks.value_info import ValueInformationBlock
4 changes: 3 additions & 1 deletion pymbus/telegrams/blocks/data_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

from pymbus.exceptions import MBusError
from pymbus.telegrams.base import (
TelegramBlock,
TelegramBytesType,
)
from pymbus.telegrams.base import (
TelegramContainer as TelegramBlock,
)
from pymbus.telegrams.fields.data_info import (
DataInformationField as DIF,
)
Expand Down
4 changes: 3 additions & 1 deletion pymbus/telegrams/blocks/value_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

from pymbus.exceptions import MBusError
from pymbus.telegrams.base import (
TelegramBlock,
TelegramBytesType,
)
from pymbus.telegrams.base import (
TelegramContainer as TelegramBlock,
)
from pymbus.telegrams.fields.value_info import (
ValueInformationField as VIF,
)
Expand Down
46 changes: 46 additions & 0 deletions pymbus/telegrams/records.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from pymbus.exceptions import MBusError
from pymbus.telegrams.base import (
TelegramBytesType,
)
from pymbus.telegrams.base import (
TelegramContainer as TelegramRecord,
)
from pymbus.telegrams.blocks import (
DataInformationBlock as DIB,
)
from pymbus.telegrams.blocks import (
ValueInformationBlock as VIB,
)


class DataRecord(TelegramRecord):
"""The "Data Record" (DR) class.
Typically encountered as Data Record Header (DRH).
The structure of the DR(H):
-----------------
| DIB | VIB |
-----------------
DIB = Data Information Block.
VIB = Value Information Block.
"""

def __init__(self, ibytes: TelegramBytesType):
try:
it = iter(ibytes)
except TypeError as e:
msg = f"{ibytes} is not iterable"
raise MBusError(msg) from e

self._dib = DIB(it)
self._vib = VIB(it)

@property
def dib(self) -> DIB:
return self._dib

@property
def vib(self) -> VIB:
return self._vib
Loading

0 comments on commit 8173100

Please sign in to comment.