Skip to content

Commit

Permalink
fix(device)!: socket exception and process rebuild (#296)
Browse files Browse the repository at this point in the history
changes list:
1. process all the socket send/recv in try/except to prevent socket
error
2. always close socket after exception matched and force reconnect to
refresh
3. increase query timeout from 1 to 2, and only apply it to query
cmd/msg
4. recovery socket timeout after query and recv socket msg done in each
for loop.
5. rebuild process to remove the duplicate message parse.
6. rename some func and args
7. with current changes, I don't see any timeout exception in my local
device testing, if there is any new error exist, we can continue improve
it in future PRs.

Fixes #290 

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

- **New Features**
- Enhanced error handling for device discovery, now reporting
`NoSupportedProtocol` for unsupported devices.
- Streamlined socket connection process, improving reliability and
clarity in communication.
- Introduced `MessageResult` enumeration for improved clarity in message
parsing.

- **Bug Fixes**
- Updated tests to reflect changes in exception handling, ensuring
accurate responses to device compatibility issues.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Lucas Mindêllo de Andrade <[email protected]>
  • Loading branch information
wuwentao and rokam authored Sep 20, 2024
1 parent f2e5e24 commit 7f2e572
Show file tree
Hide file tree
Showing 4 changed files with 311 additions and 155 deletions.
9 changes: 7 additions & 2 deletions midealocal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
get_midea_cloud,
get_preset_account_cloud,
)
from midealocal.device import AuthException, MideaDevice, ProtocolVersion, RefreshFailed
from midealocal.device import (
AuthException,
MideaDevice,
NoSupportedProtocol,
ProtocolVersion,
)
from midealocal.devices import device_selector
from midealocal.discover import discover
from midealocal.exceptions import SocketException
Expand Down Expand Up @@ -121,7 +126,7 @@ async def discover(self) -> list[MideaDevice]:
_LOGGER.debug("Unable to connect with key: %s", key)
except SocketException:
_LOGGER.exception("Device socket closed.")
except RefreshFailed:
except NoSupportedProtocol:
_LOGGER.exception("Unable to retrieve device attributes.")
else:
_LOGGER.info("Found device:\n%s", dev.attributes)
Expand Down
Loading

0 comments on commit 7f2e572

Please sign in to comment.