• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021-2022 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# -----------------------------------------------------------------------------
16# Imports
17# -----------------------------------------------------------------------------
18import asyncio
19import os
20import logging
21import click
22
23from bumble.device import Device
24from bumble.keys import JsonKeyStore
25
26
27# -----------------------------------------------------------------------------
28async def unbond(keystore_file, device_config, address):
29    # Create a device to manage the host
30    device = Device.from_config_file(device_config)
31
32    # Get all entries in the keystore
33    if keystore_file:
34        keystore = JsonKeyStore(None, keystore_file)
35    else:
36        keystore = device.keystore
37
38    if keystore is None:
39        print('no keystore')
40        return
41
42    if address is None:
43        await keystore.print()
44    else:
45        try:
46            await keystore.delete(address)
47        except KeyError:
48            print('!!! pairing not found')
49
50
51# -----------------------------------------------------------------------------
52@click.command()
53@click.option('--keystore-file', help='File in which to store the pairing keys')
54@click.argument('device-config')
55@click.argument('address', required=False)
56def main(keystore_file, device_config, address):
57    logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'INFO').upper())
58    asyncio.run(unbond(keystore_file, device_config, address))
59
60
61# -----------------------------------------------------------------------------
62if __name__ == '__main__':
63    main()
64