home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.06k stars 29.72k forks source link

Issue with UPnP/IGD #17229

Closed DavidFW1960 closed 5 years ago

DavidFW1960 commented 5 years ago

0.80.0b1 Home Assistant release with the issue:

Last working Home Assistant release (if known): It's a new integration in 0.80

Operating environment (Hass.io/Docker/Windows/etc.):

PR 16300 Component/platform:

Description of problem: @dgomes suggested I report this and tag @StevenLooman

I am prompted to add integration for my Fritz 7490 and 7590. I can't save unless I tick on both the traffic sensor and port mapping checkboxes. I would like to ignore the 7490 as it is just a repeater and the traffic stays at 0 - ie no useful information

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

Traceback (if applicable):

This was the error from yesterday:

2018-10-07 14:45:16 ERROR (MainThread) [homeassistant.components.upnp] Could not add port mapping: 8123:10.90.11.100:8123
2018-10-07 14:45:17 ERROR (MainThread) [homeassistant.components.upnp] Could not add port mapping: 8123:10.90.11.100:8123
2018-10-07 14:45:17 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry InternetGatewayDeviceV2 - FRITZ!Box 7590 for upnp
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/config_entries.py", line 236, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/upnp/__init__.py", line 128, in async_setup_entry
    await device.async_add_port_mappings(ports, local_ip=local_ip)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/upnp/device.py", line 69, in async_add_port_mappings
    internal_port)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/upnp/device.py", line 90, in _async_add_port_mapping
    lease_duration=None)
  File "/usr/local/lib/python3.6/site-packages/async_upnp_client/igd.py", line 83, in async_add_port_mapping
    await action.async_call(
AttributeError: 'NoneType' object has no attribute 'async_call'
2018-10-07 14:45:17 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry InternetGatewayDeviceV2 - FRITZ!Box 7490 for upnp
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/config_entries.py", line 236, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/upnp/__init__.py", line 128, in async_setup_entry
    await device.async_add_port_mappings(ports, local_ip=local_ip)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/upnp/device.py", line 69, in async_add_port_mappings
    internal_port)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/upnp/device.py", line 90, in _async_add_port_mapping
    lease_duration=None)
  File "/usr/local/lib/python3.6/site-packages/async_upnp_client/igd.py", line 83, in async_add_port_mapping
    await action.async_call(
AttributeError: 'NoneType' object has no attribute 'async_call'

As per @dgomes I have added debug logging. Here is that log.

2018-10-08 10:44:08 DEBUG (MainThread) [async_upnp_client.traffic] Sending request:
POST http://10.90.11.12:1887/AVTransport/bb762f71-7a40-eb83-4b32-1b31b86cdb79/control.xml
SOAPAction: "urn:schemas-upnp-org:service:AVTransport:1#GetTransportInfo"
Host: 10.90.11.12:1887
Content-Type: text/xml
Content-Length: 399
<?xml version="1.0"?>
        <s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
          <s:Body>
            <u:GetTransportInfo xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
                <InstanceID>0</InstanceID>
            </u:GetTransportInfo>
           </s:Body>
        </s:Envelope>

2018-10-08 10:44:08 DEBUG (MainThread) [async_upnp_client.traffic] Sending request:
POST http://10.90.11.39:8888/upnp_control_2
SOAPAction: "urn:schemas-upnp-org:service:AVTransport:1#GetTransportInfo"
Host: 10.90.11.39:8888
Content-Type: text/xml
Content-Length: 399
<?xml version="1.0"?>
        <s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
          <s:Body>
            <u:GetTransportInfo xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
                <InstanceID>0</InstanceID>
            </u:GetTransportInfo>
           </s:Body>
        </s:Envelope>

2018-10-08 10:44:08 DEBUG (MainThread) [async_upnp_client.traffic] Got response:
200
Ext: 
Date: Sun, 07 Oct 2018 23:44:08 GMT
Content-Length: 439
Content-Type: text/xml; charset="utf-8"
Server: UPnP/1.0 DLNADOC/1.50 Kodi

<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><u:GetTransportInfoResponse xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><CurrentTransportState>STOPPED</CurrentTransportState><CurrentTransportStatus>OK</CurrentTransportStatus><CurrentSpeed>1</CurrentSpeed></u:GetTransportInfoResponse></s:Body></s:Envelope>
2018-10-08 10:44:08 DEBUG (MainThread) [async_upnp_client.traffic] Got response:
200
Server: Linux/2.6.33-rc4 UPnP/1.0 MediabolicUPnP/1.8.225
Content-Type: text/xml; charset="utf-8"
Content-Length: 446
Connection: keep-alive

<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetTransportInfoResponse xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><CurrentTransportState>NO_MEDIA_PRESENT</CurrentTransportState><CurrentTransportStatus>OK</CurrentTransportStatus><CurrentSpeed>1</CurrentSpeed></u:GetTransportInfoResponse></s:Body></s:Envelope>

Additional information: Prompted for integration of my Fritz! 7590 and 7490. The 7490 is just a WLAN repeater. I keeps prompting me and I can't ignore it if that makes sense. 10.90.11.1 is 7590, .12 is osmc/vero/kodi, .100 is hassio (debian nuc), .39 is onkyo receiver, .90 is 7490 repeater FULL LOG HERE https://codeshare.io/5ZjxKQ

StevenLooman commented 5 years ago

I can't save unless I tick on both the traffic sensor and port mapping checkboxes.

Confirmed: defaults in config_flow.UpnpFlowHandler.async_step_user were removed before, now causing a traceback. Will create a new pull request handling this.

I would like to ignore the 7490 as it is just a repeater and the traffic stays at 0 - ie no useful information

If you always keep getting a pop-up stating you can add a new integration, then either the component should be able to get activated without any port-mapping or sensors, or hass itself should be able to ignore devices and/or complete components.

StevenLooman commented 5 years ago

The traceback is surprising though. Both the 7590 and 7490 advertise they support the AddPortMapping call. However, when the library tries to call it, it cannot find the action. Can you try this, in a terminal/console? Not sure if you are using a virtualenv, or a docker container, or something else. If you don't know what to do, please let me and/or @dgomes know.

$ upnp-client --pprint --device http://10.90.11.1:49000/igddesc.xml call-action WANIPConn1/AddPortMapping NewRemoteHost= NewExternalPort=8123 NewProtocol=TCP NewInternalPort=8123 NewInternalClient=10.90.11.99 NewEnabled=1 NewPortMappingDescription=test NewLeaseDuration=300

This will call your router and try to make a port mapping with these settings:

Example output:

{
    "timestamp": 1539029627.371163,
    "service_id": "urn:upnp-org:serviceId:WANIPConn1",
    "service_type": "urn:schemas-upnp-org:service:WANIPConnection:1",
    "action": "AddPortMapping",
    "in_parameters": {
        "NewRemoteHost": "",
        "NewExternalPort": 8123,
        "NewProtocol": "TCP",
        "NewInternalPort": 8123,
        "NewInternalClient": "192.168.178.14",
        "NewEnabled": true,
        "NewPortMappingDescription": "test",
        "NewLeaseDuration": 0
    },
    "out_parameters": {}
}

To remove it, either wait for the timeout, or run this:

$ upnp-client --pprint --device http://10.90.11.1:49000/igddesc.xml call-action WANIPConn1/DeletePortMapping NewExternalPort=8123 NewProtocol=TCP NewRemoteHost=
DavidFW1960 commented 5 years ago

Steven, I am running hass.io in docker. So I tried the command using the ssh add-on but it can't find the upnp-client

I also ran a console (via portainer) in the Home Assistant container. It produced nothing like what you show above.

bash-4.4# upnp-client --pprint --device http://10.90.11.1:49000/igddesc.xml call-action WANIPConn1/AddPortMapping NewRemoteHosternalPort=8123 NewProtocol=TCP NewInternalPort=8123 NewInternalClient=10.90.11.99 NewEnabled=1 NewPortMappingDescription=test Nuration=300
Traceback (most recent call last):
  File "/usr/local/bin/upnp-client", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/site-packages/async_upnp_client/cli.py", line 205, in main
    loop.run_until_complete(async_main())
  File "/usr/local/lib/python3.6/asyncio/base_events.py", line 468, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.6/site-packages/async_upnp_client/cli.py", line 193, in async_main
    await call_action(device, getattr(args, 'call-action'))
  File "/usr/local/lib/python3.6/site-packages/async_upnp_client/cli.py", line 132, in call_action
    result = await action.async_call(**coerced_args)
  File "/usr/local/lib/python3.6/site-packages/async_upnp_client/__init__.py", line 590, in async_call
    (status_code, response_body))
async_upnp_client.UpnpError: Error during async_call(), status: 500, body: <?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<s:Fault>
<faultcode>s:Client</faultcode>
<faultstring>UPnPError</faultstring>
<detail>
<UPnPError xmlns="urn:schemas-upnp-org:control-1-0">
<errorCode>403</errorCode>
<errorDescription>Not available Action</errorDescription>
</UPnPError>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
bash-4.4#
StevenLooman commented 5 years ago

@DavidFW1960 That is the same error as seen in the logs. Not sure what is happening. Can you try again, but the with IP from which you are running it from?

DavidFW1960 commented 5 years ago

@StevenLooman not sure what you are asking me to do.. I am now on b4 and it seems to allow me to just add traffic sensors now and ignore the port mapping option. Also isn't continually giving me notifications about new component to add anymore either. As my 7490 is only a repeater I didn't add that anyway and I have upnp turned off in the 7490 anyway. I also don't seem to be getting any log errors anymore.. (On restart - it's discovering the 7490 again. Click dismiss and is gone but I guess it will do this every restart. Not sure why it sees this given upnp is off for that device) Settings for 7490: image 7590 is the same except it has UPnP checked on.

rafiw commented 5 years ago

Hi i have this related error how can i solve this?

2019-01-09 09:48:15 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Actiontec xDSL Router for upnp
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/config_entries.py", line 249, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/upnp/__init__.py", line 143, in async_setup_entry
    await device.async_add_port_mappings(ports, local_ip)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/upnp/device.py", line 66, in async_add_port_mappings
    internal_port)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/upnp/device.py", line 87, in _async_add_port_mapping
    lease_duration=None)
  File "/usr/local/lib/python3.6/site-packages/async_upnp_client/igd.py", line 219, in async_add_port_mapping
    await action.async_call(
AttributeError: 'NoneType' object has no attribute 'async_call'
2019-01-09 09:48:15 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/cloud/__init__.py", line 254, in async_start
    info = await self.hass.async_add_job(load_config)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/cloud/__init__.py", line 252, in load_config
    return json.loads(file.read())
  File "/usr/local/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
dgomes commented 5 years ago

@rafiw please don't add comments to closed issues.

We have new code for UPnP coming up in 0.85 (already in beta) can you please test that ?

If you still find this error please start a new issue.