kbr / fritzconnection

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

Question: how to dial? #22

Closed WolfgangFahl closed 4 years ago

WolfgangFahl commented 4 years ago

Thx for creating this excellent library!

Using 0.8.4 which was installed by pip I am trying fc.call_action("X_VoIP:1", "X_AVM-DE_DialNumber",arguments={'NewX_AVM-DE_PhoneNumber':'**612#'}) and get an empty result and nothing happens fc.call_action("X_VoIP:1", "X_AVM-DE_DialNumber",NewX_AVM-DE_PhoneNumber='**612#'}) would probably work but is invalid syntax due to the dash in the parameter name ...

What would be needed to get this working?

WolfgangFahl commented 4 years ago

I don't get what the issue is. According to https://github.com/kbr/fritzconnection/blob/master/fritzconnection/core/fritzconnection.py I tried this to find out why the dict approach does not work:

def test_args(service_name, action_name, *,
                    arguments=None, **kwargs):    
    arguments = arguments if arguments else dict()
    if not arguments:
        arguments.update(kwargs)
    print (type(arguments),arguments)    

test_args("X_VoIP:1", "X_AVM-DE_DialNumber",arguments={'NewX_AVM-DE_PhoneNumber':'**612#'})
test_args("X_VoIP:1", "X_AVM-DE_DialNumber",NewX_AVM_DE_PhoneNumber='**612#') 

<class 'dict'> {'NewX_AVM-DE_PhoneNumber': '**612#'}
<class 'dict'> {'NewX_AVM_DE_PhoneNumber': '**612#'}
WolfgangFahl commented 4 years ago

In fact the 0.8.4 source code is different:

 def call_action(self, service_name, action_name, **kwargs):
        """
        Executes the given action. Raise a KeyError on unkown actions.
        service_name can end with an identifier ':n' (with n as an
        integer) to differentiate between different services with the
        same name, like WLANConfiguration:1 or WLANConfiguration:2. In
        case the service_name does not end with an identifier the id
        ':1' will get added by default.
        """
        if ':' not in service_name:
            service_name += ':1'
        action = self._get_action(service_name, action_name)
        return action.execute(**kwargs)
WolfgangFahl commented 4 years ago

Could you please update the pip repository?

kbr commented 4 years ago

You are already using the brand new 1.0b1 version from the master branch, which is not officially released yet and is significantly different to the 0.8.4 version. But it is planned to make the 1.0 release soon. Then pip gets also updated.

WolfgangFahl commented 4 years ago

Thx for looking into this. My pip installation is 0.8.4 i just assumed I'd have the version from git and that assumption was wrong. I'll not use the dial function until it's properly available.

WolfgangFahl commented 4 years ago

https://stackoverflow.com/questions/1769403/what-is-the-purpose-and-use-of-kwargs helped:

 def call(self,number):
        # https://github.com/kbr/fritzconnection/issues/22
        kwargs={'NewX_AVM-DE_PhoneNumber':number}
        self.fc.call_action("X_VoIP:1", "X_AVM-DE_DialNumber",**kwargs) 

works with 0.8.4

kbr commented 4 years ago

version 1.0 is out (has been scheduled for today) and available on PyPi. The FritzCall module from the library now supports also dialing ;)

WolfgangFahl commented 4 years ago

Nice.

  def dial(self,number):
        # https://github.com/kbr/fritzconnection/issues/22
        self.fc.call_action("X_VoIP:1", "X_AVM-DE_DialNumber",arguments={'NewX_AVM-DE_PhoneNumber':number}) 

now works.