Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Extend COSEM DataArray in to_bytes #73

Closed
real-tintin opened this issue Jan 22, 2024 · 2 comments · Fixed by #76
Closed

Bug: Extend COSEM DataArray in to_bytes #73

real-tintin opened this issue Jan 22, 2024 · 2 comments · Fixed by #76
Assignees
Labels
bug Something isn't working

Comments

@real-tintin
Copy link

Hi Henrik,

Thanks for your DLMS package, it has been proved very useful.

Issue
I found a bug in dlms_cosem/dlms_data.py when converting the COSEM DataArray object to bytes. Atm, it appends to its bytearray from encode_variable_integer which returns bytes, this raises:

TypeError: 'bytes' object cannot be interpreted as an integer

I guess the intention is to extend as done in DataStructure.

Proposal

Change:

class DataArray(BaseDlmsData):
    """Sequence of Data"""

    TAG = 1
    LENGTH = VARIABLE_LENGTH

    def to_bytes(self) -> bytes:
        out = bytearray()
        out.append(self.TAG)
        out.append(encode_variable_integer(len(self.value)))

to:

class DataArray(BaseDlmsData):
    """Sequence of Data"""

    TAG = 1
    LENGTH = VARIABLE_LENGTH

    def to_bytes(self) -> bytes:
        out = bytearray()
        out.append(self.TAG)
        out.extend(encode_variable_integer(len(self.value)))
@Krolken Krolken self-assigned this Jan 22, 2024
@Krolken Krolken added the bug Something isn't working label Jan 22, 2024
@Krolken
Copy link
Contributor

Krolken commented Jan 22, 2024

Thanks for spotting that. I will make a change in the upcoming release.

Krolken pushed a commit that referenced this issue Jan 22, 2024
Error when creating data from DlmsData. Function returns bytes and not an int so should have been extend instead of append.

Fixes #73
(fix) Append on bytes in DataArray.to_bytes

Error when creating data from DlmsData. Function returns bytes and not an int so should have been extend instead of append.

Fixes #73
(fix) Append on bytes in DataArray.to_bytes

Error when creating data from DlmsData. Function returns bytes and not an int so should have been extend instead of append.

Fixes #73
(fix) Append on bytes in DataArray.to_bytes

Error when creating data from DlmsData. Function returns bytes and not an int so should have been extend instead of append.

Fixes #73
(fix) Append on bytes in DataArray.to_bytes

Error when creating data from DlmsData. Function returns bytes and not an int so should have been extend instead of append.

Fixes #73
(fix) Append on bytes in DataArray.to_bytes

Error when creating data from DlmsData. Function returns bytes and not an int so should have been extend instead of append.

Fixes #73
(fix) Append on bytes in DataArray.to_bytes

Error when creating data from DlmsData. Function returns bytes and not an int so should have been extend instead of append.

Fixes #73
(fix) Append on bytes in DataArray.to_bytes

Error when creating data from DlmsData. Function returns bytes and not an int so should have been extend instead of append.

Fixes #73
@real-tintin
Copy link
Author

Thanks for spotting that. I will make a change in the upcoming release.

Tack för den super snabba fixen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants