finish06 / pyunifi

https://unifi-sdn.ubnt.com/
MIT License
223 stars 100 forks source link

Change Password Function #28

Open helpdeskdan opened 5 years ago

helpdeskdan commented 5 years ago

Maybe something like this, probably add private 'put' function. Possibly call another function, as you can change anything with the put. Was in a rush, did this - much thanks much for your project.

    def set_wlan_pass(self, ssid, key):
        """Changes the password for a given
        ssid.  Daniel ToDo: Put method. """
        for wlan in self._api_read('list/wlanconf'):
            if wlan['name'] == ssid:
                wlan_id = wlan['_id']
                wlan_settings = {}
                wlan_settings["x_passphrase"] = key 
                params = json.dumps(wlan_settings)
                url = 'rest/wlanconf/' + wlan_id
                r = self.session.put(self._api_url() + url,
                        params)
                if r.status_code is not 200:
                    raise APIError("Login failed - status code: %i" %  
                            r.status_code)
        return 
finish06 commented 5 years ago

Commented on the Pull Request.