Beispiel #1
0
def setup_platform(opp, config, add_entities, discovery_info=None):
    """Find and return switches controlled by shell commands."""

    setup_reload_service(opp, DOMAIN, PLATFORMS)

    devices = config.get(CONF_SWITCHES, {})
    switches = []

    for object_id, device_config in devices.items():
        value_template = device_config.get(CONF_VALUE_TEMPLATE)

        if value_template is not None:
            value_template.opp = opp

        switches.append(
            CommandSwitch(
                opp,
                object_id,
                device_config.get(CONF_FRIENDLY_NAME, object_id),
                device_config[CONF_COMMAND_ON],
                device_config[CONF_COMMAND_OFF],
                device_config.get(CONF_COMMAND_STATE),
                value_template,
                device_config[CONF_COMMAND_TIMEOUT],
            )
        )

    if not switches:
        _LOGGER.error("No switches added")
        return False

    add_entities(switches)
Beispiel #2
0
def setup_platform(opp, config, add_entities, discovery_info=None):
    """Set up the trend sensors."""
    setup_reload_service(opp, DOMAIN, PLATFORMS)

    sensors = []

    for device_id, device_config in config[CONF_SENSORS].items():
        entity_id = device_config[ATTR_ENTITY_ID]
        attribute = device_config.get(CONF_ATTRIBUTE)
        device_class = device_config.get(CONF_DEVICE_CLASS)
        friendly_name = device_config.get(ATTR_FRIENDLY_NAME, device_id)
        invert = device_config[CONF_INVERT]
        max_samples = device_config[CONF_MAX_SAMPLES]
        min_gradient = device_config[CONF_MIN_GRADIENT]
        sample_duration = device_config[CONF_SAMPLE_DURATION]

        sensors.append(
            SensorTrend(
                opp,
                device_id,
                friendly_name,
                entity_id,
                attribute,
                device_class,
                invert,
                max_samples,
                min_gradient,
                sample_duration,
            ))
    if not sensors:
        _LOGGER.error("No sensors added")
        return
    add_entities(sensors)
Beispiel #3
0
def setup_platform(opp, config, add_entities, discovery_info=None):
    """Set up cover controlled by shell commands."""

    setup_reload_service(opp, DOMAIN, PLATFORMS)

    devices = config.get(CONF_COVERS, {})
    covers = []

    for device_name, device_config in devices.items():
        value_template = device_config.get(CONF_VALUE_TEMPLATE)
        if value_template is not None:
            value_template.opp = opp

        covers.append(
            CommandCover(
                opp,
                device_config.get(CONF_FRIENDLY_NAME, device_name),
                device_config[CONF_COMMAND_OPEN],
                device_config[CONF_COMMAND_CLOSE],
                device_config[CONF_COMMAND_STOP],
                device_config.get(CONF_COMMAND_STATE),
                value_template,
                device_config[CONF_COMMAND_TIMEOUT],
            ))

    if not covers:
        _LOGGER.error("No covers added")
        return False

    add_entities(covers)
Beispiel #4
0
def setup_platform(opp, config, add_entities, discovery_info=None):
    """Set up the Raspberry PI GPIO devices."""
    setup_reload_service(opp, DOMAIN, PLATFORMS)

    invert_logic = config.get(CONF_INVERT_LOGIC)

    switches = []
    ports = config.get(CONF_PORTS)
    for port, name in ports.items():
        switches.append(RPiGPIOSwitch(name, port, invert_logic))
    add_entities(switches)
Beispiel #5
0
def setup_platform(opp, config, add_entities, discovery_info=None):
    """Set up the file size sensor."""

    setup_reload_service(opp, DOMAIN, PLATFORMS)

    sensors = []
    for path in config.get(CONF_FILE_PATHS):
        if not opp.config.is_allowed_path(path):
            _LOGGER.error("Filepath %s is not valid or allowed", path)
            continue
        sensors.append(Filesize(path))

    if sensors:
        add_entities(sensors, True)
Beispiel #6
0
def setup_platform(opp, config, add_entities, discovery_info=None):
    """Set up the Raspberry PI GPIO devices."""
    setup_reload_service(opp, DOMAIN, PLATFORMS)

    pull_mode = config.get(CONF_PULL_MODE)
    bouncetime = config.get(CONF_BOUNCETIME)
    invert_logic = config.get(CONF_INVERT_LOGIC)

    binary_sensors = []
    ports = config.get("ports")
    for port_num, port_name in ports.items():
        binary_sensors.append(
            RPiGPIOBinarySensor(port_name, port_num, pull_mode, bouncetime,
                                invert_logic))
    add_entities(binary_sensors, True)
Beispiel #7
0
def setup_platform(opp, config, add_entities, discovery_info=None):
    """Set up the Command Sensor."""

    setup_reload_service(opp, DOMAIN, PLATFORMS)

    name = config.get(CONF_NAME)
    command = config.get(CONF_COMMAND)
    unit = config.get(CONF_UNIT_OF_MEASUREMENT)
    value_template = config.get(CONF_VALUE_TEMPLATE)
    command_timeout = config.get(CONF_COMMAND_TIMEOUT)
    if value_template is not None:
        value_template.opp = opp
    json_attributes = config.get(CONF_JSON_ATTRIBUTES)
    data = CommandSensorData(opp, command, command_timeout)

    add_entities([
        CommandSensor(opp, data, name, unit, value_template, json_attributes)
    ], True)
Beispiel #8
0
def get_service(opp, config, discovery_info=None):
    """Get the mail notification service."""
    setup_reload_service(opp, DOMAIN, PLATFORMS)
    mail_service = MailNotificationService(
        config.get(CONF_SERVER),
        config.get(CONF_PORT),
        config.get(CONF_TIMEOUT),
        config.get(CONF_SENDER),
        config.get(CONF_ENCRYPTION),
        config.get(CONF_USERNAME),
        config.get(CONF_PASSWORD),
        config.get(CONF_RECIPIENT),
        config.get(CONF_SENDER_NAME),
        config.get(CONF_DEBUG),
    )

    if mail_service.connection_is_valid():
        return mail_service

    return None
Beispiel #9
0
def setup_platform(opp, config, add_entities, discovery_info=None):
    """Set up the RPi cover platform."""
    setup_reload_service(opp, DOMAIN, PLATFORMS)

    relay_time = config.get(CONF_RELAY_TIME)
    state_pull_mode = config.get(CONF_STATE_PULL_MODE)
    invert_state = config.get(CONF_INVERT_STATE)
    invert_relay = config.get(CONF_INVERT_RELAY)
    covers = []
    covers_conf = config.get(CONF_COVERS)

    for cover in covers_conf:
        covers.append(
            RPiGPIOCover(
                cover[CONF_NAME],
                cover[CONF_RELAY_PIN],
                cover[CONF_STATE_PIN],
                state_pull_mode,
                relay_time,
                invert_state,
                invert_relay,
            ))
    add_entities(covers)
Beispiel #10
0
def setup_platform(opp, config, add_entities, discovery_info=None):
    """Set up the Command line Binary Sensor."""

    setup_reload_service(opp, DOMAIN, PLATFORMS)

    name = config.get(CONF_NAME)
    command = config.get(CONF_COMMAND)
    payload_off = config.get(CONF_PAYLOAD_OFF)
    payload_on = config.get(CONF_PAYLOAD_ON)
    device_class = config.get(CONF_DEVICE_CLASS)
    value_template = config.get(CONF_VALUE_TEMPLATE)
    command_timeout = config.get(CONF_COMMAND_TIMEOUT)
    if value_template is not None:
        value_template.opp = opp
    data = CommandSensorData(opp, command, command_timeout)

    add_entities(
        [
            CommandBinarySensor(
                opp, data, name, device_class, payload_on, payload_off, value_template
            )
        ],
        True,
    )
Beispiel #11
0
def get_service(opp, config, discovery_info=None):
    """Get the Telegram notification service."""

    setup_reload_service(opp, TELEGRAM_DOMAIN, PLATFORMS)
    chat_id = config.get(CONF_CHAT_ID)
    return TelegramNotificationService(opp, chat_id)