當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。