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

Add more types to the todoist integration #84210

Merged
merged 4 commits into from
Dec 20, 2022

Conversation

boralyl
Copy link
Contributor

@boralyl boralyl commented Dec 18, 2022

Breaking change

Proposed change

This pulls out type updates from #79481 in order to make the changeset smaller and easier to review.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@@ -169,7 +170,6 @@ def setup_platform(
# Create the custom project and add it to the devices array.
project_devices.append(
TodoistProjectEntity(
hass,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This value wasn't used so I've removed it.

Comment on lines 597 to 604
midnight = dt.as_utc(
dt.parse_datetime(
due_date.strftime("%Y-%m-%d")
+ "T00:00:00"
+ self._api.state["user"]["tz_info"]["gmt_string"]
)
gmt_string = self._api.state["user"]["tz_info"]["gmt_string"]
local_midnight = dt.parse_datetime(
f'{due_date.strftime("%Y-%m-%d")}T00:00:00{gmt_string}'
)
if local_midnight is not None:
midnight = dt.as_utc(local_midnight)
else:
midnight = due_date.replace(hour=0, minute=0, second=0, microsecond=0)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Small change here since mypy correctly pointed out dt.parse_datetime could return None and dt.as_utc only allows a datetime instance.

Comment on lines -299 to 301
self._attr_unique_id = data.get(CONF_ID)
self._attr_unique_id = (
str(data[CONF_ID]) if data.get(CONF_ID) is not None else None
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was updated since the type for unique_id must be a str | None

@@ -562,14 +560,16 @@ def select_best_task(project_tasks):
continue

if proposed_event[PRIORITY] == event[PRIORITY] and (
proposed_event[END] < event[END]
event[END] is not None and proposed_event[END] < event[END]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added an additional check as mypy pointed out this value could be None.

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting because there are other checks above like event[DEND].date()...

Copy link
Contributor

Choose a reason for hiding this comment

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

Consider if this gets simpler with some local variables for proposed_event_end and event_end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think mypy is clever enough to figure out that if event[END] is None that we will never reach this block: https://github.com/home-assistant/core/pull/84210/files/14e27151ca85b347a610279310035ae35cc793c4#diff-0df90a93485af80ce0879138de9155f75b1a60a63454406902e6246df2da2194R543-R546.

mypy is instead inferring the type from the TodoistEvent typed dict which says the end key could be datetime | None.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the loop is confusing it, otherwise I think it usually can tell when you have is None guards. Anyway, a local variable might make it easier, but also adds more cruft.

@MartinHjelmare MartinHjelmare changed the title Add more types to the todoist integration. Add more types to the todoist integration Dec 18, 2022
@boralyl boralyl marked this pull request as ready for review December 18, 2022 21:03
@boralyl boralyl force-pushed the features/todoist-types branch from adab3f4 to 59e793d Compare December 20, 2022 01:22
@allenporter allenporter merged commit 3405fa6 into home-assistant:dev Dec 20, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Dec 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants