Skip to content

Upnp properties#8067

Merged
balloob merged 14 commits into
home-assistant:devfrom
dgomes:upnp_properties
Jun 19, 2017
Merged

Upnp properties#8067
balloob merged 14 commits into
home-assistant:devfrom
dgomes:upnp_properties

Conversation

@dgomes
Copy link
Copy Markdown
Contributor

@dgomes dgomes commented Jun 16, 2017

This pull request improves the UPnP component with IGD sensors containing bytes sent/received and packets sent/received

@mention-bot
Copy link
Copy Markdown

@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.

Comment thread homeassistant/components/sensor/upnp.py Outdated

class IGDSensor(Entity):
"""Representation of a UPnP IGD sensor."""

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

blank line contains whitespace

@fabaff
Copy link
Copy Markdown
Member

fabaff commented Jun 17, 2017

The checklist of the PR template covers a bunch of topics which are missing in the PR.

@dgomes
Copy link
Copy Markdown
Contributor Author

dgomes commented Jun 17, 2017

Where can I find the template ? More than willing to cover whats needed

(I've since checked other pull requests and followed the checklist)

dgomes added a commit to dgomes/home-assistant.github.io that referenced this pull request Jun 17, 2017
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()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You cannot do I/O inside a coroutine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You cannot call sync methods inside a coroutine.

I would suggest you change it back to setup and not make it async.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will do

Comment thread homeassistant/components/upnp.py Outdated
discovery.load_platform(hass, 'sensor', DOMAIN, {'unit': unit}, config)

port_mapping = config[DOMAIN].get(CONF_ENABLE_PORT_MAPPING)
if port_mapping:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Make it a guard clause:

if not port_mapping:
    return True

base_url =

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

check

Comment thread homeassistant/components/sensor/upnp.py Outdated

_LOGGER = logging.getLogger(__name__)

""" sensor_type: [friendly_name, convert_unit, icon] """
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use # for comments. Only use """ for first line in module/class/method to indicate it's a doc string.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

check

def async_update(self):
"""Get the latest information from the IGD."""
if self.type == "byte_received":
self._state = self._upnp.totalbytereceived()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do these methods do I/O ? If so, this shouldn't be async_update but instead update

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

check

from homeassistant.helpers import config_validation as cv
from homeassistant.helpers import discovery

REQUIREMENTS = ['miniupnpc==1.9']
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will this install miniupnp ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes

Copy link
Copy Markdown
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

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.

@fabaff
Copy link
Copy Markdown
Member

fabaff commented Jun 18, 2017

Documentation PR: #2832

miniupnpc will do network calls, so this component can’t be moved to
coroutine
Comment thread homeassistant/components/sensor/upnp.py Outdated
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.upnp/
"""
import asyncio
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

'asyncio' imported but unused

forgot to remove import ot asyncio
Copy link
Copy Markdown
Contributor Author

@dgomes dgomes left a comment

Choose a reason for hiding this comment

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

I've addressed all the changes

@balloob balloob merged commit 83b7914 into home-assistant:dev Jun 19, 2017
@balloob
Copy link
Copy Markdown
Member

balloob commented Jun 19, 2017

Awesome, thanks!

@dgomes
Copy link
Copy Markdown
Contributor Author

dgomes commented Jun 19, 2017

Thanks for the mentoring, looking forward to more contributions.

fabaff pushed a commit to home-assistant/home-assistant.io that referenced this pull request Jun 19, 2017
@balloob balloob mentioned this pull request Jul 1, 2017
This was referenced Jul 2, 2017
balloob pushed a commit to home-assistant/home-assistant.io that referenced this pull request Jul 7, 2017
* Update to UPnP documentation

In accordance to pull request
home-assistant/core#8067

* updated with new option

* Improved

thanks for the comments / review
dethpickle pushed a commit to dethpickle/home-assistant that referenced this pull request Aug 18, 2017
* 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
@home-assistant home-assistant locked and limited conversation to collaborators Oct 20, 2017
@ghost ghost removed the platform: sensor.upnp label Mar 21, 2019
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.

7 participants