kbr / fritzconnection

Python-Tool to communicate with the AVM Fritz!Box by the TR-064 protocol and the AHA-HTTP-Interface
MIT License
303 stars 59 forks source link

fritzconnection.core.exceptions.FritzServiceError: unknown service: "WANIPConn1" #137

Closed enkama closed 2 years ago

enkama commented 2 years ago

Hey. So on the newest Homeassistant version using fritzconnection library I am gettin this error messages:

2022-01-09 12:08:37 ERROR (MainThread) [homeassistant.components.binary_sensor] fritz: Error on device update!
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 281, in call_action
    service = self.device_manager.services[service_name]
KeyError: 'WANIPConn1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 686, in async_device_update
    await task
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/fritz/binary_sensor.py", line 95, in update
    self._attr_is_on = bool(self._avm_device.fritz_status.is_connected)
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/lib/fritzstatus.py", line 49, in is_connected
    status = self.fc.call_action("WANIPConn", "GetStatusInfo")
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 283, in call_action
    raise FritzServiceError(f'unknown service: "{service_name}"')
fritzconnection.core.exceptions.FritzServiceError: unknown service: "WANIPConn1"
2022-01-09 12:08:37 ERROR (MainThread) [homeassistant.components.binary_sensor] fritz: Error on device update!
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 281, in call_action
    service = self.device_manager.services[service_name]
KeyError: 'WANCommonIFC1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 686, in async_device_update
    await task
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/fritz/binary_sensor.py", line 97, in update
    self._attr_is_on = bool(self._avm_device.fritz_status.is_linked)
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/lib/fritzstatus.py", line 40, in is_linked
    status = self.fc.call_action("WANCommonIFC", "GetCommonLinkProperties")
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 283, in call_action
    raise FritzServiceError(f'unknown service: "{service_name}"')
fritzconnection.core.exceptions.FritzServiceError: unknown service: "WANCommonIFC1"
2022-01-09 12:08:37 ERROR (MainThread) [homeassistant.components.sensor] fritz: Error on device update!
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 281, in call_action
    service = self.device_manager.services[service_name]
KeyError: 'WANIPConn1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 686, in async_device_update
    await task
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/fritz/sensor.py", line 345, in update
    ) = self.entity_description.value_fn(status, self._last_device_value)
  File "/usr/src/homeassistant/homeassistant/components/fritz/sensor.py", line 72, in _retrieve_external_ip_state
    return status.external_ip  # type: ignore[no-any-return]
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/lib/fritzstatus.py", line 55, in external_ip
    return self.fc.call_action("WANIPConn", "GetExternalIPAddress")[
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 283, in call_action
    raise FritzServiceError(f'unknown service: "{service_name}"')
fritzconnection.core.exceptions.FritzServiceError: unknown service: "WANIPConn1"
2022-01-09 12:08:37 ERROR (MainThread) [homeassistant.components.sensor] fritz: Error on device update!
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 281, in call_action
    service = self.device_manager.services[service_name]
KeyError: 'WANIPConn1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 686, in async_device_update
    await task
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/fritz/sensor.py", line 345, in update
    ) = self.entity_description.value_fn(status, self._last_device_value)
  File "/usr/src/homeassistant/homeassistant/components/fritz/sensor.py", line 67, in _retrieve_connection_uptime_state
    return _uptime_calculation(status.connection_uptime, last_value)
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/lib/fritzstatus.py", line 94, in connection_uptime
    status = self.fc.call_action("WANIPConn", "GetStatusInfo")
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 283, in call_action
    raise FritzServiceError(f'unknown service: "{service_name}"')
fritzconnection.core.exceptions.FritzServiceError: unknown service: "WANIPConn1"
2022-01-09 12:08:37 ERROR (MainThread) [homeassistant.components.sensor] fritz: Error on device update!
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 281, in call_action
    service = self.device_manager.services[service_name]
KeyError: 'WANCommonIFC1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 686, in async_device_update
    await task
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/fritz/sensor.py", line 345, in update
    ) = self.entity_description.value_fn(status, self._last_device_value)
  File "/usr/src/homeassistant/homeassistant/components/fritz/sensor.py", line 77, in _retrieve_kb_s_sent_state
    return round(status.transmission_rate[0] / 1000, 1)  # type: ignore[no-any-return]
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/lib/fritzstatus.py", line 152, in transmission_rate
    status = self.fc.call_action("WANCommonIFC1", "GetAddonInfos")
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 283, in call_action
    raise FritzServiceError(f'unknown service: "{service_name}"')
fritzconnection.core.exceptions.FritzServiceError: unknown service: "WANCommonIFC1"
2022-01-09 12:08:37 ERROR (MainThread) [homeassistant.components.sensor] fritz: Error on device update!
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 281, in call_action
    service = self.device_manager.services[service_name]
KeyError: 'WANCommonIFC1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 686, in async_device_update
    await task
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/fritz/sensor.py", line 345, in update
    ) = self.entity_description.value_fn(status, self._last_device_value)
  File "/usr/src/homeassistant/homeassistant/components/fritz/sensor.py", line 82, in _retrieve_kb_s_received_state
    return round(status.transmission_rate[1] / 1000, 1)  # type: ignore[no-any-return]
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/lib/fritzstatus.py", line 152, in transmission_rate
    status = self.fc.call_action("WANCommonIFC1", "GetAddonInfos")
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 283, in call_action
    raise FritzServiceError(f'unknown service: "{service_name}"')
fritzconnection.core.exceptions.FritzServiceError: unknown service: "WANCommonIFC1"
2022-01-09 12:08:37 ERROR (MainThread) [homeassistant.components.sensor] fritz: Error on device update!
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 281, in call_action
    service = self.device_manager.services[service_name]
KeyError: 'WANCommonIFC1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 686, in async_device_update
    await task
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/fritz/sensor.py", line 345, in update
    ) = self.entity_description.value_fn(status, self._last_device_value)
  File "/usr/src/homeassistant/homeassistant/components/fritz/sensor.py", line 87, in _retrieve_max_kb_s_sent_state
    return round(status.max_bit_rate[0] / 1000, 1)  # type: ignore[no-any-return]
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/lib/fritzstatus.py", line 180, in max_bit_rate
    return self._get_max_bit_rate("WANCommonIFC")
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/lib/fritzstatus.py", line 187, in _get_max_bit_rate
    status = self.fc.call_action(servicename, "GetCommonLinkProperties")
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 283, in call_action
    raise FritzServiceError(f'unknown service: "{service_name}"')
fritzconnection.core.exceptions.FritzServiceError: unknown service: "WANCommonIFC1"
2022-01-09 12:08:37 ERROR (MainThread) [homeassistant.components.sensor] fritz: Error on device update!
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 281, in call_action
    service = self.device_manager.services[service_name]
KeyError: 'WANCommonIFC1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 686, in async_device_update
    await task
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/fritz/sensor.py", line 345, in update
    ) = self.entity_description.value_fn(status, self._last_device_value)
  File "/usr/src/homeassistant/homeassistant/components/fritz/sensor.py", line 92, in _retrieve_max_kb_s_received_state
    return round(status.max_bit_rate[1] / 1000, 1)  # type: ignore[no-any-return]
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/lib/fritzstatus.py", line 180, in max_bit_rate
    return self._get_max_bit_rate("WANCommonIFC")
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/lib/fritzstatus.py", line 187, in _get_max_bit_rate
    status = self.fc.call_action(servicename, "GetCommonLinkProperties")
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 283, in call_action
    raise FritzServiceError(f'unknown service: "{service_name}"')
fritzconnection.core.exceptions.FritzServiceError: unknown service: "WANCommonIFC1"
2022-01-09 12:08:37 ERROR (MainThread) [homeassistant.components.sensor] fritz: Error on device update!
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 281, in call_action
    service = self.device_manager.services[service_name]
KeyError: 'WANCommonIFC1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 686, in async_device_update
    await task
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/fritz/sensor.py", line 345, in update
    ) = self.entity_description.value_fn(status, self._last_device_value)
  File "/usr/src/homeassistant/homeassistant/components/fritz/sensor.py", line 97, in _retrieve_gb_sent_state
    return round(status.bytes_sent / 1000 / 1000 / 1000, 1)  # type: ignore[no-any-return]
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/lib/fritzstatus.py", line 122, in bytes_sent
    status = self.fc.call_action("WANCommonIFC1", "GetAddonInfos")
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 283, in call_action
    raise FritzServiceError(f'unknown service: "{service_name}"')
fritzconnection.core.exceptions.FritzServiceError: unknown service: "WANCommonIFC1"
2022-01-09 12:08:37 ERROR (MainThread) [homeassistant.components.sensor] fritz: Error on device update!
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 281, in call_action
    service = self.device_manager.services[service_name]
KeyError: 'WANCommonIFC1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 686, in async_device_update
    await task
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/fritz/sensor.py", line 345, in update
    ) = self.entity_description.value_fn(status, self._last_device_value)
  File "/usr/src/homeassistant/homeassistant/components/fritz/sensor.py", line 102, in _retrieve_gb_received_state
    return round(status.bytes_received / 1000 / 1000 / 1000, 1)  # type: ignore[no-any-return]
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/lib/fritzstatus.py", line 136, in bytes_received
    status = self.fc.call_action("WANCommonIFC1", "GetAddonInfos")
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 283, in call_action
    raise FritzServiceError(f'unknown service: "{service_name}"')
fritzconnection.core.exceptions.FritzServiceError: unknown service: "WANCommonIFC1"

On fritzconnection -s -i 192.168.178.1 I am getting the following:

                    DeviceInfo1
                    DeviceConfig1
                    Layer3Forwarding1
                    LANConfigSecurity1
                    ManagementServer1
                    Time1
                    UserInterface1
                    X_AVM-DE_Storage1
                    X_AVM-DE_WebDAVClient1
                    X_AVM-DE_UPnP1
                    X_AVM-DE_Speedtest1
                    X_AVM-DE_RemoteAccess1
                    X_AVM-DE_MyFritz1
                    X_VoIP1
                    X_AVM-DE_OnTel1
                    X_AVM-DE_Dect1
                    X_AVM-DE_TAM1
                    X_AVM-DE_AppSetup1
                    X_AVM-DE_Homeauto1
                    X_AVM-DE_Homeplug1
                    X_AVM-DE_Filelinks1
                    X_AVM-DE_Auth1
                    X_AVM-DE_HostFilter1
                    WLANConfiguration1
                    WLANConfiguration2
                    WLANConfiguration3
                    Hosts1
                    LANEthernetInterfaceConfig1
                    LANHostConfigManagement1
                    WANCommonInterfaceConfig1
                    WANDSLInterfaceConfig1
                    WANDSLLinkConfig1
                    WANEthernetLinkConfig1
                    WANPPPConnection1
                    WANIPConnection1

So I guess the service is called something else on my router. What can I do about that. Its a Fritbox 7590 on firmware 7.29. Related HA Issue: https://github.com/home-assistant/core/issues/63725

kbr commented 2 years ago

It's unlikely that the service is called something else on your router. It's more likely that AVM may have removed the service. At least I'm unable to find the according documentation in the current AVM publications. Also some services can be different for DSL, cable or fiber connections. May be it's time to go into this again. Edit: may be that labeled boxes are customized and also differ. But that's guessing – I don't know it.

chemelli74 commented 2 years ago

I also think that this is due to a customized firmware from some connection provider and this is not a standard firmware behavior

chemelli74 commented 2 years ago

@kbr as we are finding more devices with those different names, would you consider a patch that will handle both ? Something like:

if "WANCommonIFC1" in services:
    call WANCommonIFC1
else:
   call WANCommonInterfaceConfig1

Simone

kbr commented 2 years ago

These are two different services with partly different information. Back in bitbucket times the wrong service has been used in the library providing strange results. However I don't remember why and can't find the according documentation in the AVM-files. So we need some more investigation here.

boennhoff commented 2 years ago

