Fix typing for wemo#62157
Conversation
1ce1598 to
1a70e8b
Compare
Its probably actually going to reach
|
|
This one has a conflict |
8525c18 to
519ca6c
Compare
Rebased. |
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| HostPortTuple = Tuple[str, Optional[str]] |
There was a problem hiding this comment.
No it is not. Nice catch, thank you! I missed the cv.port() call. Fixed.
| def current_power_w(self): | ||
| def current_power_w(self) -> float | None: | ||
| """Return the current power usage in W.""" | ||
| if isinstance(self.wemo, Insight): |
There was a problem hiding this comment.
Would save some indent if you reversed the condition and return None in the indent, then outdent below
There was a problem hiding this comment.
Thanks! Rearranged this method and the one below.
Co-authored-by: J. Nick Koston <nick@koston.org>
| """Support for WeMo device discovery.""" | ||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import MutableSet, Sequence |
There was a problem hiding this comment.
Yes. You're quick! I didn't get e92b075 pushed fast enough. :)
|
Will take another look tomorrow. 3am here so sleep time |
| async def discover_statics(self): | ||
| async def discover_statics(self) -> None: | ||
| """Initialize or Re-Initialize connections to statically configured devices.""" | ||
| if self._static_config: |
There was a problem hiding this comment.
If you reverse this condition and return, you can outdent below
| if standby_state == WEMO_STANDBY: | ||
| return STATE_STANDBY | ||
| return STATE_UNKNOWN | ||
| return "" |
There was a problem hiding this comment.
| return "" | |
| return "" |
I think you can assert False since this should be unreachable
There was a problem hiding this comment.
Thank you. Done. 21f3ea8
frenck
left a comment
There was a problem hiding this comment.
Left a couple of comments, but could leave quite a few more of these. Why are we converting types so much in this PR?
| def name(self) -> str: | ||
| """Return the name of the device if any.""" | ||
| return self.light.name | ||
| return str(self.light.name) |
There was a problem hiding this comment.
This seems odd, why do we convert it to a string here? Is it an int?
| def unique_id(self) -> str: | ||
| """Return the ID of this light.""" | ||
| return self.light.uniqueID | ||
| return str(self.light.uniqueID) |
| def brightness(self) -> int: | ||
| """Return the brightness of this light between 0..255.""" | ||
| return self.light.state.get("level", 255) | ||
| return int(self.light.state.get("level", 255)) |
There was a problem hiding this comment.
Why do we convert it here? Is it not an int?
| """Return the color temperature of this light in mireds.""" | ||
| return self.light.state.get("temperature_mireds") | ||
| if (temp := self.light.state.get("temperature_mireds")) is not None: | ||
| return int(temp) |
|
I'm pretty sure this is because it looks like pywemo hasn't implemented PEP 561 yet |
|
But in that case, we should cast, not convert... |
|
Thanks for catching that. I'll send a new PR to correct this tonight after work. |
Proposed change
Fix & enable type checking for the wemo component.
These type checks, in wemo_device.py, uncovered an mistake with passing an Awaitable to
hass.add_jobrather than tohass.create_task. Fixed in #62159. As noted in the comment below, though, this wouldn't have caused an issue.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.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: