Skip to content
This repository was archived by the owner on Aug 27, 2021. It is now read-only.

Conversation

@SourceryAI
Copy link

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch https://github.com/sourcery-ai-bot/O365-HomeAssistant master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Comment on lines -43 to +57
if not alt_config:
if alt_config:
callback_url = AUTH_CALLBACK_PATH_ALT

else:
try:
callback_url = f"{get_url(hass)}{AUTH_CALLBACK_PATH}"
except NameError:
callback_url = f"{hass.config.api.base_url}{AUTH_CALLBACK_PATH}"
else:
callback_url = AUTH_CALLBACK_PATH_ALT

account = Account(credentials, token_backend=TOKEN_BACKEND)
is_authenticated = account.is_authenticated
permissions = validate_permissions()
if not is_authenticated or not permissions:
if is_authenticated and permissions:
do_setup(hass, conf, account)

else:
Copy link
Author

Choose a reason for hiding this comment

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

Function setup refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

return
email_service = O365EmailService(account)
return email_service
return O365EmailService(account)
Copy link
Author

Choose a reason for hiding this comment

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

Function async_get_service refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

Comment on lines -40 to +49
if not os.path.exists(full_token_path) or not os.path.isfile(full_token_path):
if not (
os.path.exists(full_token_path) and os.path.isfile(full_token_path)
):
_LOGGER.warning(f"Could not loacte token at {full_token_path}")
return False
with open(full_token_path, "r", encoding="UTF-8") as fh:
raw = fh.read()
permissions = json.loads(raw)["scope"]
scope = [x for x in MINIMUM_REQUIRED_SCOPES]
all_permissions_granted = all([x in permissions for x in scope])
all_permissions_granted = all(x in permissions for x in scope)
Copy link
Author

Choose a reason for hiding this comment

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

Function validate_permissions refactored with the following changes:

  • Replace unneeded comprehension with generator (comprehension-to-generator)
  • Simplify logical expression using De Morgan identities (de-morgan)

Comment on lines -194 to +196
calendar_info = CALENDAR_DEVICE_SCHEMA(
return CALENDAR_DEVICE_SCHEMA(
Copy link
Author

Choose a reason for hiding this comment

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

Function get_calendar_info refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant