Skip to content

Conversation

@rytilahti
Copy link
Owner

@rytilahti rytilahti commented Mar 23, 2022

This is a first draft towards enforcing interfaces among vacuum integrations,
aimed to consolidate them to allow easier downstream support no matter implementation details.

Open questions:

  • Is this even a sane approach, wrt. simply creating an abstract base-class to inherit from
  • Status containers need their own interface
  • Find out a better way than importing typing internals for metaclass handling
  • Tests

"""Start vacuuming."""

def pause(self):
"""Pause vacuuming."""
Copy link
Contributor

@2pirko 2pirko Mar 23, 2022

Choose a reason for hiding this comment

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

Some implementation does not contain pause method. It would be good to describe, what should happen, if the method is not supported. Raise an exception?

Copy link
Owner Author

Choose a reason for hiding this comment

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

On roborock, calling pause differs from stop in sense that resuming from a pause will continue using the existing internal map if the cleaning is resumed, in contrast to starting a completely new cleaning round.

"""Return device status."""

def set_fan_speed(self, int):
"""Set fan speed."""
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to describe argument. Is argument in range 0-100 (percent)? Or can the argument be only one of the "presets"? What the method do if the argument does not match?

Copy link
Owner Author

Choose a reason for hiding this comment

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

So this was just based on the current roborock implementation, but neither viomi nor g1vacuum seem to support percentage-based fan speed setting.

The solution would be to have a set_fan_speed_preset(x) that accepts "something" that is returned by the implementations' fan_speed_presets(). A feature flag & a separate set_fan_speed_percentage(int) could be introduced for devices that support arbitrary fan speeds.

I think this is more clearly visible on some fan/air(de)humidifer implementations where the "levels" or "presets" are more common than continuous values between 0 and 100.



@runtime_checkable
class Vacuum(Protocol):
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider rename interface to IVacuum. It is useful to understand from the name, whether it is a class or interface.

@runtime_checkable
class Vacuum(Protocol):
def start(self):
"""Start vacuuming."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally it is good to specify more details about behavior of the interface methods, format of the arguments and returning value. This helps to keep implementations more consistent.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Agreed. I just made this PR to show the idea, but your earlier proposal feels like a better solution than this.

Copy link
Owner Author

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

Thanks for the comments @2pirko, I added a couple of notes how I was thinking about this. In hindsight, I think that your proposal on using abstract base classes is a better approach, at least for the very basic common interface.

"""Start vacuuming."""

def pause(self):
"""Pause vacuuming."""
Copy link
Owner Author

Choose a reason for hiding this comment

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

On roborock, calling pause differs from stop in sense that resuming from a pause will continue using the existing internal map if the cleaning is resumed, in contrast to starting a completely new cleaning round.

"""Return device status."""

def set_fan_speed(self, int):
"""Set fan speed."""
Copy link
Owner Author

Choose a reason for hiding this comment

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

So this was just based on the current roborock implementation, but neither viomi nor g1vacuum seem to support percentage-based fan speed setting.

The solution would be to have a set_fan_speed_preset(x) that accepts "something" that is returned by the implementations' fan_speed_presets(). A feature flag & a separate set_fan_speed_percentage(int) could be introduced for devices that support arbitrary fan speeds.

I think this is more clearly visible on some fan/air(de)humidifer implementations where the "levels" or "presets" are more common than continuous values between 0 and 100.

@runtime_checkable
class Vacuum(Protocol):
def start(self):
"""Start vacuuming."""
Copy link
Owner Author

Choose a reason for hiding this comment

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

Agreed. I just made this PR to show the idea, but your earlier proposal feels like a better solution than this.

@rytilahti
Copy link
Owner Author

Obsoleted in favor of #1404 - it is better to have some common API that is enforced through the abstract base class.

@rytilahti rytilahti closed this Apr 30, 2022
@rytilahti rytilahti deleted the feat/add_vacuum_protocol branch April 30, 2022 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants