'Initialize the Threshold sensor.'

def __init__(self, hass, entity_id, name, threshold, limit_type, device_class):

    self._hass = hass
    self._entity_id = entity_id
    self.is_upper = (limit_type == 'upper')
    self._name = name
    self._threshold = threshold
    self._device_class = device_class
    self._deviation = False
    self.sensor_value = 0
    @callback
    def async_threshold_sensor_state_listener(entity, old_state, new_state):
        'Handle    sensor    state    changes.'
        if (new_state.state == STATE_UNKNOWN):
            return
        try:
            self.sensor_value = float(new_state.state)
        except ValueError:
            _LOGGER.error('State    is    not    numerical')
        hass.async_add_job(self.async_update_ha_state, True)
    async_track_state_change(hass, entity_id, async_threshold_sensor_state_listener)
