-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Add more types to the todoist integration #84210
Conversation
@@ -169,7 +170,6 @@ def setup_platform( | |||
# Create the custom project and add it to the devices array. | |||
project_devices.append( | |||
TodoistProjectEntity( | |||
hass, |
There was a problem hiding this comment.
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.
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) |
There was a problem hiding this comment.
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.
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 | ||
) | ||
|
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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()
...
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
Pass f-string directly to strftime. Co-authored-by: Allen Porter <allen.porter@gmail.com>
adab3f4
to
59e793d
Compare
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
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: