Example #1
0
    def __init__(
        self,
        host,
        port,
        username,
        password,
        profile_on,
        profile_off,
        device_list,
    ):
        # pylint: disable=import-error
        import fritzconnection as fc
        from fritz_switch_profiles import FritzProfileSwitch

        self.connection = fc.FritzConnection(address=host,
                                             port=port,
                                             user=username,
                                             password=password)

        if device_list != DEFAULT_DEVICES:
            self.profile_switch = FritzProfileSwitch("http://" + host,
                                                     username, password)

        self.fritzstatus = fc.FritzStatus(fc=self.connection)
        self.ha_ip = get_local_ip()
        self.profile_on = profile_on
        self.profile_off = profile_off
        self.profile_last_updated = time.time()
        self.device_list = device_list

        self.username = username
        self.password = password
        self.port = port
        self.host = host
Example #2
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)
Example #3
0
    def __init__(
        self,
        password,
        username = DEFAULT_USERNAME,
        host = DEFAULT_HOST,
        port=DEFAULT_PORT,
        profile_on = DEFAULT_PROFILE_ON,
        profile_off = DEFAULT_PROFILE_OFF,
        device_list = DEFAULT_DEVICES,
        use_port = DEFAULT_USE_PORT,
        use_deflections = DEFAULT_USE_DEFLECTIONS,
        use_wifi = DEFAULT_USE_WIFI,
        use_devices = DEFAULT_USE_DEVICES,
    ):
        # pylint: disable=import-error
        from fritzconnection import FritzConnection
        from fritzconnection.lib.fritzstatus import FritzStatus
        from fritz_switch_profiles import FritzProfileSwitch

        # general timeout for all requests to the router. Some calls need quite some time.
        self.connection = FritzConnection(
            address=host, port=port, user=username, password=password, timeout=30.0
        )

        if device_list != DEFAULT_DEVICES:
            self.profile_switch = FritzProfileSwitch(
                "http://" + host, username, password
            )

        self.fritzstatus = FritzStatus(fc=self.connection)
        self.ha_ip = get_local_ip()
        self.profile_on = profile_on
        self.profile_off = profile_off
        self.profile_last_updated = time.time()
        self.device_list = device_list

        self.username = username
        self.password = password
        self.port = port
        self.host = host

        self.use_wifi = use_wifi
        self.use_port = use_port
        self.use_deflections = use_deflections
        self.use_devices = use_devices

        self._unique_id = self.connection.call_action("DeviceInfo:1", "GetInfo")[
            "NewSerialNumber"
        ]
        self._device_info = self._fetch_device_info()
Example #4
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)