def update(self):
        try:
            self._state = template.render(self.hass, self._template)
        except TemplateError as ex:
            if ex.args and ex.args[0].startswith(
                    "UndefinedError: 'None' has no attribute"):
                # Common during HA startup - so just a warning
                _LOGGER.warning(ex)
                return
            self._state = None
            _LOGGER.error(ex)
Get the latest data and update the states.
dataset/ETHPy150Open home-assistant/home-assistant/homeassistant/components/sensor/template.py/SensorTemplate.update