As documented here, I am experiencing the same issue on a vanilla Fritzbox 7590 using the latest labor firmware. Are there any new findings here @kbr?

kbr commented 2 years ago

The two services have attribute-sets just partly overlapping. So i.e. calling the action GetAddonInfos on the service WANCommonIFC1 and switching internal to WANCommonInterfaceConfig1 in case that the former service is not available, the call will result in a FritzActionError, what is wrong.

Same with the WANIPConn1 / WANIPConnection1 services where is the situation, that actions with the same name can return different results, like GetTotalBytesReceived can return the bytes received since the last sync or the last reboot.

A FritzServiceError (inherited from KeyError) indicates that the router does not provide this API. I don't know why this happens on routers of the same series (or at least with the same labels), but this is an issue that should not get handled on the interface level, because it may return wrong results and also the interface has no idea about the intention of the application.

chk1 commented 2 years ago

I had this error in my logs with Home Assistant and Fritzbox 7530 (firmware 7.29, unbranded/retail DSL version). It was weird because I have this very similar setup in two locations, but only one location showed the error.

I compared my configs and it appears to be this setting is the cause for it, if you turn it off:

Statusinformationen über UPnP übertragen

Found in network settings, translation in English approx. "Transmit status information via UPnP"

Screenshot: Fritzbox Settings page in German, highlighted in yellow "Statusinformationen über UPnP übertragen"

As soon as you turn it on & restart HA, the log errors disappear, two new UPnP devices are found. And new sensors are available on the Fritzbox integration, which were previously missing (e.g. current download throughput).

Screenshot: Home-Assistant found two new UPnP devices

chemelli74 commented 2 years ago

Hi @chk1, great finding !

Let's see if this settings fix it for everyone. Fingers crossed.

Simone

kbr commented 2 years ago

To activate the TR-064 API, the UPnP flag has to get set. This is known and documented.

Regarding the issue itself: the service WANIPConn1 allows access to the IPv6 settings. To make this service available, activate IPv6:

"Internet -> Account Information -> IPv6 -> IPv6 Support enabled"

kbr commented 2 years ago

I close this, because the issue is triggered by the settings.

chemelli74 commented 2 years ago

Found in network settings, translation in English approx. "Transmit status information via UPnP"

Do you mind providing the output of http://fritz.box:49000/x_upnpSCPD.xml ? With both the flag on and off.

Thx,

Simone

enkama commented 2 years ago

Found in network settings, translation in English approx. "Transmit status information via UPnP"

Do you mind providing the output of http://fritz.box:49000/x_upnpSCPD.xml ? With both the flag on and off.

Thx,

Simone

Should it be changing when changing it from on to off? If yes it stays the same for me.

Both times it is

<scpd>
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<actionList>
<action>
<name>GetInfo</name>
<argumentList>
<argument>
<name>NewEnable</name>
<direction>out</direction>
<relatedStateVariable>Enable</relatedStateVariable>
</argument>
<argument>
<name>NewUPnPMediaServer</name>
<direction>out</direction>
<relatedStateVariable>UPnPMediaServer</relatedStateVariable>
</argument>
</argumentList>
</action>
<action>
<name>SetConfig</name>
<argumentList>
<argument>
<name>NewEnable</name>
<direction>in</direction>
<relatedStateVariable>Enable</relatedStateVariable>
</argument>
<argument>
<name>NewUPnPMediaServer</name>
<direction>in</direction>
<relatedStateVariable>UPnPMediaServer</relatedStateVariable>
</argument>
</argumentList>
</action>
</actionList>
<serviceStateTable>
<stateVariable sendEvents="no">
<name>Enable</name>
<dataType>boolean</dataType>
<defaultValue>0</defaultValue>
</stateVariable>
<stateVariable sendEvents="no">
<name>UPnPMediaServer</name>
<dataType>boolean</dataType>
<defaultValue>0</defaultValue>
</stateVariable>
</serviceStateTable>
</scpd>
chemelli74 commented 2 years ago

That's fine, I posted the description request and not the query itself. My fault.

In the mean time I found the way to programmatically check the flag: #153

Simone