示例#1
0
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the RPi cover platform."""
    setup_reload_service(hass, DOMAIN, PLATFORMS)

    relay_time = config[CONF_RELAY_TIME]
    state_pull_mode = config[CONF_STATE_PULL_MODE]
    invert_state = config[CONF_INVERT_STATE]
    invert_relay = config[CONF_INVERT_RELAY]
    covers = []
    covers_conf = config[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)
示例#2
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the trend sensors."""
    setup_reload_service(hass, 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(
                hass,
                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)
示例#3
0
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the file size sensor."""

    setup_reload_service(hass, DOMAIN, PLATFORMS)

    sensors = []
    paths = set()
    for path in config[CONF_FILE_PATHS]:
        try:
            fullpath = str(pathlib.Path(path).absolute())
        except OSError as error:
            _LOGGER.error("Can not access file %s, error %s", path, error)
            continue

        if fullpath in paths:
            continue
        paths.add(fullpath)

        if not hass.config.is_allowed_path(path):
            _LOGGER.error("Filepath %s is not valid or allowed", path)
            continue

        sensors.append(Filesize(fullpath))

    if sensors:
        add_entities(sensors, True)
示例#4
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up cover controlled by shell commands."""

    setup_reload_service(hass, 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.hass = hass

        covers.append(
            CommandCover(
                hass,
                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)
示例#5
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Find and return switches controlled by shell commands."""

    setup_reload_service(hass, 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.hass = hass

        switches.append(
            CommandSwitch(
                hass,
                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)
示例#6
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the History Stats sensor."""
    setup_reload_service(hass, DOMAIN, PLATFORMS)

    entity_id = config.get(CONF_ENTITY_ID)
    entity_states = config.get(CONF_STATE)
    start = config.get(CONF_START)
    end = config.get(CONF_END)
    duration = config.get(CONF_DURATION)
    sensor_type = config.get(CONF_TYPE)
    name = config.get(CONF_NAME)

    for template in [start, end]:
        if template is not None:
            template.hass = hass

    add_entities(
        [
            HistoryStatsSensor(
                hass, entity_id, entity_states, start, end, duration, sensor_type, name
            )
        ]
    )

    return True
示例#7
0
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the Command Sensor."""

    setup_reload_service(hass, 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)
    unique_id = config.get(CONF_UNIQUE_ID)
    if value_template is not None:
        value_template.hass = hass
    json_attributes = config.get(CONF_JSON_ATTRIBUTES)
    data = CommandSensorData(hass, command, command_timeout)

    add_entities(
        [
            CommandSensor(hass, data, name, unit, value_template,
                          json_attributes, unique_id)
        ],
        True,
    )
示例#8
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the RESTful sensor."""
    setup_reload_service(hass, DOMAIN, PLATFORMS)

    name = config.get(CONF_NAME)
    resource = config.get(CONF_RESOURCE)
    resource_template = config.get(CONF_RESOURCE_TEMPLATE)
    method = config.get(CONF_METHOD)
    payload = config.get(CONF_PAYLOAD)
    verify_ssl = config.get(CONF_VERIFY_SSL)
    username = config.get(CONF_USERNAME)
    password = config.get(CONF_PASSWORD)
    headers = config.get(CONF_HEADERS)
    unit = config.get(CONF_UNIT_OF_MEASUREMENT)
    device_class = config.get(CONF_DEVICE_CLASS)
    value_template = config.get(CONF_VALUE_TEMPLATE)
    json_attrs = config.get(CONF_JSON_ATTRS)
    json_attrs_path = config.get(CONF_JSON_ATTRS_PATH)
    force_update = config.get(CONF_FORCE_UPDATE)
    timeout = config.get(CONF_TIMEOUT)

    if value_template is not None:
        value_template.hass = hass

    if resource_template is not None:
        resource_template.hass = hass
        resource = resource_template.render()

    if username and password:
        if config.get(CONF_AUTHENTICATION) == HTTP_DIGEST_AUTHENTICATION:
            auth = HTTPDigestAuth(username, password)
        else:
            auth = HTTPBasicAuth(username, password)
    else:
        auth = None
    rest = RestData(method, resource, auth, headers, payload, verify_ssl,
                    timeout)
    rest.update()
    if rest.data is None:
        raise PlatformNotReady

    # Must update the sensor now (including fetching the rest resource) to
    # ensure it's updating its state.
    add_entities(
        [
            RestSensor(
                hass,
                rest,
                name,
                unit,
                device_class,
                value_template,
                json_attrs,
                force_update,
                resource_template,
                json_attrs_path,
            )
        ],
        True,
    )
示例#9
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Raspberry PI GPIO devices."""
    setup_reload_service(hass, 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)
示例#10
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the REST binary sensor."""

    setup_reload_service(hass, DOMAIN, PLATFORMS)

    name = config.get(CONF_NAME)
    resource = config.get(CONF_RESOURCE)
    resource_template = config.get(CONF_RESOURCE_TEMPLATE)
    method = config.get(CONF_METHOD)
    payload = config.get(CONF_PAYLOAD)
    verify_ssl = config.get(CONF_VERIFY_SSL)
    timeout = config.get(CONF_TIMEOUT)
    username = config.get(CONF_USERNAME)
    password = config.get(CONF_PASSWORD)
    headers = config.get(CONF_HEADERS)
    device_class = config.get(CONF_DEVICE_CLASS)
    value_template = config.get(CONF_VALUE_TEMPLATE)
    force_update = config.get(CONF_FORCE_UPDATE)

    if resource_template is not None:
        resource_template.hass = hass
        resource = resource_template.render()

    if value_template is not None:
        value_template.hass = hass

    if username and password:
        if config.get(CONF_AUTHENTICATION) == HTTP_DIGEST_AUTHENTICATION:
            auth = HTTPDigestAuth(username, password)
        else:
            auth = HTTPBasicAuth(username, password)
    else:
        auth = None

    rest = RestData(method, resource, auth, headers, payload, verify_ssl,
                    timeout)
    rest.update()
    if rest.data is None:
        raise PlatformNotReady

    add_entities([
        RestBinarySensor(
            hass,
            rest,
            name,
            device_class,
            value_template,
            force_update,
            resource_template,
        )
    ])
示例#11
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the file size sensor."""

    setup_reload_service(hass, DOMAIN, PLATFORMS)

    sensors = []
    for path in config.get(CONF_FILE_PATHS):
        if not hass.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)
示例#12
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Raspberry PI GPIO devices."""
    setup_reload_service(hass, 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)
示例#13
0
文件: switch.py 项目: 2Fake/core
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the Raspberry PI GPIO devices."""
    setup_reload_service(hass, DOMAIN, PLATFORMS)

    invert_logic = config[CONF_INVERT_LOGIC]

    switches = []
    ports = config[CONF_PORTS]
    for port, name in ports.items():
        switches.append(RPiGPIOSwitch(name, port, invert_logic))
    add_entities(switches)
示例#14
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Command Sensor."""

    setup_reload_service(hass, 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.hass = hass
    json_attributes = config.get(CONF_JSON_ATTRIBUTES)
    data = CommandSensorData(hass, command, command_timeout)

    add_entities([
        CommandSensor(hass, data, name, unit, value_template, json_attributes)
    ], True)
示例#15
0
def setup_platform(hass, config, add_entities, discovery_info=None) -> None:
    """Set up the Ping Binary sensor."""
    setup_reload_service(hass, DOMAIN, PLATFORMS)

    host = config[CONF_HOST]
    count = config[CONF_PING_COUNT]
    name = config.get(CONF_NAME, f"{DEFAULT_NAME} {host}")

    try:
        # Verify we can create a raw socket, or
        # fallback to using a subprocess
        icmp_ping("127.0.0.1", count=0, timeout=0)
        ping_cls = PingDataICMPLib
    except SocketPermissionError:
        ping_cls = PingDataSubProcess

    ping_data = ping_cls(hass, host, count)

    add_entities([PingBinarySensor(name, ping_data)], True)
示例#16
0
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Find and return switches controlled by shell commands."""

    setup_reload_service(hass, 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.hass = hass

        icon_template = device_config.get(CONF_ICON_TEMPLATE)
        if icon_template is not None:
            icon_template.hass = hass

        switches.append(
            CommandSwitch(
                hass,
                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),
                icon_template,
                value_template,
                device_config[CONF_COMMAND_TIMEOUT],
                device_config.get(CONF_UNIQUE_ID),
            )
        )

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

    add_entities(switches)
示例#17
0
文件: sensor.py 项目: 2Fake/core
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the file size sensor."""

    setup_reload_service(hass, DOMAIN, PLATFORMS)

    sensors = []
    for path in config[CONF_FILE_PATHS]:
        if not hass.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)
示例#18
0
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the Raspberry PI GPIO devices."""
    setup_reload_service(hass, DOMAIN, PLATFORMS)

    pull_mode = config[CONF_PULL_MODE]
    bouncetime = config[CONF_BOUNCETIME]
    invert_logic = config[CONF_INVERT_LOGIC]

    binary_sensors = []
    ports = config[CONF_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)
示例#19
0
文件: notify.py 项目: Claret-Srl/core
def get_service(hass, config, discovery_info=None):
    """Get the mail notification service."""
    setup_reload_service(hass, 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
示例#20
0
def get_service(hass, config, discovery_info=None):
    """Get the RESTful notification service."""
    setup_reload_service(hass, DOMAIN, PLATFORMS)

    resource = config.get(CONF_RESOURCE)
    method = config.get(CONF_METHOD)
    headers = config.get(CONF_HEADERS)
    params = config.get(CONF_PARAMS)
    message_param_name = config.get(CONF_MESSAGE_PARAMETER_NAME)
    title_param_name = config.get(CONF_TITLE_PARAMETER_NAME)
    target_param_name = config.get(CONF_TARGET_PARAMETER_NAME)
    data = config.get(CONF_DATA)
    data_template = config.get(CONF_DATA_TEMPLATE)
    username = config.get(CONF_USERNAME)
    password = config.get(CONF_PASSWORD)
    verify_ssl = config.get(CONF_VERIFY_SSL)

    if username and password:
        if config.get(CONF_AUTHENTICATION) == HTTP_DIGEST_AUTHENTICATION:
            auth = requests.auth.HTTPDigestAuth(username, password)
        else:
            auth = requests.auth.HTTPBasicAuth(username, password)
    else:
        auth = None

    return RestNotificationService(
        hass,
        resource,
        method,
        headers,
        params,
        message_param_name,
        title_param_name,
        target_param_name,
        data,
        data_template,
        auth,
        verify_ssl,
    )
示例#21
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the RPi cover platform."""
    setup_reload_service(hass, 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)
示例#22
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Command line Binary Sensor."""

    setup_reload_service(hass, 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.hass = hass
    data = CommandSensorData(hass, command, command_timeout)

    add_entities(
        [
            CommandBinarySensor(hass, data, name, device_class, payload_on,
                                payload_off, value_template)
        ],
        True,
    )
示例#23
0
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the Command line Binary Sensor."""

    setup_reload_service(hass, 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)
    unique_id = config.get(CONF_UNIQUE_ID)
    if value_template is not None:
        value_template.hass = hass
    data = CommandSensorData(hass, command, command_timeout)

    add_entities(
        [
            CommandBinarySensor(
                hass,
                data,
                name,
                device_class,
                payload_on,
                payload_off,
                value_template,
                unique_id,
            )
        ],
        True,
    )
示例#24
0
文件: cover.py 项目: 2Fake/core
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up cover controlled by shell commands."""

    setup_reload_service(hass, 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.hass = hass

        covers.append(
            CommandCover(
                hass,
                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],
                device_config.get(CONF_UNIQUE_ID),
            )
        )

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

    add_entities(covers)
示例#25
0
文件: notify.py 项目: rikroe/core
def get_service(hass, config, discovery_info=None):
    """Get the Telegram notification service."""

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