Skip to content

Reading some parameters return 'None' rather than the correct value #9

@krcook

Description

@krcook

Version 1.4.0 (latest on PyPi)

When I read some parameters via pyebus they return a value on 'None' rather than the correct value. Reading the same parameter via ebusctl works correctly.

For example 'WaterPressure' should return a value in this example of 1.951 (bar)

I've narrowed it down to the decode() function in the IntType class (types.py)

    def decode(self, value):
        """Decode `value`."""
        if value not in ("-", ""):
            if self.divider and self.divider > 0:
                value = float(value)
            else:
                value = int(value)
            if value < self.min_:
                raise ValueError(f"Value {value} deceeds lower limit of {self.min_}")
            if value > self.max_:
                raise ValueError(f"Value {value} exceeds upper limit of {self.max_}")
            return value
        else:
            return None

In this case:
value = '1.951'
self.divider = 1000000
self.min_ = -3.2767e-5
self.max_ = 3.2767e-5

So clearly here the problem is that value is greater than self.max_ and the result is rejected.

I'm not certain how this is supposed to work - but I would speculate that self.min_ and self.max_ should be multiplied by self.divider before the bounds are checked as follows:

            if value < self.min_ * self.divider:
                raise ValueError(f"Value {value} deceeds lower limit of {self.min_ * self.divider}")
            if value > self.max_ * self.divider:
                raise ValueError(f"Value {value} exceeds upper limit of {self.max_ * self.divider}")
            return value

But I don't know if that's how it's supposed to work, or what the side effects of that change might be.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions