Skip to content

Add support for Summing up deque of quantities #26

@matthias-wende-frequenz

Description

@matthias-wende-frequenz

What's needed?

from frequenz.quantities import Power
from collections import deque

power1 = Power.from_watts(230.0)
power2 = Power.from_watts(240.0)

power_deque = deque([power1, power2])
sum(power_deque)

This code stops with this error TypeError: unsupported operand type(s) for +: 'int' and 'Power'

Proposed solution

The reason is that the sum starts with an integer 0. This we need to implement the __add__ method for quantities that excepts integers.

Use cases

No response

Alternatives and workarounds

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions