Python dbus.Boolean() Examples
The following are 28
code examples of dbus.Boolean().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
dbus
, or try the search function
.
Example #1
Source File: bluetool.py From bluetool with GNU General Public License v3.0 | 7 votes |
def trust(self, address): try: device = bluezutils.find_device(address) except (bluezutils.BluezUtilError, dbus.exceptions.DBusException) as error: logger.error(str(error) + "\n") return False try: props = dbus.Interface( self._bus.get_object("org.bluez", device.object_path), "org.freedesktop.DBus.Properties") if not props.Get("org.bluez.Device1", "Trusted"): props.Set("org.bluez.Device1", "Trusted", dbus.Boolean(1)) except dbus.exceptions.DBusException as error: logger.error(str(error) + "\n") return False return True
Example #2
Source File: py_spotify_listener.py From polybar-spotify-controls with MIT License | 7 votes |
def unwrap(val): if isinstance(val, dbus.ByteArray): return "".join([str(x) for x in val]) if isinstance(val, (dbus.Array, list, tuple)): return [unwrap(x) for x in val] if isinstance(val, (dbus.Dictionary, dict)): return dict([(unwrap(x), unwrap(y)) for x, y in val.items()]) if isinstance(val, (dbus.Signature, dbus.String)): return str(val) if isinstance(val, dbus.Boolean): return bool(val) if isinstance(val, (dbus.Int16, dbus.UInt16, dbus.Int32, dbus.UInt32, dbus.Int64, dbus.UInt64)): return int(val) if isinstance(val, dbus.Byte): return bytes([int(val)]) return val
Example #3
Source File: test_bt_bus.py From bt-manager with GNU General Public License v3.0 | 6 votes |
def test_all(self): val = [1, 2, 3, 4, 5] self.assertEqual(bt_manager.interface.translate_to_dbus_type(dbus.Array, val), # noqa dbus.Array(val)) val = -1 self.assertEqual(bt_manager.interface.translate_to_dbus_type(dbus.Int32, val), # noqa dbus.Int32(val)) val = 1 self.assertEqual(bt_manager.interface.translate_to_dbus_type(dbus.UInt32, val), # noqa dbus.UInt32(val)) val = 'Test' self.assertEqual(bt_manager.interface.translate_to_dbus_type(dbus.String, val), # noqa dbus.String(val)) val = {'Hello': 1} self.assertEqual(bt_manager.interface.translate_to_dbus_type(dbus.Dictionary, # noqa val), dbus.Dictionary(val)) val = 'True' self.assertEqual(bt_manager.interface.translate_to_dbus_type(dbus.Boolean, val), # noqa dbus.Boolean(True)) val = 'False' self.assertEqual(bt_manager.interface.translate_to_dbus_type(dbus.Boolean, val), # noqa dbus.Boolean(False))
Example #4
Source File: networkmanayer.py From my-weather-indicator with MIT License | 6 votes |
def unwrap(self, val): if isinstance(val, dbus.ByteArray): return "".join([str(x) for x in val]) if isinstance(val, (dbus.Array, list, tuple)): return [self.unwrap(x) for x in val] if isinstance(val, (dbus.Dictionary, dict)): return dict([(self.unwrap(x), self.unwrap(y)) for x, y in val.items()]) if isinstance(val, dbus.ObjectPath): if val.startswith('/org/freedesktop/NetworkManager/'): classname = val.split('/')[4] classname = { 'Settings': 'Connection', 'Devices': 'Device', }.get(classname, classname) return globals()[classname](val) if isinstance(val, (dbus.Signature, dbus.String)): return unicode(val) if isinstance(val, dbus.Boolean): return bool(val) if isinstance(val, (dbus.Int16, dbus.UInt16, dbus.Int32, dbus.UInt32, dbus.Int64, dbus.UInt64)): return int(val) if isinstance(val, dbus.Byte): return bytes([int(val)]) return val
Example #5
Source File: screensaver_monitor.py From openrazer with GNU General Public License v2.0 | 6 votes |
def signal_callback(self, active): """ Called by DBus when a signal is found :param active: If the screensaver is active :type active: dbus.Boolean """ active = bool(active) if self.monitoring: if active: # Only trigger once per state change if self._active is None or not self._active: self._active = active self.suspend() else: if self._active is None or self._active: self._active = active self.resume()
Example #6
Source File: advertisement.py From python-bluezero with MIT License | 5 votes |
def GetAll(self, interface_name): """Return the advertisement properties. This method is registered with the D-Bus at ``org.freedesktop.DBus.Properties`` :param interface: interface to get the properties of. The interface must be ``org.bluez.LEAdvertisement1`` otherwise an exception is raised. """ if interface_name != constants.LE_ADVERTISEMENT_IFACE: raise InvalidArgsException() response = {} response['Type'] = self.props[interface_name]['Type'] if self.props[interface_name]['ServiceUUIDs'] is not None: response['ServiceUUIDs'] = dbus.Array( self.props[interface_name]['ServiceUUIDs'], signature='s') if self.props[interface_name]['ServiceData'] is not None: response['ServiceData'] = dbus.Dictionary( self.props[interface_name]['ServiceData'], signature='sv') if self.props[interface_name]['ManufacturerData'] is not None: response['ManufacturerData'] = dbus.Dictionary( self.props[interface_name]['ManufacturerData'], signature='qv') if self.props[interface_name]['SolicitUUIDs'] is not None: response['SolicitUUIDs'] = dbus.Array( self.props[interface_name]['SolicitUUIDs'], signature='s') response['IncludeTxPower'] = dbus.Boolean( self.props[interface_name]['IncludeTxPower']) return response
Example #7
Source File: other_nm.py From python-eduvpn-client with GNU General Public License v3.0 | 5 votes |
def base_to_python(val): if isinstance(val, dbus.ByteArray): return "".join([str(x) for x in val]) if isinstance(val, (dbus.Array, list, tuple)): return [fixups.base_to_python(x) for x in val] if isinstance(val, (dbus.Dictionary, dict)): return dict([(fixups.base_to_python(x), fixups.base_to_python(y)) for x, y in val.items()]) if isinstance(val, dbus.ObjectPath): for obj in (NetworkManager, Settings, AgentManager): if val == obj.object_path: return obj if val.startswith('/org/freedesktop/NetworkManager/'): classname = val.split('/')[4] classname = { 'Settings': 'Connection', 'Devices': 'Device', }.get(classname, classname) try: return globals()[classname](val) except ObjectVanished: return None if val == '/': return None if isinstance(val, (dbus.Signature, dbus.String)): return six.text_type(val) if isinstance(val, dbus.Boolean): return bool(val) if isinstance(val, (dbus.Int16, dbus.UInt16, dbus.Int32, dbus.UInt32, dbus.Int64, dbus.UInt64)): return int(val) if isinstance(val, dbus.Byte): return six.int2byte(int(val)) return val
Example #8
Source File: utils.py From BlueDot with MIT License | 5 votes |
def device_powered(device_name, powered): bus = dbus.SystemBus() adapter_path = find_adapter(device_name).object_path adapter = dbus.Interface(bus.get_object(SERVICE_NAME, adapter_path),"org.freedesktop.DBus.Properties") if powered: value = dbus.Boolean(1) else: value = dbus.Boolean(0) adapter.Set(ADAPTER_INTERFACE, "Powered", value)
Example #9
Source File: utils.py From BlueDot with MIT License | 5 votes |
def device_pairable(device_name, pairable): bus = dbus.SystemBus() adapter_path = find_adapter(device_name).object_path adapter = dbus.Interface(bus.get_object(SERVICE_NAME, adapter_path),"org.freedesktop.DBus.Properties") if pairable: value = dbus.Boolean(1) else: value = dbus.Boolean(0) adapter.Set(ADAPTER_INTERFACE, "Pairable", value)
Example #10
Source File: utils.py From BlueDot with MIT License | 5 votes |
def device_discoverable(device_name, discoverable): bus = dbus.SystemBus() adapter_path = find_adapter(device_name).object_path adapter = dbus.Interface(bus.get_object(SERVICE_NAME, adapter_path),"org.freedesktop.DBus.Properties") if discoverable: value = dbus.Boolean(1) else: value = dbus.Boolean(0) adapter.Set(ADAPTER_INTERFACE, "Discoverable", value)
Example #11
Source File: agent.py From bluetool with GNU General Public License v3.0 | 5 votes |
def run(self): _bluetooth.make_discoverable(True, self.timeout) _bluetooth.set_adapter_property("Pairable", dbus.Boolean(1)) _bluetooth.set_adapter_property("PairableTimeout", dbus.UInt32(0)) self.agent = Agent(self.client_class, self.timeout, self.path) if not self._register(): self.shutdown() return self._mainloop.run()
Example #12
Source File: bluetool.py From bluetool with GNU General Public License v3.0 | 5 votes |
def make_discoverable(self, value=True, timeout=180): try: adapter = bluezutils.find_adapter() except (bluezutils.BluezUtilError, dbus.exceptions.DBusException) as error: logger.error(str(error) + "\n") return False try: props = dbus.Interface( self._bus.get_object("org.bluez", adapter.object_path), "org.freedesktop.DBus.Properties") timeout = int(timeout) value = int(value) if int(props.Get( "org.bluez.Adapter1", "DiscoverableTimeout")) != timeout: props.Set( "org.bluez.Adapter1", "DiscoverableTimeout", dbus.UInt32(timeout)) if int(props.Get("org.bluez.Adapter1", "Discoverable")) != value: props.Set( "org.bluez.Adapter1", "Discoverable", dbus.Boolean(value)) except dbus.exceptions.DBusException as error: logger.error(str(error) + "\n") return False logger.info("Discoverable: {}".format(value)) return True
Example #13
Source File: ipaddress.py From my-weather-indicator with MIT License | 5 votes |
def convert(dbus_obj): """Converts dbus_obj from dbus type to python type. :param dbus_obj: dbus object. :returns: dbus_obj in python type. """ _isinstance = partial(isinstance, dbus_obj) ConvertType = namedtuple('ConvertType', 'pytype dbustypes') pyint = ConvertType(int, (dbus.Byte, dbus.Int16, dbus.Int32, dbus.Int64, dbus.UInt16, dbus.UInt32, dbus.UInt64)) pybool = ConvertType(bool, (dbus.Boolean, )) pyfloat = ConvertType(float, (dbus.Double, )) pylist = ConvertType(lambda _obj: list(map(convert, dbus_obj)), (dbus.Array, )) pytuple = ConvertType(lambda _obj: tuple(map(convert, dbus_obj)), (dbus.Struct, )) types_str = (dbus.ObjectPath, dbus.Signature, dbus.String) pystr = ConvertType(str, types_str) pydict = ConvertType( lambda _obj: dict(list(zip(list(map(convert, dbus_obj.keys())), list(map(convert, dbus_obj.values())) )) ), (dbus.Dictionary, ) ) for conv in (pyint, pybool, pyfloat, pylist, pytuple, pystr, pydict): if any(map(_isinstance, conv.dbustypes)): return conv.pytype(dbus_obj) else: return dbus_obj
Example #14
Source File: localGATT.py From python-bluezero with MIT License | 5 votes |
def StopNotify(self): """ DBus method for disabling notifications of the characteristic value. :return: value """ if self.props[constants.GATT_CHRC_IFACE]['Notifying'] is False: logger.info('Not Notifying, nothing to do') return self.Set(constants.GATT_CHRC_IFACE, 'Notifying', dbus.Boolean(False, variant_level=1))
Example #15
Source File: localGATT.py From python-bluezero with MIT License | 5 votes |
def StartNotify(self): """ DBus method for enabling notifications of the characteristic value. :return: value """ if not self.props[constants.GATT_CHRC_IFACE]['Notifying'] is True: logger.info('Notifying already, nothing to do') return self.Set(constants.GATT_CHRC_IFACE, 'Notifying', dbus.Boolean(True, variant_level=1))
Example #16
Source File: peripheral.py From python-bluezero with MIT License | 5 votes |
def get_properties(self): """Return a dictionary of the advert properties. The dictionary has the following keys: - Type: the advertisement type. - ServiceUUIDS: UUIDs of services to advertise - SolicitUUIDS: - ManufacturerData: dictionary of manufacturer data - ServiceData: dictionary of service data - IncludeTxPower: """ properties = dict() properties['Type'] = self.ad_type if self.service_uuids is not None: properties['ServiceUUIDs'] = dbus.Array(self.service_uuids, signature='s') if self.solicit_uuids is not None: properties['SolicitUUIDs'] = dbus.Array(self.solicit_uuids, signature='s') if self.manufacturer_data is not None: properties['ManufacturerData'] = dbus.Dictionary( self.manufacturer_data, signature='qay') if self.service_data is not None: properties['ServiceData'] = dbus.Dictionary(self.service_data, signature='say') if self.include_tx_power is not None: properties['IncludeTxPower'] = dbus.Boolean(self.include_tx_power) return {constants.LE_ADVERTISEMENT_IFACE: properties}
Example #17
Source File: gatt_linux.py From gatt-python with MIT License | 5 votes |
def is_adapter_powered(self, powered): return self._adapter_properties.Set('org.bluez.Adapter1', 'Powered', dbus.Boolean(powered))
Example #18
Source File: upower.py From cpu-g with GNU General Public License v3.0 | 5 votes |
def convert(dbus_obj): """Converts dbus_obj from dbus type to python type. :param dbus_obj: dbus object. :returns: dbus_obj in python type. """ _isinstance = partial(isinstance, dbus_obj) ConvertType = namedtuple('ConvertType', 'pytype dbustypes') pyint = ConvertType(int, (dbus.Byte, dbus.Int16, dbus.Int32, dbus.Int64, dbus.UInt16, dbus.UInt32, dbus.UInt64)) pybool = ConvertType(bool, (dbus.Boolean, )) pyfloat = ConvertType(float, (dbus.Double, )) pylist = ConvertType(lambda _obj: list(map(convert, dbus_obj)), (dbus.Array, )) pytuple = ConvertType(lambda _obj: tuple(map(convert, dbus_obj)), (dbus.Struct, )) types_str = (dbus.ObjectPath, dbus.Signature, dbus.String) pystr = ConvertType(str, types_str) pydict = ConvertType( lambda _obj: dict(zip(map(convert, dbus_obj.keys()), map(convert, dbus_obj.values()) ) ), (dbus.Dictionary, ) ) for conv in (pyint, pybool, pyfloat, pylist, pytuple, pystr, pydict): if any(map(_isinstance, conv.dbustypes)): return conv.pytype(dbus_obj) return dbus_obj
Example #19
Source File: btspeaker.py From intel-iot-refkit with MIT License | 5 votes |
def do_pair(): global pairing global mainloop bus = dbus.SystemBus() #remove connected and paired device from bluez remove_paired_bt_device() # we are using our own agent to bypass authorization and get callback for connected state path = "/test/agent" agent = my_bt_agent(bus, path) obj = bus.get_object('org.bluez', "/org/bluez"); manager = dbus.Interface(obj, "org.bluez.AgentManager1") manager.RegisterAgent(path, 'NoInputNoOutput') manager.RequestDefaultAgent(path) adapter1_path = "/org/bluez/hci0" adapter1 = dbus.Interface(bus.get_object("org.bluez", adapter1_path), "org.freedesktop.DBus.Properties") adapter1.Set("org.bluez.Adapter1", "Powered", dbus.Boolean(1)) adapter1.Set("org.bluez.Adapter1", "Pairable", dbus.Boolean(1)) adapter1.Set("org.bluez.Adapter1", "Discoverable", dbus.Boolean(1)) # let's wait for paired callback from bluez or timeout from led blink mainloop.run() pairing = False manager.UnregisterAgent(path) agent.remove_from_connection()
Example #20
Source File: advertisement.py From cputemp with MIT License | 5 votes |
def get_properties(self): properties = dict() properties["Type"] = self.ad_type if self.local_name is not None: properties["LocalName"] = dbus.String(self.local_name) if self.service_uuids is not None: properties["ServiceUUIDs"] = dbus.Array(self.service_uuids, signature='s') if self.solicit_uuids is not None: properties["SolicitUUIDs"] = dbus.Array(self.solicit_uuids, signature='s') if self.manufacturer_data is not None: properties["ManufacturerData"] = dbus.Dictionary( self.manufacturer_data, signature='qv') if self.service_data is not None: properties["ServiceData"] = dbus.Dictionary(self.service_data, signature='sv') if self.include_tx_power is not None: properties["IncludeTxPower"] = dbus.Boolean(self.include_tx_power) if self.local_name is not None: properties["LocalName"] = dbus.String(self.local_name) return {LE_ADVERTISEMENT_IFACE: properties}
Example #21
Source File: bletools.py From cputemp with MIT License | 5 votes |
def power_adapter(self): adapter = self.get_adapter() adapter_props = dbus.Interface(bus.get_object(BLUEZ_SERVICE_NAME, adapter), "org.freedesktop.DBus.Properties"); adapter_props.Set("org.bluez.Adapter1", "Powered", dbus.Boolean(1))
Example #22
Source File: NetworkManager.py From AstroBox with GNU Affero General Public License v3.0 | 5 votes |
def base_to_python(val): if isinstance(val, dbus.ByteArray): return "".join([str(x) for x in val]) if isinstance(val, (dbus.Array, list, tuple)): return [fixups.base_to_python(x) for x in val] if isinstance(val, (dbus.Dictionary, dict)): return dict([(fixups.base_to_python(x), fixups.base_to_python(y)) for x,y in val.items()]) if isinstance(val, dbus.ObjectPath): for obj in (NetworkManager, Settings, AgentManager): if val == obj.object_path: return obj if val.startswith('/org/freedesktop/NetworkManager/'): classname = val.split('/')[4] classname = { 'Settings': 'Connection', 'Devices': 'Device', }.get(classname, classname) return globals()[classname](val) if val == '/': return None if isinstance(val, (dbus.Signature, dbus.String)): return six.text_type(val) if isinstance(val, dbus.Boolean): return bool(val) if isinstance(val, (dbus.Int16, dbus.UInt16, dbus.Int32, dbus.UInt32, dbus.Int64, dbus.UInt64)): return int(val) if isinstance(val, dbus.Byte): return six.int2byte(int(val)) return val
Example #23
Source File: dbuswpasupplicant.py From pywificontrol with BSD 3-Clause "New" or "Revised" License | 5 votes |
def set_debug_show_keys(self, parameter): self.__set_property(dbus.String("DebugShowKeys"), dbus.Boolean(parameter))
Example #24
Source File: dbuswpasupplicant.py From pywificontrol with BSD 3-Clause "New" or "Revised" License | 5 votes |
def set_debug_level(self, parameter): self.__set_property(dbus.String("DebugTimestamp"), dbus.Boolean(parameter))
Example #25
Source File: test_bt_bus.py From bt-manager with GNU General Public License v3.0 | 5 votes |
def StopDiscovery(self): self._props[dbus.String(u'Discovering')] = \ dbus.Boolean(False, variant_level=1)
Example #26
Source File: test_bt_bus.py From bt-manager with GNU General Public License v3.0 | 5 votes |
def StartDiscovery(self): self._props[dbus.String(u'Discovering')] = \ dbus.Boolean(True, variant_level=1)
Example #27
Source File: bt-audio.py From bt-audio with GNU General Public License v3.0 | 5 votes |
def discoverableSet(self, status): print("Making adapter " + self.path + " discoverable") self.prop.Set("org.bluez.Adapter1", "Discoverable", dbus.Boolean(status))
Example #28
Source File: bt-audio.py From bt-audio with GNU General Public License v3.0 | 5 votes |
def powerSet(self, status): print("Turning on adapter " + self.path) self.prop.Set("org.bluez.Adapter1", "Powered", dbus.Boolean(status))