Skip to content
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

refactor - on-events - test cases #426

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

MVladislav
Copy link
Contributor

@MVladislav MVladislav commented Feb 18, 2024

  • move some static values into const.py
  • update code syntax
  • update imports
  • update/extend get-command by combine with on-messages
  • fix comments
  • update/extend test cases
  • project config files updated

- move some command into message
- small fixes/cleans
- add on clean info v2 (same as v1)
- refactor code syntax
- fix comments
- move static values into const.py
- remove not needed lines
- refactor lines
- fix comments
- fix namings
- update syntax
- fix last push for pos
- add more and extended test cases
- cleanup imports
- create on major map
- general code clean
- test case updates
Copy link

codecov bot commented Feb 18, 2024

Codecov Report

Attention: 11 lines in your changes are missing coverage. Please review.

Comparison is base (e766567) 83.30% compared to head (9604532) 85.78%.

Files Patch % Lines
deebot_client/messages/json/map.py 86.20% 2 Missing and 2 partials ⚠️
deebot_client/commands/json/map.py 80.00% 1 Missing and 2 partials ⚠️
deebot_client/commands/json/clean.py 91.66% 1 Missing ⚠️
deebot_client/commands/json/life_span.py 75.00% 0 Missing and 1 partial ⚠️
deebot_client/commands/json/stats.py 75.00% 1 Missing ⚠️
deebot_client/messages/__init__.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #426      +/-   ##
==========================================
+ Coverage   83.30%   85.78%   +2.47%     
==========================================
  Files          74       80       +6     
  Lines        2977     3003      +26     
  Branches      531      519      -12     
==========================================
+ Hits         2480     2576      +96     
+ Misses        443      385      -58     
+ Partials       54       42      -12     

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

- move mypy/pytest into project.toml
- update scripts
- upgrade pre-commit
- extend pre-commit
Copy link
Contributor

@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.

Please split this PR into multiple PRs as it is too big to review. Aslo there are some merge conflicts


repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
Copy link
Contributor

Choose a reason for hiding this comment

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

ruff and co should stay at the beginning as pre-commit executes the checks in order and in my opinion they are more important than the codespell for example

@@ -31,7 +30,7 @@ def _handle_body(cls, event_bus: EventBus, body: dict[str, Any]) -> HandlingResu

:return: A message response
"""
code = int(body.get(CODE, -1))
code = int(body.get("code", -1))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you remove the constant?

@@ -116,7 +100,6 @@ def _handle_response(
"""
result = super()._handle_response(event_bus, response)
if result.state == HandlingState.SUCCESS and result.args:
event_bus.notify(MajorMapEvent(requested=True, **result.args))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you remove this line?

Comment on lines +239 to +250
name = (
cls._ROOM_NUM_TO_NAME.get(subtype)
if subtype and subtype != "15"
else data.get("name")
)

# getMapSubSet used by getMapSet v1 and v2
coordinates = (
decompress_7z_base64_data(data["value"]).decode() # New bots
if data.get("compress", 0) == 1
else data["value"] # Old bots
)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should avoid multiline ternary operators as they are harder to read. In Home Assistant core we don't allow them. Please revert these changes to the old format

mop_attached = data.get("enable")
if mop_attached is not None:
mop_attached = bool(mop_attached)
mop_attached = None if data.get("enable") is None else bool(data.get("enable"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Please revert this change as the old code is more readable

match trigger, state, motion_state:
case "alert", _, _:
status = State.ERROR
case _, "clean", "working":
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice refactoring with match :)

area_values = content.get("value") if isinstance(content, dict) else content
_LOGGER.debug("Last custom area values (x1,y1,x2,y2): %s", area_values)

if status is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if status is not None:
if status:

values = data["value"].split(",")
map_id = data["mid"]

event_bus.notify(MajorMapEvent(requested=True, map_id=map_id, values=values))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
event_bus.notify(MajorMapEvent(requested=True, map_id=map_id, values=values))

A message can never be requested by the client as it was sent async by the bot.


:return: A message response
"""
# onMinorMap sends no type, so fallback to "ol"
Copy link
Contributor

Choose a reason for hiding this comment

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

From this comment, it looks like getMinorMap and onMinorMap are sending different data. This function should only have the code for the message. Code for getMinorMap should be part of the GetMinorMap class

"""
positions = []

for type_str in ["deebotPos", "chargePos"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure that we are getting multiple positions on a onPos message? I think it's only possible on the getPos command and onPos is only providing a single position.

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.

2 participants