• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

chrvadala / node-ble / 21502446189

30 Jan 2026 02:38AM UTC coverage: 89.526%. First build
21502446189

Pull #74

github

web-flow
Merge fb2c6d2a1 into 2eddf23cc
Pull Request #74: add getUUIDbyHandle

88 of 110 branches covered (80.0%)

Branch coverage included in aggregate %.

0 of 16 new or added lines in 1 file covered. (0.0%)

271 of 291 relevant lines covered (93.13%)

14.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

42.86
/src/GattServer.js
1
const BusHelper = require('./BusHelper')
16✔
2
const GattService = require('./GattService')
16✔
3

4
/**
5
 * @classdesc GattServer class that provides interaction with device GATT profile.
6
 * @class GattServer
7
 * @see You can construct a Device object via {@link Device#gatt} method
8
 */
9
class GattServer {
10
  constructor (dbus, adapter, device) {
11
    this.dbus = dbus
4✔
12
    this.adapter = adapter
4✔
13
    this.device = device
4✔
14
    this.helper = new BusHelper(dbus, 'org.bluez', `/org/bluez/${adapter}/${device}`, 'org.bluez.Device1')
4✔
15

16
    this._services = {}
4✔
17
  }
18

19
  async init () {
20
    // TODO add lock to avoid race conditions
21
    this._services = {}
4✔
22

23
    const servicesResolved = await this.helper.prop('ServicesResolved')
4✔
24
    if (!servicesResolved) {
4!
25
      await this.helper.waitPropChange('ServicesResolved')
×
26
    }
27

28
    const children = await this.helper.children()
4✔
29
    for (const s of children) {
4✔
30
      const service = new GattService(this.dbus, this.adapter, this.device, s)
12✔
31
      const uuid = await service.getUUID()
12✔
32
      await service.init()
12✔
33
      this._services[uuid] = service
12✔
34
    }
35
  }
36

37
  /**
38
   * List of available services
39
   * @returns {string[]}
40
   */
41
  async services () {
42
    return Object.keys(this._services)
4✔
43
  }
44

45
  /**
46
   * Init a GattService instance and return it
47
   * @param {string} uuid
48
   * @returns {GattService}
49
   */
50
  async getPrimaryService (uuid) {
51
    if (uuid in this._services) {
4!
52
      return this._services[uuid]
4✔
53
    }
54

55
    throw new Error('Service not available')
×
56
  }
57

58
  /**
59
   * Find the service UUID and characteristic UUID based on a characteristic handle
60
   * @param {number} charHandle
61
   * @returns {Object|null}
62
   */
63
  async getUUIDbyHandle (charHandle) {
NEW
64
    const handle = charHandle - 1
×
NEW
65
    const handleStr = 'char' + handle.toString(16).padStart(4, '0')
×
66

NEW
67
    for (const key in this.dbus._matchRules) {
×
NEW
68
      if (key.includes(handleStr)) {
×
NEW
69
        const match = key.match(/service[0-9a-fA-F]+/)
×
NEW
70
        if (match) {
×
NEW
71
          const service = match[0]
×
NEW
72
          const services = this._services
×
NEW
73
          for (const skey in services) {
×
NEW
74
            if (services[skey].service === service) {
×
NEW
75
              const characteristics = services[skey]._characteristics
×
NEW
76
              for (const ckey in characteristics) {
×
NEW
77
                if (characteristics[ckey].characteristic === handleStr) {
×
NEW
78
                  return { service: skey, char: ckey }
×
79
                }
80
              }
NEW
81
              return null
×
82
            }
83
          }
84
        }
85
      }
86
    }
NEW
87
    return null
×
88
  }
89
}
90

91
module.exports = GattServer
16✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc