config: store the protocol used by the device in the config file

Instead of having to detect the protocol multiple times, we should just
store it once so we can detect oddities when they arrive.
This commit is contained in:
Benjamin Tissoires 2018-02-07 16:04:57 +01:00
parent ad145cc078
commit ffe803b8cc
2 changed files with 17 additions and 3 deletions

View File

@ -167,7 +167,10 @@ class TuhiDevice(GObject.Object):
self._tuhi_dbus_device.notify_button_press_required()
def _on_uuid_updated(self, wacom_device, pspec, bluez_device):
self.config.new_device(bluez_device.address, wacom_device.uuid)
protocol = TuhiConfig.Protocol.SLATE
if wacom_device.is_spark():
protocol = TuhiConfig.Protocol.SPARK
self.config.new_device(bluez_device.address, wacom_device.uuid, protocol)
self.registered = True
def _on_listening_updated(self, dbus_device, pspec):
@ -287,7 +290,7 @@ class Tuhi(GObject.Object):
if uuid is None:
logger.info(f'{bluez_device.address}: device without config, must be registered first')
return
logger.debug(f'{bluez_device.address}: UUID {uuid}')
logger.debug(f'{bluez_device.address}: UUID {uuid} protocol: {config["Protocol"]}')
# create the device if unknown from us
if bluez_device.address not in self.devices:

View File

@ -16,6 +16,7 @@ from gi.repository import GObject
import xdg.BaseDirectory
import os
import configparser
import enum
import re
import logging
from .drawing import Drawing
@ -30,6 +31,13 @@ def is_btaddr(addr):
class TuhiConfig(GObject.Object):
class Protocol(enum.Enum):
UNKNOWN = 0
SPARK = 1
SLATE = 2
INTUOS_PRO = 3
def __init__(self):
GObject.Object.__init__(self)
try:
@ -67,9 +75,11 @@ class TuhiConfig(GObject.Object):
self._purge_drawings(entry)
assert config['Device']['Address'] == entry.name
if 'Protocol' not in config['Device']:
config['Device']['Protocol'] = str(TuhiConfig.Protocol.UNKNOWN)
self._devices[entry.name] = config['Device']
def new_device(self, address, uuid):
def new_device(self, address, uuid, protocol):
assert is_btaddr(address)
assert len(uuid) == 12
@ -92,6 +102,7 @@ class TuhiConfig(GObject.Object):
config['Device'] = {
'Address': address,
'UUID': uuid,
'Protocol': protocol,
}
with open(path, 'w') as configfile: