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


Python config_validation.template方法代码示例

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


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

示例1: __init__

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import template [as 别名]
def __init__(self,hass,intents):
        super().__init__()

        _LOGGER.debug("DingdongIntentsView init ")

        self.hass = hass
        intents = copy.deepcopy(intents)
        template.attach(hass, intents)

        for name, intent in intents.items():
            if CONF_ACTION in intent:
                intent[CONF_ACTION] = script.Script(hass,intent[CONF_ACTION],"DingDong {}".format(name))

        self.intents = intents 
开发者ID:charleyzhu,项目名称:HomeAssistant_Components,代码行数:16,代码来源:dingdong.py

示例2: add_speech

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import template [as 别名]
def add_speech(self, text):
        """Add speech to the response."""
        assert self.speech is None

        if isinstance(text, template.Template):
            text = text.async_render(self.parameters)

        self.speech = text 
开发者ID:charleyzhu,项目名称:HomeAssistant_Components,代码行数:10,代码来源:dingdong.py

示例3: async_update

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import template [as 别名]
def async_update(self):
        """Update the state."""
        value = None
        if self._temperature and self._humidity:
            if self._sensor_type == "dewpoint":
                value = self.computeDewPoint(self._temperature, self._humidity)
            if self._sensor_type == "heatindex":
                value = self.computeHeatIndex(self._temperature, self._humidity)
            elif self._sensor_type == "perception":
                value = self.computePerception(self._temperature, self._humidity)
            elif self._sensor_type == "absolutehumidity":
                value = self.computeAbsoluteHumidity(self._temperature, self._humidity)
            elif self._sensor_type == "comfortratio":
                value = "comfortratio"

        self._state = value
        self._device_state_attributes[ATTR_TEMPERATURE] = self._temperature
        self._device_state_attributes[ATTR_HUMIDITY] = self._humidity

        for property_name, template in (
                ('_icon', self._icon_template),
                ('_entity_picture', self._entity_picture_template)):
            if template is None:
                continue

            try:
                setattr(self, property_name, template.async_render())
            except TemplateError as ex:
                friendly_property_name = property_name[1:].replace('_', ' ')
                if ex.args and ex.args[0].startswith(
                        "UndefinedError: 'None' has no attribute"):
                    # Common during HA startup - so just a warning
                    _LOGGER.warning('Could not render %s template %s,'
                                    ' the state is unknown.',
                                    friendly_property_name, self._name)
                    continue

                try:
                    setattr(self, property_name,
                            getattr(super(), property_name))
                except AttributeError:
                    _LOGGER.error('Could not render %s template %s: %s',
                                  friendly_property_name, self._name, ex) 
开发者ID:dolezsa,项目名称:thermal_comfort,代码行数:45,代码来源:sensor.py

示例4: update

# 需要导入模块: from homeassistant.helpers import config_validation [as 别名]
# 或者: from homeassistant.helpers.config_validation import template [as 别名]
def update(self):
        """Get the latest value for this sensor."""
        with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
            sock.settimeout(self._config[CONF_TIMEOUT])
            try:
                sock.connect(
                    (self._config[CONF_HOST], self._config[CONF_PORT]))
            except socket.error as err:
                _LOGGER.error(
                    "Unable to connect to %s on port %s: %s",
                    self._config[CONF_HOST], self._config[CONF_PORT], err)
                return

            try:
                sock.send(self._config[CONF_PAYLOAD].encode())
            except socket.error as err:
                _LOGGER.error(
                    "Unable to send payload %r to %s on port %s: %s",
                    self._config[CONF_PAYLOAD], self._config[CONF_HOST],
                    self._config[CONF_PORT], err)
                return

            readable, _, _ = select.select(
                [sock], [], [], self._config[CONF_TIMEOUT])
            if not readable:
                _LOGGER.warning(
                    "Timeout (%s second(s)) waiting for a response after "
                    "sending %r to %s on port %s.",
                    self._config[CONF_TIMEOUT], self._config[CONF_PAYLOAD],
                    self._config[CONF_HOST], self._config[CONF_PORT])
                return

            value = sock.recv(self._config[CONF_BUFFER_SIZE]).decode()

        if self._config[CONF_VALUE_TEMPLATE] is not None:
            try:
                self._state = self._config[CONF_VALUE_TEMPLATE].render(
                    value=value)
                return
            except TemplateError:
                _LOGGER.error(
                    "Unable to render template of %r with value: %r",
                    self._config[CONF_VALUE_TEMPLATE], value)
                return

        self._state = value 
开发者ID:skalavala,项目名称:mysmarthome,代码行数:48,代码来源:udp.py


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