-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Add Braava support to iRobot Roomba component #33616
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
88020be
Add Braava support to iRobot Roomba component
shenxn bb826fa
Replace async_add_job with async_add_executor_job in roomba
shenxn 523fd76
Improve readability in roomba
shenxn 2cf221a
Improve error handling in roomba
shenxn 7400abe
Cleanup async_update in roomba
shenxn 1b2acec
Split into multiple files in roomba
shenxn a516e00
Hide protocal details in braava
shenxn 4b77a3a
Switch to push in braava
shenxn bf5a640
Bump roombapy version to 1.5.1
shenxn 0a364b1
Add roomba files to .coveragerc
shenxn 7044f5a
Fix typo
shenxn ab2e0ea
Remove side effects from init in roomba
shenxn 50522b0
Implement StateVacuumDevice in Roomba
shenxn aa59bee
Add IRobotEntity base class to braava
shenxn 67ac480
Fix state in roomba
shenxn 79ad110
Add @shenxn as a codeowner of braava
shenxn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| """Class for Braava devices.""" | ||
| import logging | ||
|
|
||
| from homeassistant.components.vacuum import SUPPORT_FAN_SPEED | ||
|
|
||
| from .irobot_base import SUPPORT_IROBOT, IRobotVacuum | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| ATTR_DETECTED_PAD = "detected_pad" | ||
| ATTR_LID_CLOSED = "lid_closed" | ||
| ATTR_TANK_PRESENT = "tank_present" | ||
| ATTR_TANK_LEVEL = "tank_level" | ||
| ATTR_PAD_WETNESS = "spray_amount" | ||
|
|
||
| OVERLAP_STANDARD = 67 | ||
| OVERLAP_DEEP = 85 | ||
| OVERLAP_EXTENDED = 25 | ||
| MOP_STANDARD = "Standard" | ||
| MOP_DEEP = "Deep" | ||
| MOP_EXTENDED = "Extended" | ||
| BRAAVA_MOP_BEHAVIORS = [MOP_STANDARD, MOP_DEEP, MOP_EXTENDED] | ||
| BRAAVA_SPRAY_AMOUNT = [1, 2, 3] | ||
|
|
||
| # Braava Jets can set mopping behavior through fanspeed | ||
| SUPPORT_BRAAVA = SUPPORT_IROBOT | SUPPORT_FAN_SPEED | ||
|
|
||
|
|
||
| class BraavaJet(IRobotVacuum): | ||
| """Braava Jet.""" | ||
|
|
||
| def __init__(self, roomba, blid): | ||
| """Initialize the Roomba handler.""" | ||
| super().__init__(roomba, blid) | ||
|
|
||
| # Initialize fan speed list | ||
| speed_list = [] | ||
| for behavior in BRAAVA_MOP_BEHAVIORS: | ||
| for spray in BRAAVA_SPRAY_AMOUNT: | ||
| speed_list.append(f"{behavior}-{spray}") | ||
| self._speed_list = speed_list | ||
|
|
||
| @property | ||
| def supported_features(self): | ||
| """Flag vacuum cleaner robot features that are supported.""" | ||
| return SUPPORT_BRAAVA | ||
|
|
||
| @property | ||
| def fan_speed(self): | ||
| """Return the fan speed of the vacuum cleaner.""" | ||
| # Mopping behavior and spray amount as fan speed | ||
| rank_overlap = self.vacuum_state.get("rankOverlap", {}) | ||
| behavior = None | ||
| if rank_overlap == OVERLAP_STANDARD: | ||
| behavior = MOP_STANDARD | ||
| elif rank_overlap == OVERLAP_DEEP: | ||
| behavior = MOP_DEEP | ||
| elif rank_overlap == OVERLAP_EXTENDED: | ||
| behavior = MOP_EXTENDED | ||
| pad_wetness = self.vacuum_state.get("padWetness", {}) | ||
| # "disposable" and "reusable" values are always the same | ||
| pad_wetness_value = pad_wetness.get("disposable") | ||
| return f"{behavior}-{pad_wetness_value}" | ||
|
|
||
| @property | ||
| def fan_speed_list(self): | ||
| """Get the list of available fan speed steps of the vacuum cleaner.""" | ||
| return self._speed_list | ||
|
|
||
| async def async_set_fan_speed(self, fan_speed, **kwargs): | ||
| """Set fan speed.""" | ||
| try: | ||
| split = fan_speed.split("-", 1) | ||
| behavior = split[0] | ||
| spray = int(split[1]) | ||
| if behavior.capitalize() in BRAAVA_MOP_BEHAVIORS: | ||
| behavior = behavior.capitalize() | ||
| except IndexError: | ||
| _LOGGER.error( | ||
| "Fan speed error: expected {behavior}-{spray_amount}, got '%s'", | ||
| fan_speed, | ||
| ) | ||
| return | ||
| except ValueError: | ||
| _LOGGER.error("Spray amount error: expected integer, got '%s'", split[1]) | ||
| return | ||
| if behavior not in BRAAVA_MOP_BEHAVIORS: | ||
| _LOGGER.error( | ||
| "Mop behavior error: expected one of %s, got '%s'", | ||
| str(BRAAVA_MOP_BEHAVIORS), | ||
| behavior, | ||
| ) | ||
| return | ||
| if spray not in BRAAVA_SPRAY_AMOUNT: | ||
| _LOGGER.error( | ||
| "Spray amount error: expected one of %s, got '%d'", | ||
| str(BRAAVA_SPRAY_AMOUNT), | ||
| spray, | ||
| ) | ||
| return | ||
|
|
||
| overlap = 0 | ||
| if behavior == MOP_STANDARD: | ||
| overlap = OVERLAP_STANDARD | ||
| elif behavior == MOP_DEEP: | ||
| overlap = OVERLAP_DEEP | ||
| else: | ||
| overlap = OVERLAP_EXTENDED | ||
| await self.hass.async_add_executor_job( | ||
| self.vacuum.set_preference, "rankOverlap", overlap | ||
| ) | ||
| await self.hass.async_add_executor_job( | ||
| self.vacuum.set_preference, | ||
| "padWetness", | ||
| {"disposable": spray, "reusable": spray}, | ||
| ) | ||
|
|
||
| @property | ||
| def device_state_attributes(self): | ||
| """Return the state attributes of the device.""" | ||
| state_attrs = super().device_state_attributes | ||
|
|
||
| # Get Braava state | ||
| state = self.vacuum_state | ||
| detected_pad = state.get("detectedPad") | ||
| mop_ready = state.get("mopReady", {}) | ||
| lid_closed = mop_ready.get("lidClosed") | ||
| tank_present = mop_ready.get("tankPresent") | ||
| tank_level = state.get("tankLvl") | ||
| state_attrs[ATTR_DETECTED_PAD] = detected_pad | ||
| state_attrs[ATTR_LID_CLOSED] = lid_closed | ||
| state_attrs[ATTR_TANK_PRESENT] = tank_present | ||
| state_attrs[ATTR_TANK_LEVEL] = tank_level | ||
|
|
||
| return state_attrs |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.