当前位置: 首页>>代码示例>>Python>>正文


Python entity_component.EntityComponent方法代码示例

本文整理汇总了Python中homeassistant.helpers.entity_component.EntityComponent方法的典型用法代码示例。如果您正苦于以下问题:Python entity_component.EntityComponent方法的具体用法?Python entity_component.EntityComponent怎么用?Python entity_component.EntityComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在homeassistant.helpers.entity_component的用法示例。


在下文中一共展示了entity_component.EntityComponent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: async_setup

# 需要导入模块: from homeassistant.helpers import entity_component [as 别名]
# 或者: from homeassistant.helpers.entity_component import EntityComponent [as 别名]
def async_setup(hass, config):
    """Set up an input select."""
    component = hass.data[DOMAIN] = EntityComponent(_LOGGER, DOMAIN, hass)

    entities = []

    for object_id, cfg in config[DOMAIN].items():
        name = cfg.get(CONF_NAME)
        options = cfg.get(CONF_OPTIONS)
        initial = cfg.get(CONF_INITIAL)
        icon = cfg.get(CONF_ICON)
        entities.append(InputSelect(object_id, name, initial, options, icon))

    if not entities:
        return False

    component.async_register_entity_service(
        SERVICE_SELECT_OPTION, SERVICE_SELECT_OPTION_SCHEMA,
        'async_select_option'
    )

    component.async_register_entity_service(
        SERVICE_SELECT_NEXT, SERVICE_SELECT_NEXT_SCHEMA,
        lambda entity, call: entity.async_offset_index(1)
    )

    component.async_register_entity_service(
        SERVICE_SELECT_PREVIOUS, SERVICE_SELECT_PREVIOUS_SCHEMA,
        lambda entity, call: entity.async_offset_index(-1)
    )

    component.async_register_entity_service(
        SERVICE_SET_OPTIONS, SERVICE_SET_OPTIONS_SCHEMA,
        'async_set_options'
    )

    await component.async_add_entities(entities)
    return True 
开发者ID:cnk700i,项目名称:common_timer,代码行数:40,代码来源:__init__.py

示例2: async_setup

# 需要导入模块: from homeassistant.helpers import entity_component [as 别名]
# 或者: from homeassistant.helpers.entity_component import EntityComponent [as 别名]
def async_setup(hass, config):
    """Set up an input text box."""
    component = hass.data[DOMAIN] = EntityComponent(_LOGGER, DOMAIN, hass)

    entities = []

    for object_id, cfg in config[DOMAIN].items():
        name = cfg.get(CONF_NAME)
        minimum = cfg.get(CONF_MIN)
        maximum = cfg.get(CONF_MAX)
        initial = cfg.get(CONF_INITIAL)
        icon = cfg.get(CONF_ICON)
        unit = cfg.get(ATTR_UNIT_OF_MEASUREMENT)
        pattern = cfg.get(ATTR_PATTERN)
        mode = cfg.get(CONF_MODE)

        entities.append(InputText(
            object_id, name, initial, minimum, maximum, icon, unit,
            pattern, mode))

    if not entities:
        return False

    component.async_register_entity_service(
        SERVICE_SET_VALUE, SERVICE_SET_VALUE_SCHEMA,
        'async_set_value'
    )

    await component.async_add_entities(entities)
    return True 
开发者ID:cnk700i,项目名称:common_timer,代码行数:32,代码来源:__init__.py

示例3: async_setup

# 需要导入模块: from homeassistant.helpers import entity_component [as 别名]
# 或者: from homeassistant.helpers.entity_component import EntityComponent [as 别名]
def async_setup(hass, config):
    """Set up an input boolean."""
    component = hass.data[DOMAIN] = EntityComponent(_LOGGER, DOMAIN, hass)

    entities = []

    for object_id, cfg in config[DOMAIN].items():
        if not cfg:
            cfg = {}

        name = cfg.get(CONF_NAME)
        initial = cfg.get(CONF_INITIAL)
        icon = cfg.get(CONF_ICON)

        entities.append(InputBoolean(object_id, name, initial, icon))

    if not entities:
        return False

    component.async_register_entity_service(
        SERVICE_TURN_ON, SERVICE_SCHEMA,
        'async_turn_on'
    )

    component.async_register_entity_service(
        SERVICE_TURN_OFF, SERVICE_SCHEMA,
        'async_turn_off'
    )

    component.async_register_entity_service(
        SERVICE_TOGGLE, SERVICE_SCHEMA,
        'async_toggle'
    )

    await component.async_add_entities(entities)
    return True 
开发者ID:cnk700i,项目名称:common_timer,代码行数:38,代码来源:__init__.py

示例4: async_setup

# 需要导入模块: from homeassistant.helpers import entity_component [as 别名]
# 或者: from homeassistant.helpers.entity_component import EntityComponent [as 别名]
def async_setup(hass, config):
    """Set up a input_label."""
    component = EntityComponent(_LOGGER, DOMAIN, hass)

    entities = []

    for object_id, cfg in config[DOMAIN].items():
        if not cfg:
            cfg = {}
        name = cfg.get(CONF_NAME)
        initial = cfg.get(ATTR_VALUE)
        icon = cfg.get(CONF_ICON)

        entities.append(InputLabel(object_id, name, initial, icon))

    if not entities:
        return False

    component.async_register_entity_service(
        SERVICE_SETNAME, SERVICE_SCHEMA,
        'async_set_name'
    )

    component.async_register_entity_service(
        SERVICE_SETVALUE, SERVICE_SCHEMA,
        'async_set_value'
    )

    component.async_register_entity_service(
        SERVICE_SETICON, SERVICE_SCHEMA,
        'async_set_icon'
    )

    await component.async_add_entities(entities)
    return True 
开发者ID:skalavala,项目名称:mysmarthome,代码行数:37,代码来源:input_label.py

示例5: async_setup

# 需要导入模块: from homeassistant.helpers import entity_component [as 别名]
# 或者: from homeassistant.helpers.entity_component import EntityComponent [as 别名]
def async_setup(hass, config):
    component = EntityComponent(_LOGGER, DOMAIN, hass)

    entities = []

    for slug, config in config[DOMAIN].items():
        if not config:
            config = {}

        name = config.get(NAME)
        hour = config.get(HOUR)
        minute = config.get(MINUTE)
        day = None
        month = None
        year = None
        message = config.get(MESSAGE)
        days_notice = config.get(DAYS_NOTICE)
        notifier = config.get(NOTIFIER).replace(NOTIFY_DOMAIN + '.', '')
        countdown = config.get(COUNTDOWN)
        recurrence = ATTR_DAILY
        if config.get(DAY):
            day = config.get(DAY)
            recurrence = ATTR_MONTHLY
        if config.get(MONTH):
            month = config.get(MONTH)
            recurrence = ATTR_YEARLY
        if config.get(YEAR):
            year = config.get(YEAR)
            calc_date = datetime.datetime.now().replace(second=0, microsecond=0)
            reminder_set = datetime.datetime.strptime(str(year) + '-' + str(month) + '-' + str(day) + ' ' + str(hour) + ':' + str(minute), '%Y-%m-%d %H:%M') + datetime.timedelta(-days_notice)
            if calc_date > reminder_set:
                recurrence = ATTR_PAST_DUE
            else:
                recurrence = ATTR_ON_DATE

        entities.append(DateNotifier(hass, slug, name, hour, minute, day, month, year, message, days_notice, notifier, recurrence, countdown))

    @asyncio.coroutine
    def async_scan_dates_service(call):
        for entity in component.entities:
            target_notifiers = [entity]
            tasks = [notifier.scan_dates() for notifier in target_notifiers]
            if tasks:
                yield from asyncio.wait(tasks, loop=hass.loop)
            else:
                _LOGGER.error('no tasks initialized')

    async_track_time_interval(hass, async_scan_dates_service, INTERVAL)

    yield from component.async_add_entities(entities)
    return True 
开发者ID:TomerFi,项目名称:home-assistant-custom-components,代码行数:53,代码来源:__init__.py

示例6: add_devices

# 需要导入模块: from homeassistant.helpers import entity_component [as 别名]
# 或者: from homeassistant.helpers.entity_component import EntityComponent [as 别名]
def add_devices(
    account: Text,
    devices: List[EntityComponent],
    add_devices_callback: Callable,
    include_filter: List[Text] = None,
    exclude_filter: List[Text] = None,
) -> bool:
    """Add devices using add_devices_callback."""
    include_filter = [] or include_filter
    exclude_filter = [] or exclude_filter
    new_devices = []
    for device in devices:
        if (
            include_filter
            and device.name not in include_filter
            or exclude_filter
            and device.name in exclude_filter
        ):
            _LOGGER.debug("%s: Excluding device: %s", account, device)
            continue
        new_devices.append(device)
    devices = new_devices
    if devices:
        _LOGGER.debug("%s: Adding %s", account, devices)
        try:
            add_devices_callback(devices, False)
            return True
        except HomeAssistantError as exception_:
            message = exception_.message  # type: str
            if message.startswith("Entity id already exists"):
                _LOGGER.debug("%s: Device already added: %s", account, message)
            else:
                _LOGGER.debug(
                    "%s: Unable to add devices: %s : %s", account, devices, message
                )
        except BaseException as ex:
            template = "An exception of type {0} occurred." " Arguments:\n{1!r}"
            message = template.format(type(ex).__name__, ex.args)
            _LOGGER.debug("%s: Unable to add devices: %s", account, message)
    else:
        return True
    return False 
开发者ID:macbury,项目名称:SmartHouse,代码行数:44,代码来源:helpers.py


注:本文中的homeassistant.helpers.entity_component.EntityComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。