DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • Reactive Programming
  • Java Concurrency: Condition
  • 5 Common Data Structures and Algorithms Used in Machine Learning
  • New ORM Framework for Kotlin

Trending

  • Reactive Programming
  • Java Concurrency: Condition
  • 5 Common Data Structures and Algorithms Used in Machine Learning
  • New ORM Framework for Kotlin

Kill Switch For Bluetooth Device

Chmouel Boudjnah user avatar by
Chmouel Boudjnah
·
Nov. 17, 09 · Code Snippet
Like (1)
Save
Tweet
Share
2.03K Views

Join the DZone community and get the full member experience.

Join For Free
Ripped from http://blog.homac.de/?p=153 to make a cli enable/disable/get client.

Adjust your HAL_PATH to your device....


#!/usr/bin/python
import dbus
HAL_PATH = "/org/freedesktop/Hal/devices/dell_bluetooth_switch"

# Copied from http://blog.homac.de/?p=153
class KSADBus:
    def __init__(self):
        from dbus.mainloop.glib import DBusGMainLoop

        dbus_loop = DBusGMainLoop()

        self.bus = dbus.SystemBus(mainloop=dbus_loop)

    def get_object(self, dest, udi):
        return self.bus.get_object(dest, udi)
    
    def listen_to_signal(self, cb, signal, iface, destination, udi):
        self.bus.add_signal_receiver(cb,
                                     signal,
                                     iface,
                                     destination,
                                     udi, path_keyword="path")
class Hal(KSADBus):
    def __init__(self):
        KSADBus.__init__(self)

        self.hal_manager = self.bus.get_object('org.freedesktop.Hal',
                                               '/org/freedesktop/Hal/Manager')

        self.hal_manager_iface = dbus.Interface(self.hal_manager,
                                                dbus_interface='org.freedesktop.Hal.Manager')

    def get_property(self, udi, key):
        manager = self.bus.get_object('org.freedesktop.Hal',
                                      udi)
        iface = dbus.Interface(manager,
                               dbus_interface='org.freedesktop.Hal.Device')
        if not iface.PropertyExists(key):
            return False
        return iface.GetProperty(key)

    def get_kswitch_devices(self):
        return self.hal_manager_iface.FindDeviceByCapability("killswitch")

    def get_state(self, udi):
        manager = self.bus.get_object('org.freedesktop.Hal',
                                      udi)
        manager_interface = dbus.Interface(manager,
                                           dbus_interface='org.freedesktop.Hal.Device.KillSwitch')
        return manager_interface.GetPower()

    def set_state(self, udi, state):
        manager = self.bus.get_object('org.freedesktop.Hal',
                                      udi)
        manager_interface = dbus.Interface(manager,
                                           dbus_interface='org.freedesktop.Hal.Device.KillSwitch')
        manager_interface.SetPower(state)        

if __name__ == '__main__':
    import sys
    if len(sys.argv) != 2 or sys.argv[1] not in ("0", "1", "get"):
        print "Usage: bluetooth-switch 0 / 1 / get"
        sys.exit(1)

    arg = sys.argv[1]
    bus = Hal()

    if arg in ("0", "1"):
        bus.set_state(HAL_PATH, int(arg))
    elif arg in ("get"):
        print bus.get_state(HAL_PATH) and "enabled" or "disabled"
        
    #main()

Opinions expressed by DZone contributors are their own.

Trending

  • Reactive Programming
  • Java Concurrency: Condition
  • 5 Common Data Structures and Algorithms Used in Machine Learning
  • New ORM Framework for Kotlin

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: