Salamek / huawei-lte-api

API For huawei LAN/WAN LTE Modems
GNU Lesser General Public License v3.0
376 stars 92 forks source link

e3371 - pb module - question #89

Closed SCiunczyk closed 3 years ago

SCiunczyk commented 3 years ago

Hi,

first of all - many thanks for your library - IMHO the best available now in our corner of Galaxy! I'm using it on my project based on HUAWEI E3372. BTW if you want I can send you the hardware - as I have spare one.

I would like to use Phonebook (PB) module but I'm missing many functions. Mostly I need two functions pb-new and pb-delete.

I think that I can program this functions myself and create PR, but I have no idea how to pass request xml data for pb-new. The API is expecting structure like that:

<request>
    <GroupID></GroupID>
    <SaveType></SaveType>
    <Field>
        <Name>FormattedName</Name>
        <Value></Value>
    </Field>
    <Field>
        <Name>MobilePhone</Name>
        <Value></Value>
    </Field>
    <Field>
        <Name>HomePhone</Name>
        <Value></Value>
    </Field>
    <Field>
        <Name>WorkPhone</Name>
        <Value></Value>
    </Field>
    <Field>
        <Name>WorkEmail</Name>
        <Value></Value>
    </Field>
</request>

Is that possible ? I mean passing nested dictionary parameter to the _connection.post_set call.

Salamek commented 3 years ago

@SCiunczyk hi, sadly i don't have any Huawei device here that supports PB module, but you should be able to write working code and create a PR... the pb_new code should look something like this:

def pb_new(self, name: str, mobile_phone: str, home_phone: str, work_phone: str, work_email: str) -> SetResponseType:

    class Node:
        def __init__(self, name):
            self._name = name

        def __str__(self):
            return self._name

    data = OrderedDict([
        ('GroupID', ''),
        ('SaveType', ''),
        (Node('Field'), {
            'Name': 'FormattedName',
            'Value': name
        }),
        (Node('Field'), {
            'Name': 'MobilePhone',
            'Value': mobile_phone
        }),
        (Node('Field'), {
            'Name': 'HomePhone',
            'Value': home_phone
        }),
        (Node('Field'), {
            'Name': 'WorkPhone',
            'Value': work_phone
        }),
        (Node('Field'), {
            'Name': 'WorkEmail',
            'Value': work_email
        }),
    ])

    dicttoxml_xargs = {
        'attr_type': False
    }

    return self._connection.post_set('pb/pb-new', data, dicttoxml_xargs=dicttoxml_xargs)

PS: Testing HW is always welcomed, send me a email so i can send you shipping info...

SCiunczyk commented 3 years ago

Thanks @Salamek your code works as expected. So I'll create all pb module functions and then prepare PR...

Please check your e-mali and send me info with your address.