Пример #1
0
async def uplink_mock(loop):
    uplink = asynctest.Mock(nibeuplink.Uplink("", "", ""))

    def get_parameter(system_id, parameter_id):
        return PARAMETERS[parameter_id]

    uplink.get_parameter.side_effect = get_parameter
    return uplink
Пример #2
0
async def default_uplink(loop, request, session, server):

    uplink = nibeuplink.Uplink(
        session=session,
        base=server.base,
        throttle=0,
    )

    yield uplink
Пример #3
0
async def default_uplink(event_loop):
    def access_write(data):
        pass

    server = fake_uplink.Uplink(event_loop)

    await server.start()

    async with nibeuplink.Uplink(DEFAULT_CLIENT_ID,
                                 DEFAULT_CLIENT_SECRET,
                                 server.redirect,
                                 None,
                                 access_write,
                                 scope=DEFAULT_SCOPE,
                                 base=server.base) as uplink:

        # Override the default throttling to 0 to speed up tests
        uplink.THROTTLE = timedelta(seconds=0)
        yield uplink, server

    await server.stop()
Пример #4
0
async def run():

    scope = ["READSYSTEM"]

    async with nibeuplink.UplinkSession(
            client_id=
            '9b1e683e2c904adfb52313b4a327b634',  # NIBE Uplink API: Identifier
            client_secret=
            '8YL79duUZWfQAgVdjQmuNZczAtaed5fawULKfhcPzQM=',  # NIBE Uplink API: Secret
            redirect_uri=
            'https://firm-ware.cz/oauth2callback/index.php',  # NIBE Uplink API: Callback URL
            access_data=token_read(),
            access_data_write=token_write,
            scope=scope,
    ) as session:

        if not session.access_data:
            auth_uri = session.get_authorize_url()
            print(auth_uri)
            result = input("Enter full redirect url: ")
            await session.get_access_token(session.get_code_from_url(result))

        uplink = nibeuplink.Uplink(session)

        todo = []
        todo.extend(  # Get outdoor temp
            [uplink.get_parameter(DEFAULT_CLIENT_ID, "40004")])
        todo.extend(  # Get compressor starts
            [uplink.get_parameter(DEFAULT_CLIENT_ID, "43416")])

        if not len(todo):
            todo.extend([uplink.get_system(DEFAULT_CLIENT_ID)])

        res = await asyncio.gather(*todo)
        for a in res:
            try:
                print(json.dumps(a, indent=1))
            except TypeError:
                print(a)
Пример #5
0
async def default_uplink(loop, request):
    def access_write(data):
        pass

    server = fake_uplink.Uplink(loop)

    request.addfinalizer(fin_async(loop, server.stop))

    await server.start()

    uplink = nibeuplink.Uplink(DEFAULT_CLIENT_ID,
                               DEFAULT_CLIENT_SECRET,
                               server.redirect,
                               None,
                               access_write,
                               scope=DEFAULT_SCOPE,
                               base=server.base)

    request.addfinalizer(fin_async(loop, uplink.close))

    # Override the default throttling to 0 to speed up tests
    uplink.THROTTLE = timedelta(seconds=0)
    return uplink, server
Пример #6
0
async def run():

    scope = ["READSYSTEM"]
    if args.put_parameter or args.put_smarthome_mode:
        scope.append("WRITESYSTEM")

    async with nibeuplink.UplinkSession(
        client_id=args.client_id,
        client_secret=args.client_secret,
        redirect_uri=args.redirect_uri,
        access_data=token_read(),
        access_data_write=token_write,
        scope=scope,
    ) as session:

        if not session.access_data:
            auth_uri = session.get_authorize_url()
            print(auth_uri)
            result = input("Enter full redirect url: ")
            await session.get_access_token(session.get_code_from_url(result))

        uplink = nibeuplink.Uplink(session)

        todo = []
        if not args.system:
            todo.extend([uplink.get_systems()])
        else:

            if args.parameter:
                todo.extend(
                    [uplink.get_parameter(args.system, p) for p in args.parameter]
                )

            if args.categories:
                todo.extend([uplink.get_categories(args.system, False, args.unit)])

            if args.category:
                todo.extend(
                    [
                        uplink.get_category(args.system, p, args.unit)
                        for p in args.category
                    ]
                )

            if args.status:
                todo.extend([uplink.get_status(args.system)])

            if args.unit_status:
                todo.extend([uplink.get_unit_status(args.system, args.unit)])

            if args.units:
                todo.extend([uplink.get_units(args.system)])

            if args.alarms:
                todo.extend([uplink.get_notifications(args.system)])

            if args.info:
                todo.extend([uplink.get_notifications(args.system, notifiction_type=1)])

            if args.put_parameter:
                todo.extend(
                    [
                        uplink.put_parameter(args.system, p[0], p[1])
                        for p in args.put_parameter
                    ]
                )

            if args.smarthome_mode:
                todo.extend([uplink.get_smarthome_mode(args.system)])

            if args.put_smarthome_mode:
                todo.extend(
                    [uplink.put_smarthome_mode(args.system, args.put_smarthome_mode)]
                )

            if args.smarthome_thermostats:
                todo.extend([uplink.get_smarthome_thermostats(args.system)])

            if args.post_smarthome_thermostats:
                todo.extend(
                    [
                        uplink.post_smarthome_thermostats(
                            args.system, args.post_smarthome_thermostats
                        )
                    ]
                )

            if args.subsystems:

                async def named(coroutine):
                    data = await coroutine
                    return [x.name for x in data.values()]

                todo.extend(
                    [
                        named(nibeuplink.get_active_climate(uplink, args.system)),
                        named(nibeuplink.get_active_hotwater(uplink, args.system)),
                        named(nibeuplink.get_active_ventilations(uplink, args.system)),
                    ]
                )

            if not len(todo):
                todo.extend([uplink.get_system(args.system)])

        res = await asyncio.gather(*todo)
        for a in res:
            try:
                print(json.dumps(a, indent=1))
            except TypeError:
                print(a)
Пример #7
0
async def run():

    scope = ['READSYSTEM']
    if args.setparameter:
        scope.append('WRITESYSTEM')

    async with nibeuplink.Uplink(client_id=args.client_id,
                                 client_secret=args.client_secret,
                                 redirect_uri=args.redirect_uri,
                                 access_data=token_read(),
                                 access_data_write=token_write,
                                 scope=scope) as uplink:

        if not uplink.access_data:
            auth_uri = uplink.get_authorize_url()
            print(auth_uri)
            result = input('Enter full redirect url: ')
            await uplink.get_access_token(uplink.get_code_from_url(result))

        todo = []
        if not args.system:
            todo.extend([uplink.get_systems()])
        else:

            if args.parameter:
                todo.extend([
                    uplink.get_parameter(args.system, p)
                    for p in args.parameter
                ])

            if args.categories:
                todo.extend(
                    [uplink.get_categories(args.system, False, args.unit)])

            if args.category:
                todo.extend([
                    uplink.get_category(args.system, p, args.unit)
                    for p in args.category
                ])

            if args.status:
                todo.extend([uplink.get_status(args.system)])

            if args.unit_status:
                todo.extend([uplink.get_unit_status(args.system, args.unit)])

            if args.units:
                todo.extend([uplink.get_units(args.system)])

            if args.notifications:
                todo.extend([uplink.get_notifications(args.system)])

            if args.setparameter:
                todo.extend([
                    uplink.set_parameter(args.system, p[0], p[1])
                    for p in args.setparameter
                ])

            if not len(todo):
                todo.extend([uplink.get_system(args.system)])

        res = await asyncio.gather(*todo)
        print(json.dumps(res, indent=1))