Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions canopen/objectdictionary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,12 @@ def decode_phys(self, value: int) -> Union[int, bool, float, str, bytes]:

def encode_phys(self, value: Union[int, bool, float, str, bytes]) -> int:
if self.data_type in INTEGER_TYPES:
value /= self.factor
value = int(round(value))
if self.factor == 1:
pass
elif isinstance(value, int) and isinstance(self.factor, int):
value = value // self.factor
else:
value = int(round(value / self.factor))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

round() already returns an integer if ndigits is omitted.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round was the original code. My contribution is only the // division, which is my use case is the right thing to do. What do you suggest?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you touch / edit this code and such a useless call is found, please remove it as part of your change.

return value

def decode_desc(self, value: int) -> str:
Expand Down