The bluetooth BLE plugin must also implement get_measurement to work with the scanner backend
This commit is contained in:
parent
59e3f81202
commit
fc7982378a
1 changed files with 18 additions and 3 deletions
|
@ -3,13 +3,15 @@ import os
|
|||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from typing import Optional, Dict
|
||||
|
||||
from platypush.plugins import Plugin, action
|
||||
from platypush.plugins import action
|
||||
from platypush.plugins.sensor import SensorPlugin
|
||||
from platypush.message.response.bluetooth import BluetoothScanResponse, BluetoothDiscoverPrimaryResponse, \
|
||||
BluetoothDiscoverCharacteristicsResponse
|
||||
|
||||
|
||||
class BluetoothBlePlugin(Plugin):
|
||||
class BluetoothBlePlugin(SensorPlugin):
|
||||
"""
|
||||
Bluetooth BLE (low-energy) plugin
|
||||
|
||||
|
@ -76,7 +78,7 @@ class BluetoothBlePlugin(Plugin):
|
|||
'\t[sudo] setcap "cap_net_raw,cap_net_admin+eip" {}'.format(exe))
|
||||
|
||||
@action
|
||||
def scan(self, interface: str = None, duration: int = 10) -> BluetoothScanResponse:
|
||||
def scan(self, interface: Optional[str] = None, duration: int = 10) -> BluetoothScanResponse:
|
||||
"""
|
||||
Scan for nearby bluetooth low-energy devices
|
||||
|
||||
|
@ -93,6 +95,19 @@ class BluetoothBlePlugin(Plugin):
|
|||
devices = svc.discover(duration)
|
||||
return BluetoothScanResponse(devices)
|
||||
|
||||
@action
|
||||
def get_measurement(self, interface: Optional[str] = None, duration: Optional[int] = 10, *args, **kwargs) \
|
||||
-> Dict[str, dict]:
|
||||
"""
|
||||
Wrapper for ``scan`` that returns bluetooth devices in a format usable by sensor backends.
|
||||
|
||||
:param interface: Bluetooth adapter name to use (default configured if None)
|
||||
:param duration: Scan duration in seconds
|
||||
:return: Device address -> info map.
|
||||
"""
|
||||
devices = self.scan(interface=interface, duration=duration).output
|
||||
return {device['addr']: device for device in devices}
|
||||
|
||||
# noinspection PyArgumentList
|
||||
@action
|
||||
def connect(self, device: str, interface: str = None, wait: bool = True, channel_type: str = 'public',
|
||||
|
|
Loading…
Reference in a new issue