# Buggy code
def setup(hass, config):
    """Setup the RFXtrx component."""

    # Declare the Handle event
    def handle_receive(event):
        """Callback all subscribers for RFXtrx gateway."""

        # Log RFXCOM event
        entity_id = slugify(event.device.id_string.lower())
        packet_id = "".join("{0:02x}".format(x) for x in event.data)
        entity_name = "%s : %s" % (entity_id, packet_id)
        _LOGGER.info("Receive RFXCOM event from %s => %s", event.device, entity_name)

        # Callback to HA registered components
        for subscriber in RECEIVED_EVT_SUBSCRIBERS:
            subscriber(event)

    # Try to load the RFXtrx module
    import RFXtrx as rfxtrxmod

    # Init the rfxtrx module
    global RFXOBJECT

    if ATTR_DEVICE not in config[DOMAIN]:
        _LOGGER.exception(
            "can found device parameter in %s YAML configuration section", DOMAIN
        )
        return False

    device = config[DOMAIN][ATTR_DEVICE]
    debug = config[DOMAIN].get(ATTR_DEBUG, False)

    RFXOBJECT = rfxtrxmod.Core(device, handle_receive, debug=debug)

    return True


# Traceback (KeyError)
INFO:homeassistant.components.rfxtrx:Receive RFXCOM event from <class 'RFXtrx.LightingDevice'> type='LightwaveRF, Siemens' id='f11043:16' => f1104316 : 0a140005f1104310050050
INFO:homeassistant.components.switch.rfxtrx:Automatic add f1104316 rfxtrx.switch (Class: LightingDevice Sub: 0)
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: new_state=<state switch.f1104316__0a140005f1104310050050=off; friendly_name=f1104316 : 0a140005f1104310050050 @ 20:34:47 03-02-2016>, entity_id=switch.f1104316__0a140005f1104310050050>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: new_state=<state group.all_switches=off; hidden=True, order=0, entity_id=('switch.f1104316__0a140005f1104310050050',), auto=True, friendly_name=all switches @ 20:34:47 03-02-2016>, entity_id=group.all_switches>
Traceback (most recent call last):
File "/usr/local/lib/python3.4/threading.py", line 911, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.4/threading.py", line 859, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.4/site-packages/RFXtrx/__init__.py", line 55, in _connect
self._event_callback(event)
File "/usr/src/app/homeassistant/components/rfxtrx.py", line 48, in handle_receive
subscriber(event)
File "/usr/src/app/homeassistant/components/switch/rfxtrx.py", line 81, in switch_update
event.values['Command']
KeyError: 'Command'

# Fixed code
def setup(hass, config):
    """Setup the RFXtrx component."""

    # Declare the Handle event
    def handle_receive(event):
        """Callback all subscribers for RFXtrx gateway."""

        # Log RFXCOM event
        if not event.device.id_string:
            return
        entity_id = slugify(event.device.id_string.lower())
        packet_id = "".join("{0:02x}".format(x) for x in event.data)
        entity_name = "%s : %s" % (entity_id, packet_id)
        _LOGGER.info("Receive RFXCOM event from %s => %s", event.device, entity_name)

        # Callback to HA registered components
        for subscriber in RECEIVED_EVT_SUBSCRIBERS:
            subscriber(event)

    # Try to load the RFXtrx module
    import RFXtrx as rfxtrxmod

    # Init the rfxtrx module
    global RFXOBJECT

    if ATTR_DEVICE not in config[DOMAIN]:
        _LOGGER.exception(
            "can found device parameter in %s YAML configuration section", DOMAIN
        )
        return False

    device = config[DOMAIN][ATTR_DEVICE]
    debug = config[DOMAIN].get(ATTR_DEBUG, False)

    RFXOBJECT = rfxtrxmod.Core(device, handle_receive, debug=debug)

    return True