Ejemplo n.º 1
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Find and return switches controlled by a generic RF device via GPIO."""
    import rpi_rf
    from threading import RLock

    gpio = config.get(CONF_GPIO)
    rfdevice = rpi_rf.RFDevice(gpio)
    rfdevice_lock = RLock()
    switches = config.get(CONF_SWITCHES)

    devices = []
    for dev_name, properties in switches.items():
        devices.append(
            RPiRFSwitch(properties.get(CONF_NAME, dev_name), rfdevice,
                        rfdevice_lock, properties.get(CONF_PROTOCOL),
                        properties.get(CONF_PULSELENGTH),
                        properties.get(CONF_SIGNAL_REPETITIONS),
                        properties.get(CONF_CODE_ON),
                        properties.get(CONF_CODE_OFF)))
    if devices:
        rfdevice.enable_tx()

    add_devices(devices)

    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP,
                         lambda event: rfdevice.cleanup())
Ejemplo n.º 2
0
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
    """Find and return switches controlled by a generic RF device via GPIO."""
    import rpi_rf

    gpio = config.get('gpio')
    if not gpio:
        _LOGGER.error("No GPIO specified")
        return False

    rfdevice = rpi_rf.RFDevice(gpio)

    switches = config.get('switches', {})
    devices = []
    for dev_name, properties in switches.items():
        if not properties.get('code_on'):
            _LOGGER.error("%s: code_on not specified", dev_name)
            continue
        if not properties.get('code_off'):
            _LOGGER.error("%s: code_off not specified", dev_name)
            continue

        devices.append(
            RPiRFSwitch(
                hass,
                properties.get('name', dev_name),
                rfdevice,
                properties.get('protocol', None),
                properties.get('pulselength', None),
                properties.get('code_on'),
                properties.get('code_off')))
    if devices:
        rfdevice.enable_tx()

    add_devices_callback(devices)
Ejemplo n.º 3
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Find and return switches controlled by a generic RF device via GPIO."""
    import rpi_rf

    gpio = config.get(CONF_GPIO)
    rfdevice = rpi_rf.RFDevice(gpio)
    switches = config.get(CONF_SWITCHES)

    devices = []
    for dev_name, properties in switches.items():
        devices.append(
            RPiRFSwitch(
                hass,
                properties.get(CONF_NAME, dev_name),
                rfdevice,
                properties.get(CONF_PROTOCOL),
                properties.get(CONF_PULSELENGTH),
                properties.get(CONF_CODE_ON),
                properties.get(CONF_CODE_OFF)
            )
        )
    if devices:
        rfdevice.enable_tx()

    add_devices(devices)
Ejemplo n.º 4
0
 def __init__(self, rf_config: RFConfig, db_config: PostgresConfig,
              redis_config: RedisConfig):
     self.rf_device = rpi_rf.RFDevice(gpio=rf_config.gpio_pin)
     self.data_storage = SensorDataStorage(
         create_engine(db_config.engine_url))
     self.cache = SensorDataCache(
         Redis(host=redis_config.host,
               port=redis_config.port,
               db=redis_config.database))
     self.shutdown_wanted = False
Ejemplo n.º 5
0
    def status_setter(self, status):
        if rpi_rf:
            logging.debug('Enable TX for device \'%s\'...' % self.unique_name)
            device = rpi_rf.RFDevice(self._gpio)
            enabled = device.enable_tx()

            if not enabled:
                logging.error('Failed to enable TX for \'%s\''
                              % self.unique_name)

            if status['state']:
                device.tx_code(self._code_on)
            elif not status['state']:
                device.tx_code(self._code_off)

            device.cleanup()
            del(device)
        else:
            logging.error('\'%s\' needs to run on a Raspberry Pi.'
                          % self.unique_name)

        super(RFLight, self).status_setter(status)
Ejemplo n.º 6
0
    def __init__(self, pin: int, pulse: int):
        self.pulse = pulse

        self.rf_device = rpi_rf.RFDevice(pin)
        self.rf_device.enable_tx()