Skip to content

Commit

Permalink
chore(library_test): more details on login failure (#194)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Bug Fixes**
- Improved error messages for cloud service login failures by including
device details, offering better context for users.

- **Chores**
- Removed unnecessary linting rule for `print` statements to streamline
development.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Lucas Mindêllo de Andrade <[email protected]>
  • Loading branch information
chemelli74 and rokam authored Jul 2, 2024
1 parent f60a4ce commit ab3942b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
31 changes: 14 additions & 17 deletions library_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from midealocal.devices import device_selector
from midealocal.discover import discover

_LOGGER = logging.getLogger("library_test")


def get_arguments() -> tuple[ArgumentParser, Namespace]:
"""Get parsed passed in arguments."""
Expand Down Expand Up @@ -55,22 +57,18 @@ async def main() -> None:
parser, args = get_arguments()

if not args.password or not args.username or not args.cloud_name:
print("You have to specify all parameters: username, password and Cloud name")
_LOGGER.error("All parameters needed: username, password and Cloud name")
parser.print_help()
sys.exit(1)

print("-" * 20)
print("Starting network discovery...")
_LOGGER.info("Starting network discovery...")
devices = discover(ip_address=args.ip)
print("-" * 20)
print("Devices: ", devices)
_LOGGER.info("Devices: %s", devices)
first_device = next(iter(devices.values()))
print("-" * 20)
print("First device: ", first_device)
_LOGGER.info("First device: %s", first_device)
# The device type is in hexadecimal as in midealocal/devices/TYPE
type_code = hex(first_device["type"])[2:]
print("-" * 20)
print("First device type: ", type_code)
_LOGGER.info("First device type: %s", type_code)

session = aiohttp.ClientSession()
cloud = get_midea_cloud(
Expand All @@ -82,22 +80,22 @@ async def main() -> None:
cloud_keys = {}
if cloud:
if not await cloud.login():
print("ERROR: cannot login")
msg = f"Cannot login into device {first_device['device_id']} \
[{first_device['ip_address']}]"
_LOGGER.error(msg)
await session.close()
sys.exit(2)
cloud_keys = await cloud.get_keys(first_device["device_id"])
print("-" * 20)
print("Fist device Cloud info: ", cloud_keys)
_LOGGER.info("Fist device Cloud info: %s", cloud_keys)

token = ""
key = ""
for v in cloud_keys.values():
token = v["token"]
key = v["key"]

print("-" * 20)
print("Fist device Cloud token: ", token)
print("Fist device Cloud key: ", key)
_LOGGER.info("Fist device Cloud token: %s", token)
_LOGGER.info("Fist device Cloud key: %s", key)

# Select the device
ac = device_selector(
Expand All @@ -118,8 +116,7 @@ async def main() -> None:
ac.connect()

# Getting the attributes
print("-" * 20)
print("First device attributes: ", ac.attributes)
_LOGGER.info("First device attributes: %s", ac.attributes)

# Close session
await session.close()
Expand Down
1 change: 0 additions & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ lint.ignore = [
[lint.per-file-ignores]
"library_test.py" = [
"PLR0915", # Too many statements
"T201", # `print` found
]
"midealocal/security.py" = [
"S324", # Probable use of insecure hash functions in `hashlib`: `md5`
Expand Down

0 comments on commit ab3942b

Please sign in to comment.