Skip to content

Conversation

@brendanm720
Copy link
Contributor

@brendanm720 brendanm720 commented Dec 7, 2024

Good Evening!

Apparently the white and black vaccums each have a different class ID. I only have the White one at my disposal, and someone commented on my original pull request that theirs wasn't working with the log.

Please merge this file to add support for the Deebot N8+ Black Variant. It is the same as the other one I submitted as they are identical vacuums other than the color of the plastic.

Thank you.

Summary by CodeRabbit

  • New Features

    • Introduced a new file for the DEEBOT N8+ vacuum cleaner, enhancing its capabilities, including cleaning actions, battery management, and error handling.
  • Tests

    • Expanded test coverage by adding the new device identifier "b2jqs4" to the test suite, ensuring comprehensive validation of device functionalities.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 7, 2024

Walkthrough

The changes introduce a new file, b2jqs4.py, which implements the capabilities of the DEEBOT N8+ vacuum cleaner. This file encapsulates various functionalities within a StaticDeviceInfo instance, including device specifications, battery management, cleaning actions, and error handling. Additionally, modifications to the test suite in tests/hardware/test_init.py enhance test coverage by adding the new device identifier "b2jqs4" and updating event-command mappings for existing device classes.

Changes

File Path Change Summary
deebot_client/hardware/deebot/b2jqs4.py New file introduced for DEEBOT N8+ capabilities, defining functionalities like cleaning, fan control, and error handling.
tests/hardware/test_init.py Added new device identifier "b2jqs4" to test_all_models_loaded; updated test_capabilities_event_extraction for new event-command mappings.

Possibly related PRs

Suggested labels

pr: new-feature

Suggested reviewers

  • edenhaus

🐰 In the world of dust and cheer,
The DEEBOT N8+ now draws near.
With cleaning skills and fan so bright,
It sweeps away the dirt from sight!
A new device, a test to see,
Hop along, let's set it free! 🧹✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Dec 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.81%. Comparing base (e0fde3d) to head (8de0439).
Report is 6 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #644      +/-   ##
==========================================
+ Coverage   86.68%   86.81%   +0.12%     
==========================================
  Files          90       91       +1     
  Lines        3365     3397      +32     
  Branches      298      298              
==========================================
+ Hits         2917     2949      +32     
  Misses        394      394              
  Partials       54       54              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
tests/hardware/test_init.py (1)

268-268: Automate the device list to reduce maintenance overhead

The current test hardcodes the list of device class IDs, which requires manual updates whenever a new device is added. Consider generating the list dynamically from the DEVICES dictionary to prevent test failures due to missing updates.

You can modify the test function as follows:

 def test_all_models_loaded() -> None:
     """Test that all models are loaded."""
     _load()
-    assert list(DEVICES) == [
-        "1vxt52",
-        "2ap5uq",
-        # ... other device IDs ...
-        "zjavof",
-        "zwkcqc",
-    ]
+    expected_devices = [
+        "1vxt52",
+        "2ap5uq",
+        # ... other device IDs ...
+        "zjavof",
+        "zwkcqc",
+    ]
+    assert set(DEVICES.keys()) == set(expected_devices)

Alternatively, if the exact order of devices is not crucial, you can simplify the assertion:

 def test_all_models_loaded() -> None:
     """Test that all models are loaded."""
     _load()
-    assert list(DEVICES) == [
-        # ... device IDs ...
-    ]
+    assert len(DEVICES) == expected_number_of_devices
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e0fde3d and 8de0439.

📒 Files selected for processing (2)
  • deebot_client/hardware/deebot/b2jqs4.py (1 hunks)
  • tests/hardware/test_init.py (1 hunks)

