2013-12-11 08:07:30 +00:00
|
|
|
"""
|
|
|
|
homeassistant.components.keyboard
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Provides functionality to emulate keyboard presses on host machine.
|
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
2014-01-05 01:55:05 +00:00
|
|
|
DOMAIN = "keyboard"
|
2013-12-11 08:07:30 +00:00
|
|
|
|
|
|
|
SERVICE_KEYBOARD_VOLUME_UP = "volume_up"
|
|
|
|
SERVICE_KEYBOARD_VOLUME_DOWN = "volume_down"
|
|
|
|
SERVICE_KEYBOARD_VOLUME_MUTE = "volume_mute"
|
|
|
|
SERVICE_KEYBOARD_MEDIA_PLAY_PAUSE = "media_play_pause"
|
|
|
|
SERVICE_KEYBOARD_MEDIA_NEXT_TRACK = "media_next_track"
|
|
|
|
SERVICE_KEYBOARD_MEDIA_PREV_TRACK = "media_prev_track"
|
|
|
|
|
|
|
|
|
|
|
|
def setup(bus):
|
|
|
|
""" Listen for keyboard events. """
|
|
|
|
try:
|
|
|
|
import pykeyboard
|
|
|
|
except ImportError:
|
|
|
|
logging.getLogger(__name__).exception(
|
|
|
|
"MediaButtons: Error while importing dependency PyUserInput.")
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
keyboard = pykeyboard.PyKeyboard()
|
|
|
|
keyboard.special_key_assignment()
|
|
|
|
|
2014-01-05 01:55:05 +00:00
|
|
|
bus.register_service(DOMAIN, SERVICE_KEYBOARD_VOLUME_UP,
|
2013-12-11 08:07:30 +00:00
|
|
|
lambda service:
|
|
|
|
keyboard.tap_key(keyboard.volume_up_key))
|
|
|
|
|
2014-01-05 01:55:05 +00:00
|
|
|
bus.register_service(DOMAIN, SERVICE_KEYBOARD_VOLUME_DOWN,
|
2013-12-11 08:07:30 +00:00
|
|
|
lambda service:
|
|
|
|
keyboard.tap_key(keyboard.volume_down_key))
|
|
|
|
|
2014-01-05 01:55:05 +00:00
|
|
|
bus.register_service(DOMAIN, SERVICE_KEYBOARD_VOLUME_MUTE,
|
2013-12-11 08:07:30 +00:00
|
|
|
lambda service:
|
|
|
|
keyboard.tap_key(keyboard.volume_mute_key))
|
|
|
|
|
2014-01-05 01:55:05 +00:00
|
|
|
bus.register_service(DOMAIN, SERVICE_KEYBOARD_MEDIA_PLAY_PAUSE,
|
2013-12-11 08:07:30 +00:00
|
|
|
lambda service:
|
|
|
|
keyboard.tap_key(keyboard.media_play_pause_key))
|
|
|
|
|
2014-01-05 01:55:05 +00:00
|
|
|
bus.register_service(DOMAIN, SERVICE_KEYBOARD_MEDIA_NEXT_TRACK,
|
2013-12-11 08:07:30 +00:00
|
|
|
lambda service:
|
|
|
|
keyboard.tap_key(keyboard.media_next_track_key))
|
|
|
|
|
2014-01-05 01:55:05 +00:00
|
|
|
bus.register_service(DOMAIN, SERVICE_KEYBOARD_MEDIA_PREV_TRACK,
|
2013-12-11 08:07:30 +00:00
|
|
|
lambda service:
|
|
|
|
keyboard.tap_key(keyboard.media_prev_track_key))
|
|
|
|
|
|
|
|
return True
|