def __adapter_handler(self, sender, path, interface, signal, parameters): interface, properties, optional = parameters if 'Discovering' in properties: log.info('Discovering active. Looking for devices.') try: self.__connect_to_paired_media_device() except: log.info('No paired devices found.')
def get_org(id): log.info("get org", id=id, client=g.user['_id']) org = mongo.db.orgs.find_one({'_id': ObjectId(id)}, { 'last_changed_by': 0, 'last_changed_on': 0 }) if not org: return jsonify(), 404 return jsonify(org), 200
def _archive_model(self, model, action): old = mongo.db.orgs.find_one({'_id': model.get('_id')}) if has_model_changed(old, model): old['id'] = old.get('_id') del old['_id'] old['action'] = action log.info("archiving org record", id=old.get('id'), action=action, remote_user=request.remote_user) mongo.db.orgs_archive.insert_one(old)
def delete_model(self, model): try: log.info("deleting org", remote_user=request.remote_user, id=model.get('_id')) return super().delete_model(model) except Exception as e: log.error("could not delete org", exc_info=e, remote_user=request.remote_user, id=model.get('_id')) raise
def update_model(self, form, model): try: log.info("updating org", remote_user=request.remote_user, id=model.get('_id')) return super().update_model(form, model) except Exception as e: log.error("could not update org", exc_info=e, remote_user=request.remote_user, id=model.get('_id')) raise
def get_orgs(): query = request.args log.info("search orgs", query=query, client=g.user['_id']) orgs = [ o for o in mongo.db.orgs.find(query, { 'last_changed_by': 0, 'last_changed_on': 0 }) ] return jsonify(orgs), 200
def __connect_to_paired_media_device(self): devices = self.__get_paired_media_devices() device_path = list(devices.keys())[0] device_object = self.__bus.get(BLUEZ_SERVICE, device_path) device = device_object[INTERFACE['DEVICE']] if device.Connected: log.info('Connected to device %s.', device.Name) player_path = device_object[INTERFACE['MEDIA_CONTROL']].Player self.__init_player(player_path) else: try: device.Connect() except GLib.GError as err: log.warning('Can\'t connect to device %s.', device.Alias)
#!/usr/bin/python3 import threading import serial from gi.repository import GLib from modules.bluetooth import Bluetooth from modules.ipod import IPod from modules.logger import log # Car name shown via bluetooth CAR_NAME = 'Carputer' SERIAL_PORT = '/dev/ttyS1' log.info('Starting iAP to AVRCP with name %s on serial port %s', CAR_NAME, SERIAL_PORT) serial_connection = serial.Serial(SERIAL_PORT, 38400) bluetooth = Bluetooth(CAR_NAME) ipod = IPod(serial_connection, bluetooth) bluetooth.start_discovery() thread = threading.Thread(target=ipod.listen) thread.start() loop = GLib.MainLoop() loop.run()