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


Python config_validation.slug方法代码示例

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


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

示例1: __init__

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import slug [as 别名]
def __init__(self, hass, slug, name, hour, minute, day, month, year, message, days_notice, notifier, recurrence, countdown):
        self.hass = hass
        self.entity_id = async_generate_entity_id(ENTITY_ID_FORMAT, slug, hass=hass)
        self._name = name
        self._hour = hour
        self._minute = minute
        self._day = day
        self._month = month
        self._message = message
        self._days_notice = days_notice
        self._notifier = notifier
        self._year = year
        self._recurrence = recurrence
        self._countdown = countdown
        self._dates_list = []
        if self._recurrence != ATTR_PAST_DUE:
            if self._countdown and self._days_notice > 0:
                for i in range(0, self._days_notice + 1):
                    self._dates_list.append(self.create_due_date(i))
            else:
                self._dates_list.append(self.create_due_date(self._days_notice)) 
开发者ID:TomerFi,项目名称:home-assistant-custom-components,代码行数:23,代码来源:__init__.py

示例2: async_setup

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import slug [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


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