Comment on lines +95 to +198
DEVICES[short_name(__name__)] = StaticDeviceInfo(
DataType.JSON,
Capabilities(
device_type=DeviceType.VACUUM,
availability=CapabilityEvent(
AvailabilityEvent, [GetBattery(is_available_check=True)]
),
battery=CapabilityEvent(BatteryEvent, [GetBattery()]),
charge=CapabilityExecute(Charge),
clean=CapabilityClean(
action=CapabilityCleanAction(command=Clean, area=CleanArea),
continuous=CapabilitySetEnable(
ContinuousCleaningEvent,
[GetContinuousCleaning()],
SetContinuousCleaning,
),
count=CapabilitySet(CleanCountEvent, [GetCleanCount()], SetCleanCount),
log=CapabilityEvent(CleanLogEvent, [GetCleanLogs()]),
preference=CapabilitySetEnable(
CleanPreferenceEvent, [GetCleanPreference()], SetCleanPreference
),
),
custom=CapabilityCustomCommand(
event=CustomCommandEvent, get=[], set=CustomCommand
),
error=CapabilityEvent(ErrorEvent, [GetError()]),
fan_speed=CapabilitySetTypes(
event=FanSpeedEvent,
get=[GetFanSpeed()],
set=SetFanSpeed,
types=(
FanSpeedLevel.QUIET,
FanSpeedLevel.NORMAL,
FanSpeedLevel.MAX,
FanSpeedLevel.MAX_PLUS,
),
),
life_span=CapabilityLifeSpan(
types=(
LifeSpan.BRUSH,
LifeSpan.FILTER,
LifeSpan.SIDE_BRUSH,
LifeSpan.UNIT_CARE,
),
event=LifeSpanEvent,
get=[
GetLifeSpan(
[
LifeSpan.BRUSH,
LifeSpan.FILTER,
LifeSpan.SIDE_BRUSH,
LifeSpan.UNIT_CARE,
]
)
],
reset=ResetLifeSpan,
),
map=CapabilityMap(
cached_info=CapabilityEvent(CachedMapInfoEvent, [GetCachedMapInfo()]),
changed=CapabilityEvent(MapChangedEvent, []),
major=CapabilityEvent(MajorMapEvent, [GetMajorMap()]),
multi_state=CapabilitySetEnable(
MultimapStateEvent, [GetMultimapState()], SetMultimapState
),
position=CapabilityEvent(PositionsEvent, [GetPos()]),
relocation=CapabilityExecute(SetRelocationState),
rooms=CapabilityEvent(RoomsEvent, [GetCachedMapInfo()]),
trace=CapabilityEvent(MapTraceEvent, [GetMapTrace()]),
),
network=CapabilityEvent(NetworkInfoEvent, [GetNetInfo()]),
play_sound=CapabilityExecute(PlaySound),
settings=CapabilitySettings(
advanced_mode=CapabilitySetEnable(
AdvancedModeEvent, [GetAdvancedMode()], SetAdvancedMode
),
carpet_auto_fan_boost=CapabilitySetEnable(
CarpetAutoFanBoostEvent,
[GetCarpetAutoFanBoost()],
SetCarpetAutoFanBoost,
),
true_detect=CapabilitySetEnable(
TrueDetectEvent, [GetTrueDetect()], SetTrueDetect
),
volume=CapabilitySet(VolumeEvent, [GetVolume()], SetVolume),
),
state=CapabilityEvent(StateEvent, [GetChargeState(), GetCleanInfo()]),
stats=CapabilityStats(
clean=CapabilityEvent(StatsEvent, [GetStats()]),
report=CapabilityEvent(ReportStatsEvent, []),
total=CapabilityEvent(TotalStatsEvent, [GetTotalStats()]),
),
water=CapabilitySetTypes(
event=WaterInfoEvent,
get=[GetWaterInfo()],
set=SetWaterInfo,
types=(
WaterAmount.LOW,
WaterAmount.MEDIUM,
WaterAmount.HIGH,
WaterAmount.ULTRAHIGH,
),
),
),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider reusing existing capabilities to avoid code duplication

Since the DEEBOT N8+ Black variant ("b2jqs4") is functionally identical to the white variant, you can register the new class ID to point to the existing StaticDeviceInfo instance of the white variant. This approach reduces code duplication and simplifies future maintenance.

You can modify the device registration in the existing file for the white variant (e.g., b2jqs3.py) to include the new class ID:

 # In b2jqs3.py
 DEVICES[short_name(__name__)] = StaticDeviceInfo(
     # existing capabilities...
 )
+DEVICES["b2jqs4"] = DEVICES[short_name(__name__)]

Alternatively, if the devices are identical except for the class ID, you can create a shared module for common capabilities and import it in both files.

Committable suggestion skipped: line range outside the PR's diff.

@brendanm720 brendanm720 marked this pull request as draft December 8, 2024 20:36
@brendanm720
Copy link
Contributor Author

Looks like the code checks failed because something wasn't imported when it ran.

@brendanm720 brendanm720 marked this pull request as ready for review December 8, 2024 20:38
@flangio
Copy link

flangio commented Dec 9, 2024

Hi,
can you also support N8 (not plus) black variant, model 7zya6u?
Thanks!

Copy link
Member

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

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

Thanks @brendanm720 👍

@edenhaus edenhaus added the pr: new-feature PR, which adds a new feature label Dec 10, 2024
@edenhaus edenhaus merged commit dcfdf89 into DeebotUniverse:dev Dec 10, 2024
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: new-feature PR, which adds a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants