Exemplo n.º 1
0
    def allowDevice(self, host_name):
        """Login to fritzbox and assign the 'Internet Access' profile to the device with the given host name"""
        fps = FritzProfileSwitch(self.fritzbox_url, self.fritzbox_user,
                                 self.fritzbox_password)
        devices = fps.get_devices()
        profiles = fps.get_profiles()

        #Get the device_id for the host name
        device_id = None
        for device in devices:
            if device['name'] == host_name:
                device_id = device['id1']

        if device_id:
            #Get the profile id for the Internet access profile
            profile_id = None
            for profile in profiles:
                if profile['name'] == self.fritzbox_profile_name:
                    profile_id = profile['id']

            if profile_id:
                #construct the array to set the profile for the device
                profile_for_device = [(device_id, profile_id)]
                #set device profile
                fps.set_profiles(profile_for_device)
            else:
                message = "Could not find profile with the name: {}".format(
                    self.fritzbox_profile_name)
                self.log(message)
                self.notifier.notify(self.notify_name, message)
        else:
            message = "Could not find device with the hostname: {}".format(
                host_name)
            self.log(message)
            self.notifier.notify(self.notify_name, message)
Exemplo n.º 2
0
from fritz_switch_profiles import FritzProfileSwitch

url = 'http://fritz.box'
user = ''
password = '******'

fps = FritzProfileSwitch(url, user, password)
devices = fps.get_devices()
profiles = fps.get_profiles()

fps.print_devices()
fps.print_profiles()

profile_for_device = [devices[0]['id1'], profiles[2]['id']]

fps.set_profiles(profile_for_device)