Python homeassistant.helpers.config_validation.template() Examples
The following are 4
code examples of homeassistant.helpers.config_validation.template().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
homeassistant.helpers.config_validation
, or try the search function
.
Example #1
Source File: dingdong.py From HomeAssistant_Components with Apache License 2.0 | 5 votes |
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
Example #2
Source File: dingdong.py From HomeAssistant_Components with Apache License 2.0 | 5 votes |
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
Example #3
Source File: sensor.py From thermal_comfort with MIT License | 4 votes |
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)
Example #4
Source File: udp.py From mysmarthome with MIT License | 4 votes |
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