Upnp properties#8067
Conversation
|
@dgomes, thanks for your PR! By analyzing the history of the files in this pull request, we identified @robbiet480 and @fabaff to be potential reviewers. |
|
|
||
| class IGDSensor(Entity): | ||
| """Representation of a UPnP IGD sensor.""" | ||
|
|
|
The checklist of the PR template covers a bunch of topics which are missing in the PR. |
|
Where can I find the template ? More than willing to cover whats needed (I've since checked other pull requests and followed the checklist) |
In accordance to pull request home-assistant/core#8067
Latest version of miniupnpc is 2.0, but pypi only has 1.9 Fortunately it is enough
| hass.data[DATA_UPNP] = upnp | ||
|
|
||
| upnp.discoverdelay = 200 | ||
| upnp.discover() |
There was a problem hiding this comment.
You cannot do I/O inside a coroutine.
There was a problem hiding this comment.
I understood hass.data would be a global dictionary and wouldn't involve any I/O
But I'm moving everything back to setup() and update()
There was a problem hiding this comment.
Assigning to data doesn't do I/O. This comment was about upnp.discover() call. Since you changed it back to no longer be a coroutine this comment can be ignored.
| host = base_url.hostname | ||
| external_port = internal_port = base_url.port | ||
| unit = config[DOMAIN].get(CONF_UNITS) | ||
| discovery.load_platform(hass, 'sensor', DOMAIN, {'unit': unit}, config) |
There was a problem hiding this comment.
You cannot call sync methods inside a coroutine.
I would suggest you change it back to setup and not make it async.
| discovery.load_platform(hass, 'sensor', DOMAIN, {'unit': unit}, config) | ||
|
|
||
| port_mapping = config[DOMAIN].get(CONF_ENABLE_PORT_MAPPING) | ||
| if port_mapping: |
There was a problem hiding this comment.
Make it a guard clause:
if not port_mapping:
return True
base_url = …|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| """ sensor_type: [friendly_name, convert_unit, icon] """ |
There was a problem hiding this comment.
Use # for comments. Only use """ for first line in module/class/method to indicate it's a doc string.
| def async_update(self): | ||
| """Get the latest information from the IGD.""" | ||
| if self.type == "byte_received": | ||
| self._state = self._upnp.totalbytereceived() |
There was a problem hiding this comment.
Do these methods do I/O ? If so, this shouldn't be async_update but instead update
| from homeassistant.helpers import config_validation as cv | ||
| from homeassistant.helpers import discovery | ||
|
|
||
| REQUIREMENTS = ['miniupnpc==1.9'] |
balloob
left a comment
There was a problem hiding this comment.
You've updated a few places to be async instead of the sync version. However, it seems that there is still I/O being done in those methods. Anything that hits a network interface or talks to disk/network cannot be run inside a coroutine.
|
Documentation PR: #2832 |
miniupnpc will do network calls, so this component can’t be moved to coroutine
| For more details about this platform, please refer to the documentation at | ||
| https://home-assistant.io/components/sensor.upnp/ | ||
| """ | ||
| import asyncio |
dgomes
left a comment
There was a problem hiding this comment.
I've addressed all the changes
|
Awesome, thanks! |
|
Thanks for the mentoring, looking forward to more contributions. |
In accordance to pull request home-assistant/core#8067
* Update to UPnP documentation In accordance to pull request home-assistant/core#8067 * updated with new option * Improved thanks for the comments / review
* make port mapping optional * dependencies + improvements * Added bytes and packets sensors from IGD * flake8 check * new sensor with upnp counters * checks * whitespaces in blank line * requirements update * added sensor.upnp to .coveragerc * downgrade miniupnpc Latest version of miniupnpc is 2.0, but pypi only has 1.9 Fortunately it is enough * revert to non async miniupnpc will do network calls, so this component can’t be moved to coroutine * hof hof forgot to remove import ot asyncio
This pull request improves the UPnP component with IGD sensors containing bytes sent/received and packets sent/received